[Devel] [PATCH RHEL7 COMMIT] ub: introduce helper for real "held" value (without precharge)

Konstantin Khorenko khorenko at virtuozzo.com
Wed Apr 1 20:35:13 MSK 2020


The commit is pushed to "branch-rh7-3.10.0-1062.12.1.vz7.145.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-1062.12.1.vz7.145.5
------>
commit b09011a3ecd2e2d13cd4e5287038a2cea5926fd5
Author: Valeriy Vdovin <valeriy.vdovin at virtuozzo.com>
Date:   Wed Apr 1 13:54:58 2020 +0300

    ub: introduce helper for real "held" value (without precharge)
    
    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" held + precharge
     - /proc/bc/$CTID/resources shows real held values with precharge
       substructed.
    
    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 : "",


More information about the Devel mailing list