Skip to content

Commit 67c8b11

Browse files
haowenchaoakpm00
authored andcommitted
mm: add per-order mTHP swap-in fallback/fallback_charge counters
Currently, large folio swap-in is supported, but we lack a method to analyze their success ratio. Similar to anon_fault_fallback, we introduce per-order mTHP swpin_fallback and swpin_fallback_charge counters for calculating their success ratio. The new counters are located at: /sys/kernel/mm/transparent_hugepage/hugepages-<size>/stats/ swpin_fallback swpin_fallback_charge Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Wenchao Hao <[email protected]> Reviewed-by: Barry Song <[email protected]> Reviewed-by: Lance Yang <[email protected]> Cc: Baolin Wang <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: Jonathan Corbet <[email protected]> Cc: Matthew Wilcox <[email protected]> Cc: Peter Xu <[email protected]> Cc: Ryan Roberts <[email protected]> Cc: Usama Arif <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 4817f70 commit 67c8b11

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

Documentation/admin-guide/mm/transhuge.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,16 @@ swpin
591591
is incremented every time a huge page is swapped in from a non-zswap
592592
swap device in one piece.
593593

594+
swpin_fallback
595+
is incremented if swapin fails to allocate or charge a huge page
596+
and instead falls back to using huge pages with lower orders or
597+
small pages.
598+
599+
swpin_fallback_charge
600+
is incremented if swapin fails to charge a huge page and instead
601+
falls back to using huge pages with lower orders or small pages
602+
even though the allocation was successful.
603+
594604
swpout
595605
is incremented every time a huge page is swapped out to a non-zswap
596606
swap device in one piece without splitting.

include/linux/huge_mm.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ enum mthp_stat_item {
121121
MTHP_STAT_ANON_FAULT_FALLBACK_CHARGE,
122122
MTHP_STAT_ZSWPOUT,
123123
MTHP_STAT_SWPIN,
124+
MTHP_STAT_SWPIN_FALLBACK,
125+
MTHP_STAT_SWPIN_FALLBACK_CHARGE,
124126
MTHP_STAT_SWPOUT,
125127
MTHP_STAT_SWPOUT_FALLBACK,
126128
MTHP_STAT_SHMEM_ALLOC,

mm/huge_memory.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,8 @@ DEFINE_MTHP_STAT_ATTR(anon_fault_fallback, MTHP_STAT_ANON_FAULT_FALLBACK);
617617
DEFINE_MTHP_STAT_ATTR(anon_fault_fallback_charge, MTHP_STAT_ANON_FAULT_FALLBACK_CHARGE);
618618
DEFINE_MTHP_STAT_ATTR(zswpout, MTHP_STAT_ZSWPOUT);
619619
DEFINE_MTHP_STAT_ATTR(swpin, MTHP_STAT_SWPIN);
620+
DEFINE_MTHP_STAT_ATTR(swpin_fallback, MTHP_STAT_SWPIN_FALLBACK);
621+
DEFINE_MTHP_STAT_ATTR(swpin_fallback_charge, MTHP_STAT_SWPIN_FALLBACK_CHARGE);
620622
DEFINE_MTHP_STAT_ATTR(swpout, MTHP_STAT_SWPOUT);
621623
DEFINE_MTHP_STAT_ATTR(swpout_fallback, MTHP_STAT_SWPOUT_FALLBACK);
622624
#ifdef CONFIG_SHMEM
@@ -637,6 +639,8 @@ static struct attribute *anon_stats_attrs[] = {
637639
#ifndef CONFIG_SHMEM
638640
&zswpout_attr.attr,
639641
&swpin_attr.attr,
642+
&swpin_fallback_attr.attr,
643+
&swpin_fallback_charge_attr.attr,
640644
&swpout_attr.attr,
641645
&swpout_fallback_attr.attr,
642646
#endif
@@ -669,6 +673,8 @@ static struct attribute *any_stats_attrs[] = {
669673
#ifdef CONFIG_SHMEM
670674
&zswpout_attr.attr,
671675
&swpin_attr.attr,
676+
&swpin_fallback_attr.attr,
677+
&swpin_fallback_charge_attr.attr,
672678
&swpout_attr.attr,
673679
&swpout_fallback_attr.attr,
674680
#endif

mm/memory.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4258,8 +4258,10 @@ static struct folio *alloc_swap_folio(struct vm_fault *vmf)
42584258
if (!mem_cgroup_swapin_charge_folio(folio, vma->vm_mm,
42594259
gfp, entry))
42604260
return folio;
4261+
count_mthp_stat(order, MTHP_STAT_SWPIN_FALLBACK_CHARGE);
42614262
folio_put(folio);
42624263
}
4264+
count_mthp_stat(order, MTHP_STAT_SWPIN_FALLBACK);
42634265
order = next_order(&orders, order);
42644266
}
42654267

0 commit comments

Comments
 (0)