From: Mike Yuan Date: Sun, 10 Dec 2023 17:44:13 +0000 (+0800) Subject: core/unit: raise log level for unit_log_resources on certain memory thresholds X-Git-Tag: v256-rc1~1488^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b1b84bc59031816376cf82284a51bdf1c937bb92;p=thirdparty%2Fsystemd.git 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. --- diff --git a/src/core/unit.c b/src/core/unit.c index b407387fc13..a268083e5e8 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++) {