[Libguestfs] [PATCH libnbd 4/9] golang: aio_buffer.go: Add MakeAioBufferZero()
Nir Soffer
nsoffer at redhat.com
Thu Feb 10 21:09:47 UTC 2022
On Tue, Feb 8, 2022 at 10:45 PM Eric Blake <eblake at redhat.com> wrote:
>
> 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
Will fix
>
> > 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 at 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?
The AioBuffer type is documented here:
https://pkg.go.dev/libguestfs.org/libnbd#AioBuffer
Patch #3 golang: aio_buffer.go: Add missing documentation
adds the missing documentation for the functions,
We can add more documentation for the type. If we need
task-based documentation I think improving libnbd-golang
is the best way.
More information about the Libguestfs
mailing list