[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[PATCH 1/4] dpkg: On Linux initiate writeback of unpacked files ASAP



To avoid performance degradation on filesystems with "allocate on
flush" semantics (like xfs, ubifs, hfs+, and ext4 without nodelalloc),
start writing back each file once it has finished being extracted.
This doesn't actually wait for the write to finish; it just starts
the writeback.

The sync_file_range call has been available since Linux 2.6.17.
On non-Linux systems we can skip it.

Suggested-by: Ted Ts'o <tytso@mit.edu>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 src/archives.c |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/src/archives.c b/src/archives.c
index d68f9d6..d423f45 100644
--- a/src/archives.c
+++ b/src/archives.c
@@ -66,6 +66,20 @@
 struct pkginfo *conflictor[MAXCONFLICTORS];
 int cflict_index = 0;
 
+#ifdef SYNC_FILE_RANGE_WRITE
+static int
+begin_writeback(int fd)
+{
+  return sync_file_range(fd, 0, 0, SYNC_FILE_RANGE_WRITE);
+}
+#else
+static int
+begin_writeback(int fd)
+{
+  return 0;
+}
+#endif
+
 /**
  * Special routine to handle partial reads from the tarfile.
  */
@@ -712,6 +726,8 @@ tarobject(void *ctx, struct tar_entry *ti)
       ohshite(_("error setting ownership of `%.255s'"), ti->name);
     if (fchmod(fd, st->mode & ~S_IFMT))
       ohshite(_("error setting permissions of `%.255s'"), ti->name);
+    if (begin_writeback(fd))
+      ohshite(_("error beginning writeback of '%.255s'"), ti->name);
 
     /* Postpone the fsync, to try to avoid massive I/O degradation. */
     if (!fc_unsafe_io)
-- 
1.7.2.3


Reply to: