valeriyvdovin / rpms / systemd

Forked from rpms/systemd 4 years ago
Clone

Blame SOURCES/0038-journal-simplify-pre-allocation-logic.patch

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