Skip to contentSkip to conversation

mm-multi-gen-lru-per-node-lru_gen_folio-lists.patch removed from -mm tree

merged mm-stable Andrew Morton 1 participant 1 message Jan 19, 2023

lore
Share & tools
lore

Andrew Morton

author tree notice Applied
#0 lore raw

The quilt patch titled
Subject: mm: multi-gen LRU: per-node lru_gen_folio lists
has been removed from the -mm tree. Its filename was
mm-multi-gen-lru-per-node-lru_gen_folio-lists.patch

This patch was dropped because it was merged into the mm-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

------------------------------------------------------
From: Yu Zhao <[email protected]>
Subject: mm: multi-gen LRU: per-node lru_gen_folio lists
Date: Wed, 21 Dec 2022 21:19:04 -0700

For each node, memcgs are divided into two generations: the old and the young. For each generation, memcgs are randomly sharded into multiple bins to improve scalability. For each bin, an RCU hlist_nulls is virtually divided into three segments: the head, the tail and the default.

An onlining memcg is added to the tail of a random bin in the old generation. The eviction starts at the head of a random bin in the old generation. The per-node memcg generation counter, whose reminder (mod
2) indexes the old generation, is incremented when all its bins become empty.

There are four operations:
1. MEMCG_LRU_HEAD, which moves an memcg to the head of a random bin in its current generation (old or young) and updates its "seg" to "head";
2. MEMCG_LRU_TAIL, which moves an memcg to the tail of a random bin in its current generation (old or young) and updates its "seg" to "tail";
3. MEMCG_LRU_OLD, which moves an memcg to the head of a random bin in the old generation, updates its "gen" to "old" and resets its "seg" to "default";
4. MEMCG_LRU_YOUNG, which moves an memcg to the tail of a random bin in the young generation, updates its "gen" to "young" and resets its "seg" to "default".

The events that trigger the above operations are:
1. Exceeding the soft limit, which triggers MEMCG_LRU_HEAD;
2. The first attempt to reclaim an memcg below low, which triggers MEMCG_LRU_TAIL;
3. The first attempt to reclaim an memcg below reclaimable size threshold, which triggers MEMCG_LRU_TAIL;
4. The second attempt to reclaim an memcg below reclaimable size threshold, which triggers MEMCG_LRU_YOUNG;
5. Attempting to reclaim an memcg below min, which triggers MEMCG_LRU_YOUNG;
6. Finishing the aging on the eviction path, which triggers MEMCG_LRU_YOUNG;
7. Offlining an memcg, which triggers MEMCG_LRU_OLD.

Note that memcg LRU only applies to global reclaim, and the round-robin incrementing of their max_seq counters ensures the eventual fairness to all eligible memcgs. For memcg reclaim, it still relies on mem_cgroup_iter().

Cc Johannes Weiner <[email protected]>
Cc Jonathan Corbet <[email protected]>
Cc Michael Larabel <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Mike Rapoport <[email protected]>
Cc Roman Gushchin <[email protected]>
Cc Suren Baghdasaryan <[email protected]>

---

 include/linux/memcontrol.h |   10 
 include/linux/mm_inline.h  |   17 +
 include/linux/mmzone.h     |  117 ++++++++++
 mm/memcontrol.c            |   16 +
 mm/page_alloc.c            |    1 
 mm/vmscan.c                |  374 +++++++++++++++++++++++++++++++----
 6 files changed, 500 insertions(+), 35 deletions(-)
include/linux/memcontrol.h renamed from include/linux/memcontrol.h~mm-multi-gen-lru-per-node-lru_gen_folio-lists +10 -0
@@ -794,6 +794,11 @@ static inline void obj_cgroup_put(struct
 	percpu_ref_put(&objcg->refcnt);
 }
 
+static inline bool mem_cgroup_tryget(struct mem_cgroup *memcg)
+{
+	return !memcg || css_tryget(&memcg->css);
+}
+
 static inline void mem_cgroup_put(struct mem_cgroup *memcg)
 {
 	if (memcg)
@@ -1301,6 +1306,11 @@ static inline void obj_cgroup_put(struct
 {
 }
 
+static inline bool mem_cgroup_tryget(struct mem_cgroup *memcg)
+{
+	return true;
+}
+
 static inline void mem_cgroup_put(struct mem_cgroup *memcg)
 {
 }
include/linux/mm_inline.h renamed from include/linux/mm_inline.h~mm-multi-gen-lru-per-node-lru_gen_folio-lists +17 -0
@@ -122,6 +122,18 @@ static inline bool lru_gen_in_fault(void
 	return current->in_lru_fault;
 }
 
+#ifdef CONFIG_MEMCG
+static inline int lru_gen_memcg_seg(struct lruvec *lruvec)
+{
+	return READ_ONCE(lruvec->lrugen.seg);
+}
+#else
+static inline int lru_gen_memcg_seg(struct lruvec *lruvec)
+{
+	return 0;
+}
+#endif
+
 static inline int lru_gen_from_seq(unsigned long seq)
 {
 	return seq % MAX_NR_GENS;
@@ -297,6 +309,11 @@ static inline bool lru_gen_in_fault(void
 	return false;
 }
 
+static inline int lru_gen_memcg_seg(struct lruvec *lruvec)
+{
+	return 0;
+}
+
 static inline bool lru_gen_add_folio(struct lruvec *lruvec, struct folio *folio, bool reclaiming)
 {
 	return false;
include/linux/mmzone.h renamed from include/linux/mmzone.h~mm-multi-gen-lru-per-node-lru_gen_folio-lists +115 -2

164 lines not on this page · raw message

mm/memcontrol.c renamed from mm/memcontrol.c~mm-multi-gen-lru-per-node-lru_gen_folio-lists +16 -0
@@ -478,6 +478,16 @@ static void mem_cgroup_update_tree(struc
 	struct mem_cgroup_per_node *mz;
 	struct mem_cgroup_tree_per_node *mctz;
 
+	if (lru_gen_enabled()) {
+		struct lruvec *lruvec = &memcg->nodeinfo[nid]->lruvec;
+
+		/* see the comment on MEMCG_NR_GENS */
+		if (soft_limit_excess(memcg) && lru_gen_memcg_seg(lruvec) != MEMCG_LRU_HEAD)
+			lru_gen_rotate_memcg(lruvec, MEMCG_LRU_HEAD);
+
+		return;
+	}
+
 	mctz = soft_limit_tree.rb_tree_per_node[nid];
 	if (!mctz)
 		return;
@@ -3530,6 +3540,9 @@ unsigned long mem_cgroup_soft_limit_recl
 	struct mem_cgroup_tree_per_node *mctz;
 	unsigned long excess;
 
+	if (lru_gen_enabled())
+		return 0;
+
 	if (order > 0)
 		return 0;
 
@@ -5391,6 +5404,7 @@ static int mem_cgroup_css_online(struct
 	if (unlikely(mem_cgroup_is_root(memcg)))
 		queue_delayed_work(system_unbound_wq, &stats_flush_dwork,
 				   2UL*HZ);
+	lru_gen_online_memcg(memcg);
 	return 0;
 offline_kmem:
 	memcg_offline_kmem(memcg);
@@ -5422,6 +5436,7 @@ static void mem_cgroup_css_offline(struc
 	memcg_offline_kmem(memcg);
 	reparent_shrinker_deferred(memcg);
 	wb_memcg_offline(memcg);
+	lru_gen_offline_memcg(memcg);
 
 	drain_all_stock(memcg);
 
@@ -5433,6 +5448,7 @@ static void mem_cgroup_css_released(stru
 	struct mem_cgroup *memcg = mem_cgroup_from_css(css);
 
 	invalidate_reclaim_iterators(memcg);
+	lru_gen_release_memcg(memcg);
 }
 
 static void mem_cgroup_css_free(struct cgroup_subsys_state *css)
mm/page_alloc.c renamed from mm/page_alloc.c~mm-multi-gen-lru-per-node-lru_gen_folio-lists +1 -0
@@ -7941,6 +7941,7 @@ static void __init free_area_init_node(i
 	pgdat_set_deferred_range(pgdat);
 
 	free_area_init_core(pgdat);
+	lru_gen_init_pgdat(pgdat);
 }
 
 static void __init free_area_init_memoryless_node(int nid)
mm/vmscan.c renamed from mm/vmscan.c~mm-multi-gen-lru-per-node-lru_gen_folio-lists +341 -33

487 lines not on this page · raw message

_

Patches currently in -mm which might be from [email protected] are

mm-multi-gen-lru-fix-crash-during-cgroup-migration.patch