mm: add per-order mTHP swap-in fallback/fallback_charge counters
Subsystems (5)
PATCH v3 1/1 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
---
V3:
Update description about swpin_fallback and swpin_fallback_charge
V2:
Introduce swapin_fallback_charge, which increments if it fails to charge a huge page to memory despite successful allocation.
Documentation/admin-guide/mm/transhuge.rst | 10 ++++++++++ include/linux/huge_mm.h | 2 ++ mm/huge_memory.c | 6 ++++++ mm/memory.c | 2 ++ 4 files changed, 20 insertions(+)
Documentation/admin-guide/mm/transhuge.rst +10 -0
@@ -591,6 +591,16 @@ swpin is incremented every time a huge page is swapped in from a non-zswap swap device in one piece. +swpin_fallback + is incremented if swapin fails to allocate or charge a huge page + and instead falls back to using huge pages with lower orders or + small pages. + +swpin_fallback_charge + is incremented if swapin fails to charge a huge page and instead + falls back to using huge pages with lower orders or small pages + even though the allocation was successful. + swpout is incremented every time a huge page is swapped out to a non-zswap swap device in one piece without splitting.
include/linux/huge_mm.h +2 -0
@@ -121,6 +121,8 @@ enum mthp_stat_item {MTHP_STAT_ANON_FAULT_FALLBACK_CHARGE ,MTHP_STAT_ZSWPOUT ,MTHP_STAT_SWPIN , +MTHP_STAT_SWPIN_FALLBACK , +MTHP_STAT_SWPIN_FALLBACK_CHARGE ,MTHP_STAT_SWPOUT ,MTHP_STAT_SWPOUT_FALLBACK , MTHP_STAT_SHMEM_ALLOC,
mm/huge_memory.c +6 -0
@@ -617,6 +617,8 @@ DEFINE_MTHP_STAT_ATTR(anon_fault_fallback, MTHP_STAT_ANON_FAULT_FALLBACK);DEFINE_MTHP_STAT_ATTR (anon_fault_fallback_charge,MTHP_STAT_ANON_FAULT_FALLBACK_CHARGE );DEFINE_MTHP_STAT_ATTR (zswpout,MTHP_STAT_ZSWPOUT );DEFINE_MTHP_STAT_ATTR (swpin,MTHP_STAT_SWPIN ); +DEFINE_MTHP_STAT_ATTR (swpin_fallback,MTHP_STAT_SWPIN_FALLBACK ); +DEFINE_MTHP_STAT_ATTR (swpin_fallback_charge,MTHP_STAT_SWPIN_FALLBACK_CHARGE );DEFINE_MTHP_STAT_ATTR (swpout,MTHP_STAT_SWPOUT );DEFINE_MTHP_STAT_ATTR (swpout_fallback,MTHP_STAT_SWPOUT_FALLBACK );#ifdef CONFIG_SHMEM
@@ -637,6 +639,8 @@ static struct attribute *anon_stats_attrs[] = {#ifndef CONFIG_SHMEM &zswpout_attr.attr, &swpin_attr.attr, + &swpin_fallback_attr.attr, + &swpin_fallback_charge_attr.attr, &swpout_attr.attr, &swpout_fallback_attr.attr, #endif
@@ -669,6 +673,8 @@ static struct attribute *any_stats_attrs[] = {#ifdef CONFIG_SHMEM &zswpout_attr.attr, &swpin_attr.attr, + &swpin_fallback_attr.attr, + &swpin_fallback_charge_attr.attr, &swpout_attr.attr, &swpout_fallback_attr.attr, #endif
mm/memory.c +2 -0
@@ -4189,8 +4189,10 @@ static struct folio *alloc_swap_folio(struct vm_fault *vmf)if (!mem_cgroup_swapin_charge_folio (folio, vma->vm_mm, gfp, entry))return folio; +count_mthp_stat (order,MTHP_STAT_SWPIN_FALLBACK_CHARGE );folio_put (folio); } +count_mthp_stat (order,MTHP_STAT_SWPIN_FALLBACK ); order =next_order (&orders, order); }
Signature · 1 line
2.45.0
Quoted 11 lines · Wenchao Hao
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 mTHPswpin_fallbackandswpin_fallback_chargecounters for calculating their success ratio. The new counters are located at:/sys/kernel/mm/transparent_hugepage/hugepages-<size>/stats/
swpin_fallback
swpin_fallback_chargeSigned-off-by Wenchao Hao <[email protected]>
LGTM, thanks!
Quoted 97 lines
---
V3:
Update description aboutswpin_fallbackandswpin_fallback_chargeV2:
Introduceswapin_fallback_charge, which increments if it fails to charge a huge page to memory despite successful allocation.Documentation/admin-guide/mm/transhuge.rst | 10 ++++++++++ include/linux/huge_mm.h | 2 ++ mm/huge_memory.c | 6 ++++++ mm/memory.c | 2 ++ 4 files changed, 20 insertions(+)Documentation/admin-guide/mm/transhuge.rst +10
-0@@ -591,6 +591,16 @@ swpin is incremented every time a huge page is swapped in from a non-zswap swap device in one piece. +swpin_fallback + is incremented if swapin fails to allocate or charge a huge page + and instead falls back to using huge pages with lower orders or + small pages. + +swpin_fallback_charge + is incremented if swapin fails to charge a huge page and instead + falls back to using huge pages with lower orders or small pages + even though the allocation was successful. + swpout is incremented every time a huge page is swapped out to a non-zswap swap device in one piece without splitting.include/linux/huge_mm.h +2
-0@@ -121,6 +121,8 @@ enum mthp_stat_item {MTHP_STAT_ANON_FAULT_FALLBACK_CHARGE ,MTHP_STAT_ZSWPOUT ,MTHP_STAT_SWPIN , +MTHP_STAT_SWPIN_FALLBACK , +MTHP_STAT_SWPIN_FALLBACK_CHARGE ,MTHP_STAT_SWPOUT ,MTHP_STAT_SWPOUT_FALLBACK , MTHP_STAT_SHMEM_ALLOC,mm/huge_memory.c +6
-0@@ -617,6 +617,8 @@ DEFINE_MTHP_STAT_ATTR(anon_fault_fallback, MTHP_STAT_ANON_FAULT_FALLBACK);DEFINE_MTHP_STAT_ATTR (anon_fault_fallback_charge,MTHP_STAT_ANON_FAULT_FALLBACK_CHARGE );DEFINE_MTHP_STAT_ATTR (zswpout,MTHP_STAT_ZSWPOUT );DEFINE_MTHP_STAT_ATTR (swpin,MTHP_STAT_SWPIN ); +DEFINE_MTHP_STAT_ATTR (swpin_fallback,MTHP_STAT_SWPIN_FALLBACK ); +DEFINE_MTHP_STAT_ATTR (swpin_fallback_charge,MTHP_STAT_SWPIN_FALLBACK_CHARGE );DEFINE_MTHP_STAT_ATTR (swpout,MTHP_STAT_SWPOUT );DEFINE_MTHP_STAT_ATTR (swpout_fallback,MTHP_STAT_SWPOUT_FALLBACK );#ifdef CONFIG_SHMEM @@ -637,6 +639,8 @@ static struct attribute *anon_stats_attrs[] = {#ifndef CONFIG_SHMEM &zswpout_attr.attr, &swpin_attr.attr, + &swpin_fallback_attr.attr, + &swpin_fallback_charge_attr.attr, &swpout_attr.attr, &swpout_fallback_attr.attr, #endif@@ -669,6 +673,8 @@ static struct attribute *any_stats_attrs[] = {#ifdef CONFIG_SHMEM &zswpout_attr.attr, &swpin_attr.attr, + &swpin_fallback_attr.attr, + &swpin_fallback_charge_attr.attr, &swpout_attr.attr, &swpout_fallback_attr.attr, #endifmm/memory.c +2
-1@@ -4189,8 +4189,10 @@ static struct folio *alloc_swap_folio(struct vm_fault *vmf)if (!mem_cgroup_swapin_charge_folio (folio, vma->vm_mm, gfp, entry))return folio; +count_mthp_stat (order,MTHP_STAT_SWPIN_FALLBACK_CHARGE );folio_put (folio); } +count_mthp_stat (order,MTHP_STAT_SWPIN_FALLBACK ); order =next_order (&orders, order); } --2.45.0
Quoted 11 lines · Wenchao Hao
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 mTHPswpin_fallbackandswpin_fallback_chargecounters for calculating their success ratio. The new counters are located at:/sys/kernel/mm/transparent_hugepage/hugepages-<size>/stats/
swpin_fallback
swpin_fallback_chargeSigned-off-by Wenchao Hao <[email protected]>
LGTM. Feel free to add:
Thanks,
Lance
Quoted 97 lines
---
V3:
Update description aboutswpin_fallbackandswpin_fallback_chargeV2:
Introduceswapin_fallback_charge, which increments if it fails to charge a huge page to memory despite successful allocation.Documentation/admin-guide/mm/transhuge.rst | 10 ++++++++++ include/linux/huge_mm.h | 2 ++ mm/huge_memory.c | 6 ++++++ mm/memory.c | 2 ++ 4 files changed, 20 insertions(+)Documentation/admin-guide/mm/transhuge.rst +10
-0@@ -591,6 +591,16 @@ swpin is incremented every time a huge page is swapped in from a non-zswap swap device in one piece. +swpin_fallback + is incremented if swapin fails to allocate or charge a huge page + and instead falls back to using huge pages with lower orders or + small pages. + +swpin_fallback_charge + is incremented if swapin fails to charge a huge page and instead + falls back to using huge pages with lower orders or small pages + even though the allocation was successful. + swpout is incremented every time a huge page is swapped out to a non-zswap swap device in one piece without splitting.include/linux/huge_mm.h +2
-0@@ -121,6 +121,8 @@ enum mthp_stat_item {MTHP_STAT_ANON_FAULT_FALLBACK_CHARGE ,MTHP_STAT_ZSWPOUT ,MTHP_STAT_SWPIN , +MTHP_STAT_SWPIN_FALLBACK , +MTHP_STAT_SWPIN_FALLBACK_CHARGE ,MTHP_STAT_SWPOUT ,MTHP_STAT_SWPOUT_FALLBACK , MTHP_STAT_SHMEM_ALLOC,mm/huge_memory.c +6
-0@@ -617,6 +617,8 @@ DEFINE_MTHP_STAT_ATTR(anon_fault_fallback, MTHP_STAT_ANON_FAULT_FALLBACK);DEFINE_MTHP_STAT_ATTR (anon_fault_fallback_charge,MTHP_STAT_ANON_FAULT_FALLBACK_CHARGE );DEFINE_MTHP_STAT_ATTR (zswpout,MTHP_STAT_ZSWPOUT );DEFINE_MTHP_STAT_ATTR (swpin,MTHP_STAT_SWPIN ); +DEFINE_MTHP_STAT_ATTR (swpin_fallback,MTHP_STAT_SWPIN_FALLBACK ); +DEFINE_MTHP_STAT_ATTR (swpin_fallback_charge,MTHP_STAT_SWPIN_FALLBACK_CHARGE );DEFINE_MTHP_STAT_ATTR (swpout,MTHP_STAT_SWPOUT );DEFINE_MTHP_STAT_ATTR (swpout_fallback,MTHP_STAT_SWPOUT_FALLBACK );#ifdef CONFIG_SHMEM @@ -637,6 +639,8 @@ static struct attribute *anon_stats_attrs[] = {#ifndef CONFIG_SHMEM &zswpout_attr.attr, &swpin_attr.attr, + &swpin_fallback_attr.attr, + &swpin_fallback_charge_attr.attr, &swpout_attr.attr, &swpout_fallback_attr.attr, #endif@@ -669,6 +673,8 @@ static struct attribute *any_stats_attrs[] = {#ifdef CONFIG_SHMEM &zswpout_attr.attr, &swpin_attr.attr, + &swpin_fallback_attr.attr, + &swpin_fallback_charge_attr.attr, &swpout_attr.attr, &swpout_fallback_attr.attr, #endifmm/memory.c +2
-1@@ -4189,8 +4189,10 @@ static struct folio *alloc_swap_folio(struct vm_fault *vmf)if (!mem_cgroup_swapin_charge_folio (folio, vma->vm_mm, gfp, entry))return folio; +count_mthp_stat (order,MTHP_STAT_SWPIN_FALLBACK_CHARGE );folio_put (folio); } +count_mthp_stat (order,MTHP_STAT_SWPIN_FALLBACK ); order =next_order (&orders, order); } --2.45.0