On Wed, Jan 04, 2023 at 09:43:57PM +0000, Richard W.M. Jones wrote: > On Wed, Jan 04, 2023 at 06:14:34PM +0000, Richard W.M. Jones wrote: > > (3) It seems like some drivers require pre-allocated memory regions, > > and since some do that means we might as well implement this. It > > also seems like some drivers require file-backed pre-allocated > > memory regions, and so we might as well implement that too. > > > > However what is not clear: does memfd_create(2) always allocate > > sufficiently aligned memory regions, such that we never need to bother > > reading the mem-region-alignment property? > > > > I notice that the example: > > https://gitlab.com/libblkio/libblkio/-/blob/main/examples/blkio-copy.c > > just passes on this and calls blkio_alloc_mem_region(). Is that the > > safest and easiest thing to do which will always work? > > So this seems to be the reverse of what I thought. > > In nbdkit plugins ideally we'd like to avoid using bounce buffers if > possible. Also NBD requests can be up to (IIRC) 32M, although we can > hint to the client to limit them to some smaller number. > > If I call blkio_alloc_mem_region() unconditionally then it seems as if > I always need to use this as a bounce buffer. Plus, is 32M too large > for a memory region allocated this way? The example allocates 128K.
Allocating 32 MB with blkio_alloc_mem_region() is fine. > > It seems like for drivers which _don't_ require pre-allocated memory > regions then we should avoid calling blkio_alloc_mem_region which > would avoid bounce buffers. > > Some guidance about this would be appreciated. The most efficient approach is to use blkio_alloc_mem_region() in the core of your code so that no memory copies are necessary. If that's not possible (e.g. the network code cannot easily use the blkio buffer for NBD payloads), then a memory copy will be necessary. Stefan
signature.asc
Description: PGP signature
_______________________________________________ Libguestfs mailing list Libguestfs@redhat.com https://listman.redhat.com/mailman/listinfo/libguestfs