summaryrefslogtreecommitdiff
path: root/src/journal/journal-file.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2012-10-16 21:40:48 +0200
committerLennart Poettering <lennart@poettering.net>2012-10-16 21:40:48 +0200
commit1f2da9ec5152cbf48c214969e079d9281ef68660 (patch)
tree196f3e97eb832d2fe236d77ae45fd8614fb0f40d /src/journal/journal-file.c
parentb87705cdd2f791f8520edb78791d3e6f78afd481 (diff)
journal: sort data items of entries by offset
This should slightly optimize disk access patterns on rotating disks for simple readers.
Diffstat (limited to 'src/journal/journal-file.c')
-rw-r--r--src/journal/journal-file.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c
index f775fec444..ba04d1667b 100644
--- a/src/journal/journal-file.c
+++ b/src/journal/journal-file.c
@@ -1053,6 +1053,16 @@ void journal_file_post_change(JournalFile *f) {
log_error("Failed to truncate file to its own size: %m");
}
+static int entry_item_cmp(const void *_a, const void *_b) {
+ const EntryItem *a = _a, *b = _b;
+
+ if (le64toh(a->object_offset) < le64toh(b->object_offset))
+ return -1;
+ if (le64toh(a->object_offset) > le64toh(b->object_offset))
+ return 1;
+ return 0;
+}
+
int journal_file_append_entry(JournalFile *f, const dual_timestamp *ts, const struct iovec iovec[], unsigned n_iovec, uint64_t *seqnum, Object **ret, uint64_t *offset) {
unsigned i;
EntryItem *items;
@@ -1097,6 +1107,10 @@ int journal_file_append_entry(JournalFile *f, const dual_timestamp *ts, const st
items[i].hash = o->data.hash;
}
+ /* Order by the position on disk, in order to improve seek
+ * times for rotating media. */
+ qsort(items, n_iovec, sizeof(EntryItem), entry_item_cmp);
+
r = journal_file_append_entry_internal(f, ts, xor_hash, items, n_iovec, seqnum, ret, offset);
journal_file_post_change(f);