Skip to contentSkip to conversation

sched/numa: Skip VMA scanning on memory pinned

PATCH Superseded Libo Chen 4 participants 15 messages Apr 17, 2025 – Apr 23, 2025

Subsystems (3)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Libo Chen

author
#0 lore raw

v3 cover sched/numa: Skip VMA scanning on memory pinned

v1->v2:
1. add perf improvment numbers in commit log. Yet to find perf diff on will-it-scale, so not included here. Plan to run more workloads.
2. add tracepoint.
3. To peterz's comment, this will make it impossible to attract tasks to those memory just like other VMA skippings. This is the current implementation, I think we can improve that in the future, but at the moment it's probabaly better to keep it consistent.

v2->v3:
1. add enable_cpuset() based on Mel's suggestion but again I think it's redundant
2. print out nodemask with %*p.. format in the tracepoint

Libo Chen (2):
sched/numa: Skip VMA scanning on memory pinned to one NUMA node via
cpuset.mems
sched/numa: Add tracepoint that tracks the skipping of numa balancing
due to cpuset memory pinning

 include/trace/events/sched.h | 30 ++++++++++++++++++++++++++++++
 kernel/sched/fair.c          |  9 +++++++++
 2 files changed, 39 insertions(+)
Signature · 1 line
2.43.5
author
#1 lore raw

PATCH v3 1/2 sched/numa: Skip VMA scanning on memory pinned to one NUMA node via cpuset.mems

When the memory of the current task is pinned to one NUMA node by cgroup, there is no point in continuing the rest of VMA scanning and hinting page faults as they will just be overhead. With this change, there will be no more unnecessary PTE updates or page faults in this scenario.

We have seen up to a 6x improvement on a typical java workload running on VMs with memory and CPU pinned to one NUMA node via cpuset in a two-socket AARCH64 system. With the same pinning, on a 18-cores-per-socket Intel platform, we have seen 20% improvment in a microbench that creates a 30-vCPU selftest KVM guest with 4GB memory, where each vCPU reads 4KB pages in a fixed number of loops.

---
 kernel/sched/fair.c | 7 +++++++
 1 file changed, 7 insertions(+)
kernel/sched/fair.c +7 -0
index e43993a4e5807..c9903b1b39487 100644
@@ -3329,6 +3329,13 @@ static void task_numa_work(struct callback_head *work)
 	if (p->flags & PF_EXITING)
 		return;
 
+	/*
+	 * Memory is pinned to only one NUMA node via cpuset.mems, naturally
+	 * no page can be migrated.
+	 */
+	if (cpusets_enabled() && nodes_weight(cpuset_current_mems_allowed) == 1)
+		return;
+
 	if (!mm->numa_next_scan) {
 		mm->numa_next_scan = now +
 			msecs_to_jiffies(sysctl_numa_balancing_scan_delay);
Signature · 1 line
2.43.5
#2 lore raw

Re: [PATCH v3 1/2] sched/numa: Skip VMA scanning on memory pinned to one NUMA node via cpuset.mems

Hi Libo,

Quoted 5 lines · Libo Chen

When the memory of the current task is pinned to one NUMA node by cgroup, there is no point in continuing the rest of VMA scanning and hinting page faults as they will just be overhead. With this change, there will be no more unnecessary PTE updates or page faults in this scenario.

Quoted 8 lines

We have seen up to a 6x improvement on a typical java workload running on VMs with memory and CPU pinned to one NUMA node via cpuset in a two-socket AARCH64 system. With the same pinning, on a 18-cores-per-socket Intel platform, we have seen 20% improvment in a microbench that creates a 30-vCPU selftest KVM guest with 4GB memory, where each vCPU reads 4KB pages in a fixed number of loops.

I think this is a promising change that we can perform fine-grain NUMA balance control on a per-cgroup basis rather than system-wide NUMA balance for every task, which is costly.

Quoted 9 lines
---
  kernel/sched/fair.c | 7 +++++++
  1 file changed, 7 insertions(+)
kernel/sched/fair.c +0 -0
index e43993a4e5807..c9903b1b39487 100644

kernel/sched/fair.c static void task_numa_work(struct callback_head *work) · line 3338

Quoted 10 lines
kernel/sched/fair.c +7 -0
@@ -3329,6 +3329,13 @@ static void task_numa_work(struct callback_head *work)
  	if (p->flags & PF_EXITING)
  		return;
 
+	/*
+	 * Memory is pinned to only one NUMA node via cpuset.mems, naturally
+	 * no page can be migrated.
+	 */
+	if (cpusets_enabled() && nodes_weight(cpuset_current_mems_allowed) == 1)
+		return;
+

I found that you had a proposal in V1 to address Peter's concern[1]:
Allow the task to be migrated to its preferred Node, even if the task's
memory policy is restricted to 1 Node. In your previous proposal, only if the task's cpumask is bound to the same Node as its memory policy node, the NUMA balance scanning is skipped, because a cgroup usually binds its tasks and memory allocation policy to the same node. Not sure if that could be turned into:

If the task's memory policy node's CPU mask is a subset of the task's cpumask, the NUMA balance scan is allowed.

For example,
Suppose p's memory is only allocated on node0, which contains CPU2, CPU3.
1. If p's CPU affinity is CPU0, CPU1, there is no need to do NUMA balancing scanning, because CPU0,1 are not in p's legitimate cpumask.
2. If p's CPU affinity is CPU3, there is no need to do NUMA balancing scanning. p is already on its preferred node.
3. But if p's CPU affinity is CPU2, CPU3, CPU6, the NUMA balancing scan should be allowed. Because it is possible to migrate p from CPU6 to either CPU2 or CPU3.

What I'm thinking of is something as follows(untested):
if (cpusets_enabled() &&

    nodes_weight(cpuset_current_mems_allowed) == 1 &&
    !cpumask_subset(cpumask_of_node(cpuset_current_mems_allowed),
		    p->cpus_ptr))
	return;

I tested your patch on top of the latest sched/core,
binding task CPU affinity to Node1 and memory allocation node on Node1:
echo "8-15" > /sys/fs/cgroup/mytest/cpuset.cpus
echo "1" > /sys/fs/cgroup/mytest/cpuset.mems
cgexec -g cpuset:mytest ./run-mmtests.sh --no-monitor --config config-numa skip_scan

And it works as expected:

# bpftrace numa_trace.bt

@sched_skip_cpuset_numa: 133

thanks,
Chenyu

[1] https://lore.kernel.org/lkml/[email protected]/

Quoted 3 lines
kernel/sched/fair.c +0 -0
  	if (!mm->numa_next_scan) {
  		mm->numa_next_scan = now +
  			msecs_to_jiffies(sysctl_numa_balancing_scan_delay);
author
#3 lore raw

Re: [PATCH v3 1/2] sched/numa: Skip VMA scanning on memory pinned to one NUMA node via cpuset.mems

Hi Yu

Quoted 15 lines · Yu C

Hi Libo,

Quoted 12 lines · Libo Chen

When the memory of the current task is pinned to one NUMA node by cgroup, there is no point in continuing the rest of VMA scanning and hinting page faults as they will just be overhead. With this change, there will be no more unnecessary PTE updates or page faults in this scenario.

We have seen up to a 6x improvement on a typical java workload running on VMs with memory and CPU pinned to one NUMA node via cpuset in a two-socket AARCH64 system. With the same pinning, on a 18-cores-per-socket Intel platform, we have seen 20% improvment in a microbench that creates a 30-vCPU selftest KVM guest with 4GB memory, where each vCPU reads 4KB pages in a fixed number of loops.

Quoted 6 lines
Quoted 1 line

I think this is a promising change that we can perform fine-grain NUMA balance control on a per-cgroup basis rather than system-wide NUMA balance for every task, which is costly.

Yes indeed, the cost, from we have seen, can be quite astonishing

Quoted 23 lines
Quoted 11 lines

---
  kernel/sched/fair.c | 7 +++++++

  1 file changed, 7 insertions(+)
kernel/sched/fair.c +0 -0
index e43993a4e5807..c9903b1b39487 100644
@@ -3329,6 +3329,13 @@ static void task_numa_work(struct callback_head *work)
       if (p->flags & PF_EXITING)
           return;
Quoted 7 lines

  +    /*
+     * Memory is pinned to only one NUMA node via cpuset.mems, naturally +     * no page can be migrated.
+     */
+    if (cpusets_enabled() && nodes_weight(cpuset_current_mems_allowed) == 1) +        return;
+

I found that you had a proposal in V1 to address Peter's concern[1]:
Allow the task to be migrated to its preferred Node, even if the task's
memory policy is restricted to 1 Node. In your previous proposal, only if the task's cpumask is bound to the same Node as its memory policy node, the NUMA balance scanning is skipped, because a cgroup usually binds its tasks and memory allocation policy to the same node. Not sure if that could be turned into:

Quoted 2 lines

If the task's memory policy node's CPU mask is a subset of the task's cpumask, the NUMA balance scan is allowed.

I guess fundamentally is this really worth it? Do the benefits of NUMA task migrations only outweigh the overheads of VMA scanning, PTE updates and page faults etc? I suppose this is workload-dependent, but what about the best-case scenario? I think we probably need more data. Also if we do that, we also need to do the same for other VMA skipping scenarios.

Thanks,
Libo

Quoted 35 lines

For example,
Suppose p's memory is only allocated on node0, which contains CPU2, CPU3.
1. If p's CPU affinity is CPU0, CPU1, there is no need to do NUMA balancing scanning, because CPU0,1 are not in p's legitimate cpumask.
2. If p's CPU affinity is CPU3, there is no need to do NUMA balancing scanning. p is already on its preferred node.
3. But if p's CPU affinity is CPU2, CPU3, CPU6, the NUMA balancing scan should be allowed. Because it is possible to migrate p from CPU6 to either CPU2 or CPU3.

What I'm thinking of is something as follows(untested):
if (cpusets_enabled() && nodes_weight(cpuset_current_mems_allowed) == 1 && !cpumask_subset(cpumask_of_node(cpuset_current_mems_allowed), p->cpus_ptr))
    return;

I tested your patch on top of the latest sched/core,
binding task CPU affinity to Node1 and memory allocation node on Node1:
echo "8-15" > /sys/fs/cgroup/mytest/cpuset.cpus
echo "1" > /sys/fs/cgroup/mytest/cpuset.mems
cgexec -g cpuset:mytest ./run-mmtests.sh --no-monitor --config config-numa skip_scan

And it works as expected:

# bpftrace numa_trace.bt

@sched_skip_cpuset_numa: 133

thanks,
Chenyu

[1] https://urldefense.com/v3/__https://lore.kernel.org/lkml/[email protected]/__;!!ACWV5N9M2RV99hQ!OvO0A__dCkeSB4eze2TYZYDHWGg0ubi04-u8lW5NCQGRE6vZkCGahdWMzHtpKMMDSt-L1wCkM8ILMIP3YA$

Quoted 3 lines

      if (!mm->numa_next_scan) {
          mm->numa_next_scan = now + msecs_to_jiffies(sysctl_numa_balancing_scan_delay);

Tested-by
#4 lore raw

Re: [PATCH v3 1/2] sched/numa: Skip VMA scanning on memory pinned to one NUMA node via cpuset.mems

Quoted 50 lines · Libo Chen

Hi Yu

Quoted 15 lines · Yu C

Hi Libo,

Quoted 12 lines · Libo Chen

When the memory of the current task is pinned to one NUMA node by cgroup, there is no point in continuing the rest of VMA scanning and hinting page faults as they will just be overhead. With this change, there will be no more unnecessary PTE updates or page faults in this scenario.

We have seen up to a 6x improvement on a typical java workload running on VMs with memory and CPU pinned to one NUMA node via cpuset in a two-socket AARCH64 system. With the same pinning, on a 18-cores-per-socket Intel platform, we have seen 20% improvment in a microbench that creates a 30-vCPU selftest KVM guest with 4GB memory, where each vCPU reads 4KB pages in a fixed number of loops.

Quoted 6 lines
Quoted 1 line

I think this is a promising change that we can perform fine-grain NUMA balance control on a per-cgroup basis rather than system-wide NUMA balance for every task, which is costly.

Yes indeed, the cost, from we have seen, can be quite astonishing

Quoted 23 lines
Quoted 9 lines
---
   kernel/sched/fair.c | 7 +++++++
   1 file changed, 7 insertions(+)
kernel/sched/fair.c +0 -0
index e43993a4e5807..c9903b1b39487 100644

kernel/sched/fair.c static void task_numa_work(struct callback_head *work) · line 3337

Quoted 9 lines
kernel/sched/fair.c +6 -0
@@ -3329,6 +3329,13 @@ static void task_numa_work(struct callback_head *work)
       if (p->flags & PF_EXITING)
           return;
   +    /*
+     * Memory is pinned to only one NUMA node via cpuset.mems, naturally
+     * no page can be migrated.
+     */
+    if (cpusets_enabled() && nodes_weight(cpuset_current_mems_allowed) == 1)
+        return;
+

I found that you had a proposal in V1 to address Peter's concern[1]:
Allow the task to be migrated to its preferred Node, even if the task's
memory policy is restricted to 1 Node. In your previous proposal, only if the task's cpumask is bound to the same Node as its memory policy node, the NUMA balance scanning is skipped, because a cgroup usually binds its tasks and memory allocation policy to the same node. Not sure if that could be turned into:

Quoted 5 lines
Quoted 2 lines

If the task's memory policy node's CPU mask is a subset of the task's cpumask, the NUMA balance scan is allowed.

I guess fundamentally is this really worth it? Do the benefits of NUMA task migrations only outweigh the overheads of VMA scanning, PTE updates and page faults etc? I suppose this is workload-dependent, but what about the best-case scenario? I think we probably need more data. Also if we do that, we also need to do the same for other VMA skipping scenarios.

Overall that can be a future work and I agree for now this patch is simple enough and feel free to add:

thanks,
Chenyu

author
#5 lore raw

PATCH v3 2/2 sched/numa: Add tracepoint that tracks the skipping of numa balancing due to cpuset memory pinning

In reply to Libo Chen

Unlike sched_skip_vma_numa tracepoint which tracks skipped VMAs, this tracks the task subjected to cpuset.mems pinning and prints out its allowed memory node mask.

---
 include/trace/events/sched.h | 30 ++++++++++++++++++++++++++++++
 kernel/sched/fair.c          |  4 +++-
 2 files changed, 33 insertions(+), 1 deletion(-)
include/trace/events/sched.h +30 -0
index 8994e97d86c13..25ee542fa0063 100644
@@ -745,6 +745,36 @@ TRACE_EVENT(sched_skip_vma_numa,
 		  __entry->vm_end,
 		  __print_symbolic(__entry->reason, NUMAB_SKIP_REASON))
 );
+
+TRACE_EVENT(sched_skip_cpuset_numa,
+
+	TP_PROTO(struct task_struct *tsk, nodemask_t *mem_allowed_ptr),
+
+	TP_ARGS(tsk, mem_allowed_ptr),
+
+	TP_STRUCT__entry(
+		__array( char,		comm,		TASK_COMM_LEN	)
+		__field( pid_t,		pid				)
+		__field( pid_t,		tgid				)
+		__field( pid_t,		ngid				)
+		__field( nodemask_t *,	mem_allowed_ptr			)
+	),
+
+	TP_fast_assign(
+		memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
+		__entry->pid		 = task_pid_nr(tsk);
+		__entry->tgid		 = task_tgid_nr(tsk);
+		__entry->ngid		 = task_numa_group_id(tsk);
+		__entry->mem_allowed_ptr = mem_allowed_ptr;
+	),
+
+	TP_printk("comm=%s pid=%d tgid=%d ngid=%d mem_nodes_allowed=%*pbl",
+		  __entry->comm,
+		  __entry->pid,
+		  __entry->tgid,
+		  __entry->ngid,
+		  nodemask_pr_args(__entry->mem_allowed_ptr))
+);
 #endif /* CONFIG_NUMA_BALANCING */
 
 /*
kernel/sched/fair.c +3 -1
index c9903b1b39487..cc892961ce157 100644
@@ -3333,8 +3333,10 @@ static void task_numa_work(struct callback_head *work)
 	 * Memory is pinned to only one NUMA node via cpuset.mems, naturally
 	 * no page can be migrated.
 	 */
-	if (cpusets_enabled() && nodes_weight(cpuset_current_mems_allowed) == 1)
+	if (cpusets_enabled() && nodes_weight(cpuset_current_mems_allowed) == 1) {
+		trace_sched_skip_cpuset_numa(current, &cpuset_current_mems_allowed);
 		return;
+	}
 
 	if (!mm->numa_next_scan) {
 		mm->numa_next_scan = now +
Signature · 1 line
2.43.5
maintainer
#6 lore raw

Re: [PATCH v3 2/2] sched/numa: Add tracepoint that tracks the skipping of numa balancing due to cpuset memory pinning

Quoted 19 lines · On Thu, 17 Apr 2025 12:15:43 -0700 Libo Chen <[email protected]> wrote:
include/trace/events/sched.h +11 -0
index 8994e97d86c13..25ee542fa0063 100644
@@ -745,6 +745,36 @@ TRACE_EVENT(sched_skip_vma_numa,
 		  __entry->vm_end,
 		  __print_symbolic(__entry->reason, NUMAB_SKIP_REASON))
 );
+
+TRACE_EVENT(sched_skip_cpuset_numa,
+
+	TP_PROTO(struct task_struct *tsk, nodemask_t *mem_allowed_ptr),
+
+	TP_ARGS(tsk, mem_allowed_ptr),
+
+	TP_STRUCT__entry(
+		__array( char,		comm,		TASK_COMM_LEN	)
+		__field( pid_t,		pid				)
+		__field( pid_t,		tgid				)

include/trace/events/sched.h TRACE_EVENT(sched_skip_vma_numa, · line 768

Quoted 10 lines
include/trace/events/sched.h +10 -0
+		__field( pid_t,		ngid				)
+		__field( nodemask_t *,	mem_allowed_ptr			)
+	),
+
+	TP_fast_assign(
+		memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
+		__entry->pid		 = task_pid_nr(tsk);
+		__entry->tgid		 = task_tgid_nr(tsk);
+		__entry->ngid		 = task_numa_group_id(tsk);
+		__entry->mem_allowed_ptr = mem_allowed_ptr;

This is a bug. You can't save random pointers in the TP_fast_assign() and reference it later in the TP_printk().

The TP_fast_assign() is executed during the normal kernel workflow when the tracepoint is triggered. The pointer is saved into the ring buffer.

include/trace/events/sched.h TRACE_EVENT(sched_skip_vma_numa, · line 776

Quoted 8 lines
include/trace/events/sched.h +8 -0
+	),
+
+	TP_printk("comm=%s pid=%d tgid=%d ngid=%d mem_nodes_allowed=%*pbl",
+		  __entry->comm,
+		  __entry->pid,
+		  __entry->tgid,
+		  __entry->ngid,
+		  nodemask_pr_args(__entry->mem_allowed_ptr))

The TP_printk() is executed when a user reads the /sys/kernel/tracing/trace file. Which could be literally months later.

The nodemask_pr_args() will dereference the __entry->mem_allowed_ptr from what was saved in the ring buffer, which the content it points to could have been freed days ago.

If that happens, then BOOM! Kernel goes bye-bye!

The trace event verifier is made to find bugs like his. And with the recent update to handle "%*p" it found this bug. ;-)

-- Steve

Quoted 2 lines
include/trace/events/sched.h +1 -0
+);
 #endif /* CONFIG_NUMA_BALANCING */
author
#7 lore raw

Re: [PATCH v3 2/2] sched/numa: Add tracepoint that tracks the skipping of numa balancing due to cpuset memory pinning

Quoted 31 lines · Steven Rostedt
Quoted 24 lines · On Thu, 17 Apr 2025 12:15:43 -0700 Libo Chen <[email protected]> wrote:
include/trace/events/sched.h +16 -0
index 8994e97d86c13..25ee542fa0063 100644
@@ -745,6 +745,36 @@ TRACE_EVENT(sched_skip_vma_numa,
 __entry->vm_end,
 __print_symbolic(__entry->reason, NUMAB_SKIP_REASON))
 );
+
+TRACE_EVENT(sched_skip_cpuset_numa,
+
+ TP_PROTO(struct task_struct *tsk, nodemask_t *mem_allowed_ptr),
+
+ TP_ARGS(tsk, mem_allowed_ptr),
+
+ TP_STRUCT__entry(
+ __array( char, comm, TASK_COMM_LEN )
+ __field( pid_t, pid )
+ __field( pid_t, tgid )
+ __field( pid_t, ngid )
+ __field( nodemask_t *, mem_allowed_ptr )
+ ),
+
+ TP_fast_assign(
Quoted 9 lines

include/trace/events/sched.h TRACE_EVENT(sched_skip_vma_numa, · line 768

Quoted 5 lines
include/trace/events/sched.h +5 -0
+ memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
+ __entry->pid = task_pid_nr(tsk);
+ __entry->tgid = task_tgid_nr(tsk);
+ __entry->ngid = task_numa_group_id(tsk);
+ __entry->mem_allowed_ptr = mem_allowed_ptr;

This is a bug. You can't save random pointers in the TP_fast_assign() and reference it later in the TP_printk().

Admittedly I was a bit nervous about dereferencing this pointer at TP_printk() time. Will fix it!

Also wondering if we can fail the build in this scenario so it will be easier to catch this bug at the build time.

Thanks
Libo

Quoted 29 lines

The TP_fast_assign() is executed during the normal kernel workflow when the tracepoint is triggered. The pointer is saved into the ring buffer.

include/trace/events/sched.h TRACE_EVENT(sched_skip_vma_numa, · line 776

Quoted 8 lines
include/trace/events/sched.h +8 -0
+ ),
+
+ TP_printk("comm=%s pid=%d tgid=%d ngid=%d mem_nodes_allowed=%*pbl",
+  __entry->comm,
+  __entry->pid,
+  __entry->tgid,
+  __entry->ngid,
+  nodemask_pr_args(__entry->mem_allowed_ptr))

The TP_printk() is executed when a user reads the /sys/kernel/tracing/trace file. Which could be literally months later.

The nodemask_pr_args() will dereference the __entry->mem_allowed_ptr from what was saved in the ring buffer, which the content it points to could have been freed days ago.

If that happens, then BOOM! Kernel goes bye-bye!

The trace event verifier is made to find bugs like his. And with the recent update to handle "%*p" it found this bug. ;-)

-- Steve

Quoted 2 lines
include/trace/events/sched.h +1 -0
+);
 #endif /* CONFIG_NUMA_BALANCING */
maintainer
#8 lore raw

Re: [PATCH v3 2/2] sched/numa: Add tracepoint that tracks the skipping of numa balancing due to cpuset memory pinning

Quoted 2 lines · On Wed, 23 Apr 2025 16:05:44 +0000 Libo Chen <[email protected]> wrote:

Also wondering if we can fail the build in this scenario so it will be easier to catch this bug at the build time.

return -EPONYS ;-)

I wish. It's hard enough to catch this at runtime.

-- Steve

author
#9 lore raw

Re: [PATCH v3 2/2] sched/numa: Add tracepoint that tracks the skipping of numa balancing due to cpuset memory pinning

Quoted 7 lines · Steven Rostedt

On Wed, 23 Apr 2025 16:05:44 +0000
Libo Chen <[email protected]> wrote:

Quoted 7 lines
Quoted 2 lines

Also wondering if we can fail the build in this scenario so it will be easier to catch this bug at the build time.

return -EPONYS ;-)

I wish. It's hard enough to catch this at runtime.

Correct me if I'm wrong but can you disallow any passed-in pointers to be dereferenced when TP_printk() is executed? This is something you can check at the build time, right?

Libo

Quoted 1 line

-- Steve

maintainer
#10 lore raw

Re: [PATCH v3 2/2] sched/numa: Add tracepoint that tracks the skipping of numa balancing due to cpuset memory pinning

Quoted 3 lines · On Wed, 23 Apr 2025 16:50:15 +0000 Libo Chen <[email protected]> wrote:

Correct me if I'm wrong but can you disallow any passed-in pointers to be dereferenced when TP_printk() is executed? This is something you can check at the build time, right?

You can dereference if the pointer is to the content on the ring buffer. For instance, you can have:

"%p*h", &__entry->val

It dereferences to the content stored on the ring buffer.

What we can't have is:

"%p*h", __entry->val

-- Steve

maintainer
#11 lore raw

Re: [PATCH v3 2/2] sched/numa: Add tracepoint that tracks the skipping of numa balancing due to cpuset memory pinning

Quoted 3 lines · On Wed, 23 Apr 2025 12:56:59 -0400 Steven Rostedt <[email protected]> wrote:

For instance, you can have:

"%p*h", &__entry->val

That should have been:

"%p*h", __entry->size, &__entry->val

-- Steve

author
#12 lore raw

Re: [PATCH v3 2/2] sched/numa: Add tracepoint that tracks the skipping of numa balancing due to cpuset memory pinning

In reply to Steven Rostedt
Quoted 14 lines · Steven Rostedt
Quoted 3 lines · On Wed, 23 Apr 2025 16:50:15 +0000 Libo Chen <[email protected]> wrote:

Correct me if I'm wrong but can you disallow any passed-in pointers to be dereferenced when TP_printk() is executed? This is something you can check at the build time, right?

You can dereference if the pointer is to the content on the ring buffer. For instance, you can have:

Quoted 7 lines

"%p*h", &__entry->val

It dereferences to the content stored on the ring buffer.

What we can't have is:

"%p*h", __entry->val

Right, I was thinking something stricter such as disallowing point-type field in TP_STRUCT__entry {} to avoid direct assignment to point-type field so there will be no chance to have unsafe dereference but then I realize C doesn’t have built-in mechanism to detect various types of pointers at the compile time, maybe rust can do that. Anyway I give up.

Thanks,
Libo

Quoted 2 lines

-- Steve

#13 lore raw
In reply to Libo Chen
Quoted 9 lines · On Thu, 17 Apr 2025 12:15:41 -0700 Libo Chen <[email protected]> wrote:

v1->v2:
1. add perf improvment numbers in commit log. Yet to find perf diff on will-it-scale, so not included here. Plan to run more workloads.
2. add tracepoint.
3. To peterz's comment, this will make it impossible to attract tasks to those memory just like other VMA skippings. This is the current implementation, I think we can improve that in the future, but at the moment it's probabaly better to keep it consistent.

Quoted 4 lines

v2->v3:
1. add enable_cpuset() based on Mel's suggestion but again I think it's redundant
2. print out nodemask with %*p.. format in the tracepoint

I do agree with Mel - bitmap_weight() is somewhat expensive and cpusets_enabled() is super fast. So the benefit to cpusets_enabled()=false kernels will exceed to cost to cpusets_enabled()=true kernels.

This isn't traditionally mm.git material, but it's close. I'll grab the patchset for some testing. and shall drop it again if it turns up via another tree.

author
#14 lore raw
Quoted 16 lines · Andrew Morton
Quoted 9 lines · On Thu, 17 Apr 2025 12:15:41 -0700 Libo Chen <[email protected]> wrote:

v1->v2:
1. add perf improvment numbers in commit log. Yet to find perf diff on will-it-scale, so not included here. Plan to run more workloads.
2. add tracepoint.
3. To peterz's comment, this will make it impossible to attract tasks to those memory just like other VMA skippings. This is the current implementation, I think we can improve that in the future, but at the moment it's probabaly better to keep it consistent.

Quoted 4 lines

v2->v3:
1. add enable_cpuset() based on Mel's suggestion but again I think it's redundant
2. print out nodemask with %*p.. format in the tracepoint

Quoted 5 lines

I do agree with Mel - bitmap_weight() is somewhat expensive and cpusets_enabled() is super fast. So the benefit to cpusets_enabled()=false kernels will exceed to cost to cpusets_enabled()=true kernels.

Ah yes, that's right. Thanks for grabbing it~

Libo

Quoted 4 lines

This isn't traditionally mm.git material, but it's close. I'll grab the patchset for some testing. and shall drop it again if it turns up via another tree.