From: Zbigniew Jędrzejewski-Szmek Date: Wed, 30 Jul 2025 09:39:35 +0000 (+0200) Subject: journal: store counts, not byte sizes, in table size constants X-Git-Tag: v258-rc2~33^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=fbbcd0edefd2921b117eebfeab8eefc3d26bd0c2;p=thirdparty%2Fsystemd.git journal: store counts, not byte sizes, in table size constants It's easier to think about the size in "objects", not bytes. Let's convert to bytes at the last moment. Also drop some of the pointless size suffixes. In general, it's the size of the variable that matters, not the constant that is written to it. No functional change. --- diff --git a/src/libsystemd/sd-journal/journal-file.c b/src/libsystemd/sd-journal/journal-file.c index f47e94fac8b..3e9da297bac 100644 --- a/src/libsystemd/sd-journal/journal-file.c +++ b/src/libsystemd/sd-journal/journal-file.c @@ -46,11 +46,11 @@ #include "user-util.h" #include "xattr-util.h" -#define DEFAULT_DATA_HASH_TABLE_SIZE (2047ULL*sizeof(HashItem)) -#define DEFAULT_FIELD_HASH_TABLE_SIZE (333ULL*sizeof(HashItem)) +#define DEFAULT_DATA_HASH_TABLE_SIZE 2047U +#define DEFAULT_FIELD_HASH_TABLE_SIZE 333U -#define DEFAULT_COMPRESS_THRESHOLD (512ULL) -#define MIN_COMPRESS_THRESHOLD (8ULL) +#define DEFAULT_COMPRESS_THRESHOLD 512U +#define MIN_COMPRESS_THRESHOLD 8U /* This is the minimum journal file size */ #define JOURNAL_FILE_SIZE_MIN (512 * U64_KB) /* 512 KiB */ @@ -1286,15 +1286,14 @@ static int journal_file_setup_data_hash_table(JournalFile *f) { beyond 75% fill level. Calculate the hash table size for the maximum file size based on these metrics. */ - s = (f->metrics.max_size * 4 / 768 / 3) * sizeof(HashItem); - if (s < DEFAULT_DATA_HASH_TABLE_SIZE) - s = DEFAULT_DATA_HASH_TABLE_SIZE; + s = MAX(f->metrics.max_size * 4 / 768 / 3, + DEFAULT_DATA_HASH_TABLE_SIZE); - log_debug("Reserving %"PRIu64" entries in data hash table.", s / sizeof(HashItem)); + log_debug("Reserving %"PRIu64" entries in data hash table.", s); r = journal_file_append_object(f, OBJECT_DATA_HASH_TABLE, - offsetof(Object, hash_table.items) + s, + offsetof(Object, hash_table.items) + s * sizeof(HashItem), &o, &p); if (r < 0) return r; @@ -1302,7 +1301,7 @@ static int journal_file_setup_data_hash_table(JournalFile *f) { memzero(o->hash_table.items, s); f->header->data_hash_table_offset = htole64(p + offsetof(Object, hash_table.items)); - f->header->data_hash_table_size = htole64(s); + f->header->data_hash_table_size = htole64(s * sizeof(HashItem)); return 0; } @@ -1319,19 +1318,19 @@ static int journal_file_setup_field_hash_table(JournalFile *f) { * number should grow very slowly only */ s = DEFAULT_FIELD_HASH_TABLE_SIZE; - log_debug("Reserving %"PRIu64" entries in field hash table.", s / sizeof(HashItem)); + log_debug("Reserving %"PRIu64" entries in field hash table.", s); r = journal_file_append_object(f, OBJECT_FIELD_HASH_TABLE, - offsetof(Object, hash_table.items) + s, + offsetof(Object, hash_table.items) + s * sizeof(HashItem), &o, &p); if (r < 0) return r; - memzero(o->hash_table.items, s); + memzero(o->hash_table.items, s * sizeof(HashItem)); f->header->field_hash_table_offset = htole64(p + offsetof(Object, hash_table.items)); - f->header->field_hash_table_size = htole64(s); + f->header->field_hash_table_size = htole64(s * sizeof(HashItem)); return 0; }