[Devel] [PATCH rh7 v3 1/2] ub: introduce helper for real "held" value (without precharge)
Konstantin Khorenko
khorenko at virtuozzo.com
Wed Apr 1 14:56:23 MSK 2020
From: Valeriy Vdovin <valeriy.vdovin at virtuozzo.com>
Just an helper, no functional changes here.
Note: we do show different "held" values in beancounter cgroup
and in /proc/bc/$CTID/resources:
- beancounter cgroup (/sys/fs/cgroup/beancounter/$CTID/*.held)
values show "real" help + precharge
- /proc/bc/$CTID/resources shows real held values with precharge
substituted.
This way we can calculate the precharge in userspace if needed.
https://jira.sw.ru/browse/PSBM-95266
Signed-off-by: Valeriy Vdovin <valeriy.vdovin at virtuozzo.com>
Acked-by: Konstantin Khorenko <khorenko at virtuozzo.com>
---
include/bc/beancounter.h | 18 ++++++++++++++++++
kernel/bc/proc.c | 3 +--
2 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/include/bc/beancounter.h b/include/bc/beancounter.h
index a06d9b6ecfd3e..6db175e8c6ac1 100644
--- a/include/bc/beancounter.h
+++ b/include/bc/beancounter.h
@@ -483,6 +483,24 @@ static inline void uncharge_beancounter_fast(struct user_beancounter *ub,
local_irq_restore(flags);
}
+/*
+ * For a particular beancounter param return real 'held' value with
+ * respect to precharge.
+ */
+static inline unsigned long get_beancounter_held_real(struct ubparm *ubparm,
+ int precharge)
+{
+ unsigned long val = ubparm->held;
+
+ /*
+ * We want to catch cases where precharge might be greater
+ * than held.
+ */
+ WARN_ON_ONCE(val < precharge);
+
+ return (val > precharge) ? (val - precharge) : 0;
+}
+
unsigned long __get_beancounter_usage_percpu(struct user_beancounter *ub,
int resource);
diff --git a/kernel/bc/proc.c b/kernel/bc/proc.c
index 70ec6ff5f2163..268f1b41a733e 100644
--- a/kernel/bc/proc.c
+++ b/kernel/bc/proc.c
@@ -52,8 +52,7 @@ static void ub_show_res(struct seq_file *f, struct user_beancounter *ub,
unsigned long held;
p = &ub->ub_parms[r];
- held = p->held;
- held = (held > precharge) ? (held - precharge) : 0;
+ held = get_beancounter_held_real(p, precharge);
seq_printf(f, res_fmt,
show_uid && r == 0 ? ub->ub_name : "",
--
2.15.1
More information about the Devel
mailing list