[Devel] [PATCH rh7 v3 2/2] ub: show up to date data counters in beancounter cgroup

Konstantin Khorenko khorenko at virtuozzo.com
Wed Apr 1 14:56:24 MSK 2020


From: Valeriy Vdovin <valeriy.vdovin at virtuozzo.com>

Sync beancounter params from pid and mem cgroups when reading counters
though beancounter cgroup.

Also sync data from CT pid cgroup upon legacy sys_ubstat() syscall
(memcg data is already synced there, only pids data was missing).

https://jira.sw.ru/browse/PSBM-95266

Signed-off-by: Valeriy Vdovin <valeriy.vdovin at virtuozzo.com>
Acked-off-by: Konstantin Khorenko <khorenko at virtuozzo.com>
---
 kernel/bc/beancounter.c | 16 ++++++++++++++++
 kernel/bc/statd.c       | 12 ++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/kernel/bc/beancounter.c b/kernel/bc/beancounter.c
index fb63023907631..87d7fb1079c92 100644
--- a/kernel/bc/beancounter.c
+++ b/kernel/bc/beancounter.c
@@ -729,6 +729,22 @@ static ssize_t ub_cgroup_resource_read(struct cgroup *cg, struct cftype *cft,
 	char str[32];
 
 	res = UB_CGROUP_RES(cft->private);
+
+	switch (res) {
+	case UB_NUMPROC:
+		ub_sync_pids(ub);
+		break;
+	case UB_KMEMSIZE:
+	case UB_DCACHESIZE:
+	case UB_PHYSPAGES:
+	case UB_SWAPPAGES:
+	case UB_OOMGUARPAGES:
+		ub_sync_memcg(ub);
+		break;
+	default:
+		break;
+	}
+
 	attr = UB_CGROUP_ATTR(cft->private);
 
 	ubparm = &ub->ub_parms[res];
diff --git a/kernel/bc/statd.c b/kernel/bc/statd.c
index a49252e2e5999..dc81959132708 100644
--- a/kernel/bc/statd.c
+++ b/kernel/bc/statd.c
@@ -223,6 +223,16 @@ int ubstat_alloc_store(struct user_beancounter *ub)
 }
 EXPORT_SYMBOL(ubstat_alloc_store);
 
+static bool ubstat_need_pids_sync(long cmd)
+{
+	if (UBSTAT_CMD(cmd) != UBSTAT_READ_ONE)
+		return true;
+
+	if (UBSTAT_PARMID(cmd) == UB_NUMPROC)
+		return true;
+	return false;
+}
+
 static bool ubstat_need_memcg_sync(long cmd)
 {
 	if (UBSTAT_CMD(cmd) != UBSTAT_READ_ONE)
@@ -272,6 +282,8 @@ static int ubstat_get_stat(struct user_beancounter *ub, long cmd,
 
 	if (ubstat_need_memcg_sync(cmd))
 		ub_sync_memcg(ub);
+	if (ubstat_need_pids_sync(cmd))
+		ub_sync_pids(ub);
 
 	spin_lock(&ubs_notify_lock);
 	switch (UBSTAT_CMD(cmd)) {
-- 
2.15.1



More information about the Devel mailing list