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

Submitted by Konstantin Khorenko on April 1, 2020, 11:56 a.m.

Details

Message ID 20200401115624.10677-3-khorenko@virtuozzo.com
State New
Series "ub: make bc cgroup in sync with pids and memory cgroups"
Headers show

Commit Message

Konstantin Khorenko April 1, 2020, 11:56 a.m.
From: Valeriy Vdovin <valeriy.vdovin@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@virtuozzo.com>
Acked-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
---
 kernel/bc/beancounter.c | 16 ++++++++++++++++
 kernel/bc/statd.c       | 12 ++++++++++++
 2 files changed, 28 insertions(+)

Patch hide | download patch | download mbox

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)) {