2021-04-06 08:27:48

by Tim Chen

[permalink] [raw]
Subject: [RFC PATCH v1 04/11] mm: Report top tier memory usage in sysfs

In memory cgroup's sysfs, report the memory cgroup's usage
of top tier memory in a new field: "toptier_usage_in_bytes".

Signed-off-by: Tim Chen <[email protected]>
---
mm/memcontrol.c | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index fe7bb8613f5a..68590f46fa76 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -3631,6 +3631,7 @@ enum {
RES_FAILCNT,
RES_SOFT_LIMIT,
RES_TOPTIER_SOFT_LIMIT,
+ RES_TOPTIER_USAGE,
};

static u64 mem_cgroup_read_u64(struct cgroup_subsys_state *css,
@@ -3673,6 +3674,8 @@ static u64 mem_cgroup_read_u64(struct cgroup_subsys_state *css,
return (u64)memcg->soft_limit * PAGE_SIZE;
case RES_TOPTIER_SOFT_LIMIT:
return (u64)memcg->toptier_soft_limit * PAGE_SIZE;
+ case RES_TOPTIER_USAGE:
+ return (u64)page_counter_read(&memcg->toptier) * PAGE_SIZE;
default:
BUG();
}
@@ -5073,6 +5076,11 @@ static struct cftype mem_cgroup_legacy_files[] = {
.write = mem_cgroup_write,
.read_u64 = mem_cgroup_read_u64,
},
+ {
+ .name = "toptier_usage_in_bytes",
+ .private = MEMFILE_PRIVATE(_MEM, RES_TOPTIER_USAGE),
+ .read_u64 = mem_cgroup_read_u64,
+ },
{
.name = "failcnt",
.private = MEMFILE_PRIVATE(_MEM, RES_FAILCNT),
--
2.20.1