Skip to contentSkip to conversation

mm: add per-order mTHP swap-in fallback/fallback_charge counters

PATCH Superseded Wenchao Hao 4 participants 11 messages Nov 22, 2024 – Nov 30, 2024

Subsystems (5)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 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

---
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
index 5034915f4e8e..9c07612281b5 100644
@@ -561,6 +561,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 a huge page 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 a page 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
index b94c2e8ee918..93e509b6c00e 100644
@@ -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
index ee335d96fc39..46749dded1c9 100644
@@ -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
index 209885a4134f..774dfd309cfe 100644
@@ -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
#1 lore raw

Hi Wenchao,

Quoted 27 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 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

---
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 +0 -0
index 5034915f4e8e..9c07612281b5 100644

Documentation/admin-guide/mm/transhuge.rst swpin · line 563

Quoted 3 lines
Documentation/admin-guide/mm/transhuge.rst +0 -0
@@ -561,6 +561,16 @@ swpin
        is incremented every time a huge page is swapped in from a non-zswap
        swap device in one piece.
 

Would the following be better?

+swpin_fallback
+ is incremented if a huge page swapin fails to allocate or charge
+ it and instead falls back to using small pages.

+swpin_fallback_charge

+       is incremented if a huge page swapin fails to charge it and instead
+       falls back to using small pages even though the allocation was
+       successful.

Thanks,
Lance

Quoted 75 lines
Documentation/admin-guide/mm/transhuge.rst +10 -0
+swpin_fallback
+       is incremented if a huge page 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 a page 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
index b94c2e8ee918..93e509b6c00e 100644
@@ -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
index ee335d96fc39..46749dded1c9 100644
@@ -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 -1
index 209885a4134f..774dfd309cfe 100644
@@ -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

reviewer
#2 lore raw
Quoted 37 lines · Lance Yang

Hi Wenchao,

Quoted 27 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 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

---
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 +0 -0
index 5034915f4e8e..9c07612281b5 100644

Documentation/admin-guide/mm/transhuge.rst swpin · line 563

Quoted 3 lines
Documentation/admin-guide/mm/transhuge.rst +0 -0
@@ -561,6 +561,16 @@ swpin
        is incremented every time a huge page is swapped in from a non-zswap
        swap device in one piece.
 

Would the following be better?

Review

Quoted 8 lines
(quoted diff) +7 -0
+swpin_fallback
+       is incremented if a huge page swapin fails to allocate or charge
+       it and instead falls back to using small pages.
 
+swpin_fallback_charge
+       is incremented if a huge page swapin fails to charge it and instead
+       falls back to using small pages even though the allocation was
+       successful.

much better, but it is better to align with "huge pages with lower orders or small pages."

anon_fault_fallback
is incremented if a page fault fails to allocate or charge a huge page and instead falls back to using huge pages with lower orders or small pages.

anon_fault_fallback_charge
is incremented if a page fault 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.

Quoted 76 lines

Thanks,
Lance

Quoted 72 lines
Documentation/admin-guide/mm/transhuge.rst +10 -0
+swpin_fallback
+       is incremented if a huge page 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 a page 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
index b94c2e8ee918..93e509b6c00e 100644
@@ -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
index ee335d96fc39..46749dded1c9 100644
@@ -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
index 209885a4134f..774dfd309cfe 100644
@@ -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);
        }
 
Quoted 3 lines
Quoted 3 lines

--
2.45.0

Thanks
Barry

#3 lore raw
In reply to Lance Yang
Quoted 37 lines · Lance Yang

Hi Wenchao,

Quoted 27 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 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

---
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 +0 -0
index 5034915f4e8e..9c07612281b5 100644

Documentation/admin-guide/mm/transhuge.rst swpin · line 563

Quoted 3 lines
Documentation/admin-guide/mm/transhuge.rst +0 -0
@@ -561,6 +561,16 @@ swpin
        is incremented every time a huge page is swapped in from a non-zswap
        swap device in one piece.
 

Would the following be better?

Review

Quoted 8 lines
(quoted diff) +7 -0
+swpin_fallback
+       is incremented if a huge page swapin fails to allocate or charge
+       it and instead falls back to using small pages.
 
+swpin_fallback_charge
+       is incremented if a huge page swapin fails to charge it and instead
+       falls back to using small pages even though the allocation was
+       successful.

much better, but it is better to align with "huge pages with lower orders or small pages", not necessarily small pages:

anon_fault_fallback
is incremented if a page fault fails to allocate or charge a huge page and instead falls back to using huge pages with lower orders or small pages.

anon_fault_fallback_charge
is incremented if a page fault 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.

Quoted 76 lines

Thanks,
Lance

Quoted 72 lines
Documentation/admin-guide/mm/transhuge.rst +10 -0
+swpin_fallback
+       is incremented if a huge page 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 a page 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
index b94c2e8ee918..93e509b6c00e 100644
@@ -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
index ee335d96fc39..46749dded1c9 100644
@@ -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
index 209885a4134f..774dfd309cfe 100644
@@ -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);
        }
 
Quoted 3 lines
Quoted 3 lines

--
2.45.0

Thanks
Barry

#4 lore raw
Quoted 56 lines · Barry Song
Quoted 37 lines · Lance Yang

Hi Wenchao,

Quoted 27 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 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

---
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 +0 -0
index 5034915f4e8e..9c07612281b5 100644

Documentation/admin-guide/mm/transhuge.rst swpin · line 563

Quoted 3 lines
Documentation/admin-guide/mm/transhuge.rst +0 -0
@@ -561,6 +561,16 @@ swpin
        is incremented every time a huge page is swapped in from a non-zswap
        swap device in one piece.
 

Would the following be better?

Review

Quoted 8 lines
(quoted diff) +7 -0
+swpin_fallback
+       is incremented if a huge page swapin fails to allocate or charge
+       it and instead falls back to using small pages.
 
+swpin_fallback_charge
+       is incremented if a huge page swapin fails to charge it and instead
+       falls back to using small pages even though the allocation was
+       successful.

much better, but it is better to align with "huge pages with lower orders or small pages", not necessarily small pages:

anon_fault_fallback
is incremented if a page fault fails to allocate or charge a huge page and instead falls back to using huge pages with lower orders or small pages.

Quoted 4 lines

anon_fault_fallback_charge
is incremented if a page fault 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.

Right, I clearly overlooked that ;)

Thanks,
Lance

Quoted 83 lines
Quoted 77 lines

Thanks,
Lance

Quoted 72 lines
Documentation/admin-guide/mm/transhuge.rst +10 -0
+swpin_fallback
+       is incremented if a huge page 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 a page 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
index b94c2e8ee918..93e509b6c00e 100644
@@ -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
index ee335d96fc39..46749dded1c9 100644
@@ -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
index 209885a4134f..774dfd309cfe 100644
@@ -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);
        }
 
Quoted 3 lines
Quoted 3 lines

--
2.45.0

Thanks
Barry

#5 lore raw
Quoted 57 lines · Lance Yang
Quoted 56 lines · Barry Song
Quoted 37 lines · Lance Yang

Hi Wenchao,

Quoted 27 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 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

---
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 +0 -0
index 5034915f4e8e..9c07612281b5 100644

Documentation/admin-guide/mm/transhuge.rst swpin · line 563

Quoted 3 lines
Documentation/admin-guide/mm/transhuge.rst +0 -0
@@ -561,6 +561,16 @@ swpin
        is incremented every time a huge page is swapped in from a non-zswap
        swap device in one piece.
 

Would the following be better?

Review

Quoted 8 lines
(quoted diff) +7 -0
+swpin_fallback
+       is incremented if a huge page swapin fails to allocate or charge
+       it and instead falls back to using small pages.
 
+swpin_fallback_charge
+       is incremented if a huge page swapin fails to charge it and instead
+       falls back to using small pages even though the allocation was
+       successful.

much better, but it is better to align with "huge pages with lower orders or small pages", not necessarily small pages:

anon_fault_fallback
is incremented if a page fault fails to allocate or charge a huge page and instead falls back to using huge pages with lower orders or small pages.

Quoted 7 lines
Quoted 4 lines

anon_fault_fallback_charge
is incremented if a page fault 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.

Right, I clearly overlooked that ;)

Hi Lance and Barry,

Do you think the following expression is clear? Compared to my original version, I’ve removed the word “huge” from the first line, and it now looks almost identical to anon_fault_fallback/anon_fault_fallback_charge.

swpin_fallback
is incremented if a page 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 a page 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.

Thanks,
Wencaho

Quoted 86 lines

Thanks,
Lance

Quoted 83 lines
Quoted 77 lines

Thanks,
Lance

Quoted 72 lines
Documentation/admin-guide/mm/transhuge.rst +10 -0
+swpin_fallback
+       is incremented if a huge page 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 a page 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
index b94c2e8ee918..93e509b6c00e 100644
@@ -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
index ee335d96fc39..46749dded1c9 100644
@@ -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
index 209885a4134f..774dfd309cfe 100644
@@ -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);
        }
 
Quoted 3 lines
Quoted 3 lines

--
2.45.0

Thanks
Barry

#6 lore raw
Quoted 64 lines · Wenchao Hao
Quoted 62 lines · Lance Yang
Quoted 60 lines · Barry Song
Quoted 37 lines · Lance Yang

Hi Wenchao,

Quoted 27 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 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

---
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 +0 -0
index 5034915f4e8e..9c07612281b5 100644

Documentation/admin-guide/mm/transhuge.rst swpin · line 563

Quoted 3 lines
Documentation/admin-guide/mm/transhuge.rst +0 -0
@@ -561,6 +561,16 @@ swpin
        is incremented every time a huge page is swapped in from a non-zswap
        swap device in one piece.
 

Would the following be better?

Review

Quoted 8 lines
(quoted diff) +7 -0
+swpin_fallback
+       is incremented if a huge page swapin fails to allocate or charge
+       it and instead falls back to using small pages.
 
+swpin_fallback_charge
+       is incremented if a huge page swapin fails to charge it and instead
+       falls back to using small pages even though the allocation was
+       successful.

much better, but it is better to align with "huge pages with lower orders or small pages", not necessarily small pages:

anon_fault_fallback
is incremented if a page fault fails to allocate or charge a huge page and instead falls back to using huge pages with lower orders or small pages.

anon_fault_fallback_charge
is incremented if a page fault 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.

Quoted 8 lines
Quoted 2 lines

Right, I clearly overlooked that ;)

Hi Lance and Barry,

Do you think the following expression is clear? Compared to my original version, I’ve removed the word “huge” from the first line, and it now looks almost identical to anon_fault_fallback/anon_fault_fallback_charge.

Well, that's fine with me. And let's see Barry's opinion as well ;)

Thanks,
Lance

Quoted 101 lines

swpin_fallback
is incremented if a page 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 a page 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.

Thanks,
Wencaho

Quoted 86 lines

Thanks,
Lance

Quoted 83 lines
Quoted 77 lines

Thanks,
Lance

Quoted 72 lines
Documentation/admin-guide/mm/transhuge.rst +10 -0
+swpin_fallback
+       is incremented if a huge page 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 a page 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
index b94c2e8ee918..93e509b6c00e 100644
@@ -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
index ee335d96fc39..46749dded1c9 100644
@@ -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
index 209885a4134f..774dfd309cfe 100644
@@ -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);
        }
 
Quoted 3 lines
Quoted 3 lines

--
2.45.0

Thanks
Barry

#7 lore raw
Quoted 69 lines · Lance Yang
Quoted 67 lines · Wenchao Hao
Quoted 64 lines · Lance Yang
Quoted 56 lines · Barry Song
Quoted 37 lines · Lance Yang

Hi Wenchao,

Quoted 27 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 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

---
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 +0 -0
index 5034915f4e8e..9c07612281b5 100644

Documentation/admin-guide/mm/transhuge.rst swpin · line 563

Quoted 3 lines
Documentation/admin-guide/mm/transhuge.rst +0 -0
@@ -561,6 +561,16 @@ swpin
        is incremented every time a huge page is swapped in from a non-zswap
        swap device in one piece.
 

Would the following be better?

Review

Quoted 8 lines
(quoted diff) +7 -0
+swpin_fallback
+       is incremented if a huge page swapin fails to allocate or charge
+       it and instead falls back to using small pages.
 
+swpin_fallback_charge
+       is incremented if a huge page swapin fails to charge it and instead
+       falls back to using small pages even though the allocation was
+       successful.

much better, but it is better to align with "huge pages with lower orders or small pages", not necessarily small pages:

anon_fault_fallback
is incremented if a page fault fails to allocate or charge a huge page and instead falls back to using huge pages with lower orders or small pages.

Quoted 4 lines

anon_fault_fallback_charge
is incremented if a page fault 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.

Right, I clearly overlooked that ;)

Quoted 7 lines
Quoted 5 lines

Hi Lance and Barry,

Do you think the following expression is clear? Compared to my original version, I’ve removed the word “huge” from the first line, and it now looks almost identical to anon_fault_fallback/anon_fault_fallback_charge.

Well, that's fine with me. And let's see Barry's opinion as well ;)

I still prefer Lance's version. The fallback path in it only needs to be adjusted to
include huge pages with lower orders. In contrast, Wenchao's version feels less natural to me because "page swapin" sounds quite odd - we often hear "page fault,"
but we have never encountered "page swapin."

So I mean:

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.

Quoted 102 lines

Thanks,
Lance

Quoted 98 lines

swpin_fallback
is incremented if a page 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 a page 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.

Thanks,
Wencaho

Quoted 84 lines

Thanks,
Lance

Quoted 81 lines
Quoted 80 lines

Thanks,
Lance

Quoted 75 lines
Documentation/admin-guide/mm/transhuge.rst +10 -0
+swpin_fallback
+       is incremented if a huge page 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 a page 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
index b94c2e8ee918..93e509b6c00e 100644
@@ -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
index ee335d96fc39..46749dded1c9 100644
@@ -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 -1
index 209885a4134f..774dfd309cfe 100644
@@ -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

Thanks
Barry

#8 lore raw
Quoted 77 lines · Barry Song
Quoted 75 lines · Lance Yang
Quoted 72 lines · Wenchao Hao
Quoted 57 lines · Lance Yang
Quoted 56 lines · Barry Song
Quoted 37 lines · Lance Yang

Hi Wenchao,

Quoted 27 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 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

---
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 +0 -0
index 5034915f4e8e..9c07612281b5 100644

Documentation/admin-guide/mm/transhuge.rst swpin · line 563

Quoted 3 lines
Documentation/admin-guide/mm/transhuge.rst +0 -0
@@ -561,6 +561,16 @@ swpin
        is incremented every time a huge page is swapped in from a non-zswap
        swap device in one piece.
 

Would the following be better?

Review

Quoted 8 lines
(quoted diff) +7 -0
+swpin_fallback
+       is incremented if a huge page swapin fails to allocate or charge
+       it and instead falls back to using small pages.
 
+swpin_fallback_charge
+       is incremented if a huge page swapin fails to charge it and instead
+       falls back to using small pages even though the allocation was
+       successful.

much better, but it is better to align with "huge pages with lower orders or small pages", not necessarily small pages:

anon_fault_fallback
is incremented if a page fault fails to allocate or charge a huge page and instead falls back to using huge pages with lower orders or small pages.

Quoted 7 lines
Quoted 4 lines

anon_fault_fallback_charge
is incremented if a page fault 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.

Right, I clearly overlooked that ;)

Hi Lance and Barry,

Do you think the following expression is clear? Compared to my original version, I’ve removed the word “huge” from the first line, and it now looks almost identical to anon_fault_fallback/anon_fault_fallback_charge.

Quoted 8 lines
Quoted 1 line

Well, that's fine with me. And let's see Barry's opinion as well ;)

I still prefer Lance's version. The fallback path in it only needs to be adjusted to
include huge pages with lower orders. In contrast, Wenchao's version feels less natural to me because "page swapin" sounds quite odd - we often hear "page fault,"
but we have never encountered "page swapin."

Yeah, it makes sense to me ~

Quoted 8 lines

So I mean:

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.

Quoted 5 lines

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.

IHMO, much better and clearer than before ;)

Thank,
Lance

Quoted 106 lines
Quoted 103 lines

Thanks,
Lance

Quoted 98 lines

swpin_fallback
is incremented if a page 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 a page 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.

Thanks,
Wencaho

Quoted 84 lines

Thanks,
Lance

Quoted 81 lines
Quoted 80 lines

Thanks,
Lance

Quoted 75 lines
Documentation/admin-guide/mm/transhuge.rst +10 -0
+swpin_fallback
+       is incremented if a huge page 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 a page 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
index b94c2e8ee918..93e509b6c00e 100644
@@ -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
index ee335d96fc39..46749dded1c9 100644
@@ -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 -1
index 209885a4134f..774dfd309cfe 100644
@@ -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

Thanks
Barry

#9 lore raw
Quoted 97 lines · Lance Yang
Quoted 77 lines · Barry Song
Quoted 75 lines · Lance Yang
Quoted 72 lines · Wenchao Hao
Quoted 57 lines · Lance Yang
Quoted 56 lines · Barry Song
Quoted 37 lines · Lance Yang

Hi Wenchao,

Quoted 27 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 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

---
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 +0 -0
index 5034915f4e8e..9c07612281b5 100644

Documentation/admin-guide/mm/transhuge.rst swpin · line 563

Quoted 3 lines
Documentation/admin-guide/mm/transhuge.rst +0 -0
@@ -561,6 +561,16 @@ swpin
        is incremented every time a huge page is swapped in from a non-zswap
        swap device in one piece.
 

Would the following be better?

Review

Quoted 8 lines
(quoted diff) +7 -0
+swpin_fallback
+       is incremented if a huge page swapin fails to allocate or charge
+       it and instead falls back to using small pages.
 
+swpin_fallback_charge
+       is incremented if a huge page swapin fails to charge it and instead
+       falls back to using small pages even though the allocation was
+       successful.

much better, but it is better to align with "huge pages with lower orders or small pages", not necessarily small pages:

anon_fault_fallback
is incremented if a page fault fails to allocate or charge a huge page and instead falls back to using huge pages with lower orders or small pages.

Quoted 7 lines
Quoted 4 lines

anon_fault_fallback_charge
is incremented if a page fault 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.

Right, I clearly overlooked that ;)

Hi Lance and Barry,

Do you think the following expression is clear? Compared to my original version, I’ve removed the word “huge” from the first line, and it now looks almost identical to anon_fault_fallback/anon_fault_fallback_charge.

Quoted 8 lines
Quoted 1 line

Well, that's fine with me. And let's see Barry's opinion as well ;)

I still prefer Lance's version. The fallback path in it only needs to be adjusted to
include huge pages with lower orders. In contrast, Wenchao's version feels less natural to me because "page swapin" sounds quite odd - we often hear "page fault,"
but we have never encountered "page swapin."

Yeah, it makes sense to me ~

Quoted 8 lines

So I mean:

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.

Quoted 8 lines
Quoted 5 lines

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.

IHMO, much better and clearer than before ;)

Hi,

Thank you both very much for your valuable suggestions. I am only now able to respond to your emails due to a network issue.

I will make the revisions based on your feedback and send the third version of the patch.

Should I include a "Reviewed-by" or any other tags?

Thanks again,
Wenchao

Quoted 109 lines

Thank,
Lance

Quoted 106 lines
Quoted 103 lines

Thanks,
Lance

Quoted 98 lines

swpin_fallback
is incremented if a page 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 a page 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.

Thanks,
Wencaho

Quoted 84 lines

Thanks,
Lance

Quoted 81 lines
Quoted 80 lines

Thanks,
Lance

Quoted 75 lines
Documentation/admin-guide/mm/transhuge.rst +10 -0
+swpin_fallback
+       is incremented if a huge page 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 a page 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
index b94c2e8ee918..93e509b6c00e 100644
@@ -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
index ee335d96fc39..46749dded1c9 100644
@@ -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 -1
index 209885a4134f..774dfd309cfe 100644
@@ -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

Thanks
Barry

#10 lore raw
Quoted 108 lines · Wenchao Hao
Quoted 97 lines · Lance Yang
Quoted 77 lines · Barry Song
Quoted 75 lines · Lance Yang
Quoted 72 lines · Wenchao Hao
Quoted 57 lines · Lance Yang
Quoted 56 lines · Barry Song
Quoted 37 lines · Lance Yang

Hi Wenchao,

Quoted 27 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 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

---
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 +0 -0
index 5034915f4e8e..9c07612281b5 100644

Documentation/admin-guide/mm/transhuge.rst swpin · line 563

Quoted 3 lines
Documentation/admin-guide/mm/transhuge.rst +0 -0
@@ -561,6 +561,16 @@ swpin
        is incremented every time a huge page is swapped in from a non-zswap
        swap device in one piece.
 

Would the following be better?

Review

Quoted 8 lines
(quoted diff) +7 -0
+swpin_fallback
+       is incremented if a huge page swapin fails to allocate or charge
+       it and instead falls back to using small pages.
 
+swpin_fallback_charge
+       is incremented if a huge page swapin fails to charge it and instead
+       falls back to using small pages even though the allocation was
+       successful.

much better, but it is better to align with "huge pages with lower orders or small pages", not necessarily small pages:

anon_fault_fallback
is incremented if a page fault fails to allocate or charge a huge page and instead falls back to using huge pages with lower orders or small pages.

Quoted 7 lines
Quoted 4 lines

anon_fault_fallback_charge
is incremented if a page fault 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.

Right, I clearly overlooked that ;)

Hi Lance and Barry,

Do you think the following expression is clear? Compared to my original version, I’ve removed the word “huge” from the first line, and it now looks almost identical to anon_fault_fallback/anon_fault_fallback_charge.

Quoted 8 lines
Quoted 1 line

Well, that's fine with me. And let's see Barry's opinion as well ;)

I still prefer Lance's version. The fallback path in it only needs to be adjusted to
include huge pages with lower orders. In contrast, Wenchao's version feels less natural to me because "page swapin" sounds quite odd - we often hear "page fault,"
but we have never encountered "page swapin."

Yeah, it makes sense to me ~

Quoted 8 lines

So I mean:

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.

Quoted 8 lines
Quoted 5 lines

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.

IHMO, much better and clearer than before ;)

Quoted 7 lines

Hi,

Thank you both very much for your valuable suggestions. I am only now able to respond to your emails due to a network issue.

I will make the revisions based on your feedback and send the third version of the patch.

Thanks for following up.

Quoted 2 lines

Should I include a "Reviewed-by" or any other tags?

Seems like there is no RB yet. I think we just tweak the doc as Barry suggested, resend out the new version, and then wait for the folks to review it ;)

Thanks,
Lance

Quoted 115 lines

Thanks again,
Wenchao

Quoted 109 lines

Thank,
Lance

Quoted 106 lines
Quoted 103 lines

Thanks,
Lance

Quoted 98 lines

swpin_fallback
is incremented if a page 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 a page 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.

Thanks,
Wencaho

Quoted 84 lines

Thanks,
Lance

Quoted 81 lines
Quoted 80 lines

Thanks,
Lance

Quoted 75 lines
Documentation/admin-guide/mm/transhuge.rst +10 -0
+swpin_fallback
+       is incremented if a huge page 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 a page 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
index b94c2e8ee918..93e509b6c00e 100644
@@ -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
index ee335d96fc39..46749dded1c9 100644
@@ -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 -1
index 209885a4134f..774dfd309cfe 100644
@@ -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

Thanks
Barry