]> git.ipfire.org Git - thirdparty/systemd.git/commit
sd-journal: rate-limit tail timestamp refresh during iteration
authordongshengyuan <545258830@qq.com>
Wed, 24 Jun 2026 05:01:32 +0000 (13:01 +0800)
committerLuca Boccassi <luca.boccassi@gmail.com>
Tue, 30 Jun 2026 12:46:05 +0000 (13:46 +0100)
commit8f8ab4bf98f930fcbbdd7efcbba8577981d31df9
treec319479eea74517fa8320456ca687c6712f69380
parentbbb863a008ec29ffd7da0fab518f841f20664fd7
sd-journal: rate-limit tail timestamp refresh during iteration

journal_file_read_tail_timestamp() is called unconditionally in
next_beyond_location() for every file on every iteration step,
resulting in O(N x files) volatile mmap reads. For large queries
like 'journalctl -n 1000000' this makes the command unusably slow
(~5 minutes on systems with many journal files).

Rather than suppressing the call entirely (which would make the
inotify path fully load-bearing for cross-boot ordering), rate-limit
it to at most once per second per file. This reduces the overhead
from O(N x files) to O(T x files) where T is the iteration time in
seconds, while still providing periodic refresh as a fallback for
any missed inotify events and keeping cross-boot ordering
reasonably fresh.

Embed a RateLimit struct in JournalFile for this purpose.

Measured improvement on a real system: 5:24 -> 2:39 (-51%) for
'journalctl -n 1000000'.

Fixes: #42521
Regression introduced in: #26355 (34af74946e)

Signed-off-by: dongshengyuan <dongshengyuan@uniontech.com>
src/libsystemd/sd-journal/journal-file.c
src/libsystemd/sd-journal/journal-file.h
src/libsystemd/sd-journal/sd-journal.c