Re: [ovs-dev] [PATCH] stream-ssl: Avoid unnecessary memory copies on send.

2021-11-30 Thread Ilya Maximets
On 11/29/21 13:12, Dumitru Ceara wrote:
> On 11/22/21 00:46, Ilya Maximets wrote:
>> ssl_send() clones the data before sending, but if SSL_write() succeeds
>> at the first attempt, this is only a waste of CPU cycles.
>>
>> Trying to send the original buffer instead and only copying remaining
>> data if it's not possible to send it all right away.
>>
>> This should save a few cycles on every send.
>>
>> Note:
>> It's probably possible to avoid the copy even if we can't send
>> everything at once, but will, likely, require some major change
>> of the stream-sll module in order to take into account all the
>> corner cases related to SSL connection.  So, not trying to do that
>> for now.
>>
>> Signed-off-by: Ilya Maximets 
>> ---
> 
> Looks good to me; this passes OVS and OVN unit tests (when
> https://patchwork.ozlabs.org/project/openvswitch/list/?series=273948=*
> is also applied).
> 
> Acked-by: Dumitru Ceara 

Applied.  Thanks!

Best regards, Ilya Maximets.
___
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev


Re: [ovs-dev] [PATCH] stream-ssl: Avoid unnecessary memory copies on send.

2021-11-29 Thread Dumitru Ceara
On 11/22/21 00:46, Ilya Maximets wrote:
> ssl_send() clones the data before sending, but if SSL_write() succeeds
> at the first attempt, this is only a waste of CPU cycles.
> 
> Trying to send the original buffer instead and only copying remaining
> data if it's not possible to send it all right away.
> 
> This should save a few cycles on every send.
> 
> Note:
> It's probably possible to avoid the copy even if we can't send
> everything at once, but will, likely, require some major change
> of the stream-sll module in order to take into account all the
> corner cases related to SSL connection.  So, not trying to do that
> for now.
> 
> Signed-off-by: Ilya Maximets 
> ---

Looks good to me; this passes OVS and OVN unit tests (when
https://patchwork.ozlabs.org/project/openvswitch/list/?series=273948=*
is also applied).

Acked-by: Dumitru Ceara 

Thanks!

___
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev


[ovs-dev] [PATCH] stream-ssl: Avoid unnecessary memory copies on send.

2021-11-21 Thread Ilya Maximets
ssl_send() clones the data before sending, but if SSL_write() succeeds
at the first attempt, this is only a waste of CPU cycles.

Trying to send the original buffer instead and only copying remaining
data if it's not possible to send it all right away.

This should save a few cycles on every send.

Note:
It's probably possible to avoid the copy even if we can't send
everything at once, but will, likely, require some major change
of the stream-sll module in order to take into account all the
corner cases related to SSL connection.  So, not trying to do that
for now.

Signed-off-by: Ilya Maximets 
---
 lib/stream-ssl.c | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/lib/stream-ssl.c b/lib/stream-ssl.c
index 0ea3f2c08..f4fe3432e 100644
--- a/lib/stream-ssl.c
+++ b/lib/stream-ssl.c
@@ -762,18 +762,22 @@ ssl_send(struct stream *stream, const void *buffer, 
size_t n)
 if (sslv->txbuf) {
 return -EAGAIN;
 } else {
+struct ofpbuf buf;
 int error;
 
-sslv->txbuf = ofpbuf_clone_data(buffer, n);
+ofpbuf_use_const(, buffer, n);
+sslv->txbuf = 
 error = ssl_do_tx(stream);
 switch (error) {
 case 0:
-ssl_clear_txbuf(sslv);
+sslv->txbuf = NULL;
 return n;
 case EAGAIN:
+/* Copy remaining data. */
+sslv->txbuf = ofpbuf_clone_data(buf.data, buf.size);
 return n;
 default:
-ssl_clear_txbuf(sslv);
+sslv->txbuf = NULL;
 return -error;
 }
 }
-- 
2.31.1

___
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev