From b1b84bc59031816376cf82284a51bdf1c937bb92 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Mon, 11 Dec 2023 01:44:13 +0800 Subject: [PATCH] core/unit: raise log level for unit_log_resources on certain memory thresholds We already do this for all other types of accountings. Let's make this nicer for memory accounting too. --- src/core/unit.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/core/unit.c b/src/core/unit.c index b407387fc1..a268083e5e 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -67,14 +67,16 @@ #endif /* Thresholds for logging at INFO level about resource consumption */ -#define MENTIONWORTHY_CPU_NSEC (1 * NSEC_PER_SEC) -#define MENTIONWORTHY_IO_BYTES (1024 * 1024ULL) -#define MENTIONWORTHY_IP_BYTES (0ULL) +#define MENTIONWORTHY_CPU_NSEC (1 * NSEC_PER_SEC) +#define MENTIONWORTHY_MEMORY_BYTES (64 * U64_MB) +#define MENTIONWORTHY_IO_BYTES (1 * U64_MB) +#define MENTIONWORTHY_IP_BYTES UINT64_C(0) -/* Thresholds for logging at INFO level about resource consumption */ -#define NOTICEWORTHY_CPU_NSEC (10*60 * NSEC_PER_SEC) /* 10 minutes */ -#define NOTICEWORTHY_IO_BYTES (10 * 1024 * 1024ULL) /* 10 MB */ -#define NOTICEWORTHY_IP_BYTES (128 * 1024 * 1024ULL) /* 128 MB */ +/* Thresholds for logging at NOTICE level about resource consumption */ +#define NOTICEWORTHY_CPU_NSEC (10 * NSEC_PER_MINUTE) +#define NOTICEWORTHY_MEMORY_BYTES (512 * U64_MB) +#define NOTICEWORTHY_IO_BYTES (10 * U64_MB) +#define NOTICEWORTHY_IP_BYTES (128 * U64_MB) const UnitVTable * const unit_vtable[_UNIT_TYPE_MAX] = { [UNIT_SERVICE] = &service_vtable, @@ -2406,6 +2408,10 @@ static int unit_log_resources(Unit *u) { goto finish; } message_parts[n_message_parts++] = t; + + log_level = raise_level(log_level, + memory_peak > MENTIONWORTHY_MEMORY_BYTES, + memory_peak > NOTICEWORTHY_MEMORY_BYTES); } (void) unit_get_memory_accounting(u, CGROUP_MEMORY_SWAP_PEAK, &memory_swap_peak); @@ -2424,6 +2430,10 @@ static int unit_log_resources(Unit *u) { goto finish; } message_parts[n_message_parts++] = t; + + log_level = raise_level(log_level, + memory_swap_peak > MENTIONWORTHY_MEMORY_BYTES, + memory_swap_peak > NOTICEWORTHY_MEMORY_BYTES); } for (CGroupIOAccountingMetric k = 0; k < _CGROUP_IO_ACCOUNTING_METRIC_MAX; k++) { -- 2.25.1