Przeglądaj źródła

dpkg: On non-Linux use fadvise(FADV_DONTNEED) to initiate writeback

Use the posix_fadvise(POSIX_FADV_DONTNEED) hint to notify the kernel
dpkg does not need the unpacked files any longer and as such it can
start writeback asynchronously.

Although POSIX does not explicitly say so, and this is merely a hint,
this is the only sensible thing to do for the kernel. On Linux at least
it also evicts the pages if they are not currently under writeback,
locked or dirty, which might be undesired if a maintainer script has
to use the data, but unlikely as the writeback will still be ongoing
if it started at all.

In addition it could be argued the Linux implementation is not optimal
as the standard talks about the application not needing the data any
longer, not the system. So it seems the NetBSD implementation which
just marks the pages as not active would be more correct.
Guillem Jover 15 lat temu
rodzic
commit
8e7f545a9d
2 zmienionych plików z 5 dodań i 0 usunięć
  1. 3 0
      debian/changelog
  2. 2 0
      src/archives.c

+ 3 - 0
debian/changelog

@@ -7,6 +7,9 @@ dpkg (1.15.8.7) UNRELEASED; urgency=low
   * On Linux use sync_file_range() to initiate asynchronous writeback
     of just unpacked files. Suggested by Ted Ts'o <tytso@mit.edu>.
     Thanks to Jonathan Nieder <jrnieder@gmail.com>. Closes: #605009
+  * On non-Linux use posix_fadvise(POSIX_FADV_DONTNEED) to notify the kernel
+    dpkg does not need the unpacked files any longer, and that it can start
+    writeback to be able to evict them from the cache at a later point.
 
   [ Updated manpage translations ]
   * French (Christian Perrier).

+ 2 - 0
src/archives.c

@@ -87,6 +87,8 @@ fd_writeback_init(int fd)
 {
 #if defined(SYNC_FILE_RANGE_WRITE)
   sync_file_range(fd, 0, 0, SYNC_FILE_RANGE_WRITE);
+#elif defined(HAVE_POSIX_FADVISE)
+  posix_fadvise(fd, 0, 0, POSIX_FADV_DONTNEED);
 #endif
 }