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

Submitted by Konstantin Khorenko on April 1, 2020, 5:35 p.m.

Details

Message ID 202004011735.031HZDEM011307@finist-ce7.sw.ru
State New
Series "ub: make bc cgroup in sync with pids and memory cgroups"
Headers show

Commit Message

Konstantin Khorenko April 1, 2020, 5:35 p.m.
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@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@virtuozzo.com>
    Acked-by: Konstantin Khorenko <khorenko@virtuozzo.com>
---
 include/bc/beancounter.h | 18 ++++++++++++++++++
 kernel/bc/proc.c         |  3 +--
 2 files changed, 19 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

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 : "",