[ovs-dev] [PATCH] stream-ssl: Avoid unnecessary memory copies on send.
Ilya Maximets
i.maximets at ovn.org
Sun Nov 21 23:46:39 UTC 2021
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 <i.maximets at ovn.org>
---
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(&buf, buffer, n);
+ sslv->txbuf = &buf;
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
More information about the dev
mailing list