Skip to contentSkip to conversation

Per memcg lru_gen node stat

PATCH RESEND In review Huan Yang 3 participants 9 messages Oct 9, 2023 – Oct 20, 2023

Subsystems (8)
lore
Share & tools
lore

Huan Yang

author
#0 lore raw

cover Per memcg lru_gen node stat

On original global lru_gen node in debugfs, it can all show each memcg's lru gen info in "lru_gen" or "lru_gen_full", and can type cmd into lru_gen. But which show info contains all memcg's info, and cmd need to know memcg's id.

This patchset add lru_gen node in per memcg, with this node, we can get lru_gen info in each memcg.
Also, we can type cmd to control each memcg's lru_gen seq, but, this node don't support multi cmd, single memcg just process one cmd once time.

HuanYang (3):
mm: multi-gen LRU: fold lru_gen run cmd
mm: memcg: add per memcg "lru_gen" node
mm: multi-gen LRU: add per memcg "lru_gen" document

 Documentation/admin-guide/mm/multigen_lru.rst |  10 ++
 include/linux/mm_inline.h                     |   9 +
 include/linux/mmzone.h                        |   4 +-
 mm/memcontrol.c                               | 163 ++++++++++++++++++
 mm/vmscan.c                                   |  82 ++++++---
 5 files changed, 246 insertions(+), 22 deletions(-)
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH 1/3 mm: multi-gen LRU: fold lru_gen run cmd

From: HuanYang <[email protected]>

This patch move LRU_GEN define helper into mm_inline which will used in per memcg lru gen node.

let run aging/eviction into func, per memcg also will run this.

---
 include/linux/mm_inline.h |  9 ++++++++
 mm/vmscan.c               | 45 +++++++++++++++++++++------------------
 2 files changed, 33 insertions(+), 21 deletions(-)
include/linux/mm_inline.h +9 -0
index 8148b30a9df1..b953b305c8a2 100644
@@ -101,6 +101,15 @@ static __always_inline enum lru_list folio_lru_list(struct folio *folio)
 
 #ifdef CONFIG_LRU_GEN
 
+#define DEFINE_MAX_SEQ(lruvec)						\
+	unsigned long max_seq = READ_ONCE((lruvec)->lrugen.max_seq)
+
+#define DEFINE_MIN_SEQ(lruvec)						\
+	unsigned long min_seq[ANON_AND_FILE] = {			\
+		READ_ONCE((lruvec)->lrugen.min_seq[LRU_GEN_ANON]),	\
+		READ_ONCE((lruvec)->lrugen.min_seq[LRU_GEN_FILE]),	\
+	}
+
 #ifdef CONFIG_LRU_GEN_ENABLED
 static inline bool lru_gen_enabled(void)
 {
mm/vmscan.c +24 -21

64 lines not on this page · raw message

Signature · 1 line
2.34.1
author
#2 lore raw

PATCH 2/3 mm: memcg: add per memcg "lru_gen" node

In reply to Huan Yang

From: HuanYang <[email protected]>

This patch add "lru_gen" node in mem cgroup both in v1 and v2.

mem_cgroup_lru_gen_show just like global node, show lru_gen info, but always show the full info due to per memcg no need to simple output.

Just like global node, per memcg "lru_gen" node can input cmd, but we no need to type memcgid anymore to select one memcg.

---
 include/linux/mmzone.h |   4 +-
 mm/memcontrol.c        | 163 +++++++++++++++++++++++++++++++++++++++++
 mm/vmscan.c            |  37 ++++++++++
 3 files changed, 203 insertions(+), 1 deletion(-)
include/linux/mmzone.h +3 -1
index 4106fbc5b4b3..3d399ef177a4 100644
@@ -553,7 +553,9 @@ void lru_gen_online_memcg(struct mem_cgroup *memcg);
 void lru_gen_offline_memcg(struct mem_cgroup *memcg);
 void lru_gen_release_memcg(struct mem_cgroup *memcg);
 void lru_gen_soft_reclaim(struct mem_cgroup *memcg, int nid);
-
+int mem_cgroup_lru_gen_cmd(char cmd, struct mem_cgroup *memcg, int nid,
+			   unsigned long seq, int swappiness,
+			   unsigned long opt);
 #else /* !CONFIG_MEMCG */
 
 #define MEMCG_NR_GENS	1
mm/memcontrol.c +163 -0

181 lines not on this page · raw message

mm/vmscan.c +37 -0
index f59977964e81..4da200cda0b9 100644
@@ -6072,6 +6072,43 @@ static int __process_one_cmd(char cmd, struct lruvec *lruvec, unsigned long seq,
 	return err;
 }
 
+#ifdef CONFIG_MEMCG
+int mem_cgroup_lru_gen_cmd(char cmd, struct mem_cgroup *memcg, int nid,
+			   unsigned long seq, int swappiness, unsigned long opt)
+{
+	int err;
+	struct lruvec *lruvec;
+	unsigned int flags;
+	struct blk_plug plug;
+	struct scan_control sc = {
+		.may_writepage = true,
+		.may_unmap = true,
+		.may_swap = true,
+		.reclaim_idx = MAX_NR_ZONES - 1,
+		.gfp_mask = GFP_KERNEL,
+	};
+
+	set_task_reclaim_state(current, &sc.reclaim_state);
+	flags = memalloc_noreclaim_save();
+	blk_start_plug(&plug);
+	if (!set_mm_walk(NULL, true)) {
+		err = -ENOMEM;
+		goto done;
+	}
+
+	lruvec = get_lruvec(memcg, nid);
+	err = __process_one_cmd(cmd, lruvec, seq, &sc, swappiness, opt);
+
+done:
+	clear_mm_walk();
+	blk_finish_plug(&plug);
+	memalloc_noreclaim_restore(flags);
+	set_task_reclaim_state(current, NULL);
+
+	return err;
+}
+#endif
+
 static int run_cmd(char cmd, int memcg_id, int nid, unsigned long seq,
 		   struct scan_control *sc, int swappiness, unsigned long opt)
 {
Signature · 1 line
2.34.1
author
#3 lore raw

PATCH 3/3 mm: multi-gen LRU: add per memcg "lru_gen" document

In reply to Huan Yang

From: HuanYang <[email protected]>

change multi-gen LRU document.

---
 Documentation/admin-guide/mm/multigen_lru.rst | 10 ++++++++++
 1 file changed, 10 insertions(+)
Documentation/admin-guide/mm/multigen_lru.rst +10 -0
index 33e068830497..078056b8cc7c 100644
@@ -160,3 +160,13 @@ cold pages because of the overestimation, it retries on the next
 server according to the ranking result obtained from the working set
 estimation step. This less forceful approach limits the impacts on the
 existing jobs.
+
+Per memcg lru gen node
+-----------------
+In each memcg's dir, it contains ``lru_gen`` node. you can type upon cmd
+without input memcg_id to do the same thing.
+
+    ``+ node_id max_gen_nr [can_swap [force_scan]]``
+    ``- node_id min_gen_nr [swappiness [nr_to_reclaim]]``
+
+For show info, memcg's node always show the full info.
Signature · 1 line
2.34.1
#4 lore raw
In reply to Huan Yang
Quoted 10 lines · Huan Yang

On original global lru_gen node in debugfs, it can all show each memcg's lru gen info in "lru_gen" or "lru_gen_full", and can type cmd into lru_gen. But which show info contains all memcg's info, and cmd need to know memcg's id.

This patchset add lru_gen node in per memcg, with this node, we can get lru_gen info in each memcg.
Also, we can type cmd to control each memcg's lru_gen seq, but, this node don't support multi cmd, single memcg just process one cmd once time.

Adding TJ from the Android team. (The other TJ you CC'ed is from the ChromeOS team.)

This series introduced a new ABI, which has to be maintained forever. How exactly would it be used in *production*?

Android doesn't officially support memcgs. So I want to understand the real-world use cases first.

#5 lore raw
Quoted 13 lines · Yu Zhao
Quoted 10 lines · Huan Yang

On original global lru_gen node in debugfs, it can all show each memcg's lru gen info in "lru_gen" or "lru_gen_full", and can type cmd into lru_gen. But which show info contains all memcg's info, and cmd need to know memcg's id.

This patchset add lru_gen node in per memcg, with this node, we can get lru_gen info in each memcg.
Also, we can type cmd to control each memcg's lru_gen seq, but, this node don't support multi cmd, single memcg just process one cmd once time.

Quoted 8 lines

Adding TJ from the Android team. (The other TJ you CC'ed is from the ChromeOS team.)

This series introduced a new ABI, which has to be maintained forever. How exactly would it be used in *production*?

Android doesn't officially support memcgs. So I want to understand the real-world use cases first.

Not sure how Android came up but I'm happy to chat. We want to turn on memcg v2 for Android but I'm currently working through perf impacts before that happens. Android can't use debugfs in production, but I think we'd prefer to use memory.reclaim for eviction anyway because it respects memcg limits and reclaims from slab.

So maybe it's possible to add just aging functionality specific to MGLRU? It'd be nice to know how you're going to use the aging, or why you want this version of eviction instead of what memory.reclaim does.

author
#6 lore raw
Quoted 19 lines · T.J. Mercier

[你通常不会收到来自 [email protected] 的电子邮件。请访问 https://aka.ms/LearnAboutSenderIdentification,以了解这一点为什么很重要]

Quoted 16 lines · Yu Zhao
Quoted 9 lines · Huan Yang

On original global lru_gen node in debugfs, it can all show each memcg's lru gen info in "lru_gen" or "lru_gen_full", and can type cmd into lru_gen. But which show info contains all memcg's info, and cmd need to know memcg's id.

This patchset add lru_gen node in per memcg, with this node, we can get lru_gen info in each memcg.
Also, we can type cmd to control each memcg's lru_gen seq, but, this node don't support multi cmd, single memcg just process one cmd once time.

Adding TJ from the Android team. (The other TJ you CC'ed is from the ChromeOS team.)

This series introduced a new ABI, which has to be maintained forever. How exactly would it be used in *production*?

Quoted 7 lines
Quoted 2 lines

Android doesn't officially support memcgs. So I want to understand the real-world use cases first.

Not sure how Android came up but I'm happy to chat. We want to turn on memcg v2 for Android but I'm currently working through perf impacts before that happens. Android can't use debugfs in production, but I think we'd prefer to use memory.reclaim for eviction anyway because it respects memcg limits and reclaims from slab.

Yes, shrink control this actually can use proactive reclaim.

Quoted 3 lines

So maybe it's possible to add just aging functionality specific to MGLRU? It'd be nice to know how you're going to use the aging, or why

Due to debugfs not always mount, if we want to now lrugen's info, maybe nice to offer a memcg's node to show per memcg's lrugen info.

Quoted 1 line

you want this version of eviction instead of what memory.reclaim does.

So, this node not want to instead of memory.reclaim, it's good enough. age or other control just flow debugfs global node's behavior. If no need, delete write is OK.

Thanks

#7 lore raw
Quoted 11 lines · Huan Yang
Quoted 3 lines

Android can't use debugfs in production, but I
think we'd prefer to use memory.reclaim for eviction anyway because it respects memcg limits and reclaims from slab.

Yes, shrink control this actually can use proactive reclaim.

Quoted 3 lines

So maybe it's possible to add just aging functionality specific to MGLRU? It'd be nice to know how you're going to use the aging, or why

Due to debugfs not always mount, if we want to now lrugen's info, maybe nice to offer a memcg's node to show per memcg's lrugen info.

Quoted 1 line

you want this version of eviction instead of what memory.reclaim does.

I think Yu's inquiry was about whether you will look at the lrugen info from the memcg file for a production use case, or just for debugging where you don't have debugfs for some reason. Because it's a long term commitment to add the file.

author
#8 lore raw
Quoted 6 lines · T.J. Mercier

[你通常不会收到来自 [email protected] 的电子邮件。请访问 https://aka.ms/LearnAboutSenderIdentification,以了解这一点为什么很重要]

Quoted 3 lines · Huan Yang
Quoted 3 lines

Android can't use debugfs in production, but I
think we'd prefer to use memory.reclaim for eviction anyway because it respects memcg limits and reclaims from slab.

Quoted 7 lines
Quoted 6 lines

Yes, shrink control this actually can use proactive reclaim.

Quoted 2 lines

So maybe it's possible to add just aging functionality specific to MGLRU? It'd be nice to know how you're going to use the aging, or why

Due to debugfs not always mount, if we want to now lrugen's info, maybe nice to offer a memcg's node to show per memcg's lrugen info.

Quoted 1 line

you want this version of eviction instead of what memory.reclaim does.

I think Yu's inquiry was about whether you will look at the lrugen

Thanks to point that.

Quoted 2 lines

info from the memcg file for a production use case, or just for debugging where you don't have debugfs for some reason. Because it's a

Yes, for now use, just collect log from it, not have control logic. For future use, maybe we need to control a memcg's lru_gen anon seq reclaim. (just assume)

Quoted 1 line

long term commitment to add the file.

OK, if I can offer a actually use case, I will send again

Thanks too much.