daandemeyer / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
9fc0f6
From 2d9a810729f9c209cab7aa6bf50ec5f749ebff82 Mon Sep 17 00:00:00 2001
9fc0f6
From: Lennart Poettering <lennart@poettering.net>
9fc0f6
Date: Wed, 27 Nov 2013 01:44:52 +0100
9fc0f6
Subject: [PATCH] journal: simplify pre-allocation logic
9fc0f6
9fc0f6
let's just do a single fallocate() as far as possible, and don't
9fc0f6
distuingish between allocated space and file size.
9fc0f6
9fc0f6
This way we can save a syscall for each append, which makes quite some
9fc0f6
benefits.
9fc0f6
---
9fc0f6
 src/journal/journal-file.c | 19 ++++++++-----------
9fc0f6
 1 file changed, 8 insertions(+), 11 deletions(-)
9fc0f6
9fc0f6
diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c
9fc0f6
index 94e3921..962cdd6 100644
9fc0f6
--- a/src/journal/journal-file.c
9fc0f6
+++ b/src/journal/journal-file.c
9fc0f6
@@ -315,7 +315,7 @@ static int journal_file_verify_header(JournalFile *f) {
9fc0f6
 }
9fc0f6
 
9fc0f6
 static int journal_file_allocate(JournalFile *f, uint64_t offset, uint64_t size) {
9fc0f6
-        uint64_t old_size, new_size, file_size;
9fc0f6
+        uint64_t old_size, new_size;
9fc0f6
         int r;
9fc0f6
 
9fc0f6
         assert(f);
9fc0f6
@@ -356,6 +356,11 @@ static int journal_file_allocate(JournalFile *f, uint64_t offset, uint64_t size)
9fc0f6
                 }
9fc0f6
         }
9fc0f6
 
9fc0f6
+        /* Increase by larger blocks at once */
9fc0f6
+        new_size = ((new_size+FILE_SIZE_INCREASE-1) / FILE_SIZE_INCREASE) * FILE_SIZE_INCREASE;
9fc0f6
+        if (f->metrics.max_size > 0 && new_size > f->metrics.max_size)
9fc0f6
+                new_size = f->metrics.max_size;
9fc0f6
+
9fc0f6
         /* Note that the glibc fallocate() fallback is very
9fc0f6
            inefficient, hence we try to minimize the allocation area
9fc0f6
            as we can. */
9fc0f6
@@ -363,16 +368,8 @@ static int journal_file_allocate(JournalFile *f, uint64_t offset, uint64_t size)
9fc0f6
         if (r != 0)
9fc0f6
                 return -r;
9fc0f6
 
9fc0f6
-        /* Increase the file size a bit further than this, so that we
9fc0f6
-         * we can create larger memory maps to cache */
9fc0f6
-        file_size = ((new_size+FILE_SIZE_INCREASE-1) / FILE_SIZE_INCREASE) * FILE_SIZE_INCREASE;
9fc0f6
-        if (file_size > (uint64_t) f->last_stat.st_size) {
9fc0f6
-                if (file_size > new_size)
9fc0f6
-                        ftruncate(f->fd, file_size);
9fc0f6
-
9fc0f6
-                if (fstat(f->fd, &f->last_stat) < 0)
9fc0f6
-                        return -errno;
9fc0f6
-        }
9fc0f6
+        if (fstat(f->fd, &f->last_stat) < 0)
9fc0f6
+                return -errno;
9fc0f6
 
9fc0f6
         f->header->arena_size = htole64(new_size - le64toh(f->header->header_size));
9fc0f6