]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journal: Add a minimum hole size for hole punching
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 15 Dec 2021 17:17:22 +0000 (18:17 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 15 Dec 2021 17:17:22 +0000 (18:17 +0100)
Let's not bother punching extremely small holes to avoid unnecessary
file fragmentation.

src/journal/journald-file.c

index 2d263f2cb6e4fa21ac89a4d9d3eb7d7e84d5387e..78580ca84d6777ee8bd2a70c0d8ca6feec6ff157 100644 (file)
@@ -15,6 +15,8 @@
 #include "stat-util.h"
 #include "sync-util.h"
 
+#define MINIMUM_HOLE_SIZE (1U * 1024U * 1024U / 2U)
+
 static int journald_file_truncate(JournalFile *f) {
         uint64_t p;
         int r;
@@ -66,6 +68,9 @@ static int journald_file_entry_array_punch_hole(JournalFile *f, uint64_t p, uint
                 (journal_file_entry_array_n_items(&o) - n_unused) * sizeof(le64_t);
         sz = p + le64toh(o.object.size) - offset;
 
+        if (sz < MINIMUM_HOLE_SIZE)
+                return 0;
+
         if (fallocate(f->fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, offset, sz) < 0)
                 return log_debug_errno(errno, "Failed to punch hole in entry array of %s: %m", f->path);