From: kaiyang2@cs.cmu.edu
To: linux-mm@kvack.org, cgroups@vger.kernel.org
Cc: roman.gushchin@linux.dev, shakeel.butt@linux.dev,
muchun.song@linux.dev, akpm@linux-foundation.org,
mhocko@kernel.org, nehagholkar@meta.com, abhishekd@meta.com,
hannes@cmpxchg.org, weixugc@google.com, rientjes@google.com,
Kaiyang Zhao <kaiyang2@cs.cmu.edu>
Subject: [RFC PATCH 1/4] Add get_cgroup_local_usage for estimating the top-tier memory usage
Date: Fri, 20 Sep 2024 22:11:48 +0000 [thread overview]
Message-ID: <20240920221202.1734227-2-kaiyang2@cs.cmu.edu> (raw)
In-Reply-To: <20240920221202.1734227-1-kaiyang2@cs.cmu.edu>
From: Kaiyang Zhao <kaiyang2@cs.cmu.edu>
Approximate the usage of top-tier memory of a cgroup by its anon,
file, shmem and slab sizes in the top-tier.
Signed-off-by: Kaiyang Zhao <kaiyang2@cs.cmu.edu>
---
include/linux/memcontrol.h | 2 ++
mm/memcontrol.c | 24 ++++++++++++++++++++++++
2 files changed, 26 insertions(+)
diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index 34d2da05f2f1..94aba4498fca 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -648,6 +648,8 @@ static inline bool mem_cgroup_unprotected(struct mem_cgroup *target,
memcg == target;
}
+unsigned long get_cgroup_local_usage(struct mem_cgroup *memcg, bool flush);
+
static inline bool mem_cgroup_below_low(struct mem_cgroup *target,
struct mem_cgroup *memcg)
{
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index f19a58c252f0..20b715441332 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -855,6 +855,30 @@ unsigned long memcg_events_local(struct mem_cgroup *memcg, int event)
return READ_ONCE(memcg->vmstats->events_local[i]);
}
+/* Usage is in pages. */
+unsigned long get_cgroup_local_usage(struct mem_cgroup *memcg, bool flush)
+{
+ struct lruvec *lruvec;
+ const int local_nid = 0;
+
+ if (!memcg)
+ return 0;
+
+ if (flush)
+ mem_cgroup_flush_stats_ratelimited(memcg);
+
+ lruvec = mem_cgroup_lruvec(memcg, NODE_DATA(local_nid));
+ unsigned long anon = lruvec_page_state(lruvec, NR_ANON_MAPPED);
+ unsigned long file = lruvec_page_state(lruvec, NR_FILE_PAGES);
+ unsigned long shmem = lruvec_page_state(lruvec, NR_SHMEM);
+ /* Slab size are in bytes */
+ unsigned long slab =
+ lruvec_page_state(lruvec, NR_SLAB_RECLAIMABLE_B) / PAGE_SIZE
+ + lruvec_page_state(lruvec, NR_SLAB_UNRECLAIMABLE_B) / PAGE_SIZE;
+
+ return anon + file + shmem + slab;
+}
+
struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p)
{
/*
--
2.43.0
next prev parent reply other threads:[~2024-09-20 22:12 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-20 22:11 [RFC PATCH 0/4] memory tiering fairness by per-cgroup control of promotion and demotion kaiyang2
2024-09-20 22:11 ` kaiyang2 [this message]
2024-09-20 22:11 ` [RFC PATCH 2/4] calculate memory.low for the local node and track its usage kaiyang2
2024-09-22 8:39 ` kernel test robot
2024-10-15 22:05 ` Gregory Price
2024-09-20 22:11 ` [RFC PATCH 3/4] use memory.low local node protection for local node reclaim kaiyang2
2024-10-15 21:52 ` Gregory Price
2024-09-20 22:11 ` [RFC PATCH 4/4] reduce NUMA balancing scan size of cgroups over their local memory.low kaiyang2
2024-11-08 19:01 ` [RFC PATCH 0/4] memory tiering fairness by per-cgroup control of promotion and demotion kaiyang2
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240920221202.1734227-2-kaiyang2@cs.cmu.edu \
--to=kaiyang2@cs.cmu.edu \
--cc=abhishekd@meta.com \
--cc=akpm@linux-foundation.org \
--cc=cgroups@vger.kernel.org \
--cc=hannes@cmpxchg.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=muchun.song@linux.dev \
--cc=nehagholkar@meta.com \
--cc=rientjes@google.com \
--cc=roman.gushchin@linux.dev \
--cc=shakeel.butt@linux.dev \
--cc=weixugc@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox