Skip to contentSkip to conversation

Per memcg lru_gen node stat

PATCH Superseded Huan Yang 2 participants 5 messages Sep 14, 2023 – Sep 27, 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.

Huan Yang (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

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

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

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
maintainer
#4 lore raw
In reply to Huan Yang
Quoted 9 lines · On Thu, 14 Sep 2023 18:47:42 +0800 Huan Yang <[email protected]> wrote:

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.

Strangely, I cannot find this series in my linux-mm archive. They came through in linux-kernel however.

Perhaps a resend will help move things along, thanks.