Skip to contentSkip to conversation

memory tiering: read last_cpupid correctly in do_huge_pmd_numa_page()

PATCH Superseded Zi Yan 5 participants 13 messages Jul 22, 2024 – Jul 24, 2024

Subsystems (7)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Zi Yan

author reviewer
#0 lore raw

PATCH v2 1/3 memory tiering: read last_cpupid correctly in do_huge_pmd_numa_page()

last_cpupid is only available when memory tiering is off or the folio is in toptier node. Complete the check to read last_cpupid when it is available.

Before the fix, the default last_cpupid will be used even if memory tiering mode is turned off at runtime instead of the actual value. This can prevent task_numa_fault() from getting right numa fault stats, but should not cause any crash. User might see performance changes after the fix.

---
 mm/huge_memory.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
mm/huge_memory.c +2 -1
index f4be468e06a4..825317aee88e 100644
@@ -1712,7 +1712,8 @@ vm_fault_t do_huge_pmd_numa_page(struct vm_fault *vmf)
 	 * For memory tiering mode, cpupid of slow memory page is used
 	 * to record page access time.  So use default value.
 	 */
-	if (node_is_toptier(nid))
+	if (!(sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING) ||
+	    node_is_toptier(nid))
 		last_cpupid = folio_last_cpupid(folio);
 	target_nid = numa_migrate_prep(folio, vmf, haddr, nid, &flags);
 	if (target_nid == NUMA_NO_NODE)
Signature · 1 line
2.43.0
author reviewer
#1 lore raw

PATCH v2 2/3 memory tiering: introduce folio_has_cpupid() check

Instead of open coded check for if memory tiering mode is on and a folio is in the top tier memory, use a function to encapsulate the check.

---
 include/linux/mm.h  |  6 ++++++
 kernel/sched/fair.c |  3 +--
 mm/huge_memory.c    |  6 ++----
 mm/memory-tiers.c   | 17 +++++++++++++++++
 mm/memory.c         |  3 +--
 mm/mprotect.c       |  3 +--
 6 files changed, 28 insertions(+), 10 deletions(-)
include/linux/mm.h +6 -0
index c227f22ba810..048b2a56d8a3 100644
@@ -1738,6 +1738,8 @@ static inline void vma_set_access_pid_bit(struct vm_area_struct *vma)
 		__set_bit(pid_bit, &vma->numab_state->pids_active[1]);
 	}
 }
+
+bool folio_has_cpupid(struct folio *folio);
 #else /* !CONFIG_NUMA_BALANCING */
 static inline int folio_xchg_last_cpupid(struct folio *folio, int cpupid)
 {
@@ -1791,6 +1793,10 @@ static inline bool cpupid_match_pid(struct task_struct *task, int cpupid)
 static inline void vma_set_access_pid_bit(struct vm_area_struct *vma)
 {
 }
+static inline bool folio_has_cpupid(struct folio *folio)
+{
+	return true;
+}
 #endif /* CONFIG_NUMA_BALANCING */
 
 #if defined(CONFIG_KASAN_SW_TAGS) || defined(CONFIG_KASAN_HW_TAGS)
kernel/sched/fair.c +1 -2
index 8a5b1ae0aa55..03de808cb3cc 100644
@@ -1840,8 +1840,7 @@ bool should_numa_migrate_memory(struct task_struct *p, struct folio *folio,
 	 * The pages in slow memory node should be migrated according
 	 * to hot/cold instead of private/shared.
 	 */
-	if (sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING &&
-	    !node_is_toptier(src_nid)) {
+	if (!folio_has_cpupid(folio)) {
 		struct pglist_data *pgdat;
 		unsigned long rate_limit;
 		unsigned int latency, th, def_th;
mm/huge_memory.c +2 -4
index 825317aee88e..d925a93bb9ed 100644
@@ -1712,8 +1712,7 @@ vm_fault_t do_huge_pmd_numa_page(struct vm_fault *vmf)
 	 * For memory tiering mode, cpupid of slow memory page is used
 	 * to record page access time.  So use default value.
 	 */
-	if (!(sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING) ||
-	    node_is_toptier(nid))
+	if (folio_has_cpupid(folio))
 		last_cpupid = folio_last_cpupid(folio);
 	target_nid = numa_migrate_prep(folio, vmf, haddr, nid, &flags);
 	if (target_nid == NUMA_NO_NODE)
@@ -2066,8 +2065,7 @@ int change_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma,
 		    toptier)
 			goto unlock;
 
-		if (sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING &&
-		    !toptier)
+		if (!folio_has_cpupid(folio))
 			folio_xchg_access_time(folio,
 					       jiffies_to_msecs(jiffies));
 	}
mm/memory-tiers.c +17 -0
index 4775b3a3dabe..7f0360d4e3a0 100644
@@ -6,6 +6,7 @@
 #include <linux/memory.h>
 #include <linux/memory-tiers.h>
 #include <linux/notifier.h>
+#include <linux/sched/sysctl.h>
 
 #include "internal.h"
 
@@ -50,6 +51,22 @@ static const struct bus_type memory_tier_subsys = {
 	.dev_name = "memory_tier",
 };
 
+/**
+ * folio_has_cpupid - check if a folio has cpupid information
+ * @folio: folio to check
+ *
+ * folio's _last_cpupid field is repurposed by memory tiering. In memory
+ * tiering mode, cpupid of slow memory folio (not toptier memory) is used to
+ * record page access time.
+ *
+ * Return: the folio _last_cpupid is used as cpupid
+ */
+bool folio_has_cpupid(struct folio *folio)
+{
+	return !(sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING) ||
+	       node_is_toptier(folio_nid(folio));
+}
+
 #ifdef CONFIG_MIGRATION
 static int top_tier_adistance;
 /*
mm/memory.c +1 -2
index 802d0d8a40f9..105e1a0157dd 100644
@@ -5337,8 +5337,7 @@ static vm_fault_t do_numa_page(struct vm_fault *vmf)
 	 * For memory tiering mode, cpupid of slow memory page is used
 	 * to record page access time.  So use default value.
 	 */
-	if ((sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING) &&
-	    !node_is_toptier(nid))
+	if (!folio_has_cpupid(folio))
 		last_cpupid = (-1 & LAST_CPUPID_MASK);
 	else
 		last_cpupid = folio_last_cpupid(folio);
mm/mprotect.c +1 -2
index 222ab434da54..787c3c2bf1b6 100644
@@ -161,8 +161,7 @@ static long change_pte_range(struct mmu_gather *tlb,
 				if (!(sysctl_numa_balancing_mode & NUMA_BALANCING_NORMAL) &&
 				    toptier)
 					continue;
-				if (sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING &&
-				    !toptier)
+				if (!folio_has_cpupid(folio))
 					folio_xchg_access_time(folio,
 						jiffies_to_msecs(jiffies));
 			}
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH v2 2/3] memory tiering: introduce folio_has_cpupid() check

Quoted 98 lines · Zi Yan

Instead of open coded check for if memory tiering mode is on and a folio is in the top tier memory, use a function to encapsulate the check.

---
 include/linux/mm.h  |  6 ++++++
 kernel/sched/fair.c |  3 +--
 mm/huge_memory.c    |  6 ++----
 mm/memory-tiers.c   | 17 +++++++++++++++++
 mm/memory.c         |  3 +--
 mm/mprotect.c       |  3 +--
 6 files changed, 28 insertions(+), 10 deletions(-)
include/linux/mm.h +6 -0
index c227f22ba810..048b2a56d8a3 100644
@@ -1738,6 +1738,8 @@ static inline void vma_set_access_pid_bit(struct vm_area_struct *vma)
 		__set_bit(pid_bit, &vma->numab_state->pids_active[1]);
 	}
 }
+
+bool folio_has_cpupid(struct folio *folio);
 #else /* !CONFIG_NUMA_BALANCING */
 static inline int folio_xchg_last_cpupid(struct folio *folio, int cpupid)
 {
@@ -1791,6 +1793,10 @@ static inline bool cpupid_match_pid(struct task_struct *task, int cpupid)
 static inline void vma_set_access_pid_bit(struct vm_area_struct *vma)
 {
 }
+static inline bool folio_has_cpupid(struct folio *folio)
+{
+	return true;
+}
 #endif /* CONFIG_NUMA_BALANCING */
 
 #if defined(CONFIG_KASAN_SW_TAGS) || defined(CONFIG_KASAN_HW_TAGS)
kernel/sched/fair.c +1 -2
index 8a5b1ae0aa55..03de808cb3cc 100644
@@ -1840,8 +1840,7 @@ bool should_numa_migrate_memory(struct task_struct *p, struct folio *folio,
 	 * The pages in slow memory node should be migrated according
 	 * to hot/cold instead of private/shared.
 	 */
-	if (sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING &&
-	    !node_is_toptier(src_nid)) {
+	if (!folio_has_cpupid(folio)) {
 		struct pglist_data *pgdat;
 		unsigned long rate_limit;
 		unsigned int latency, th, def_th;
mm/huge_memory.c +2 -4
index 825317aee88e..d925a93bb9ed 100644
@@ -1712,8 +1712,7 @@ vm_fault_t do_huge_pmd_numa_page(struct vm_fault *vmf)
 	 * For memory tiering mode, cpupid of slow memory page is used
 	 * to record page access time.  So use default value.
 	 */
-	if (!(sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING) ||
-	    node_is_toptier(nid))
+	if (folio_has_cpupid(folio))
 		last_cpupid = folio_last_cpupid(folio);
 	target_nid = numa_migrate_prep(folio, vmf, haddr, nid, &flags);
 	if (target_nid == NUMA_NO_NODE)
@@ -2066,8 +2065,7 @@ int change_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma,
 		    toptier)
 			goto unlock;
 
-		if (sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING &&
-		    !toptier)
+		if (!folio_has_cpupid(folio))
 			folio_xchg_access_time(folio,
 					       jiffies_to_msecs(jiffies));
 	}
mm/memory-tiers.c +7 -0
index 4775b3a3dabe..7f0360d4e3a0 100644
@@ -6,6 +6,7 @@
 #include <linux/memory.h>
 #include <linux/memory-tiers.h>
 #include <linux/notifier.h>
+#include <linux/sched/sysctl.h>
 
 #include "internal.h"
 
@@ -50,6 +51,22 @@ static const struct bus_type memory_tier_subsys = {
 	.dev_name = "memory_tier",
 };
 
+/**
+ * folio_has_cpupid - check if a folio has cpupid information
+ * @folio: folio to check
+ *
+ * folio's _last_cpupid field is repurposed by memory tiering. In memory
+ * tiering mode, cpupid of slow memory folio (not toptier memory) is used to

mm/memory-tiers.c static const struct bus_type memory_tier_subsys = { · line 69

Quoted 10 lines
mm/memory-tiers.c +10 -0
+ * record page access time.
+ *
+ * Return: the folio _last_cpupid is used as cpupid
+ */
+bool folio_has_cpupid(struct folio *folio)
+{
+	return !(sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING) ||
+	       node_is_toptier(folio_nid(folio));
+}
+

The static version of folio_has_cpupid() is defined in include/linux/mm.h if !CONFIG_NUMA_BALANCING but you define the function in memory-tiers.c unconditionally, a file that is compiled predicated on CONFIG_NUMA.

So a config with !CONFIG_NUMA_BALANCING but CONFIG_NUMA set results in a compilation error (I just hit it this morning in mm-unstable).

A minimal fix for this is to wrap the declaration in:

#ifdef CONFIG_NUMA_BALANCING
...
#endif

I've tried this locally and it resolves the issue.

Quoted 34 lines
mm/memory-tiers.c +0 -0
 #ifdef CONFIG_MIGRATION
 static int top_tier_adistance;
 /*
mm/memory.c +1 -2
index 802d0d8a40f9..105e1a0157dd 100644
@@ -5337,8 +5337,7 @@ static vm_fault_t do_numa_page(struct vm_fault *vmf)
 	 * For memory tiering mode, cpupid of slow memory page is used
 	 * to record page access time.  So use default value.
 	 */
-	if ((sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING) &&
-	    !node_is_toptier(nid))
+	if (!folio_has_cpupid(folio))
 		last_cpupid = (-1 & LAST_CPUPID_MASK);
 	else
 		last_cpupid = folio_last_cpupid(folio);
mm/mprotect.c +1 -3
index 222ab434da54..787c3c2bf1b6 100644
@@ -161,8 +161,7 @@ static long change_pte_range(struct mmu_gather *tlb,
 				if (!(sysctl_numa_balancing_mode & NUMA_BALANCING_NORMAL) &&
 				    toptier)
 					continue;
-				if (sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING &&
-				    !toptier)
+				if (!folio_has_cpupid(folio))
 					folio_xchg_access_time(folio,
 						jiffies_to_msecs(jiffies));
 			}
--

2.43.0

#3 lore raw

Re: [PATCH v2 2/3] memory tiering: introduce folio_has_cpupid() check

Quoted 8 lines

The static version of folio_has_cpupid() is defined in include/linux/mm.h if !CONFIG_NUMA_BALANCING but you define the function in memory-tiers.c unconditionally, a file that is compiled predicated on CONFIG_NUMA.

So a config with !CONFIG_NUMA_BALANCING but CONFIG_NUMA set results in a compilation error (I just hit it this morning in mm-unstable).

Quoted 7 lines

A minimal fix for this is to wrap the declaration in:

#ifdef CONFIG_NUMA_BALANCING
...
#endif

I've tried this locally and it resolves the issue.

Agreed, with that

Signature · 3 lines
Cheers,

David / dhildenb
author reviewer
#4 lore raw

Re: [PATCH v2 2/3] memory tiering: introduce folio_has_cpupid() check

Quoted 8 lines · David Hildenbrand
Quoted 8 lines

The static version of folio_has_cpupid() is defined in include/linux/mm.h if !CONFIG_NUMA_BALANCING but you define the function in memory-tiers.c unconditionally, a file that is compiled predicated on CONFIG_NUMA.

So a config with !CONFIG_NUMA_BALANCING but CONFIG_NUMA set results in a compilation error (I just hit it this morning in mm-unstable).

Quoted 7 lines
Quoted 7 lines

A minimal fix for this is to wrap the declaration in:

#ifdef CONFIG_NUMA_BALANCING
...
#endif

I've tried this locally and it resolves the issue.

Will fix it. Thanks.

Quoted 4 lines

Agreed, with that

Thanks.

Signature · 2 lines
Best Regards,
Yan, Zi
author reviewer
#5 lore raw

PATCH v2 3/3 memory tiering: count PGPROMOTE_SUCCESS when mem tiering is enabled.

In reply to Zi Yan

memory tiering can be enabled/disabled at runtime and sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING is used to check it. In migrate_misplaced_folio(), the check is missing when PGPROMOTE_SUCCESS is incremented. Add the missing check.

Fixes 33024536bafd ("memory tiering: hot page selection with hint page fault latency")
---
 mm/migrate.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
mm/migrate.c +3 -1
index bdbb5bb04c91..b819809da470 100644
@@ -2630,7 +2630,9 @@ int migrate_misplaced_folio(struct folio *folio, struct vm_area_struct *vma,
 		putback_movable_pages(&migratepages);
 	if (nr_succeeded) {
 		count_vm_numa_events(NUMA_PAGE_MIGRATE, nr_succeeded);
-		if (!node_is_toptier(folio_nid(folio)) && node_is_toptier(node))
+		if ((sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING)
+		    && !node_is_toptier(folio_nid(folio))
+		    && node_is_toptier(node))
 			mod_node_page_state(pgdat, PGPROMOTE_SUCCESS,
 					    nr_succeeded);
 	}
Signature · 1 line
2.43.0
Reviewed-by on v2 3/3
#6 lore raw

Re: [PATCH v2 3/3] memory tiering: count PGPROMOTE_SUCCESS when mem tiering is enabled.

Quoted 9 lines · Zi Yan

memory tiering can be enabled/disabled at runtime and sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING is used to check it. In migrate_misplaced_folio(), the check is missing when PGPROMOTE_SUCCESS is incremented. Add the missing check.

Fixes 33024536bafd ("memory tiering: hot page selection with hint page fault latency")
Quoted 9 lines
---
  mm/migrate.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
mm/migrate.c +0 -0
index bdbb5bb04c91..b819809da470 100644

mm/migrate.c int migrate_misplaced_folio(struct folio *folio, struct vm_area_struct *vma, · line 2637

Quoted 9 lines
mm/migrate.c +3 -1
@@ -2630,7 +2630,9 @@ int migrate_misplaced_folio(struct folio *folio, struct vm_area_struct *vma,
  		putback_movable_pages(&migratepages);
  	if (nr_succeeded) {
  		count_vm_numa_events(NUMA_PAGE_MIGRATE, nr_succeeded);
-		if (!node_is_toptier(folio_nid(folio)) && node_is_toptier(node))
+		if ((sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING)
+		    && !node_is_toptier(folio_nid(folio))
+		    && node_is_toptier(node))
  			mod_node_page_state(pgdat, PGPROMOTE_SUCCESS,
  					    nr_succeeded);

The should be in advance of patch2, and change above to use folio_has_cpupid() helper() too.

Quoted 1 line
mm/migrate.c +0 -0
  	}
author reviewer
#7 lore raw

Re: [PATCH v2 3/3] memory tiering: count PGPROMOTE_SUCCESS when mem tiering is enabled.

Quoted 8 lines · Kefeng Wang
Quoted 5 lines · Zi Yan

memory tiering can be enabled/disabled at runtime and sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING is used to check it. In migrate_misplaced_folio(), the check is missing when PGPROMOTE_SUCCESS is incremented. Add the missing check.

Quoted 7 lines
Quoted 4 lines
Fixes 33024536bafd ("memory tiering: hot page selection with hint page fault latency")

Thanks.

Quoted 13 lines
Quoted 13 lines
---
  mm/migrate.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
mm/migrate.c +0 -1
index bdbb5bb04c91..b819809da470 100644
@@ -2630,7 +2630,9 @@ int migrate_misplaced_folio(struct folio *folio, struct vm_area_struct *vma,
  		putback_movable_pages(&migratepages);
  	if (nr_succeeded) {
  		count_vm_numa_events(NUMA_PAGE_MIGRATE, nr_succeeded);
-		if (!node_is_toptier(folio_nid(folio)) && node_is_toptier(node))
Quoted 8 lines

mm/migrate.c int migrate_misplaced_folio(struct folio *folio, struct vm_area_struct *vma, · line 2637

Quoted 5 lines
mm/migrate.c +3 -0
+		if ((sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING)
+		    && !node_is_toptier(folio_nid(folio))
+		    && node_is_toptier(node))
  			mod_node_page_state(pgdat, PGPROMOTE_SUCCESS,
  					    nr_succeeded);

The should be in advance of patch2, and change above to use folio_has_cpupid() helper() too.

It shares the same logic of !folio_has_cpupid() but it might be confusing to put !folio_has_cpupid(folio) && node_is_toptier(node) here. folio's cpupid has nothing to do with the stats here, thus I did not use the function.

Signature · 2 lines
Best Regards,
Yan, Zi
#8 lore raw

Re: [PATCH v2 3/3] memory tiering: count PGPROMOTE_SUCCESS when mem tiering is enabled.

Quoted 40 lines · Zi Yan
Quoted 8 lines · Kefeng Wang
Quoted 5 lines · Zi Yan

memory tiering can be enabled/disabled at runtime and sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING is used to check it. In migrate_misplaced_folio(), the check is missing when PGPROMOTE_SUCCESS is incremented. Add the missing check.

Quoted 7 lines
Quoted 4 lines
Fixes 33024536bafd ("memory tiering: hot page selection with hint page fault latency")

Thanks.

Quoted 13 lines
Quoted 13 lines
---
   mm/migrate.c | 4 +++-
   1 file changed, 3 insertions(+), 1 deletion(-)
mm/migrate.c +0 -1
index bdbb5bb04c91..b819809da470 100644
@@ -2630,7 +2630,9 @@ int migrate_misplaced_folio(struct folio *folio, struct vm_area_struct *vma,
   		putback_movable_pages(&migratepages);
   	if (nr_succeeded) {
   		count_vm_numa_events(NUMA_PAGE_MIGRATE, nr_succeeded);
-		if (!node_is_toptier(folio_nid(folio)) && node_is_toptier(node))
Quoted 8 lines

mm/migrate.c int migrate_misplaced_folio(struct folio *folio, struct vm_area_struct *vma, · line 2637

Quoted 5 lines
mm/migrate.c +3 -0
+		if ((sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING)
+		    && !node_is_toptier(folio_nid(folio))
+		    && node_is_toptier(node))
   			mod_node_page_state(pgdat, PGPROMOTE_SUCCESS,
   					    nr_succeeded);

The should be in advance of patch2, and change above to use folio_has_cpupid() helper() too.

Quoted 4 lines

It shares the same logic of !folio_has_cpupid() but it might be confusing to put !folio_has_cpupid(folio) && node_is_toptier(node) here. folio's cpupid has nothing to do with the stats here, thus I did not use the function.

If folio don't include access time, we do migrate it but it isn't a promotion, so don't count it, other comments?

PS: Could we rename folio_has_cpupid() to folio_has_access_time(), even without memory_tiering, we still have cpupid in folio, right?

Quoted 1 line
#9 lore raw

Re: [PATCH v2 3/3] memory tiering: count PGPROMOTE_SUCCESS when mem tiering is enabled.

Quoted 40 lines · Kefeng Wang
Quoted 39 lines · Zi Yan
Quoted 8 lines · Kefeng Wang
Quoted 5 lines · Zi Yan

memory tiering can be enabled/disabled at runtime and sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING is used to check it. In migrate_misplaced_folio(), the check is missing when PGPROMOTE_SUCCESS is incremented. Add the missing check.

Quoted 7 lines
Quoted 4 lines
Fixes 33024536bafd ("memory tiering: hot page selection with hint page fault latency")

Thanks.

Quoted 21 lines
Quoted 9 lines
---
   mm/migrate.c | 4 +++-
   1 file changed, 3 insertions(+), 1 deletion(-)
mm/migrate.c +0 -0
index bdbb5bb04c91..b819809da470 100644

mm/migrate.c int migrate_misplaced_folio(struct folio *folio, struct vm_area_struct *vma, · line 2637

Quoted 9 lines
mm/migrate.c +3 -1
@@ -2630,7 +2630,9 @@ int migrate_misplaced_folio(struct folio *folio, struct vm_area_struct *vma,
   		putback_movable_pages(&migratepages);
   	if (nr_succeeded) {
   		count_vm_numa_events(NUMA_PAGE_MIGRATE, nr_succeeded);
-		if (!node_is_toptier(folio_nid(folio)) && node_is_toptier(node))
+		if ((sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING)
+		    && !node_is_toptier(folio_nid(folio))
+		    && node_is_toptier(node))
   			mod_node_page_state(pgdat, PGPROMOTE_SUCCESS,
   					    nr_succeeded);

The should be in advance of patch2, and change above to use folio_has_cpupid() helper() too.

Quoted 8 lines
Quoted 5 lines

It shares the same logic of !folio_has_cpupid() but it might be confusing to
put !folio_has_cpupid(folio) && node_is_toptier(node) here. folio's cpupid has nothing to do with the stats here, thus I did not use the function.

If folio don't include access time, we do migrate it but it isn't a promotion, so don't count it, other comments?

Personally, I prefer to use !node_is_toptier() && node_is_toptier() here. That sounds more natural for me.

Quoted 2 lines

PS: Could we rename folio_has_cpupid() to folio_has_access_time(), even without memory_tiering, we still have cpupid in folio, right?

--
Best Regards,
Huang, Ying

#10 lore raw

Re: [PATCH v2 3/3] memory tiering: count PGPROMOTE_SUCCESS when mem tiering is enabled.

In reply to Kefeng Wang
Quoted 48 lines · Kefeng Wang
Quoted 40 lines · Zi Yan
Quoted 8 lines · Kefeng Wang
Quoted 5 lines · Zi Yan

memory tiering can be enabled/disabled at runtime and sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING is used to check it. In migrate_misplaced_folio(), the check is missing when PGPROMOTE_SUCCESS is incremented. Add the missing check.

Quoted 7 lines
Quoted 4 lines
Fixes 33024536bafd ("memory tiering: hot page selection with hint page fault latency")

Thanks.

Quoted 13 lines
Quoted 13 lines
---
    mm/migrate.c | 4 +++-
    1 file changed, 3 insertions(+), 1 deletion(-)
mm/migrate.c +0 -1
index bdbb5bb04c91..b819809da470 100644
@@ -2630,7 +2630,9 @@ int migrate_misplaced_folio(struct folio *folio, struct vm_area_struct *vma,
    		putback_movable_pages(&migratepages);
    	if (nr_succeeded) {
    		count_vm_numa_events(NUMA_PAGE_MIGRATE, nr_succeeded);
-		if (!node_is_toptier(folio_nid(folio)) && node_is_toptier(node))
Quoted 8 lines

mm/migrate.c int migrate_misplaced_folio(struct folio *folio, struct vm_area_struct *vma, · line 2637

Quoted 5 lines
mm/migrate.c +3 -0
+		if ((sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING)
+		    && !node_is_toptier(folio_nid(folio))
+		    && node_is_toptier(node))
    			mod_node_page_state(pgdat, PGPROMOTE_SUCCESS,
    					    nr_succeeded);

The should be in advance of patch2, and change above to use folio_has_cpupid() helper() too.

Quoted 4 lines

It shares the same logic of !folio_has_cpupid() but it might be confusing to put !folio_has_cpupid(folio) && node_is_toptier(node) here. folio's cpupid has nothing to do with the stats here, thus I did not use the function.

Quoted 5 lines

If folio don't include access time, we do migrate it but it isn't a promotion, so don't count it, other comments?

PS: Could we rename folio_has_cpupid() to folio_has_access_time(), even without memory_tiering, we still have cpupid in folio, right?

Maybe call it "folio_use_cpupid()" or sth like that? The "has" is a bit misleading, because the folio has a cpuid in any case, no?

Signature · 3 lines
Cheers,

David / dhildenb
author reviewer
#11 lore raw

Re: [PATCH v2 3/3] memory tiering: count PGPROMOTE_SUCCESS when mem tiering is enabled.

Quoted 49 lines · David Hildenbrand
Quoted 48 lines · Kefeng Wang
Quoted 44 lines · Zi Yan
Quoted 8 lines · Kefeng Wang
Quoted 5 lines · Zi Yan

memory tiering can be enabled/disabled at runtime and sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING is used to check it. In migrate_misplaced_folio(), the check is missing when PGPROMOTE_SUCCESS is incremented. Add the missing check.

Quoted 7 lines
Quoted 4 lines
Fixes 33024536bafd ("memory tiering: hot page selection with hint page fault latency")

Thanks.

Quoted 13 lines
Quoted 13 lines
---
    mm/migrate.c | 4 +++-
    1 file changed, 3 insertions(+), 1 deletion(-)
mm/migrate.c +0 -1
index bdbb5bb04c91..b819809da470 100644
@@ -2630,7 +2630,9 @@ int migrate_misplaced_folio(struct folio *folio, struct vm_area_struct *vma,
    		putback_movable_pages(&migratepages);
    	if (nr_succeeded) {
    		count_vm_numa_events(NUMA_PAGE_MIGRATE, nr_succeeded);
-		if (!node_is_toptier(folio_nid(folio)) && node_is_toptier(node))
Quoted 8 lines

mm/migrate.c int migrate_misplaced_folio(struct folio *folio, struct vm_area_struct *vma, · line 2637

Quoted 5 lines
mm/migrate.c +3 -0
+		if ((sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING)
+		    && !node_is_toptier(folio_nid(folio))
+		    && node_is_toptier(node))
    			mod_node_page_state(pgdat, PGPROMOTE_SUCCESS,
    					    nr_succeeded);

The should be in advance of patch2, and change above to use folio_has_cpupid() helper() too.

It shares the same logic of !folio_has_cpupid() but it might be confusing to put !folio_has_cpupid(folio) && node_is_toptier(node) here. folio's cpupid has nothing to do with the stats here, thus I did not use the function.

Quoted 5 lines
Quoted 5 lines

If folio don't include access time, we do migrate it but it isn't a promotion, so don't count it, other comments?

PS: Could we rename folio_has_cpupid() to folio_has_access_time(), even without memory_tiering, we still have cpupid in folio, right?

folio_has_access_time() would be the opposite of folio_has_cpupid(). If memory tiering is off (either at compile time or dynamically), a folio has cpupid all the time.

Quoted 3 lines

Maybe call it "folio_use_cpupid()" or sth like that? The "has" is a bit misleading, because the folio has a cpuid in any case, no?

The folio's cpupid field is reused to record page access time, when the folio is !node_is_toptier() and memory tiering mode is on.

In sum, using folio_use_access_time() as !folio_has_cpupid() seems better to me, since it covers the special use of folio's cpupid field.

Let me know your thoughts.

Signature · 2 lines
Best Regards,
Yan, Zi
#12 lore raw

Re: [PATCH v2 3/3] memory tiering: count PGPROMOTE_SUCCESS when mem tiering is enabled.

Quoted 61 lines · Zi Yan
Quoted 49 lines · David Hildenbrand
Quoted 48 lines · Kefeng Wang
Quoted 44 lines · Zi Yan
Quoted 8 lines · Kefeng Wang
Quoted 5 lines · Zi Yan

memory tiering can be enabled/disabled at runtime and sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING is used to check it. In migrate_misplaced_folio(), the check is missing when PGPROMOTE_SUCCESS is incremented. Add the missing check.

Quoted 7 lines
Quoted 4 lines
Fixes 33024536bafd ("memory tiering: hot page selection with hint page fault latency")

Thanks.

Quoted 13 lines
Quoted 13 lines
---
     mm/migrate.c | 4 +++-
     1 file changed, 3 insertions(+), 1 deletion(-)
mm/migrate.c +0 -1
index bdbb5bb04c91..b819809da470 100644
@@ -2630,7 +2630,9 @@ int migrate_misplaced_folio(struct folio *folio, struct vm_area_struct *vma,
     		putback_movable_pages(&migratepages);
     	if (nr_succeeded) {
     		count_vm_numa_events(NUMA_PAGE_MIGRATE, nr_succeeded);
-		if (!node_is_toptier(folio_nid(folio)) && node_is_toptier(node))
Quoted 8 lines

mm/migrate.c int migrate_misplaced_folio(struct folio *folio, struct vm_area_struct *vma, · line 2637

Quoted 5 lines
mm/migrate.c +3 -0
+		if ((sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING)
+		    && !node_is_toptier(folio_nid(folio))
+		    && node_is_toptier(node))
     			mod_node_page_state(pgdat, PGPROMOTE_SUCCESS,
     					    nr_succeeded);

The should be in advance of patch2, and change above to use folio_has_cpupid() helper() too.

It shares the same logic of !folio_has_cpupid() but it might be confusing to put !folio_has_cpupid(folio) && node_is_toptier(node) here. folio's cpupid has nothing to do with the stats here, thus I did not use the function.

Quoted 5 lines
Quoted 5 lines

If folio don't include access time, we do migrate it but it isn't a promotion, so don't count it, other comments?

PS: Could we rename folio_has_cpupid() to folio_has_access_time(), even without memory_tiering, we still have cpupid in folio, right?

folio_has_access_time() would be the opposite of folio_has_cpupid(). If memory tiering is off (either at compile time or dynamically), a folio has cpupid all the time.

Quoted 1 line
Quoted 9 lines
Quoted 2 lines

Maybe call it "folio_use_cpupid()" or sth like that? The "has" is a bit misleading, because the folio has a cpuid in any case, no?

The folio's cpupid field is reused to record page access time, when the folio is !node_is_toptier() and memory tiering mode is on.

In sum, using folio_use_access_time() as !folio_has_cpupid() seems better to me, since it covers the special use of folio's cpupid field.

It sounds good, thanks.

Quoted 2 lines

Let me know your thoughts.