From a2799cc556fa3f8dc0bb3934077ca49e628efed2 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Wed, 15 Dec 2021 18:17:22 +0100 Subject: [PATCH] journal: Add a minimum hole size for hole punching Let's not bother punching extremely small holes to avoid unnecessary file fragmentation. --- src/journal/journald-file.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/journal/journald-file.c b/src/journal/journald-file.c index 2d263f2cb6..78580ca84d 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); -- 2.25.1