summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Yuan <me@yhndnzj.com>2023-11-13 14:27:29 +0100
committerMike Yuan <me@yhndnzj.com>2023-11-13 17:22:54 +0100
commitd4bdc202c37991d01d89b4c38c16f2490f177e89 (patch)
tree69668b771445910f5bcdef0d480b1159d9ec3935
parentcore: generalize memory accounting attribute handling (diff)
downloadsystemd-d4bdc202c37991d01d89b4c38c16f2490f177e89.tar.xz
systemd-d4bdc202c37991d01d89b4c38c16f2490f177e89.zip
core: add unit_reset_{memory,io}_accounting_last
-rw-r--r--src/core/cgroup.c18
-rw-r--r--src/core/cgroup.h2
-rw-r--r--src/core/unit.c8
3 files changed, 21 insertions, 7 deletions
diff --git a/src/core/cgroup.c b/src/core/cgroup.c
index 4e4b668f62..5b0cb15c85 100644
--- a/src/core/cgroup.c
+++ b/src/core/cgroup.c
@@ -4373,6 +4373,13 @@ int unit_reset_cpu_accounting(Unit *u) {
return 0;
}
+void unit_reset_memory_accounting_last(Unit *u) {
+ assert(u);
+
+ FOREACH_ARRAY(i, u->memory_accounting_last, ELEMENTSOF(u->memory_accounting_last))
+ *i = UINT64_MAX;
+}
+
int unit_reset_ip_accounting(Unit *u) {
int r = 0;
@@ -4389,13 +4396,19 @@ int unit_reset_ip_accounting(Unit *u) {
return r;
}
+void unit_reset_io_accounting_last(Unit *u) {
+ assert(u);
+
+ FOREACH_ARRAY(i, u->io_accounting_last, _CGROUP_IO_ACCOUNTING_METRIC_MAX)
+ *i = UINT64_MAX;
+}
+
int unit_reset_io_accounting(Unit *u) {
int r;
assert(u);
- FOREACH_ARRAY(i, u->io_accounting_last, _CGROUP_IO_ACCOUNTING_METRIC_MAX)
- *i = UINT64_MAX;
+ unit_reset_io_accounting_last(u);
r = unit_get_io_accounting_raw(u, u->io_accounting_base);
if (r < 0) {
@@ -4414,6 +4427,7 @@ int unit_reset_accounting(Unit *u) {
RET_GATHER(r, unit_reset_cpu_accounting(u));
RET_GATHER(r, unit_reset_io_accounting(u));
RET_GATHER(r, unit_reset_ip_accounting(u));
+ unit_reset_memory_accounting_last(u);
return r;
}
diff --git a/src/core/cgroup.h b/src/core/cgroup.h
index 157ac7271f..f1b674b4b7 100644
--- a/src/core/cgroup.h
+++ b/src/core/cgroup.h
@@ -376,7 +376,9 @@ int unit_get_io_accounting(Unit *u, CGroupIOAccountingMetric metric, bool allow_
int unit_get_ip_accounting(Unit *u, CGroupIPAccountingMetric metric, uint64_t *ret);
int unit_reset_cpu_accounting(Unit *u);
+void unit_reset_memory_accounting_last(Unit *u);
int unit_reset_ip_accounting(Unit *u);
+void unit_reset_io_accounting_last(Unit *u);
int unit_reset_io_accounting(Unit *u);
int unit_reset_accounting(Unit *u);
diff --git a/src/core/unit.c b/src/core/unit.c
index b88e28d77e..b37b1710f2 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -115,8 +115,9 @@ Unit* unit_new(Manager *m, size_t size) {
u->ref_gid = GID_INVALID;
u->cpu_usage_last = NSEC_INFINITY;
- FOREACH_ARRAY(i, u->memory_accounting_last, ELEMENTSOF(u->memory_accounting_last))
- *i = UINT64_MAX;
+ unit_reset_memory_accounting_last(u);
+
+ unit_reset_io_accounting_last(u);
u->cgroup_invalidated_mask |= CGROUP_MASK_BPF_FIREWALL;
u->failure_action_exit_status = u->success_action_exit_status = -1;
@@ -124,9 +125,6 @@ Unit* unit_new(Manager *m, size_t size) {
u->ip_accounting_ingress_map_fd = -EBADF;
u->ip_accounting_egress_map_fd = -EBADF;
- FOREACH_ARRAY(i, u->io_accounting_last, _CGROUP_IO_ACCOUNTING_METRIC_MAX)
- *i = UINT64_MAX;
-
u->ipv4_allow_map_fd = -EBADF;
u->ipv6_allow_map_fd = -EBADF;
u->ipv4_deny_map_fd = -EBADF;