chiark / gitweb /
journal: sort data items of entries by offset
authorLennart Poettering <lennart@poettering.net>
Tue, 16 Oct 2012 19:40:48 +0000 (21:40 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 16 Oct 2012 19:40:48 +0000 (21:40 +0200)
This should slightly optimize disk access patterns on rotating disks for
simple readers.

src/journal/journal-file.c

index f775fec444004b27e6d053aff08f2ee487fb45a2..ba04d1667b11dbda2f1eac5163252eff15773efb 100644 (file)
@@ -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);