]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
copy: avoid posix_fadvise bypassing copy offload behavior
authorPádraig Brady <P@draigBrady.com>
Wed, 29 Oct 2025 23:41:55 +0000 (23:41 +0000)
committerPádraig Brady <P@draigBrady.com>
Sat, 1 Nov 2025 11:24:59 +0000 (11:24 +0000)
* src/copy-file-data.c (): pass 0 to posix_fadvise to indicate to EOF.
coreutils 9.8 used OFF_T_MAX instead, which triggered OpenZFS 2.2.2
at least to synchronously (decompress and) populate the page cache.
Addresses https://github.com/coreutils/coreutils/issues/122

src/copy-file-data.c

index 1eefd3071f58a54f725c96dfcd2fd352012398c5..9eb6f47244f0a62c2f4934c7663794fd4dcf21bf 100644 (file)
@@ -536,9 +536,12 @@ copy_file_data (int ifd, struct stat const *ist, off_t ipos, char const *iname,
                && scantype != PLAIN_SCANTYPE)));
 
   /* Don't bother calling fadvise for small copies, as it is not
-     likely to help performance and might even hurt it.  */
+     likely to help performance and might even hurt it.
+     Note it's important to use a 0 length to indicate the whole file
+     as OpenZFS 2.2.2 at least will otherwise synchronously
+     (decompress and) populate the cache when given a specific length.  */
   if (IO_BUFSIZE < ibytes)
-    fdadvise (ifd, ipos, ibytes <= OFF_T_MAX - ipos ? ibytes : 0,
+    fdadvise (ifd, ipos, ibytes < OFF_T_MAX - ipos ? ibytes : 0,
               FADVISE_SEQUENTIAL);
 
   /* If not making a sparse file, try to use a more-efficient