From: Daan De Meyer Date: Wed, 15 Dec 2021 17:17:22 +0000 (+0100) Subject: journal: Add a minimum hole size for hole punching X-Git-Tag: v250-rc3~40^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a2799cc556fa3f8dc0bb3934077ca49e628efed2;p=thirdparty%2Fsystemd.git journal: Add a minimum hole size for hole punching Let's not bother punching extremely small holes to avoid unnecessary file fragmentation. --- diff --git a/src/journal/journald-file.c b/src/journal/journald-file.c index 2d263f2cb6e..78580ca84d6 100644 --- a/src/journal/journald-file.c +++ b/src/journal/journald-file.c @@ -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);