[systemd-commits] 2 commits - src/journal

Lennart Poettering lennart at kemper.freedesktop.org
Tue Nov 26 09:46:10 PST 2013


 src/journal/journal-file.c |   28 ++++++++++++++++++----------
 src/journal/journal-file.h |    8 ++++----
 2 files changed, 22 insertions(+), 14 deletions(-)

New commits:
commit b8e891e699e1336c5527f8203e4e8f67c9bbeb84
Author: Lennart Poettering <lennart at poettering.net>
Date:   Tue Nov 26 18:40:23 2013 +0100

    journal: make table const

diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c
index d606ada..481c242 100644
--- a/src/journal/journal-file.c
+++ b/src/journal/journal-file.c
@@ -401,7 +401,7 @@ static int journal_file_move_to(JournalFile *f, int context, bool keep_always, u
 
 static uint64_t minimum_header_size(Object *o) {
 
-        static uint64_t table[] = {
+        static const uint64_t table[] = {
                 [OBJECT_DATA] = sizeof(DataObject),
                 [OBJECT_FIELD] = sizeof(FieldObject),
                 [OBJECT_ENTRY] = sizeof(EntryObject),
diff --git a/src/journal/journal-file.h b/src/journal/journal-file.h
index 773ece0..21b0821 100644
--- a/src/journal/journal-file.h
+++ b/src/journal/journal-file.h
@@ -54,11 +54,11 @@ typedef struct JournalFile {
 
         int flags;
         int prot;
-        bool writable;
-        bool compress;
-        bool seal;
+        bool writable:1;
+        bool compress:1;
+        bool seal:1;
 
-        bool tail_entry_monotonic_valid;
+        bool tail_entry_monotonic_valid:1;
 
         direction_t last_direction;
 

commit a676e66535e12458ea6d366a653f8dd60f982504
Author: Lennart Poettering <lennart at poettering.net>
Date:   Tue Nov 26 18:39:42 2013 +0100

    journal: when appending to journal file, allocate larger blocks at once

diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c
index bc72fca..d606ada 100644
--- a/src/journal/journal-file.c
+++ b/src/journal/journal-file.c
@@ -68,6 +68,9 @@
 /* How many entries to keep in the entry array chain cache at max */
 #define CHAIN_CACHE_MAX 20
 
+/* How much to increase the journal file size at once each time we allocate something new. */
+#define FILE_SIZE_INCREASE (8ULL*1024ULL*1024ULL)              /* 8MB */
+
 static int journal_file_set_online(JournalFile *f) {
         assert(f);
 
@@ -218,8 +221,7 @@ static int journal_file_refresh_header(JournalFile *f) {
         journal_file_set_online(f);
 
         /* Sync the online state to disk */
-        msync(f->header, PAGE_ALIGN(sizeof(Header)), MS_SYNC);
-        fdatasync(f->fd);
+        fsync(f->fd);
 
         return 0;
 }
@@ -313,7 +315,7 @@ static int journal_file_verify_header(JournalFile *f) {
 }
 
 static int journal_file_allocate(JournalFile *f, uint64_t offset, uint64_t size) {
-        uint64_t old_size, new_size;
+        uint64_t old_size, new_size, file_size;
         int r;
 
         assert(f);
@@ -333,12 +335,10 @@ static int journal_file_allocate(JournalFile *f, uint64_t offset, uint64_t size)
         if (new_size <= old_size)
                 return 0;
 
-        if (f->metrics.max_size > 0 &&
-            new_size > f->metrics.max_size)
+        if (f->metrics.max_size > 0 && new_size > f->metrics.max_size)
                 return -E2BIG;
 
-        if (new_size > f->metrics.min_size &&
-            f->metrics.keep_free > 0) {
+        if (new_size > f->metrics.min_size && f->metrics.keep_free > 0) {
                 struct statvfs svfs;
 
                 if (fstatvfs(f->fd, &svfs) >= 0) {
@@ -363,8 +363,16 @@ static int journal_file_allocate(JournalFile *f, uint64_t offset, uint64_t size)
         if (r != 0)
                 return -r;
 
-        if (fstat(f->fd, &f->last_stat) < 0)
-                return -errno;
+        /* Increase the file size a bit further than this, so that we
+         * we can create larger memory maps to cache */
+        file_size = ((new_size+FILE_SIZE_INCREASE-1) / FILE_SIZE_INCREASE) * FILE_SIZE_INCREASE;
+        if (file_size > (uint64_t) f->last_stat.st_size) {
+                if (file_size > new_size)
+                        ftruncate(f->fd, file_size);
+
+                if (fstat(f->fd, &f->last_stat) < 0)
+                        return -errno;
+        }
 
         f->header->arena_size = htole64(new_size - le64toh(f->header->header_size));
 



More information about the systemd-commits mailing list