Double journal field hash table size (#38416)
This commit is contained in:
@@ -275,6 +275,10 @@ libsystemd_tests += [
|
||||
'sources' : files('sd-journal/test-journal-append.c'),
|
||||
'type' : 'manual',
|
||||
},
|
||||
{
|
||||
'sources' : files('sd-journal/test-journal-dump.c'),
|
||||
'type' : 'manual',
|
||||
},
|
||||
{
|
||||
'sources' : files('sd-journal/test-journal-verify.c'),
|
||||
'timeout' : 90,
|
||||
|
||||
@@ -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 1023U
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
#include "errno-util.h"
|
||||
#include "journal-file.h"
|
||||
#include "log.h"
|
||||
#include "main-func.h"
|
||||
#include "pager.h"
|
||||
#include "strv.h"
|
||||
|
||||
static int run(int argc, char *argv[]) {
|
||||
int r = 0;
|
||||
unsigned n = 0;
|
||||
|
||||
_cleanup_(mmap_cache_unrefp) MMapCache *m = mmap_cache_new();
|
||||
assert_se(m);
|
||||
|
||||
pager_open(/* flags= */ 0);
|
||||
|
||||
STRV_FOREACH(s, strv_skip(argv, 1)) {
|
||||
JournalFile *f = NULL;
|
||||
|
||||
int k = journal_file_open(
|
||||
/* fd= */ -EBADF,
|
||||
*s,
|
||||
O_RDONLY,
|
||||
/* file_flags= */ 0,
|
||||
0666,
|
||||
/* compress_threshold_bytes= */ UINT64_MAX,
|
||||
/* metrics= */ NULL,
|
||||
m,
|
||||
/* template= */ NULL,
|
||||
&f);
|
||||
if (k < 0)
|
||||
RET_GATHER(r, log_error_errno(k, "Failed to open %s, continuing: %m", *s));
|
||||
|
||||
if (n++ > 0)
|
||||
puts("");
|
||||
|
||||
journal_file_print_header(f);
|
||||
journal_file_close(f);
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
DEFINE_MAIN_FUNCTION(run);
|
||||
Reference in New Issue
Block a user