aboutsummaryrefslogtreecommitdiffstats
path: root/common/iobuf.h
diff options
context:
space:
mode:
authorJussi Kivilinna <[email protected]>2022-02-12 14:38:36 +0000
committerJussi Kivilinna <[email protected]>2022-03-08 18:00:31 +0000
commit15df88d135ba08797c2aaf1023c6c606aed49943 (patch)
treeac1f1b87b45e4cf1e2560723dd25c10aeb3a3248 /common/iobuf.h
parentg10/cipher-aead: add fast path for avoid memcpy when AEAD encrypting (diff)
downloadgnupg-15df88d135ba08797c2aaf1023c6c606aed49943.tar.gz
gnupg-15df88d135ba08797c2aaf1023c6c606aed49943.zip
iobuf: add zerocopy optimization for iobuf_read
* common/iobuf.h (iobuf_struct): Add 'e_d' substructure and members. * common/iobuf.c (IOBUF_ZEROCOPY_THRESHOLD): New. (iobuf_alloc): Clear 'iobuf->e_d'. (underflow_target): Use 'iobuf->e_d' when configured to bypass copying through 'iobuf->d.buf'. (iobuf_read): Configure 'iobuf->e_d' for 'underflow' if 'iobuf->d.buf' is empty and external buffer is larger than threshold. -- Zero-copy operation in iobuf_read() and underflow() allow bypassing 'iobuf->d.buf' for greater performance. This mainly helps OCB performance where additional memory copies through iobuf stack can take significant portion of program time. GnuPG-bug-id: T5828 Signed-off-by: Jussi Kivilinna <[email protected]>
Diffstat (limited to 'common/iobuf.h')
-rw-r--r--common/iobuf.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/common/iobuf.h b/common/iobuf.h
index a3d9bd547..f527fbf16 100644
--- a/common/iobuf.h
+++ b/common/iobuf.h
@@ -202,6 +202,26 @@ struct iobuf_struct
byte *buf;
} d;
+ /* A external drain buffer for reading/writting data skipping internal
+ draint buffer D.BUF. This allows zerocopy operation reducing
+ processing overhead across filter stack.
+
+ Used when by iobuf_read/iobuf_write when internal buffer has been
+ depleted and remaining external buffer length is large enough.
+ */
+ struct
+ {
+ /* The external buffer provided by iobuf_read/iobuf_write caller. */
+ byte *buf;
+ /* The number of bytes in the external buffer. */
+ size_t len;
+ /* The number of bytes that were consumed from the external buffer. */
+ size_t used;
+ /* Gives hint for processing that the external buffer is preferred and
+ that internal buffer should be consumed early. */
+ int preferred;
+ } e_d;
+
/* When FILTER is called to read some data, it may read some data
and then return EOF. We can't return the EOF immediately.
Instead, we note that we observed the EOF and when the buffer is