summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-07-19 18:42:46 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-07-26 16:45:49 +0200
commit6aae0b1af4fe67b5a80d115fa589897c763ac5f3 (patch)
treea513a4afdac2a870ee13325d1c971645c289931f /src
parent170a434c784fc7919e6ad7c269ea4f7abcc6065a (diff)
downloadsystemd-6aae0b1af4fe67b5a80d115fa589897c763ac5f3.tar.gz
systemd-6aae0b1af4fe67b5a80d115fa589897c763ac5f3.tar.bz2
systemd-6aae0b1af4fe67b5a80d115fa589897c763ac5f3.zip
journald: lower keep_free to 5% and raise min_use to 2%
https://bugzilla.redhat.com/show_bug.cgi?id=1715699 > /dev/mapper/live-rw 6.4G 5.7G 648M 91% / > systemd-journald[905]: Fixed min_use=1.0M max_use=648.7M max_size=81.0M min_size=512.0K keep_free=973.1M n_max_files=100 When journald is started, we pick keep_free as 15% of the disk size. When the fs is almost filled, we will only keep one journal file around and rotate very often (because min_size is very small). Let's set min use to something reasonable, so that we get more useful logs that will cover at least the full boot. Some cases considered in the PR: > /dev/mapper/live-rw 6.4G 5.7G 648M 91% / keep_free→MIN(327,100)→100 MB. min_use→16MB. effective range: 16 MB – 548 MB > /dev/mapper/fedora_krowka-root 78G 69G 5.7G 93% / keep_free → MIN(4GB, 100MB)→100MB min_use→16MB effective range: 16 MB – 5.6 GB (but then there's the max_use limit, which cuts the range down) > 4TB, 4GB free keep_free → MIN(209715, 100) → 100 MB min_use→16MB effective range: 16 MB – 4.9 GB (also effectively limited by max_use) Also replace unneeded width suffixes with spaces, I think this is more readable, and drop DEFAULT_ prefixes in cases where this setting is simply a bound, and cannot be overridden by user config, hence is not a default.
Diffstat (limited to 'src')
-rw-r--r--src/journal/journal-file.c87
1 files changed, 38 insertions, 49 deletions
diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c
index f0dd695adb..dcce445e9c 100644
--- a/src/journal/journal-file.c
+++ b/src/journal/journal-file.c
@@ -40,29 +40,31 @@
#define MIN_COMPRESS_THRESHOLD (8ULL)
/* This is the minimum journal file size */
-#define JOURNAL_FILE_SIZE_MIN (512ULL*1024ULL) /* 512 KiB */
+#define JOURNAL_FILE_SIZE_MIN (512 * 1024ULL) /* 512 KiB */
/* These are the lower and upper bounds if we deduce the max_use value
* from the file system size */
-#define DEFAULT_MAX_USE_LOWER (1ULL*1024ULL*1024ULL) /* 1 MiB */
-#define DEFAULT_MAX_USE_UPPER (4ULL*1024ULL*1024ULL*1024ULL) /* 4 GiB */
+#define MAX_USE_LOWER (1 * 1024 * 1024ULL) /* 1 MiB */
+#define MAX_USE_UPPER (4 * 1024 * 1024 * 1024ULL) /* 4 GiB */
-/* This is the default minimal use limit, how much we'll use even if keep_free suggests otherwise. */
-#define DEFAULT_MIN_USE (1ULL*1024ULL*1024ULL) /* 1 MiB */
+/* Those are the lower and upper bounds for the minimal use limit,
+ * i.e. how much we'll use even if keep_free suggests otherwise. */
+#define MIN_USE_LOW (1 * 1024 * 1024ULL) /* 1 MiB */
+#define MIN_USE_HIGH (16 * 1024 * 1024ULL) /* 16 MiB */
/* This is the upper bound if we deduce max_size from max_use */
-#define DEFAULT_MAX_SIZE_UPPER (128ULL*1024ULL*1024ULL) /* 128 MiB */
+#define MAX_SIZE_UPPER (128 * 1024 * 1024ULL) /* 128 MiB */
/* This is the upper bound if we deduce the keep_free value from the
* file system size */
-#define DEFAULT_KEEP_FREE_UPPER (4ULL*1024ULL*1024ULL*1024ULL) /* 4 GiB */
+#define KEEP_FREE_UPPER (4 * 1024 * 1024 * 1024ULL) /* 4 GiB */
/* This is the keep_free value when we can't determine the system
* size */
-#define DEFAULT_KEEP_FREE (1024ULL*1024ULL) /* 1 MB */
+#define DEFAULT_KEEP_FREE (1024 * 1024ULL) /* 1 MB */
/* This is the default maximum number of journal files to keep around. */
-#define DEFAULT_N_MAX_FILES (100)
+#define DEFAULT_N_MAX_FILES 100
/* n_data was the first entry we added after the initial file format design */
#define HEADER_SIZE_MIN ALIGN64(offsetof(Header, n_data))
@@ -71,7 +73,7 @@
#define CHAIN_CACHE_MAX 20
/* How much to increase the journal file size at once each time we allocate something new. */
-#define FILE_SIZE_INCREASE (8ULL*1024ULL*1024ULL) /* 8MB */
+#define FILE_SIZE_INCREASE (8 * 1024 * 1024ULL) /* 8MB */
/* Reread fstat() of the file for detecting deletions at least this often */
#define LAST_STAT_REFRESH_USEC (5*USEC_PER_SEC)
@@ -3722,30 +3724,23 @@ void journal_reset_metrics(JournalMetrics *m) {
void journal_default_metrics(JournalMetrics *m, int fd) {
char a[FORMAT_BYTES_MAX], b[FORMAT_BYTES_MAX], c[FORMAT_BYTES_MAX], d[FORMAT_BYTES_MAX], e[FORMAT_BYTES_MAX];
struct statvfs ss;
- uint64_t fs_size;
+ uint64_t fs_size = 0;
assert(m);
assert(fd >= 0);
if (fstatvfs(fd, &ss) >= 0)
fs_size = ss.f_frsize * ss.f_blocks;
- else {
+ else
log_debug_errno(errno, "Failed to determine disk size: %m");
- fs_size = 0;
- }
if (m->max_use == (uint64_t) -1) {
- if (fs_size > 0) {
- m->max_use = PAGE_ALIGN(fs_size / 10); /* 10% of file system size */
-
- if (m->max_use > DEFAULT_MAX_USE_UPPER)
- m->max_use = DEFAULT_MAX_USE_UPPER;
-
- if (m->max_use < DEFAULT_MAX_USE_LOWER)
- m->max_use = DEFAULT_MAX_USE_LOWER;
- } else
- m->max_use = DEFAULT_MAX_USE_LOWER;
+ if (fs_size > 0)
+ m->max_use = CLAMP(PAGE_ALIGN(fs_size / 10), /* 10% of file system size */
+ MAX_USE_LOWER, MAX_USE_UPPER);
+ else
+ m->max_use = MAX_USE_LOWER;
} else {
m->max_use = PAGE_ALIGN(m->max_use);
@@ -3753,18 +3748,21 @@ void journal_default_metrics(JournalMetrics *m, int fd) {
m->max_use = JOURNAL_FILE_SIZE_MIN*2;
}
- if (m->min_use == (uint64_t) -1)
- m->min_use = DEFAULT_MIN_USE;
+ if (m->min_use == (uint64_t) -1) {
+ if (fs_size > 0)
+ m->min_use = CLAMP(PAGE_ALIGN(fs_size / 50), /* 2% of file system size */
+ MIN_USE_LOW, MIN_USE_HIGH);
+ else
+ m->min_use = MIN_USE_LOW;
+ }
if (m->min_use > m->max_use)
m->min_use = m->max_use;
- if (m->max_size == (uint64_t) -1) {
- m->max_size = PAGE_ALIGN(m->max_use / 8); /* 8 chunks */
-
- if (m->max_size > DEFAULT_MAX_SIZE_UPPER)
- m->max_size = DEFAULT_MAX_SIZE_UPPER;
- } else
+ if (m->max_size == (uint64_t) -1)
+ m->max_size = MIN(PAGE_ALIGN(m->max_use / 8), /* 8 chunks */
+ MAX_SIZE_UPPER);
+ else
m->max_size = PAGE_ALIGN(m->max_size);
if (m->max_size != 0) {
@@ -3777,25 +3775,16 @@ void journal_default_metrics(JournalMetrics *m, int fd) {
if (m->min_size == (uint64_t) -1)
m->min_size = JOURNAL_FILE_SIZE_MIN;
- else {
- m->min_size = PAGE_ALIGN(m->min_size);
-
- if (m->min_size < JOURNAL_FILE_SIZE_MIN)
- m->min_size = JOURNAL_FILE_SIZE_MIN;
-
- if (m->max_size != 0 && m->min_size > m->max_size)
- m->max_size = m->min_size;
- }
+ else
+ m->min_size = CLAMP(PAGE_ALIGN(m->min_size),
+ JOURNAL_FILE_SIZE_MIN,
+ m->max_size ?: UINT64_MAX);
if (m->keep_free == (uint64_t) -1) {
-
- if (fs_size > 0) {
- m->keep_free = PAGE_ALIGN(fs_size * 3 / 20); /* 15% of file system size */
-
- if (m->keep_free > DEFAULT_KEEP_FREE_UPPER)
- m->keep_free = DEFAULT_KEEP_FREE_UPPER;
-
- } else
+ if (fs_size > 0)
+ m->keep_free = MIN(PAGE_ALIGN(fs_size / 20), /* 5% of file system size */
+ KEEP_FREE_UPPER);
+ else
m->keep_free = DEFAULT_KEEP_FREE;
}