From 672a9ac7d0e4d0852c3a7faf33ddfdf5c571119b Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 25 May 2024 05:57:03 +0900 Subject: [PATCH] journald: close runtime journal earlier Then, we can use SD_JOURNAL_ASSUME_IMMUTABLE flag, and the performance of reading runtime journal should be improved. --- src/journal/journald-server.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c index d1dc4b6ea97..514ed09566d 100644 --- a/src/journal/journald-server.c +++ b/src/journal/journald-server.c @@ -1321,6 +1321,10 @@ int server_flush_to_var(Server *s, bool require_flag_file) { if (!s->system_journal) return 0; + /* Offline and close the 'main' runtime journal file to allow the runtime journal to be opened with + * the SD_JOURNAL_ASSUME_IMMUTABLE flag in the below. */ + s->runtime_journal = journal_file_offline_close(s->runtime_journal); + /* Reset current seqnum data to avoid unnecessary rotation when switching to system journal. * See issue #30092. */ zero(*s->seqnum); @@ -1329,7 +1333,7 @@ int server_flush_to_var(Server *s, bool require_flag_file) { start = now(CLOCK_MONOTONIC); - r = sd_journal_open(&j, SD_JOURNAL_RUNTIME_ONLY); + r = sd_journal_open(&j, SD_JOURNAL_RUNTIME_ONLY | SD_JOURNAL_ASSUME_IMMUTABLE); if (r < 0) return log_ratelimit_error_errno(r, JOURNAL_LOG_RATELIMIT, "Failed to read runtime journal: %m"); @@ -1405,9 +1409,6 @@ finish: /* First, close all runtime journals opened in the above. */ sd_journal_close(j); - /* Offline and close the 'main' runtime journal file. */ - s->runtime_journal = journal_file_offline_close(s->runtime_journal); - /* Remove the runtime directory if the all entries are successfully flushed to /var/. */ if (r >= 0) { (void) rm_rf(s->runtime_storage.path, REMOVE_ROOT); -- 2.47.3