Skip to contentSkip to conversation

mm/memory.c: Add return NUMA_NO_NODE in numa_migrate_check() when folio_nid() and numa_node_id() are the same.

PATCH In review Donet Tom 2 participants 4 messages Jan 9, 2025

Subsystems (2)
lore
Share & tools
lore

Donet Tom

author
#0 lore raw

PATCH 1/1 mm/memory.c: Add return NUMA_NO_NODE in numa_migrate_check() when folio_nid() and numa_node_id() are the same.

If the folio_nid() and numa_node_id() are the same, it indicates that the folio is already on the same node as the process. In this case, there's no need to migrate the pages.

This patch adds return NUMA_NO_NODE in numa_migrate_check() when the folio_nid() and numa_node_id() match, preventing the function from executing the remaining code unnecessarily.

---
 mm/memory.c | 1 +
 1 file changed, 1 insertion(+)
mm/memory.c +1 -0
index 398c031be9ba..dfd89ff7f639 100644
@@ -5509,6 +5509,7 @@ int numa_migrate_check(struct folio *folio, struct vm_fault *vmf,
 	if (folio_nid(folio) == numa_node_id()) {
 		count_vm_numa_event(NUMA_HINT_FAULTS_LOCAL);
 		*flags |= TNF_FAULT_LOCAL;
+		return NUMA_NO_NODE;
 	}
 
 	return mpol_misplaced(folio, vmf, addr);
Signature · 1 line
2.43.5
#1 lore raw
Quoted 18 lines · Donet Tom

If the folio_nid() and numa_node_id() are the same, it indicates that the folio is already on the same node as the process. In this case, there's no need to migrate the pages.

This patch adds return NUMA_NO_NODE in numa_migrate_check() when the folio_nid() and numa_node_id() match, preventing the function from executing the remaining code unnecessarily.

---
  mm/memory.c | 1 +
  1 file changed, 1 insertion(+)
mm/memory.c +0 -0
index 398c031be9ba..dfd89ff7f639 100644

mm/memory.c int numa_migrate_check(struct folio *folio, struct vm_fault *vmf, · line 5512

Quoted 4 lines
mm/memory.c +1 -0
@@ -5509,6 +5509,7 @@ int numa_migrate_check(struct folio *folio, struct vm_fault *vmf,
  	if (folio_nid(folio) == numa_node_id()) {
  		count_vm_numa_event(NUMA_HINT_FAULTS_LOCAL);
  		*flags |= TNF_FAULT_LOCAL;
+		return NUMA_NO_NODE;

Doesn't this just mean that it is a local fault, but not necessarily that we don't want to migrate that folio?

mpol_misplaced states: "check whether current folio node is valid in policy"

Could we have a different policy set that does not indicate the local node as the target node?

Note how mpol_misplaced() obtains the target node to the do

int curnid = folio_nid(folio);
...
int polnid = NUMA_NO_NODE;
int ret = NUMA_NO_NODE

... detect polnid

if (curnid != polnid)

	ret = polnid;

...
return ret;

So mpol_misplaced() will return "NUMA_NO_NODE" if already on the correct target node.

Signature · 3 lines
Cheers,

David / dhildenb
author
#2 lore raw
Quoted 41 lines · David Hildenbrand
Quoted 18 lines · Donet Tom

If the folio_nid() and numa_node_id() are the same, it indicates that the folio is already on the same node as the process. In this case, there's no need to migrate the pages.

This patch adds return NUMA_NO_NODE in numa_migrate_check() when the folio_nid() and numa_node_id() match, preventing the function from executing the remaining code unnecessarily.

---
  mm/memory.c | 1 +

  1 file changed, 1 insertion(+)
mm/memory.c +0 -0
index 398c031be9ba..dfd89ff7f639 100644

mm/memory.c int numa_migrate_check(struct folio *folio, · line 5513

Quoted 5 lines
mm/memory.c +1 -0
@@ -5509,6 +5509,7 @@ int numa_migrate_check(struct folio *folio, 
 struct vm_fault *vmf,
       if (folio_nid(folio) == numa_node_id()) {
           count_vm_numa_event(NUMA_HINT_FAULTS_LOCAL);
           *flags |= TNF_FAULT_LOCAL;
+        return NUMA_NO_NODE;

Doesn't this just mean that it is a local fault, but not necessarily that we don't want to migrate that folio?

mpol_misplaced states: "check whether current folio node is valid in policy"

Could we have a different policy set that does not indicate the local node as the target node?

Note how mpol_misplaced() obtains the target node to the do

int curnid = folio_nid(folio);
...
int polnid = NUMA_NO_NODE;
int ret = NUMA_NO_NODE

... detect polnid

Quoted 7 lines

if (curnid != polnid)
    ret = polnid;
...
return ret;

So mpol_misplaced() will return "NUMA_NO_NODE" if already on the correct target node.

Thank you, David. I understood my patch is wrong.

I have a small question: Page access latency is lower when the folio is on the same NUMA node as the process. However, if the policy node is set to a different NUMA node and the MPOL_F_MORON flag is not set, we migrate the page to the policy node, thereby increasing access latency.  Could this have an impact on performance? What benefits do we gain from this?

#3 lore raw
Quoted 57 lines · Donet Tom
Quoted 44 lines · David Hildenbrand
Quoted 18 lines · Donet Tom

If the folio_nid() and numa_node_id() are the same, it indicates that the folio is already on the same node as the process. In this case, there's no need to migrate the pages.

This patch adds return NUMA_NO_NODE in numa_migrate_check() when the folio_nid() and numa_node_id() match, preventing the function from executing the remaining code unnecessarily.

---
   mm/memory.c | 1 +
   1 file changed, 1 insertion(+)
mm/memory.c +0 -0
index 398c031be9ba..dfd89ff7f639 100644

mm/memory.c int numa_migrate_check(struct folio *folio, · line 5513

Quoted 5 lines
mm/memory.c +1 -0
@@ -5509,6 +5509,7 @@ int numa_migrate_check(struct folio *folio,
 struct vm_fault *vmf,
       if (folio_nid(folio) == numa_node_id()) {
           count_vm_numa_event(NUMA_HINT_FAULTS_LOCAL);
           *flags |= TNF_FAULT_LOCAL;
+        return NUMA_NO_NODE;

Doesn't this just mean that it is a local fault, but not necessarily that we don't want to migrate that folio?

mpol_misplaced states: "check whether current folio node is valid in policy"

Could we have a different policy set that does not indicate the local node as the target node?

Note how mpol_misplaced() obtains the target node to the do

int curnid = folio_nid(folio);
...
int polnid = NUMA_NO_NODE;
int ret = NUMA_NO_NODE

... detect polnid

Quoted 8 lines

if (curnid != polnid)
    ret = polnid;
...
return ret;

So mpol_misplaced() will return "NUMA_NO_NODE" if already on the correct target node.

Thank you, David. I understood my patch is wrong.

Quoted 8 lines

I have a small question: Page access latency is lower when the folio is on the same NUMA
node as the process. However, if the policy node is set to a different NUMA node and the
MPOL_F_MORON flag is not set, we migrate the page to the policy node, thereby increasing
access latency.  Could this have an impact on performance? What benefits do we gain from this?

I have to admit, that I have not much idea about the details here (especially, how MORON comes into play here), so what I write below might be wrong :)

Consider the following example: making use of memory on CPU-less NUMA nodes (e.g., CXL, NVDIMM, whatsoever). In that case, access latency might be higher, but maybe that's exactly what someone wants to achieve here (e.g., placing cold data).

Maybe page demotion can come into play here as well. But the MPOL_F_MORON is slightly confusing me.

Signature · 3 lines
Cheers,

David / dhildenb