summaryrefslogtreecommitdiff
path: root/src/journal
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-01-06 19:51:03 +0100
committerLennart Poettering <lennart@poettering.net>2015-01-06 20:31:40 +0100
commitf27a386430cc7a27ebd06899d93310fb3bd4cee7 (patch)
treefaff2e8d41e70dd9477de514f2893d99859ef4ea /src/journal
parent7c75c5ca68970d2d47f211f068883e9b8c3ff5e7 (diff)
journald: whenever we rotate a file, btrfs defrag it
Our write pattern is quite awful for CoW file systems (btrfs...), as we keep updating file parts in the beginning of the file. This results in fragmented journal files. Hence: when rotating files, defragment them, since at that point we know that no further write accesses will be made.
Diffstat (limited to 'src/journal')
-rw-r--r--src/journal/journal-file.c13
-rw-r--r--src/journal/journal-file.h1
2 files changed, 14 insertions, 0 deletions
diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c
index 304ce03bd..4c7dd242e 100644
--- a/src/journal/journal-file.c
+++ b/src/journal/journal-file.c
@@ -27,6 +27,7 @@
#include <fcntl.h>
#include <stddef.h>
+#include "btrfs-util.h"
#include "journal-def.h"
#include "journal-file.h"
#include "journal-authenticate.h"
@@ -140,6 +141,9 @@ void journal_file_close(JournalFile *f) {
if (f->mmap && f->fd >= 0)
mmap_cache_close_fd(f->mmap, f->fd);
+ if (f->fd >= 0 && f->defrag_on_close)
+ btrfs_defrag_fd(f->fd);
+
safe_close(f->fd);
free(f->path);
@@ -2741,6 +2745,11 @@ int journal_file_rotate(JournalFile **f, bool compress, bool seal) {
old_file->header->state = STATE_ARCHIVED;
+ /* Currently, btrfs is not very good with out write patterns
+ * and fragments heavily. Let's defrag our journal files when
+ * we archive them */
+ old_file->defrag_on_close = true;
+
r = journal_file_open(old_file->path, old_file->flags, old_file->mode, compress, seal, NULL, old_file->mmap, old_file, &new_file);
journal_file_close(old_file);
@@ -2796,6 +2805,10 @@ int journal_file_open_reliably(
if (r < 0)
return -errno;
+ /* btrfs doesn't cope well with our write pattern and
+ * fragments heavily. Let's defrag all files we rotate */
+ (void) btrfs_defrag(p);
+
log_warning("File %s corrupted or uncleanly shut down, renaming and replacing.", fname);
return journal_file_open(fname, flags, mode, compress, seal,
diff --git a/src/journal/journal-file.h b/src/journal/journal-file.h
index b3a0679b9..6812385e1 100644
--- a/src/journal/journal-file.h
+++ b/src/journal/journal-file.h
@@ -73,6 +73,7 @@ typedef struct JournalFile {
bool compress_xz:1;
bool compress_lz4:1;
bool seal:1;
+ bool defrag_on_close:1;
bool tail_entry_monotonic_valid:1;