Skip to contentSkip to conversation

mm: memcg: add THP swap out info for anonymous reclaim

PATCH Superseded Xin Hao 2 participants 3 messages Sep 9, 2023 – Sep 12, 2023

Subsystems (6)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Xin Hao

author
#0 lore raw

PATCH 1/1 mm: memcg: add THP swap out info for anonymous reclaim

At present, we support per-memcg reclaim strategy, however we do not know the number of transparent huge pages being reclaimed, as we know the transparent huge pages need to be splited before reclaim them, and they will bring some performance bottleneck effect. for example, when two memcg (A & B) are doing reclaim for anonymous pages at same time, and 'A' memcg is reclaiming a large number of transparent huge pages, we can better analyze that the performance bottleneck will be caused by 'A' memcg. therefore, in order to better analyze such problems, there add THP swap out info for per-memcg.

---
 mm/memcontrol.c | 6 ++++++
 mm/page_io.c    | 4 +++-
 mm/vmscan.c     | 2 ++
 3 files changed, 11 insertions(+), 1 deletion(-)
mm/memcontrol.c +6 -0
index ecc07b47e813..a644f601e2ca 100644
@@ -752,6 +752,8 @@ static const unsigned int memcg_vm_event_stat[] = {
 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
 	THP_FAULT_ALLOC,
 	THP_COLLAPSE_ALLOC,
+	THP_SWPOUT,
+	THP_SWPOUT_FALLBACK,
 #endif
 };
 
@@ -4131,6 +4133,10 @@ static const unsigned int memcg1_events[] = {
 	PGPGOUT,
 	PGFAULT,
 	PGMAJFAULT,
+#ifdef CONFIG_TRANSPARENT_HUGEPAGE
+	THP_SWPOUT,
+	THP_SWPOUT_FALLBACK,
+#endif
 };
 
 static void memcg1_stat_format(struct mem_cgroup *memcg, struct seq_buf *s)
mm/page_io.c +3 -1
index fe4c21af23f2..008ada2e024a 100644
@@ -208,8 +208,10 @@ int swap_writepage(struct page *page, struct writeback_control *wbc)
 static inline void count_swpout_vm_event(struct folio *folio)
 {
 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
-	if (unlikely(folio_test_pmd_mappable(folio)))
+	if (unlikely(folio_test_pmd_mappable(folio))) {
+		count_memcg_events(folio_memcg(folio), THP_SWPOUT, 1);
 		count_vm_event(THP_SWPOUT);
+	}
 #endif
 	count_vm_events(PSWPOUT, folio_nr_pages(folio));
 }
mm/vmscan.c +2 -0
index ea57a43ebd6b..29a82b72345a 100644
@@ -1928,6 +1928,8 @@ static unsigned int shrink_folio_list(struct list_head *folio_list,
 								folio_list))
 						goto activate_locked;
 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
+					count_memcg_events(folio_memcg(folio),
+							   THP_SWPOUT_FALLBACK, 1);
 					count_vm_event(THP_SWPOUT_FALLBACK);
 #endif
 					if (!add_to_swap(folio))
Signature · 1 line
2.42.0
maintainer
#1 lore raw
Quoted 11 lines · Xin Hao

At present, we support per-memcg reclaim strategy, however we do not know the number of transparent huge pages being reclaimed, as we know the transparent huge pages need to be splited before reclaim them, and they will bring some performance bottleneck effect. for example, when two memcg (A & B) are doing reclaim for anonymous pages at same time, and 'A' memcg is reclaiming a large number of transparent huge pages, we can better analyze that the performance bottleneck will be caused by 'A' memcg. therefore, in order to better analyze such problems, there add THP swap out info for per-memcg.

That sounds reasonable. A few comments below:

mm/memcontrol.c static const unsigned int memcg1_events[] = { · line 4140

Quoted 9 lines
mm/memcontrol.c +4 -0
@@ -4131,6 +4133,10 @@ static const unsigned int memcg1_events[] = {
 	PGPGOUT,
 	PGFAULT,
 	PGMAJFAULT,
+#ifdef CONFIG_TRANSPARENT_HUGEPAGE
+	THP_SWPOUT,
+	THP_SWPOUT_FALLBACK,
+#endif
 };

Cgroup1 is maintenance-only, please drop this hunk.

mm/page_io.c int swap_writepage(struct page *page, struct writeback_control *wbc) · line 212

Quoted 12 lines
mm/memcontrol.c +0 -0
 static void memcg1_stat_format(struct mem_cgroup *memcg, struct seq_buf *s)
mm/page_io.c +2 -1
index fe4c21af23f2..008ada2e024a 100644
@@ -208,8 +208,10 @@ int swap_writepage(struct page *page, struct writeback_control *wbc)
 static inline void count_swpout_vm_event(struct folio *folio)
 {
 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
-	if (unlikely(folio_test_pmd_mappable(folio)))
+	if (unlikely(folio_test_pmd_mappable(folio))) {
+		count_memcg_events(folio_memcg(folio), THP_SWPOUT, 1);

count_memcg_folio_events()

Quoted 10 lines
mm/page_io.c +1 -0
 		count_vm_event(THP_SWPOUT);
+	}
 #endif
 	count_vm_events(PSWPOUT, folio_nr_pages(folio));
 }
mm/vmscan.c +0 -0
index ea57a43ebd6b..29a82b72345a 100644

mm/vmscan.c static unsigned int shrink_folio_list(struct list_head *folio_list, · line 1932

Quoted 5 lines
mm/vmscan.c +2 -0
@@ -1928,6 +1928,8 @@ static unsigned int shrink_folio_list(struct list_head *folio_list,
 								folio_list))
 						goto activate_locked;
 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
+					count_memcg_events(folio_memcg(folio),
+							   THP_SWPOUT_FALLBACK, 1);

count_memcg_folio_events()

author
#2 lore raw
Quoted 14 lines · Johannes Weiner
Quoted 11 lines · Xin Hao

At present, we support per-memcg reclaim strategy, however we do not know the number of transparent huge pages being reclaimed, as we know the transparent huge pages need to be splited before reclaim them, and they will bring some performance bottleneck effect. for example, when two memcg (A & B) are doing reclaim for anonymous pages at same time, and 'A' memcg is reclaiming a large number of transparent huge pages, we can better analyze that the performance bottleneck will be caused by 'A' memcg. therefore, in order to better analyze such problems, there add THP swap out info for per-memcg.

That sounds reasonable. A few comments below:

Quoted 10 lines

mm/memcontrol.c static const unsigned int memcg1_events[] = { · line 4140

Quoted 9 lines
mm/memcontrol.c +4 -0
@@ -4131,6 +4133,10 @@ static const unsigned int memcg1_events[] = {
  	PGPGOUT,
  	PGFAULT,
  	PGMAJFAULT,
+#ifdef CONFIG_TRANSPARENT_HUGEPAGE
+	THP_SWPOUT,
+	THP_SWPOUT_FALLBACK,
+#endif
  };

Cgroup1 is maintenance-only, please drop this hunk.

Will remove it next version thanks.

Quoted 14 lines

mm/page_io.c int swap_writepage(struct page *page, struct writeback_control *wbc) · line 212

Quoted 13 lines
mm/memcontrol.c +0 -0
  static void memcg1_stat_format(struct mem_cgroup *memcg, struct seq_buf *s)
mm/page_io.c +2 -1
index fe4c21af23f2..008ada2e024a 100644
@@ -208,8 +208,10 @@ int swap_writepage(struct page *page, struct writeback_control *wbc)
  static inline void count_swpout_vm_event(struct folio *folio)
  {
  #ifdef CONFIG_TRANSPARENT_HUGEPAGE
-	if (unlikely(folio_test_pmd_mappable(folio)))
+	if (unlikely(folio_test_pmd_mappable(folio))) {
+		count_memcg_events(folio_memcg(folio), THP_SWPOUT, 1);

count_memcg_folio_events()

Done.

Quoted 17 lines
Quoted 11 lines
mm/page_io.c +1 -0
  		count_vm_event(THP_SWPOUT);
+	}
  #endif
  	count_vm_events(PSWPOUT, folio_nr_pages(folio));
  }
mm/vmscan.c +0 -0
index ea57a43ebd6b..29a82b72345a 100644

mm/vmscan.c static unsigned int shrink_folio_list(struct list_head *folio_list, · line 1932

Quoted 5 lines
mm/vmscan.c +2 -0
@@ -1928,6 +1928,8 @@ static unsigned int shrink_folio_list(struct list_head *folio_list,
  								folio_list))
  						goto activate_locked;
  #ifdef CONFIG_TRANSPARENT_HUGEPAGE
+					count_memcg_events(folio_memcg(folio),
+							   THP_SWPOUT_FALLBACK, 1);

count_memcg_folio_events()

Done.

thanks.