From 1f2da9ec5152cbf48c214969e079d9281ef68660 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 16 Oct 2012 21:40:48 +0200 Subject: [PATCH] journal: sort data items of entries by offset This should slightly optimize disk access patterns on rotating disks for simple readers. --- src/journal/journal-file.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c index f775fec44..ba04d1667 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); -- 2.30.2