On 2/19/21 1:41 PM, Richard W.M. Jones wrote: >>> +#if defined (HAVE_POSIX_FADVISE) && defined (POSIX_FADV_DONTNEED) >>> + /* On Linux this will evict the pages we just read from the page >>> cache. */ >>> + posix_fadvise (fd, offset, r, POSIX_FADV_DONTNEED); >> >> I don't think this is a good idea, since this affects the current page >> cache, for >> the entire host. >> >> So if the host is having an image in cache for good reason, running nbdcopy >> will drop the cache since nbdcopy does not need it, but maybe the host will >> need that cache after running nbdcopy. >> >> The right way to avoid polluting the page cache is to bypass the cache using >> O_DIRECT, so nbdcopy is not using or affecting the page cache. >> >> This can be useful if the user can enable this with a flag. > > The trouble with O_DIRECT is it's a pain to use correctly, and I guess > doesn't use readahead or the existing cache (kind of the opposite > problem). > > However I take your point that we probably ought not to remove files > from the cache that are already there. I somehow thought that > POSIX_FADV_DONTNEED only affected the current 'fd', but looking at the > Linux impl I see it affects the whole system. > > This argues for having a flag to enable this.
If I understand correctly, unconditionally attempting FADV_SEQUENTIAL should always should be fine both for reads (from existing file) and writes (when copying to a new file), so its only FADV_DONTNEED for clearing out the cache that needs a flag? -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org _______________________________________________ Libguestfs mailing list [email protected] https://listman.redhat.com/mailman/listinfo/libguestfs
