sched/numa: Add statistics of numa balance task migration and swap
Subsystems (6)
PATCH v2 1/1 sched/numa: Add statistics of numa balance task migration and swap
On systems with NUMA balancing enabled, it is found that tracking the task activities due to NUMA balancing is helpful. NUMA balancing has two mechanisms for task migration: one is to migrate the task to an idle CPU in its preferred node, the other is to swap tasks on different nodes if they are on each other's preferred node.
The kernel already has NUMA page migration statistics in /sys/fs/cgroup/mytest/memory.stat and /proc/{PID}/sched, but does not have statistics for task migration/swap. Add the task migration and swap count accordingly.
The following two new fields:
numa_task_migratednuma_task_swapped
will be displayed in both /sys/fs/cgroup/{GROUP}/memory.stat and /proc/{PID}/sched
Introducing both pertask and permemcg NUMA balancing statistics helps to quickly evaluate the performance and resource usage of the target workload. For example, the user can first identify the container which has high NUMA balance activity and then narrow down to a specific task within that group, and tune the memory policy of that task. In summary, it is plausible to iterate the /proc/$pid/sched to find the offending task, but the introduction of per memcg tasks' Numa balancing aggregated activity can further help users identify the task in a divide-and-conquer way.
---v1->v2:
Update the Documentation/admin-guide/cgroup-v2.rst. (Michal)
--- Documentation/admin-guide/cgroup-v2.rst | 6 ++++++ include/linux/sched.h | 4 ++++ include/linux/vm_event_item.h | 2 ++ kernel/sched/core.c | 10 ++++++++-- kernel/sched/debug.c | 4 ++++ mm/memcontrol.c | 2 ++ mm/vmstat.c | 2 ++ 7 files changed, 28 insertions(+), 2 deletions(-)
Documentation/admin-guide/cgroup-v2.rst +6 -0
@@ -1652,6 +1652,12 @@ The following nested keys are defined. numa_hint_faults (npn) Number of NUMA hinting faults. + numa_task_migrated (npn) + Number of task migration by NUMA balancing. + + numa_task_swapped (npn) + Number of task swap by NUMA balancing. + pgdemote_kswapd Number of pages demoted by kswapd.
include/linux/sched.h +4 -0
@@ -549,6 +549,10 @@ struct sched_statistics {u64 nr_failed_migrations_running;u64 nr_failed_migrations_hot;u64 nr_forced_migrations; +#ifdef CONFIG_NUMA_BALANCING +u64 numa_task_migrated; +u64 numa_task_swapped; +#endif u64 nr_wakeups;u64 nr_wakeups_sync;
include/linux/vm_event_item.h +2 -0
@@ -64,6 +64,8 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,NUMA_HINT_FAULTS ,NUMA_HINT_FAULTS_LOCAL ,NUMA_PAGE_MIGRATE , +NUMA_TASK_MIGRATE , +NUMA_TASK_SWAP , #endif #ifdef CONFIG_MIGRATION PGMIGRATE_SUCCESS, PGMIGRATE_FAIL,
kernel/sched/core.c +8 -2
@@ -3352,6 +3352,11 @@ void set_task_cpu(struct task_struct *p, unsigned int new_cpu)#ifdef CONFIG_NUMA_BALANCING static void __migrate_swap_task (struct task_struct *p,int cpu) { +__schedstat_inc (p->stats.numa_task_swapped); + +if (p->mm) +count_memcg_events_mm (p->mm,NUMA_TASK_SWAP ,1 ); +if (task_on_rq_queued (p)) {struct rq *src_rq, *dst_rq;struct rq_flags srf, drf;
@@ -7955,8 +7960,9 @@ int migrate_task_to(struct task_struct *p, int target_cpu)if (!cpumask_test_cpu (target_cpu, p->cpus_ptr))return -EINVAL ; -/* TODO: This is not properly updating schedstats */ - +__schedstat_inc (p->stats.numa_task_migrated); +if (p->mm) +count_memcg_events_mm (p->mm,NUMA_TASK_MIGRATE ,1 );trace_sched_move_numa (p, curr_cpu, target_cpu);return stop_one_cpu (curr_cpu, migration_cpu_stop, &arg); }
kernel/sched/debug.c +4 -0
@@ -1206,6 +1206,10 @@ void proc_sched_show_task(struct task_struct *p, struct pid_namespace *ns,P_SCHEDSTAT (nr_failed_migrations_running);P_SCHEDSTAT (nr_failed_migrations_hot);P_SCHEDSTAT (nr_forced_migrations); +#ifdef CONFIG_NUMA_BALANCING +P_SCHEDSTAT (numa_task_migrated); +P_SCHEDSTAT (numa_task_swapped); +#endif P_SCHEDSTAT (nr_wakeups);P_SCHEDSTAT (nr_wakeups_sync);P_SCHEDSTAT (nr_wakeups_migrate);
mm/memcontrol.c +2 -0
@@ -460,6 +460,8 @@ static const unsigned int memcg_vm_event_stat[] = {NUMA_PAGE_MIGRATE ,NUMA_PTE_UPDATES ,NUMA_HINT_FAULTS , +NUMA_TASK_MIGRATE , + NUMA_TASK_SWAP, #endif };
mm/vmstat.c +2 -0
@@ -1342,6 +1342,8 @@ const char * const vmstat_text[] = {"numa_hint_faults" ,"numa_hint_faults_local" ,"numa_pages_migrated" , +"numa_task_migrated" , +"numa_task_swapped" , #endif #ifdef CONFIG_MIGRATION "pgmigrate_success",
Signature · 1 line
2.25.1
Hi Chen Yu,
I think this is quite useful! I hope it can be picked up.
I have one comment below
Quoted 95 lines · Chen Yu
On systems with NUMA balancing enabled, it is found that tracking the task activities due to NUMA balancing is helpful. NUMA balancing has two mechanisms for task migration: one is to migrate the task to an idle CPU in its preferred node, the other is to swap tasks on different nodes if they are on each other's preferred node.
The kernel already has NUMA page migration statistics in
/sys/fs/cgroup/mytest/memory.statand/proc/{PID}/sched, but does not have statistics for task migration/swap. Add the task migration and swap count accordingly.The following two new fields:
numa_task_migratednuma_task_swappedwill be displayed in both
/sys/fs/cgroup/{GROUP}/memory.statand/proc/{PID}/schedIntroducing both pertask and permemcg NUMA balancing statistics helps to quickly evaluate the performance and resource usage of the target workload. For example, the user can first identify the container which has high NUMA balance activity and then narrow down to a specific task within that group, and tune the memory policy of that task. In summary, it is plausible to iterate the
/proc/$pid/schedto find the offending task, but the introduction of per memcg tasks' Numa balancing aggregated activity can further help users identify the task in a divide-and-conquer way.Tested-by K Prateek Nayak <[email protected]>Tested-by Madadi Vineeth Reddy <[email protected]>Signed-off-by Chen Yu <[email protected]>---
v1->v2:
Update theDocumentation/admin-guide/cgroup-v2.rst. (Michal)--- Documentation/admin-guide/cgroup-v2.rst | 6 ++++++ include/linux/sched.h | 4 ++++ include/linux/vm_event_item.h | 2 ++ kernel/sched/core.c | 10 ++++++++-- kernel/sched/debug.c | 4 ++++ mm/memcontrol.c | 2 ++ mm/vmstat.c | 2 ++ 7 files changed, 28 insertions(+), 2 deletions(-)Documentation/admin-guide/cgroup-v2.rst +6
-0@@ -1652,6 +1652,12 @@ The following nested keys are defined. numa_hint_faults (npn) Number of NUMA hinting faults. + numa_task_migrated (npn) + Number of task migration by NUMA balancing. + + numa_task_swapped (npn) + Number of task swap by NUMA balancing. + pgdemote_kswapd Number of pages demoted by kswapd.include/linux/sched.h +4
-0@@ -549,6 +549,10 @@ struct sched_statistics {u64 nr_failed_migrations_running;u64 nr_failed_migrations_hot;u64 nr_forced_migrations; +#ifdef CONFIG_NUMA_BALANCING +u64 numa_task_migrated; +u64 numa_task_swapped; +#endif u64 nr_wakeups;u64 nr_wakeups_sync;include/linux/vm_event_item.h +2
-0@@ -64,6 +64,8 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,NUMA_HINT_FAULTS ,NUMA_HINT_FAULTS_LOCAL ,NUMA_PAGE_MIGRATE , +NUMA_TASK_MIGRATE , +NUMA_TASK_SWAP , #endif #ifdef CONFIG_MIGRATION PGMIGRATE_SUCCESS, PGMIGRATE_FAIL,kernel/sched/core.c +0
-0
kernel/sched/core.c void set_task_cpu(struct task_struct *p, unsigned int new_cpu) · line 3359
Quoted 8 lines
kernel/sched/core.c +5
-0@@ -3352,6 +3352,11 @@ void set_task_cpu(struct task_struct *p, unsigned int new_cpu)#ifdef CONFIG_NUMA_BALANCING static void __migrate_swap_task (struct task_struct *p,int cpu) { +__schedstat_inc (p->stats.numa_task_swapped); + +if (p->mm) +count_memcg_events_mm (p->mm,NUMA_TASK_SWAP ,1 ); +
Is p->mm check necessary? I am pretty sure a !p->mm task cannot reach to this point, task_tick_numa() will filter out those tasks, no hinting page fault on such ones. We can add a likely() macro here to minimize the overhead if there is a reason to keep that check.
Same comment to the other one in migrate_task_to().
Thanks,
Libo
Quoted 56 lines
kernel/sched/core.c +3
-2if (task_on_rq_queued (p)) {struct rq *src_rq, *dst_rq;struct rq_flags srf, drf;@@ -7955,8 +7960,9 @@ int migrate_task_to(struct task_struct *p, int target_cpu)if (!cpumask_test_cpu (target_cpu, p->cpus_ptr))return -EINVAL ; -/* TODO: This is not properly updating schedstats */ - +__schedstat_inc (p->stats.numa_task_migrated); +if (p->mm) +count_memcg_events_mm (p->mm,NUMA_TASK_MIGRATE ,1 );trace_sched_move_numa (p, curr_cpu, target_cpu);return stop_one_cpu (curr_cpu, migration_cpu_stop, &arg); }kernel/sched/debug.c +4
-0@@ -1206,6 +1206,10 @@ void proc_sched_show_task(struct task_struct *p, struct pid_namespace *ns,P_SCHEDSTAT (nr_failed_migrations_running);P_SCHEDSTAT (nr_failed_migrations_hot);P_SCHEDSTAT (nr_forced_migrations); +#ifdef CONFIG_NUMA_BALANCING +P_SCHEDSTAT (numa_task_migrated); +P_SCHEDSTAT (numa_task_swapped); +#endif P_SCHEDSTAT (nr_wakeups);P_SCHEDSTAT (nr_wakeups_sync);P_SCHEDSTAT (nr_wakeups_migrate);mm/memcontrol.c +2
-0@@ -460,6 +460,8 @@ static const unsigned int memcg_vm_event_stat[] = {NUMA_PAGE_MIGRATE ,NUMA_PTE_UPDATES ,NUMA_HINT_FAULTS , +NUMA_TASK_MIGRATE , + NUMA_TASK_SWAP, #endif };mm/vmstat.c +2
-0@@ -1342,6 +1342,8 @@ const char * const vmstat_text[] = {"numa_hint_faults" ,"numa_hint_faults_local" ,"numa_pages_migrated" , +"numa_task_migrated" , +"numa_task_swapped" , #endif #ifdef CONFIG_MIGRATION "pgmigrate_success",
Quoted 4 lines · Libo Chen
Hi Chen Yu,
I think this is quite useful! I hope it can be picked up.
oops, my bad. It looks like this has been picked up. But I think my comment still applies~
Quoted 175 lines
I have one comment below
Quoted 95 lines · Chen Yu
On systems with NUMA balancing enabled, it is found that tracking the task activities due to NUMA balancing is helpful. NUMA balancing has two mechanisms for task migration: one is to migrate the task to an idle CPU in its preferred node, the other is to swap tasks on different nodes if they are on each other's preferred node.
The kernel already has NUMA page migration statistics in
/sys/fs/cgroup/mytest/memory.statand/proc/{PID}/sched, but does not have statistics for task migration/swap. Add the task migration and swap count accordingly.The following two new fields:
numa_task_migratednuma_task_swappedwill be displayed in both
/sys/fs/cgroup/{GROUP}/memory.statand/proc/{PID}/schedIntroducing both pertask and permemcg NUMA balancing statistics helps to quickly evaluate the performance and resource usage of the target workload. For example, the user can first identify the container which has high NUMA balance activity and then narrow down to a specific task within that group, and tune the memory policy of that task. In summary, it is plausible to iterate the
/proc/$pid/schedto find the offending task, but the introduction of per memcg tasks' Numa balancing aggregated activity can further help users identify the task in a divide-and-conquer way.Tested-by K Prateek Nayak <[email protected]>Tested-by Madadi Vineeth Reddy <[email protected]>Signed-off-by Chen Yu <[email protected]>---
v1->v2:
Update theDocumentation/admin-guide/cgroup-v2.rst. (Michal)--- Documentation/admin-guide/cgroup-v2.rst | 6 ++++++ include/linux/sched.h | 4 ++++ include/linux/vm_event_item.h | 2 ++ kernel/sched/core.c | 10 ++++++++-- kernel/sched/debug.c | 4 ++++ mm/memcontrol.c | 2 ++ mm/vmstat.c | 2 ++ 7 files changed, 28 insertions(+), 2 deletions(-)Documentation/admin-guide/cgroup-v2.rst +6
-0@@ -1652,6 +1652,12 @@ The following nested keys are defined. numa_hint_faults (npn) Number of NUMA hinting faults. + numa_task_migrated (npn) + Number of task migration by NUMA balancing. + + numa_task_swapped (npn) + Number of task swap by NUMA balancing. + pgdemote_kswapd Number of pages demoted by kswapd.include/linux/sched.h +4
-0@@ -549,6 +549,10 @@ struct sched_statistics {u64 nr_failed_migrations_running;u64 nr_failed_migrations_hot;u64 nr_forced_migrations; +#ifdef CONFIG_NUMA_BALANCING +u64 numa_task_migrated; +u64 numa_task_swapped; +#endif u64 nr_wakeups;u64 nr_wakeups_sync;include/linux/vm_event_item.h +2
-0@@ -64,6 +64,8 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,NUMA_HINT_FAULTS ,NUMA_HINT_FAULTS_LOCAL ,NUMA_PAGE_MIGRATE , +NUMA_TASK_MIGRATE , +NUMA_TASK_SWAP , #endif #ifdef CONFIG_MIGRATION PGMIGRATE_SUCCESS, PGMIGRATE_FAIL,kernel/sched/core.c +0
-0kernel/sched/core.c void set_task_cpu(struct task_struct *p, unsigned int new_cpu) · line 3359
Quoted 8 lines
kernel/sched/core.c +5
-0@@ -3352,6 +3352,11 @@ void set_task_cpu(struct task_struct *p, unsigned int new_cpu)#ifdef CONFIG_NUMA_BALANCING static void __migrate_swap_task (struct task_struct *p,int cpu) { +__schedstat_inc (p->stats.numa_task_swapped); + +if (p->mm) +count_memcg_events_mm (p->mm,NUMA_TASK_SWAP ,1 ); +Is
p->mmcheck necessary? I am pretty sure a !p->mm task cannot reach to this point,task_tick_numa()will filter out those tasks, no hinting page fault on such ones. We can add alikely()macro here to minimize the overhead if there is a reason to keep that check.Same comment to the other one in
migrate_task_to().Thanks,
LiboQuoted 56 lines
kernel/sched/core.c +3
-2if (task_on_rq_queued (p)) {struct rq *src_rq, *dst_rq;struct rq_flags srf, drf;@@ -7955,8 +7960,9 @@ int migrate_task_to(struct task_struct *p, int target_cpu)if (!cpumask_test_cpu (target_cpu, p->cpus_ptr))return -EINVAL ; -/* TODO: This is not properly updating schedstats */ - +__schedstat_inc (p->stats.numa_task_migrated); +if (p->mm) +count_memcg_events_mm (p->mm,NUMA_TASK_MIGRATE ,1 );trace_sched_move_numa (p, curr_cpu, target_cpu);return stop_one_cpu (curr_cpu, migration_cpu_stop, &arg); }kernel/sched/debug.c +4
-0@@ -1206,6 +1206,10 @@ void proc_sched_show_task(struct task_struct *p, struct pid_namespace *ns,P_SCHEDSTAT (nr_failed_migrations_running);P_SCHEDSTAT (nr_failed_migrations_hot);P_SCHEDSTAT (nr_forced_migrations); +#ifdef CONFIG_NUMA_BALANCING +P_SCHEDSTAT (numa_task_migrated); +P_SCHEDSTAT (numa_task_swapped); +#endif P_SCHEDSTAT (nr_wakeups);P_SCHEDSTAT (nr_wakeups_sync);P_SCHEDSTAT (nr_wakeups_migrate);mm/memcontrol.c +2
-0@@ -460,6 +460,8 @@ static const unsigned int memcg_vm_event_stat[] = {NUMA_PAGE_MIGRATE ,NUMA_PTE_UPDATES ,NUMA_HINT_FAULTS , +NUMA_TASK_MIGRATE , + NUMA_TASK_SWAP, #endif };mm/vmstat.c +2
-0@@ -1342,6 +1342,8 @@ const char * const vmstat_text[] = {"numa_hint_faults" ,"numa_hint_faults_local" ,"numa_pages_migrated" , +"numa_task_migrated" , +"numa_task_swapped" , #endif #ifdef CONFIG_MIGRATION "pgmigrate_success",
Hi Libo,
Quoted 105 lines · Libo Chen
Hi Chen Yu,
I think this is quite useful! I hope it can be picked up.
I have one comment below
Quoted 98 lines · Chen Yu
On systems with NUMA balancing enabled, it is found that tracking the task activities due to NUMA balancing is helpful. NUMA balancing has two mechanisms for task migration: one is to migrate the task to an idle CPU in its preferred node, the other is to swap tasks on different nodes if they are on each other's preferred node.
The kernel already has NUMA page migration statistics in
/sys/fs/cgroup/mytest/memory.statand/proc/{PID}/sched, but does not have statistics for task migration/swap. Add the task migration and swap count accordingly.The following two new fields:
numa_task_migratednuma_task_swappedwill be displayed in both
/sys/fs/cgroup/{GROUP}/memory.statand/proc/{PID}/schedIntroducing both pertask and permemcg NUMA balancing statistics helps to quickly evaluate the performance and resource usage of the target workload. For example, the user can first identify the container which has high NUMA balance activity and then narrow down to a specific task within that group, and tune the memory policy of that task. In summary, it is plausible to iterate the
/proc/$pid/schedto find the offending task, but the introduction of per memcg tasks' Numa balancing aggregated activity can further help users identify the task in a divide-and-conquer way.Tested-by K Prateek Nayak <[email protected]>Tested-by Madadi Vineeth Reddy <[email protected]>Signed-off-by Chen Yu <[email protected]>---
v1->v2:
Update theDocumentation/admin-guide/cgroup-v2.rst. (Michal)--- Documentation/admin-guide/cgroup-v2.rst | 6 ++++++ include/linux/sched.h | 4 ++++ include/linux/vm_event_item.h | 2 ++ kernel/sched/core.c | 10 ++++++++-- kernel/sched/debug.c | 4 ++++ mm/memcontrol.c | 2 ++ mm/vmstat.c | 2 ++ 7 files changed, 28 insertions(+), 2 deletions(-)Documentation/admin-guide/cgroup-v2.rst +6
-0@@ -1652,6 +1652,12 @@ The following nested keys are defined. numa_hint_faults (npn) Number of NUMA hinting faults. + numa_task_migrated (npn) + Number of task migration by NUMA balancing. + + numa_task_swapped (npn) + Number of task swap by NUMA balancing. + pgdemote_kswapd Number of pages demoted by kswapd.include/linux/sched.h +4
-0@@ -549,6 +549,10 @@ struct sched_statistics {u64 nr_failed_migrations_running;u64 nr_failed_migrations_hot;u64 nr_forced_migrations; +#ifdef CONFIG_NUMA_BALANCING +u64 numa_task_migrated; +u64 numa_task_swapped; +#endif u64 nr_wakeups;u64 nr_wakeups_sync;include/linux/vm_event_item.h +2
-0@@ -64,6 +64,8 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,NUMA_HINT_FAULTS ,NUMA_HINT_FAULTS_LOCAL ,NUMA_PAGE_MIGRATE , +NUMA_TASK_MIGRATE , +NUMA_TASK_SWAP , #endif #ifdef CONFIG_MIGRATION PGMIGRATE_SUCCESS, PGMIGRATE_FAIL,kernel/sched/core.c +0
-0@@ -3352,6 +3352,11 @@ void set_task_cpu(struct task_struct *p, unsigned int new_cpu)#ifdef CONFIG_NUMA_BALANCING static void __migrate_swap_task (struct task_struct *p,int cpu) {
Quoted 8 lines
kernel/sched/core.c void set_task_cpu(struct task_struct *p, unsigned int new_cpu) · line 3359
Quoted 5 lines
kernel/sched/core.c +5
-0+__schedstat_inc (p->stats.numa_task_swapped); + +if (p->mm) +count_memcg_events_mm (p->mm,NUMA_TASK_SWAP ,1 ); +Is
p->mmcheck necessary? I am pretty sure a !p->mm task cannot reach to this point,task_tick_numa()will filter out those tasks, no hinting page fault on such ones.
Right, kernel thread is not supposed to reach here.
The swap task is obtained from env->best_task, which is assigned by the functions task_numa_compare() and task_numa_assign(), iff that task has a valid numa_preferred_nid . In other words, only when the swap task is a non-kernel thread will it possess a valid numa_preferred_nid.
Let me remove these checks both in __migrate_swap_task and migrate_task_to().
Thanks,
Chenyu
Quoted 6 lines
We can add a
likely()macro here to minimize the overhead if there is a reason to keep that check.Same comment to the other one in
migrate_task_to().