On Sun, Jan 30, 2022 at 01:33:32AM +0200, Nir Soffer wrote:
Make it easy to create a zeroed buffer via calloc(), preventing leaking sensitive info from the heap.
Benchmarking show that creating a zeroed buffer is much slower compared
shows
with uninitialized buffer, but much faster compared with manually initializing the buffer with a loop.
BenchmarkMakeAioBuffer-12 7252674 148.1 ns/op BenchmarkMakeAioBufferZero-12 262107 4181 ns/op BenchmarkAioBufferZero-12 17581 68759 ns/op
It is interesting that creating a zeroed buffer is 3 times faster compared with making a new []byte slice:
BenchmarkMakeAioBufferZero-12 247710 4440 ns/op BenchmarkMakeByteSlice-12 84117 13733 ns/op
Some of this is due to how much vectorization the standard library (whether libc or Go's core libraries) can do when bulk-zeroing (zeroing 64 bits, or even a cache line at a time, in an unrolled loop, is always going to be more performant than a naive loop of one byte at a time).
Signed-off-by: Nir Soffer <nsoffer@redhat.com> --- golang/aio_buffer.go | 6 ++++++ golang/libnbd_620_aio_buffer_test.go | 16 ++++++++++++++++
Another file that may fit better in the 0xx naming, especially if we decide to duplicate similar functionality into the python or OCaml bindings of being able to pre-generate a known-zero buffer for use in passing to nbd_pread. As a helper API, this seems useful. But do we need any man page documentation of a language-specific helper function? -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org