diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2017-07-12 22:17:06 -0700 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2017-07-12 23:59:29 -0700 |
commit | b439282e0b496923cb144954cd479949fff3aa01 (patch) | |
tree | f0a723df2fe4139b2a955c883663fe0d1f8c62db /src/journal | |
parent | b42549ad69ab51789d5b8fa9f1dfc6c2fe45f43e (diff) | |
download | systemd-b439282e0b496923cb144954cd479949fff3aa01.tar.gz |
journal: avoid unnecessary mmap_cache_get() calls
journal_file_move_to_object() can skip the second
journal_file_move_to() call if the first one already mapped a
sufficiently large area.
Now that mmap_cache_get() returns the size of the mapped area
when asked, ask for the size and only perform the second call if
the required size exceeds the mapped size instead of the object
header size.
This results in a nice performance boost in my testing, even with
a corpus of many small logs burning much CPU time elsewhere:
Before:
# time ./journalctl -b -1 --no-pager > /dev/null
real 0m16.330s
user 0m16.281s
sys 0m0.046s
# time ./journalctl -b -1 --no-pager > /dev/null
real 0m16.409s
user 0m16.358s
sys 0m0.048s
# time ./journalctl -b -1 --no-pager > /dev/null
real 0m16.625s
user 0m16.558s
sys 0m0.061s
After:
# time ./journalctl -b -1 --no-pager > /dev/null
real 0m15.311s
user 0m15.257s
sys 0m0.046s
# time ./journalctl -b -1 --no-pager > /dev/null
real 0m15.201s
user 0m15.135s
sys 0m0.062s
# time ./journalctl -b -1 --no-pager > /dev/null
real 0m15.170s
user 0m15.113s
sys 0m0.053s
Diffstat (limited to 'src/journal')
-rw-r--r-- | src/journal/journal-file.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c index 05cbf08a35..84e64aef6c 100644 --- a/src/journal/journal-file.c +++ b/src/journal/journal-file.c @@ -727,7 +727,7 @@ static unsigned type_to_context(ObjectType type) { return type > OBJECT_UNUSED && type < _OBJECT_TYPE_MAX ? type : 0; } -static int journal_file_move_to(JournalFile *f, ObjectType type, bool keep_always, uint64_t offset, uint64_t size, void **ret) { +static int journal_file_move_to(JournalFile *f, ObjectType type, bool keep_always, uint64_t offset, uint64_t size, void **ret, size_t *ret_size) { int r; assert(f); @@ -749,7 +749,7 @@ static int journal_file_move_to(JournalFile *f, ObjectType type, bool keep_alway return -EADDRNOTAVAIL; } - return mmap_cache_get(f->mmap, f->cache_fd, f->prot, type_to_context(type), keep_always, offset, size, &f->last_stat, ret, NULL); + return mmap_cache_get(f->mmap, f->cache_fd, f->prot, type_to_context(type), keep_always, offset, size, &f->last_stat, ret, ret_size); } static uint64_t minimum_header_size(Object *o) { @@ -773,6 +773,7 @@ static uint64_t minimum_header_size(Object *o) { int journal_file_move_to_object(JournalFile *f, ObjectType type, uint64_t offset, Object **ret) { int r; void *t; + size_t tsize; Object *o; uint64_t s; @@ -791,7 +792,7 @@ int journal_file_move_to_object(JournalFile *f, ObjectType type, uint64_t offset return -EBADMSG; } - r = journal_file_move_to(f, type, false, offset, sizeof(ObjectHeader), &t); + r = journal_file_move_to(f, type, false, offset, sizeof(ObjectHeader), &t, &tsize); if (r < 0) return r; @@ -822,8 +823,8 @@ int journal_file_move_to_object(JournalFile *f, ObjectType type, uint64_t offset return -EBADMSG; } - if (s > sizeof(ObjectHeader)) { - r = journal_file_move_to(f, type, false, offset, s, &t); + if (s > tsize) { + r = journal_file_move_to(f, type, false, offset, s, &t, NULL); if (r < 0) return r; @@ -893,7 +894,7 @@ int journal_file_append_object(JournalFile *f, ObjectType type, uint64_t size, O if (r < 0) return r; - r = journal_file_move_to(f, type, false, p, size, &t); + r = journal_file_move_to(f, type, false, p, size, &t, NULL); if (r < 0) return r; |