sched/numa: introduce advanced numa statistic
Subsystems (4)
cover sched/numa: introduce advanced numa statistic
Modern production environment could use hundreds of cgroup to control the resources for different workloads, along with the complicated resource binding.
On NUMA platforms where we have multiple nodes, things become even more complicated, we hope there are more local memory access to improve the performance, and NUMA Balancing keep working hard to achieve that, however, wrong memory policy or node binding could easily waste the effort, result a lot of remote page accessing.
We need to perceive such problems, then we got chance to fix it before there are too much damages, however, there are no good approach yet to help catch the mouse who introduced the remote access.
This patch set is trying to fill in the missing pieces, by introduce the per-cgroup NUMA locality/exectime statistics, and expose the per-task page migration failure counter, with these statistics, we could achieve the daily monitoring on NUMA efficiency, to give warning when things going too wrong.
Please check the third patch for more details.
Thanks to Peter, Mel and Michal for the good advices :-)
Michael Wang (3):
sched/numa: advanced per-cgroup numa statistic sched/numa: expose per-task pages-migration-failure counter sched/numa: documentation for per-cgroup numa stat
Documentation/admin-guide/cg-numa-stat.rst | 161 ++++++++++++++++++++++++ Documentation/admin-guide/kernel-parameters.txt | 4 + Documentation/admin-guide/sysctl/kernel.rst | 9 ++ include/linux/sched.h | 18 ++- include/linux/sched/sysctl.h | 6 + init/Kconfig | 9 ++ kernel/sched/core.c | 91 ++++++++++++++ kernel/sched/debug.c | 1 + kernel/sched/fair.c | 33 +++++ kernel/sched/sched.h | 17 +++ kernel/sysctl.c | 11 ++ 11 files changed, 359 insertions(+), 1 deletion(-) create mode 100644 Documentation/admin-guide/cg-numa-stat.rst
Signature · 1 line
2.14.4.44.g2045bb6
PATCH 1/3 sched/numa: advanced per-cgroup numa statistic
Currently there are no good approach to monitoring the per-cgroup numa efficiency, this could be a trouble especially when groups are sharing CPUs, it's impossible to tell which one caused the remote-memory access by reading hardware counter since multiple workloads could sharing the same CPU, which make it painful when one want to find out the root cause and fix the issue.
In order to address this, we introduced new per-cgroup statistic for numa:
* the numa locality to imply the numa balancing efficiency
* the numa execution time on each node
The task locality is the local page accessing ratio traced on numa balancing PF, and the group locality is the topology of task execution time, sectioned by the locality into 7 regions.
For example the new entry 'cpu.numa_stat' show:
locality 39541 60962 36842 72519 118605 721778 946553 exectime 1220127 1458684
Here we know the workloads in hierarchy executed 1220127ms on node_0 and 1458684ms on node_1 in total, tasks with locality around 0~13% executed for 39541 ms, and tasks with locality around 86~100% executed for 946553 ms, which imply most of the memory access are local access.
By monitoring the new statistic, we will be able to know the numa efficiency of each per-cgroup workloads on machine, whatever they sharing the CPUs or not, we will be able to find out which one introduced the remote access mostly.
Besides, per-node memory topology from 'memory.numa_stat' become more useful when we have the per-node execution time, workloads always executing on node_0 while it's memory is all on node_1 is usually a bad case.
--- include/linux/sched.h | 18 ++++++++- include/linux/sched/sysctl.h | 6 +++ init/Kconfig | 9 +++++ kernel/sched/core.c | 91 ++++++++++++++++++++++++++++++++++++++++++++ kernel/sched/fair.c | 33 ++++++++++++++++ kernel/sched/sched.h | 17 +++++++++ kernel/sysctl.c | 11 ++++++ 7 files changed, 184 insertions(+), 1 deletion(-)
include/linux/sched.h +17 -1
@@ -1113,9 +1113,25 @@ struct task_struct {* numa_faults_locality tracks if faults recorded during the last * scan window were remote/local or failed to migrate. The task scan * period is adapted based on the locality of the faults with different -* weights depending on whether they were shared or private faults +* weights depending on whether they were shared or private faults. +* +* Counter id stand for: +* 0 -- remote faults +* 1 -- local faults +* 2 -- page migration failure +* +* Extra counters when CONFIG_CGROUP_NUMA_STAT enabled: +* 3 -- remote page accessing +* 4 -- local page accessing +* +* The 'remote/local faults' records the cpu-page relationship before +* page migration, while the 'remote/local page accessing' is after. */ +#ifndef CONFIG_CGROUP_NUMA_STAT unsigned long numa_faults_locality[3 ]; +#else +unsigned long numa_faults_locality[5 ]; +#endif unsigned long numa_pages_migrated;#endif /* CONFIG_NUMA_BALANCING */
include/linux/sched/sysctl.h +6 -0
@@ -102,4 +102,10 @@ extern int sched_energy_aware_handler(struct ctl_table *table, int write, loff_t *ppos);#endif +#ifdef CONFIG_CGROUP_NUMA_STAT +extern int sysctl_cg_numa_stat (struct ctl_table *table,int write, +void __user *buffer,size_t *lenp, +loff_t *ppos); +#endif +#endif /* _LINUX_SCHED_SYSCTL_H */
init/Kconfig +9 -0
@@ -817,6 +817,15 @@ config NUMA_BALANCING_DEFAULT_ENABLED If set, automatic NUMA balancing will be enabled if running on a NUMA machine. +config CGROUP_NUMA_STAT + bool "Advanced per-cgroup NUMA statistics" + default n + depends on CGROUP_SCHED && NUMA_BALANCING + help + This option adds support for per-cgroup NUMA locality/execution + statistics, for monitoring NUMA efficiency of per-cgroup workloads + on NUMA platforms with NUMA Balancing enabled. + menuconfig CGROUPS bool "Control Group support" select KERNFS
kernel/sched/core.c +91 -0
109 lines not on this page · raw message
kernel/sched/fair.c +33 -0
@@ -2466,6 +2466,18 @@ void task_numa_fault(int last_cpupid, int mem_node, int pages, int flags) p->numa_faults[task_faults_idx (NUMA_MEMBUF , mem_node, priv)] += pages; p->numa_faults[task_faults_idx (NUMA_CPUBUF , cpu_node, priv)] += pages; p->numa_faults_locality[local] += pages; + +#ifdef CONFIG_CGROUP_NUMA_STAT +if (!static_branch_unlikely (&sched_cg_numa_stat)) +return ; + +/* +* We want to record the real local/remote page access statistic +* here, so use 'mem_node' which is the real residential node of +* page after migrate_misplaced_page(). +*/ + p->numa_faults_locality[3 + !!(mem_node ==numa_node_id ())] += pages; +#endif }static void reset_ptenuma_scan (struct task_struct *p)
@@ -4274,6 +4286,23 @@ static void put_prev_entity(struct cfs_rq *cfs_rq, struct sched_entity *prev) cfs_rq->curr =NULL ; } +#ifdef CONFIG_CGROUP_NUMA_STAT +static void update_numa_statistics (struct cfs_rq *cfs_rq) +{ +int idx; +unsigned long remote = current->numa_faults_locality[3 ]; +unsigned long local = current->numa_faults_locality[4 ]; + + cfs_rq->nstat.jiffies++; + +if (!remote && !local) +return ; + + idx = (NR_NL_INTERVAL -1 ) * local / (remote + local); + cfs_rq->nstat.locality[idx]++; +} +#endif +static void entity_tick (struct cfs_rq *cfs_rq,struct sched_entity *curr,int queued) {
@@ -4287,6 +4316,10 @@ entity_tick(struct cfs_rq *cfs_rq, struct sched_entity *curr, int queued)*/ update_load_avg (cfs_rq, curr,UPDATE_TG );update_cfs_group (curr); +#ifdef CONFIG_CGROUP_NUMA_STAT +if (static_branch_unlikely (&sched_cg_numa_stat)) +update_numa_statistics (cfs_rq); +#endif #ifdef CONFIG_SCHED_HRTICK /*
kernel/sched/sched.h +17 -0
@@ -486,6 +486,16 @@ struct cfs_bandwidth { };#endif /* CONFIG_CGROUP_SCHED */ +#ifdef CONFIG_CGROUP_NUMA_STAT +/* NUMA Locality Interval, 7 buckets for cache align */ +#define NR_NL_INTERVAL 7 + +struct numa_statistics { +u64 jiffies; +u64 locality[NR_NL_INTERVAL ]; +}; +#endif +/* CFS-related fields in a runqueue */ struct cfs_rq {struct load_weight load;
@@ -575,6 +585,9 @@ struct cfs_rq {struct list_head throttled_list;#endif /* CONFIG_CFS_BANDWIDTH */ #endif /* CONFIG_FAIR_GROUP_SCHED */ +#ifdef CONFIG_CGROUP_NUMA_STAT +struct numa_statistics nstat____cacheline_aligned ; +#endif };static inline int rt_bandwidth_enabled (void )
@@ -1601,6 +1614,10 @@ static const_debug __maybe_unused unsigned int sysctl_sched_features =extern struct static_key_false sched_numa_balancing;extern struct static_key_false sched_schedstats; +#ifdef CONFIG_CGROUP_NUMA_STAT +extern struct static_key_false sched_cg_numa_stat; +#endif +static inline u64 global_rt_period (void ) {return (u64 )sysctl_sched_rt_period *NSEC_PER_USEC ;
kernel/sysctl.c +11 -0
@@ -428,6 +428,17 @@ static struct ctl_table kern_table[] = { .extra2 = SYSCTL_ONE, }, #endif /* CONFIG_NUMA_BALANCING */ +#ifdef CONFIG_CGROUP_NUMA_STAT + { + .procname = "cg_numa_stat", + .data = NULL, /* filled in by handler */ + .maxlen = sizeof(unsigned int), + .mode = 0644, + .proc_handler = sysctl_cg_numa_stat, + .extra1 = SYSCTL_ZERO, + .extra2 = SYSCTL_ONE, + }, +#endif /* CONFIG_CGROUP_NUMA_STAT */ #endif /* CONFIG_SCHED_DEBUG */ { .procname = "sched_rt_period_us",
Signature · 1 line
2.14.4.44.g2045bb6
PATCH 2/3 sched/numa: expose per-task pages-migration-failure
In reply to 王贇NUMA balancing will try to migrate pages between nodes, which could caused by memory policy or numa group aggregation, while the page migration could failed too for eg when the target node run out of memory.
Since this is critical to the performance, admin should know how serious the problem is, and take actions before it causing too much performance damage, thus this patch expose the counter as 'migfailed' in '/proc/PID/sched'.
--- kernel/sched/debug.c | 1 + 1 file changed, 1 insertion(+)
kernel/sched/debug.c +1 -0
@@ -848,6 +848,7 @@ static void sched_show_numa(struct task_struct *p, struct seq_file *m)P (total_numa_faults);SEQ_printf (m,"current_node=%d, numa_group_id=%d\n" ,task_node (p),task_numa_group_id (p)); +SEQ_printf (m,"migfailed=%lu\n" , p->numa_faults_locality[2 ]);show_numa_stats (p, m);mpol_put (pol);#endif
Signature · 1 line
2.14.4.44.g2045bb6
PATCH 3/3 sched/numa: documentation for per-cgroup numa stat
In reply to 王贇Add the description for 'cg_numa_stat', also a new doc to explain the details on how to deal with the per-cgroup numa statistics.
--- Documentation/admin-guide/cg-numa-stat.rst | 161 ++++++++++++++++++++++++ Documentation/admin-guide/kernel-parameters.txt | 4 + Documentation/admin-guide/sysctl/kernel.rst | 9 ++ 3 files changed, 174 insertions(+) create mode 100644 Documentation/admin-guide/cg-numa-stat.rst
Documentation/admin-guide/cg-numa-stat.rst new file +161 -0
@@ -0,0 +1,161 @@ +=============================== +Per-cgroup NUMA statistics +=============================== + +Background +---------- + +On NUMA platforms, remote memory accessing always has a performance penalty, +although we have NUMA balancing working hard to maximum the local accessing +proportion, there are still situations it can't helps. + +This could happen in modern production environment, using bunch of cgroups +to classify and control resources which introduced complex configuration on +memory policy, CPUs and NUMA node, NUMA balancing could facing the wrong +memory policy or exhausted local NUMA node, lead into the low local page +accessing proportion. + +We need to perceive such cases, figure out which workloads from which cgroup +has introduced the issues, then we got chance to do adjustment to avoid +performance damages. + +However, there are no hardware counter for per-task local/remote accessing +info, we don't know how many remote page accessing has been done for a +particular task. + +Statistics +---------- + +Fortunately, we have NUMA Balancing which scan task's mapping and trigger PF +periodically, give us the opportunity to record per-task page accessing info. + +By "echo 1 > /proc/sys/kernel/cg_numa_stat" on runtime or add boot parameter +'cg_numa_stat', we will enable the accounting of per-cgroup numa statistics, +the 'cpu.numa_stat' entry of CPU cgroup will show statistics: + + locality -- execution time sectioned by task NUMA locality (in ms) + exectime -- execution time sectioned by NUMA node (in ms) + +We define 'task NUMA locality' as: + + nr_local_page_access * 100 / (nr_local_page_access + nr_remote_page_access) + +this per-task percentage value will be updated on the ticks for current task, +and the access counter will be updated on task's NUMA balancing PF, so only +the pages which NUMA Balancing paid attention to will be accounted. + +On each tick, we acquire the locality of current task on that CPU, accumulating +the ticks into the counter of corresponding locality region, tasks from the +same group sharing the counters, becoming the group locality. + +Similarly, we acquire the NUMA node of current CPU where the current task is +executing on, accumulating the ticks into the counter of corresponding node, +becoming the per-cgroup node execution time. + +To be noticed, the accounting is in a hierarchy way, which means the numa +statistics representing not only the workload of this group, but also the +workloads of all it's descendants. + +For example the 'cpu.numa_stat' show: + locality 39541 60962 36842 72519 118605 721778 946553 + exectime 1220127 1458684 + +The locality is sectioned into 7 regions, closely as: + 0-13% 14-27% 28-42% 43-56% 57-71% 72-85% 86-100% + +And exectime is sectioned into 2 nodes, 0 and 1 in this case. + +Thus we know the workload of this group and it's descendants have totally +executed 1220127ms on node_0 and 1458684ms on node_1, tasks with locality +around 0~13% executed for 39541 ms, and tasks with locality around 87~100% +executed for 946553 ms, which imply most of the memory access are local. + +Monitoring +----------------- + +By monitoring the increments of these statistics, we can easily know whether +NUMA balancing is working well for a particular workload. + +For example we take a 5 secs sample period, and consider locality under 27% +is bad, then on each sampling we have: + + region_bad = region_1 + region_2 + region_all = region_1 + region_2 + ... + region_7 + +and we have the increments as: + + region_bad_diff = region_bad - last_region_bad + region_all_diff = region_all - last_region_all + +which finally become: + + region_bad_percent = region_bad_diff * 100 / region_all_diff + +we can draw a line for region_bad_percent, when the line close to 0 things +are good, when getting close to 100% something is wrong, we can pick a proper +watermark to trigger warning message. + +You may want to drop the data if the region_all is too small, which imply +there are not much available pages for NUMA Balancing, just ignore would be +fine since most likely the workload is insensitive to NUMA. + +Monitoring root group help you control the overall situation, while you may +also want to monitoring all the leaf groups which contain the workloads, this +help to catch the mouse. + +The exectime could be useful when NUMA Balancing is disabled, or when locality +become too small, for NUMA node X we have: + + exectime_X_diff = exectime_X - last_exectime_X + exectime_all_diff = exectime_all - last_exectime_all + +try put your workload into a memory cgroup which providing per-node memory +consumption by 'memory.numa_stat' entry, then we could get: + + memory_percent_X = memory_X * 100 / memory_all + exectime_percent_X = exectime_X_diff * 100 / exectime_all_diff + +These two percentage are usually matched on each node, workload should execute +mostly on the node contain most of it's memory, but it's not guaranteed. + +Depends on which part of the memory accessed mostly by the workload, locality +could still be good with just a little piece of memory locally. + +Thus to tell if things are find or not depends on the understanding of system +resource deployment, however, if you find node X got 100% memory percent but 0% +exectime percent, definitely something is wrong. + +Troubleshooting +--------------- + +After locate which workloads introduced the bad locality, check: + +1). Is the workloads bind into a particular NUMA node? +2). Is there any NUMA node run out of resources? + +There are several ways to bind task's memory with a NUMA node, the strict way +like the MPOL_BIND memory policy or 'cpuset.mems' will limiting the memory +node where to allocate pages, in this situation, admin should make sure the +task is allowed to run on the CPUs of that NUMA node, and make sure there are +available CPU resource there. + +There are also ways to bind task's CPU with a NUMA node, like 'cpuset.cpus' or +sched_setaffinity() syscall, in this situation, NUMA Balancing help to migrate +pages into that node, admin should make sure there are available memory there. + +Admin could try rebind or unbind the NUMA node to erase the damage, make a +change then observe the statistics see if things get better until the situation +is acceptable. + +Highlights +---------- + +For some tasks, NUMA Balancing may found no necessary to scan pages, and +locality could always be 0 or small number, don't pay attention to them +since they most likely insensitive to NUMA. + +There are no accounting until the option turned on, so enable it in advance +if you want to have the whole history. + +We have per-task migfailed counter to tell how many page migration has been +failed for a particular task, you will find it in /proc/PID/sched entry.
Documentation/admin-guide/kernel-parameters.txt +4 -0
@@ -3191,6 +3191,10 @@ numa_balancing= [KNL,X86] Enable or disable automatic NUMA balancing. Allowed values are enable and disable + cg_numa_atat [KNL] Enable advanced per-cgroup numa statistics. + Useful to debug NUMA efficiency problems when there are + lot's of per-cgroup workloads. + numa_zonelist_order= [KNL, BOOT] Select zonelist order for NUMA. 'node', 'default' can be specified This can be set from sysctl after boot.
Documentation/admin-guide/sysctl/kernel.rst +9 -0
@@ -572,6 +572,15 @@ rate for each task. numa_balancing_scan_size_mb is how many megabytes worth of pages are scanned for a given scan. +cg_numa_stat: +============= + +Enables/disables advanced per-cgroup NUMA statistic. + +0: disabled (default). +1: enabled. + +Check Documentation/admin-guide/cg-numa-stat.rst for details. osrelease, ostype & version: ============================
Signature · 1 line
2.14.4.44.g2045bb6
Jonathan Corbet
maintainerRe: [PATCH 3/3] sched/numa: documentation for per-cgroup numa stat
Quoted 7 lines · On Wed, 13 Nov 2019 11:45:59 +0800 王贇 <[email protected]> wrote:
Add the description for '
cg_numa_stat', also a new doc to explain the details on how to deal with the per-cgroup numa statistics.Cc Peter Zijlstra <[email protected]>Cc Michal Koutný <[email protected]>Cc Mel Gorman <[email protected]>Signed-off-by Michael Wang <[email protected]>
Quoted 6 lines
--- Documentation/admin-guide/cg-numa-stat.rst | 161 ++++++++++++++++++++++++ Documentation/admin-guide/kernel-parameters.txt | 4 + Documentation/admin-guide/sysctl/kernel.rst | 9 ++ 3 files changed, 174 insertions(+) create mode 100644 Documentation/admin-guide/cg-numa-stat.rst
Thanks for adding documentation for your new feature! When you add a new RST file, though, you should also add it to index.rst so that it becomes a part of the docs build.
A couple of nits below...
Quoted 57 lines
Documentation/admin-guide/cg-numa-stat.rst new file +51
-0@@ -0,0 +1,161 @@ +=============================== +Per-cgroup NUMA statistics +=============================== + +Background +---------- + +On NUMA platforms, remote memory accessing always has a performance penalty, +although we have NUMA balancing working hard to maximum the local accessing +proportion, there are still situations it can't helps. + +This could happen in modern production environment, using bunch of cgroups +to classify and control resources which introduced complex configuration on +memory policy, CPUs and NUMA node, NUMA balancing could facing the wrong +memory policy or exhausted local NUMA node, lead into the low local page +accessing proportion. + +We need to perceive such cases, figure out which workloads from which cgroup +has introduced the issues, then we got chance to do adjustment to avoid +performance damages. + +However, there are no hardware counter for per-task local/remote accessing +info, we don't know how many remote page accessing has been done for a +particular task. + +Statistics +---------- + +Fortunately, we have NUMA Balancing which scan task's mapping and trigger PF +periodically, give us the opportunity to record per-task page accessing info. + +By "echo 1 > /proc/sys/kernel/cg_numa_stat" on runtime or add boot parameter +'cg_numa_stat', we will enable the accounting of per-cgroup numa statistics, +the 'cpu.numa_stat' entry of CPU cgroup will show statistics: + + locality -- execution time sectioned by task NUMA locality (in ms) + exectime -- execution time sectioned by NUMA node (in ms) + +We define 'task NUMA locality' as: + + nr_local_page_access * 100 / (nr_local_page_access + nr_remote_page_access) + +this per-task percentage value will be updated on the ticks for current task, +and the access counter will be updated on task's NUMA balancing PF, so only +the pages which NUMA Balancing paid attention to will be accounted. + +On each tick, we acquire the locality of current task on that CPU, accumulating +the ticks into the counter of corresponding locality region, tasks from the +same group sharing the counters, becoming the group locality. + +Similarly, we acquire the NUMA node of current CPU where the current task is
Documentation/admin-guide/cg-numa-stat.rst line 61
Quoted 10 lines
Documentation/admin-guide/cg-numa-stat.rst new file +10
-0+executing on, accumulating the ticks into the counter of corresponding node, +becoming the per-cgroup node execution time. + +To be noticed, the accounting is in a hierarchy way, which means the numa +statistics representing not only the workload of this group, but also the +workloads of all it's descendants. + +For example the 'cpu.numa_stat' show: + locality 39541 60962 36842 72519 118605 721778 946553 + exectime 1220127 1458684
You almost certainly want that rendered as a literal block, so say "show::". There are other places where you'll want to do that as well.
Documentation/admin-guide/cg-numa-stat.rst line 74
Quoted 12 lines
Documentation/admin-guide/cg-numa-stat.rst new file +12
-0+The locality is sectioned into 7 regions, closely as: + 0-13% 14-27% 28-42% 43-56% 57-71% 72-85% 86-100% + +And exectime is sectioned into 2 nodes, 0 and 1 in this case. + +Thus we know the workload of this group and it's descendants have totally +executed 1220127ms on node_0 and 1458684ms on node_1, tasks with locality +around 0~13% executed for 39541 ms, and tasks with locality around 87~100% +executed for 946553 ms, which imply most of the memory access are local. + +Monitoring +-----------------
A slightly long underline :)
I'll stop here; thanks again for adding documentation.
jon
Re: [PATCH 3/3] sched/numa: documentation for per-cgroup numa stat
Hi, Jonathan
Quoted 17 lines · Jonathan Corbet
Quoted 7 lines · On Wed, 13 Nov 2019 11:45:59 +0800 王贇 <[email protected]> wrote:
Add the description for '
cg_numa_stat', also a new doc to explain the details on how to deal with the per-cgroup numa statistics.Cc Peter Zijlstra <[email protected]>Cc Michal Koutný <[email protected]>Cc Mel Gorman <[email protected]>Signed-off-by Michael Wang <[email protected]>Quoted 6 lines
--- Documentation/admin-guide/cg-numa-stat.rst | 161 ++++++++++++++++++++++++ Documentation/admin-guide/kernel-parameters.txt | 4 + Documentation/admin-guide/sysctl/kernel.rst | 9 ++ 3 files changed, 174 insertions(+) create mode 100644 Documentation/admin-guide/cg-numa-stat.rst
Quoted 3 lines
Thanks for adding documentation for your new feature! When you add a new RST file, though, you should also add it to
index.rstso that it becomes a part of the docs build.
Thanks for pointing out :-) will fix this in next version.
Quoted 7 lines
A couple of nits below...
Quoted 4 lines
Documentation/admin-guide/cg-numa-stat.rst new file +0
-1--- /dev/null
[snip]
Quoted 6 lines
Documentation/admin-guide/cg-numa-stat.rst line 61
Quoted 3 lines
Documentation/admin-guide/cg-numa-stat.rst new file +3
-0+For example the 'cpu.numa_stat' show: + locality 39541 60962 36842 72519 118605 721778 946553 + exectime 1220127 1458684You almost certainly want that rendered as a literal block, so say "show::". There are other places where you'll want to do that as well.
I see, will fix such cases.
Quoted 15 lines
Documentation/admin-guide/cg-numa-stat.rst line 74
Quoted 13 lines
Documentation/admin-guide/cg-numa-stat.rst new file +12
-0+The locality is sectioned into 7 regions, closely as: + 0-13% 14-27% 28-42% 43-56% 57-71% 72-85% 86-100% + +And exectime is sectioned into 2 nodes, 0 and 1 in this case. + +Thus we know the workload of this group and it's descendants have totally +executed 1220127ms on node_0 and 1458684ms on node_1, tasks with locality +around 0~13% executed for 39541 ms, and tasks with locality around 87~100% +executed for 946553 ms, which imply most of the memory access are local. + +Monitoring +-----------------A slightly long underline :)
Aha, will fix this too.
Regards,
Michael Wang
Quoted 5 lines
I'll stop here; thanks again for adding documentation.
jon
Re: [PATCH 3/3] sched/numa: documentation for per-cgroup numa stat
In reply to 王贇Since the documentation talks about fairly advanced concepts, every little bit of readability improvement helps. I tried to make suggestions that I feel make it easier to read, hopefully my nitpicking is not too annoying.
Documentation/admin-guide/cg-numa-stat.rst line 10
Quoted 3 lines · 王贇
Documentation/admin-guide/cg-numa-stat.rst new file +3
-0+On NUMA platforms, remote memory accessing always has a performance penalty, +although we have NUMA balancing working hard to maximum the local accessing +proportion, there are still situations it can't helps.
Nit: working hard to maximize the access locality... can't helps -> can't help
Documentation/admin-guide/cg-numa-stat.rst line 16
Quoted 6 lines
Documentation/admin-guide/cg-numa-stat.rst new file +6
-0+ +This could happen in modern production environment, using bunch of cgroups +to classify and control resources which introduced complex configuration on +memory policy, CPUs and NUMA node, NUMA balancing could facing the wrong +memory policy or exhausted local NUMA node, lead into the low local page +accessing proportion.
I find the below a bit easier to read.
This could happen in modern production environment. When a large number of cgroups
are used to classify and control resources, this creates a complex memory policy configuration
for CPUs and NUMA nodes. In such cases NUMA balancing could end up with the wrong
memory policy or exhausted local NUMA node, which would lead to low percentage of local page
accesses.
Documentation/admin-guide/cg-numa-stat.rst line 20
Quoted 3 lines
Documentation/admin-guide/cg-numa-stat.rst new file +3
-0+We need to perceive such cases, figure out which workloads from which cgroup +has introduced the issues, then we got chance to do adjustment to avoid +performance damages.
Nit: perceive -> detect, got-> get, damages-> degradation
Documentation/admin-guide/cg-numa-stat.rst line 24
Quoted 3 lines
Documentation/admin-guide/cg-numa-stat.rst new file +3
-0+However, there are no hardware counter for per-task local/remote accessing +info, we don't know how many remote page accessing has been done for a +particular task.
Nit: counters.
Nit: we don't know how many remote page accesses have occurred for a
Documentation/admin-guide/cg-numa-stat.rst line 30
Quoted 6 lines
Documentation/admin-guide/cg-numa-stat.rst new file +6
-0+ +Statistics +---------- + +Fortunately, we have NUMA Balancing which scan task's mapping and trigger PF +periodically, give us the opportunity to record per-task page accessing info.
Nit: scans, triggers, gives.
Quoted 1 line
+By "echo 1 >
/proc/sys/kernel/cg_numa_stat" on runtime or add boot parameter
Nit: at runtime or adding boot parameter
Documentation/admin-guide/cg-numa-stat.rst line 57
Quoted 3 lines
Documentation/admin-guide/cg-numa-stat.rst new file +3
-0+To be noticed, the accounting is in a hierarchy way, which means the numa +statistics representing not only the workload of this group, but also the +workloads of all it's descendants.
Note that the accounting is hierarchical, which means the numa statistics for a given group represents not only the workload of this group, but also the
workloads of all it's descendants.
Documentation/admin-guide/cg-numa-stat.rst line 64
Quoted 7 lines
Documentation/admin-guide/cg-numa-stat.rst new file +7
-0+ +For example the 'cpu.numa_stat' show: + locality 39541 60962 36842 72519 118605 721778 946553 + exectime 1220127 1458684 + +The locality is sectioned into 7 regions, closely as: + 0-13% 14-27% 28-42% 43-56% 57-71% 72-85% 86-100%
Nit: closely -> approximately?
Quoted 1 line
+we can draw a line for
region_bad_percent, when the line close to 0 things
nit: we can plot?
Documentation/admin-guide/cg-numa-stat.rst line 98
Quoted 4 lines
Documentation/admin-guide/cg-numa-stat.rst new file +3
-0+are good, when getting close to 100% something is wrong, we can pick a proper +watermark to trigger warning message. +You may want to drop the data if the region_all is too small, which imply
Nit: implies
Quoted 1 line
+there are not much available pages for NUMA Balancing, just ignore would be
Nit: not many... ingoring
Documentation/admin-guide/cg-numa-stat.rst line 102
Quoted 2 lines
Documentation/admin-guide/cg-numa-stat.rst new file +2
-0+fine since most likely the workload is insensitive to NUMA. +Monitoring root group help you control the overall situation, while you may
Nit: helps
Quoted 1 line
+also want to monitoring all the leaf groups which contain the workloads, this
Nit: monitor
Quoted 1 line
+help to catch the mouse.
Nit: helps
Quoted 1 line
+become too small, for NUMA node X we have:
Nit: becomes
Quoted 1 line
+try put your workload into a memory cgroup which providing per-node memory
Nit: try to put
Quoted 1 line
+These two percentage are usually matched on each node, workload should execute
Nit: percentages
Quoted 1 line
+Depends on which part of the memory accessed mostly by the workload, locality
Depending on which part of the memory is accessed.
"mostly by the workload" - not sure what you mean here, the majority of accesses from the
workload fall into this part of memory or that accesses from processes other than the workload
are rare?
Quoted 1 line
+could still be good with just a little piece of memory locally.
?
Quoted 1 line
+Thus to tell if things are find or not depends on the understanding of system
are fine
Quoted 1 line
+After locate which workloads introduced the bad locality, check:
locate -> indentifying
Quoted 2 lines
+
+1). Is the workloads bind into a particular NUMA node?
bind into -> bound to
Quoted 1 line
+2). Is there any NUMA node run out of resources?
Has any .. run out of resources
Documentation/admin-guide/kernel-parameters.txt line 3196
Quoted 3 lines
Documentation/admin-guide/kernel-parameters.txt +1
-0+ lot's of per-cgroup workloads.
lots
Re: [PATCH 3/3] sched/numa: documentation for per-cgroup numa stat
Hi, Iurii
Quoted 3 lines · Iurii Zaikin
Since the documentation talks about fairly advanced concepts, every little bit of readability improvement helps. I tried to make suggestions that I feel make it easier to read, hopefully my nitpicking is not too annoying.
Any comments are welcomed :-)
Quoted 6 lines · 王贇
Documentation/admin-guide/cg-numa-stat.rst line 10
Quoted 3 lines
Documentation/admin-guide/cg-numa-stat.rst new file +3
-0+On NUMA platforms, remote memory accessing always has a performance penalty, +although we have NUMA balancing working hard to maximum the local accessing +proportion, there are still situations it can't helps.Nit: working hard to maximize the access locality... can't helps -> can't help>> +
Quoted 15 lines
Documentation/admin-guide/cg-numa-stat.rst line 16
Quoted 5 lines
Documentation/admin-guide/cg-numa-stat.rst new file +5
-0+This could happen in modern production environment, using bunch of cgroups +to classify and control resources which introduced complex configuration on +memory policy, CPUs and NUMA node, NUMA balancing could facing the wrong +memory policy or exhausted local NUMA node, lead into the low local page +accessing proportion.I find the below a bit easier to read.
This could happen in modern production environment. When a large number of cgroups
are used to classify and control resources, this creates a complex memory policy configuration
for CPUs and NUMA nodes. In such cases NUMA balancing could end up with the wrong
memory policy or exhausted local NUMA node, which would lead to low percentage of local page
accesses.
Sounds better, just for the configuration part, since memory policy, CPUs and NUMA nodes are configured by different approach, maybe we should still separate them like:
This could happen in modern production environment. When a large number of cgroups are used to classify and control resources, this creates a complex configuration for memory policy, CPUs and NUMA nodes. In such cases NUMA balancing could end up with the wrong memory policy or exhausted local NUMA node, which would lead to low percentage of local page accesses.
Quoted 58 lines
Documentation/admin-guide/cg-numa-stat.rst line 20
Quoted 4 lines
Documentation/admin-guide/cg-numa-stat.rst new file +3
-0+We need to perceive such cases, figure out which workloads from which cgroup +has introduced the issues, then we got chance to do adjustment to avoid +performance damages.Nit: perceive -> detect, got-> get, damages-> degradation
Documentation/admin-guide/cg-numa-stat.rst line 24
Quoted 3 lines
Documentation/admin-guide/cg-numa-stat.rst new file +3
-0+However, there are no hardware counter for per-task local/remote accessing +info, we don't know how many remote page accessing has been done for a +particular task.Nit: counters.
Nit: we don't know how many remote page accesses have occurred for aDocumentation/admin-guide/cg-numa-stat.rst line 30
Quoted 6 lines
Documentation/admin-guide/cg-numa-stat.rst new file +6
-0+ +Statistics +---------- + +Fortunately, we have NUMA Balancing which scan task's mapping and trigger PF +periodically, give us the opportunity to record per-task page accessing info.Nit: scans, triggers, gives.
Quoted 1 line
+By "echo 1 >
/proc/sys/kernel/cg_numa_stat" on runtime or add boot parameterNit: at runtime or adding boot parameter
Documentation/admin-guide/cg-numa-stat.rst line 57
Quoted 3 lines
Documentation/admin-guide/cg-numa-stat.rst new file +3
-0+To be noticed, the accounting is in a hierarchy way, which means the numa +statistics representing not only the workload of this group, but also the +workloads of all it's descendants.Note that the accounting is hierarchical, which means the numa statistics for a given group represents not only the workload of this group, but also the
workloads of all it's descendants.Documentation/admin-guide/cg-numa-stat.rst line 64
Quoted 7 lines
Documentation/admin-guide/cg-numa-stat.rst new file +7
-0+ +For example the 'cpu.numa_stat' show: + locality 39541 60962 36842 72519 118605 721778 946553 + exectime 1220127 1458684 + +The locality is sectioned into 7 regions, closely as: + 0-13% 14-27% 28-42% 43-56% 57-71% 72-85% 86-100%Nit: closely -> approximately?
Quoted 1 line
+we can draw a line for
region_bad_percent, when the line close to 0 thingsnit: we can plot?
Documentation/admin-guide/cg-numa-stat.rst line 98
Quoted 4 lines
Documentation/admin-guide/cg-numa-stat.rst new file +3
-0+are good, when getting close to 100% something is wrong, we can pick a proper +watermark to trigger warning message. +You may want to drop the data if the region_all is too small, which implyNit: implies
Quoted 1 line
+there are not much available pages for NUMA Balancing, just ignore would be
Nit: not many... ingoring
Documentation/admin-guide/cg-numa-stat.rst line 102
Quoted 2 lines
Documentation/admin-guide/cg-numa-stat.rst new file +2
-0+fine since most likely the workload is insensitive to NUMA. +Monitoring root group help you control the overall situation, while you mayNit: helps
Quoted 1 line
+also want to monitoring all the leaf groups which contain the workloads, this
Nit: monitor
Quoted 1 line
+help to catch the mouse.
Nit: helps
Quoted 1 line
+become too small, for NUMA node X we have:
Nit: becomes
Quoted 1 line
+try put your workload into a memory cgroup which providing per-node memory
Nit: try to put
Quoted 8 lines
Quoted 1 line
+These two percentage are usually matched on each node, workload should execute
Nit: percentages
Quoted 1 line
+Depends on which part of the memory accessed mostly by the workload, locality> Depending on which part of the memory is accessed.
"mostly by the workload" - not sure what you mean here, the majority of accesses from the
workload fall into this part of memory or that accesses from processes other than the workload
are rare?
The prev one actually, sometime the workload only access part of it's memory, could be a small part but as long as this part is local, things could be fine.
Quoted 2 lines
Quoted 1 line
+could still be good with just a little piece of memory locally.
?
whatabout:
workload may only access a small part of it's memory, in such cases, although the majority of memory are remotely, locality could still be good.
Quoted 6 lines
Quoted 1 line
+Thus to tell if things are find or not depends on the understanding of system
are fine
Quoted 1 line
+After locate which workloads introduced the bad locality, check:
locate -> indentifying
Quoted 2 lines
+
+1). Is the workloads bind into a particular NUMA node?
Quoted 7 lines
bind into -> bound to
Quoted 1 line
+2). Is there any NUMA node run out of resources?
Has any .. run out of resources
Documentation/admin-guide/kernel-parameters.txt line 3196
Quoted 3 lines
Documentation/admin-guide/kernel-parameters.txt +1
-0+ lot's of per-cgroup workloads.lots
Thanks for point out all these issues, very helpful :-)
Should apply them in next version.
Regards,
Michael Wang
Quoted 1 line
PATCH v2 3/3 sched/numa: documentation for per-cgroup numa stat
In reply to 王贇Add the description for 'cg_numa_stat', also a new doc to explain the details on how to deal with the per-cgroup numa statistics.
---
Since v1:
* thanks to Iurii for the better sentences
* thanks to Jonathan for the better format
Documentation/admin-guide/cg-numa-stat.rst | 163 ++++++++++++++++++++++++ Documentation/admin-guide/index.rst | 1 + Documentation/admin-guide/kernel-parameters.txt | 4 + Documentation/admin-guide/sysctl/kernel.rst | 9 ++ 4 files changed, 177 insertions(+) create mode 100644 Documentation/admin-guide/cg-numa-stat.rst
Documentation/admin-guide/cg-numa-stat.rst new file +163 -0
@@ -0,0 +1,163 @@ +=============================== +Per-cgroup NUMA statistics +=============================== + +Background +---------- + +On NUMA platforms, remote memory accessing always has a performance penalty, +although we have NUMA balancing working hard to maximize the access locality, +there are still situations it can't help. + +This could happen in modern production environment. When a large number of +cgroups are used to classify and control resources, this creates a complex +configuration for memory policy, CPUs and NUMA nodes. In such cases NUMA +balancing could end up with the wrong memory policy or exhausted local NUMA +node, which would lead to low percentage of local page accesses. + +We need to detect such cases, figure out which workloads from which cgroup +has introduced the issues, then we get chance to do adjustment to avoid +performance degradation. + +However, there are no hardware counters for per-task local/remote accessing +info, we don't know how many remote page accesses have occurred for a +particular task. + +Statistics +---------- + +Fortunately, we have NUMA Balancing which scans task's mapping and triggers PF +periodically, gives us the opportunity to record per-task page accessing info. + +By "echo 1 > /proc/sys/kernel/cg_numa_stat" at runtime or adding boot parameter +'cg_numa_stat', we will enable the accounting of per-cgroup numa statistics, +the 'cpu.numa_stat' entry of CPU cgroup will show statistics:: + + locality -- execution time sectioned by task NUMA locality (in ms) + exectime -- execution time sectioned by NUMA node (in ms) + +We define 'task NUMA locality' as:: + + nr_local_page_access * 100 / (nr_local_page_access + nr_remote_page_access) + +this per-task percentage value will be updated on the ticks for current task, +and the access counter will be updated on task's NUMA balancing PF, so only +the pages which NUMA Balancing paid attention to will be accounted. + +On each tick, we acquire the locality of current task on that CPU, accumulating +the ticks into the counter of corresponding locality region, tasks from the +same group sharing the counters, becoming the group locality. + +Similarly, we acquire the NUMA node of current CPU where the current task is +executing on, accumulating the ticks into the counter of corresponding node, +becoming the per-cgroup node execution time. + +Note that the accounting is hierarchical, which means the numa statistics for +a given group represents not only the workload of this group, but also the +workloads of all it's descendants. + +For example the 'cpu.numa_stat' show:: + + locality 39541 60962 36842 72519 118605 721778 946553 + exectime 1220127 1458684 + +The locality is sectioned into 7 regions, approximately as:: + + 0-13% 14-27% 28-42% 43-56% 57-71% 72-85% 86-100% + +And exectime is sectioned into 2 nodes, 0 and 1 in this case. + +Thus we know the workload of this group and it's descendants have totally +executed 1220127ms on node_0 and 1458684ms on node_1, tasks with locality +around 0~13% executed for 39541 ms, and tasks with locality around 87~100% +executed for 946553 ms, which imply most of the memory access are local. + +Monitoring +---------- + +By monitoring the increments of these statistics, we can easily know whether +NUMA balancing is working well for a particular workload. + +For example we take a 5 secs sample period, and consider locality under 27% +is bad, then on each sampling we have:: + + region_bad = region_1 + region_2 + region_all = region_1 + region_2 + ... + region_7 + +and we have the increments as:: + + region_bad_diff = region_bad - last_region_bad + region_all_diff = region_all - last_region_all + +which finally become:: + + region_bad_percent = region_bad_diff * 100 / region_all_diff + +we can plot a line for region_bad_percent, when the line close to 0 things +are good, when getting close to 100% something is wrong, we can pick a proper +watermark to trigger warning message. + +You may want to drop the data if the region_all is too small, which implies +there are not many available pages for NUMA Balancing, ignoring would be fine +since most likely the workload is insensitive to NUMA. + +Monitoring root group helps you control the overall situation, while you may +also want to monitor all the leaf groups which contain the workloads, this +helps to catch the mouse. + +The exectime could be useful when NUMA Balancing is disabled, or when locality +becomes too small, for NUMA node X we have:: + + exectime_X_diff = exectime_X - last_exectime_X + exectime_all_diff = exectime_all - last_exectime_all + +try to put your workload into a memory cgroup which providing per-node memory +consumption by 'memory.numa_stat' entry, then we could get:: + + memory_percent_X = memory_X * 100 / memory_all + exectime_percent_X = exectime_X_diff * 100 / exectime_all_diff + +These two percentages are usually matched on each node, workload should execute +mostly on the node contain most of it's memory, but it's not guaranteed. + +The workload may only access a small part of it's memory, in such cases although +the majority of memory are remotely, locality could still be good. + +Thus to tell if things are fine or not depends on the understanding of system +resource deployment, however, if you find node X got 100% memory percent but 0% +exectime percent, definitely something is wrong. + +Troubleshooting +--------------- + +After identifying which workload introduced the bad locality, check: + +1). Is the workload bound to a particular NUMA node? +2). Has any NUMA node run out of resources? + +There are several ways to bind task's memory with a NUMA node, the strict way +like the MPOL_BIND memory policy or 'cpuset.mems' will limiting the memory +node where to allocate pages, in this situation, admin should make sure the +task is allowed to run on the CPUs of that NUMA node, and make sure there are +available CPU resource there. + +There are also ways to bind task's CPU with a NUMA node, like 'cpuset.cpus' or +sched_setaffinity() syscall, in this situation, NUMA Balancing help to migrate +pages into that node, admin should make sure there are available memory there. + +Admin could try rebind or unbind the NUMA node to erase the damage, make a +change then observe the statistics see if things get better until the situation +is acceptable. + +Highlights +---------- + +For some tasks, NUMA Balancing may found no necessary to scan pages, and +locality could always be 0 or small number, don't pay attention to them +since they most likely insensitive to NUMA. + +There are no accounting until the option turned on, so enable it in advance +if you want to have the whole history. + +We have per-task migfailed counter to tell how many page migration has been +failed for a particular task, you will find it in /proc/PID/sched entry.
Documentation/admin-guide/index.rst +1 -0
@@ -112,6 +112,7 @@ configure specific aspects of kernel behavior to your liking. video-output wimax/index xfs + cg-numa-stat .. only:: subproject and html
Documentation/admin-guide/kernel-parameters.txt +4 -0
@@ -3191,6 +3191,10 @@ numa_balancing= [KNL,X86] Enable or disable automatic NUMA balancing. Allowed values are enable and disable + cg_numa_atat [KNL] Enable advanced per-cgroup numa statistics. + Useful to debug NUMA efficiency problems when there are + lots of per-cgroup workloads. + numa_zonelist_order= [KNL, BOOT] Select zonelist order for NUMA. 'node', 'default' can be specified This can be set from sysctl after boot.
Documentation/admin-guide/sysctl/kernel.rst +9 -0
@@ -572,6 +572,15 @@ rate for each task. numa_balancing_scan_size_mb is how many megabytes worth of pages are scanned for a given scan. +cg_numa_stat: +============= + +Enables/disables advanced per-cgroup NUMA statistic. + +0: disabled (default). +1: enabled. + +Check Documentation/admin-guide/cg-numa-stat.rst for details. osrelease, ostype & version: ============================
Signature · 1 line
2.14.4.44.g2045bb6
Hi, Mel
I hope this version has addressed the issues you mentioned :-)
Does it looks better now?
Regards,
Michael Wang
Quoted 44 lines · 王贇
Modern production environment could use hundreds of cgroup to control the resources for different workloads, along with the complicated resource binding.
On NUMA platforms where we have multiple nodes, things become even more complicated, we hope there are more local memory access to improve the performance, and NUMA Balancing keep working hard to achieve that, however, wrong memory policy or node binding could easily waste the effort, result a lot of remote page accessing.
We need to perceive such problems, then we got chance to fix it before there are too much damages, however, there are no good approach yet to help catch the mouse who introduced the remote access.
This patch set is trying to fill in the missing pieces, by introduce the per-cgroup NUMA locality/exectime statistics, and expose the per-task page migration failure counter, with these statistics, we could achieve the daily monitoring on NUMA efficiency, to give warning when things going too wrong.
Please check the third patch for more details.
Thanks to Peter, Mel and Michal for the good advices :-)
Michael Wang (3):
sched/numa: advanced per-cgroup numa statistic sched/numa: expose per-task pages-migration-failure counter sched/numa: documentation for per-cgroup numa statDocumentation/admin-guide/cg-numa-stat.rst | 161 ++++++++++++++++++++++++ Documentation/admin-guide/kernel-parameters.txt | 4 + Documentation/admin-guide/sysctl/kernel.rst | 9 ++ include/linux/sched.h | 18 ++- include/linux/sched/sysctl.h | 6 + init/Kconfig | 9 ++ kernel/sched/core.c | 91 ++++++++++++++ kernel/sched/debug.c | 1 + kernel/sched/fair.c | 33 +++++ kernel/sched/sched.h | 17 +++ kernel/sysctl.c | 11 ++ 11 files changed, 359 insertions(+), 1 deletion(-) create mode 100644 Documentation/admin-guide/cg-numa-stat.rst
Hi, Peter
How do you think about this version, does it looks fine to you?
Regards,
Michael Wang
Quoted 44 lines · 王贇
Modern production environment could use hundreds of cgroup to control the resources for different workloads, along with the complicated resource binding.
On NUMA platforms where we have multiple nodes, things become even more complicated, we hope there are more local memory access to improve the performance, and NUMA Balancing keep working hard to achieve that, however, wrong memory policy or node binding could easily waste the effort, result a lot of remote page accessing.
We need to perceive such problems, then we got chance to fix it before there are too much damages, however, there are no good approach yet to help catch the mouse who introduced the remote access.
This patch set is trying to fill in the missing pieces, by introduce the per-cgroup NUMA locality/exectime statistics, and expose the per-task page migration failure counter, with these statistics, we could achieve the daily monitoring on NUMA efficiency, to give warning when things going too wrong.
Please check the third patch for more details.
Thanks to Peter, Mel and Michal for the good advices :-)
Michael Wang (3):
sched/numa: advanced per-cgroup numa statistic sched/numa: expose per-task pages-migration-failure counter sched/numa: documentation for per-cgroup numa statDocumentation/admin-guide/cg-numa-stat.rst | 161 ++++++++++++++++++++++++ Documentation/admin-guide/kernel-parameters.txt | 4 + Documentation/admin-guide/sysctl/kernel.rst | 9 ++ include/linux/sched.h | 18 ++- include/linux/sched/sysctl.h | 6 + init/Kconfig | 9 ++ kernel/sched/core.c | 91 ++++++++++++++ kernel/sched/debug.c | 1 + kernel/sched/fair.c | 33 +++++ kernel/sched/sched.h | 17 +++ kernel/sysctl.c | 11 ++ 11 files changed, 359 insertions(+), 1 deletion(-) create mode 100644 Documentation/admin-guide/cg-numa-stat.rst
v2 cover sched/numa: introduce advanced numa statistic
In reply to 王贇Since v1:
* Improved documentation
Modern production environment could use hundreds of cgroup to control the resources for different workloads, along with the complicated resource binding.
On NUMA platforms where we have multiple nodes, things become even more complicated, we hope there are more local memory access to improve the performance, and NUMA Balancing keep working hard to achieve that, however, wrong memory policy or node binding could easily waste the effort, result a lot of remote page accessing.
We need to perceive such problems, then we got chance to fix it before there are too much damages, however, there are no good approach yet to help catch the mouse who introduced the remote access.
This patch set is trying to fill in the missing pieces, by introduce the per-cgroup NUMA locality/exectime statistics, and expose the per-task page migration failure counter, with these statistics, we could achieve the daily monitoring on NUMA efficiency, to give warning when things going too wrong.
Please check the third patch for more details.
Thanks to Peter, Mel and Michal for the good advice.
Michael Wang (3):
sched/numa: advanced per-cgroup numa statistic sched/numa: expose per-task pages-migration-failure counter sched/numa: documentation for per-cgroup numa stat
Documentation/admin-guide/cg-numa-stat.rst | 163 ++++++++++++++++++++++++ Documentation/admin-guide/index.rst | 1 + Documentation/admin-guide/kernel-parameters.txt | 4 + Documentation/admin-guide/sysctl/kernel.rst | 9 ++ include/linux/sched.h | 18 ++- include/linux/sched/sysctl.h | 6 + init/Kconfig | 9 ++ kernel/sched/core.c | 91 +++++++++++++ kernel/sched/debug.c | 1 + kernel/sched/fair.c | 33 +++++ kernel/sched/sched.h | 17 +++ kernel/sysctl.c | 11 ++ 12 files changed, 362 insertions(+), 1 deletion(-) create mode 100644 Documentation/admin-guide/cg-numa-stat.rst
Signature · 1 line
2.14.4.44.g2045bb6
PATCH v2 1/3 sched/numa: advanced per-cgroup numa statistic
Currently there are no good approach to monitoring the per-cgroup numa efficiency, this could be a trouble especially when groups are sharing CPUs, it's impossible to tell which one caused the remote-memory access by reading hardware counter since multiple workloads could sharing the same CPU, which make it painful when one want to find out the root cause and fix the issue.
In order to address this, we introduced new per-cgroup statistic for numa:
* the numa locality to imply the numa balancing efficiency
* the numa execution time on each node
The task locality is the local page accessing ratio traced on numa balancing PF, and the group locality is the topology of task execution time, sectioned by the locality into 7 regions.
For example the new entry 'cpu.numa_stat' show:
locality 39541 60962 36842 72519 118605 721778 946553 exectime 1220127 1458684
Here we know the workloads in hierarchy executed 1220127ms on node_0 and 1458684ms on node_1 in total, tasks with locality around 0~13% executed for 39541 ms, and tasks with locality around 86~100% executed for 946553 ms, which imply most of the memory access are local access.
By monitoring the new statistic, we will be able to know the numa efficiency of each per-cgroup workloads on machine, whatever they sharing the CPUs or not, we will be able to find out which one introduced the remote access mostly.
Besides, per-node memory topology from 'memory.numa_stat' become more useful when we have the per-node execution time, workloads always executing on node_0 while it's memory is all on node_1 is usually a bad case.
--- include/linux/sched.h | 18 ++++++++- include/linux/sched/sysctl.h | 6 +++ init/Kconfig | 9 +++++ kernel/sched/core.c | 91 ++++++++++++++++++++++++++++++++++++++++++++ kernel/sched/fair.c | 33 ++++++++++++++++ kernel/sched/sched.h | 17 +++++++++ kernel/sysctl.c | 11 ++++++ 7 files changed, 184 insertions(+), 1 deletion(-)
include/linux/sched.h +17 -1
@@ -1118,9 +1118,25 @@ struct task_struct {* numa_faults_locality tracks if faults recorded during the last * scan window were remote/local or failed to migrate. The task scan * period is adapted based on the locality of the faults with different -* weights depending on whether they were shared or private faults +* weights depending on whether they were shared or private faults. +* +* Counter id stand for: +* 0 -- remote faults +* 1 -- local faults +* 2 -- page migration failure +* +* Extra counters when CONFIG_CGROUP_NUMA_STAT enabled: +* 3 -- remote page accessing +* 4 -- local page accessing +* +* The 'remote/local faults' records the cpu-page relationship before +* page migration, while the 'remote/local page accessing' is after. */ +#ifndef CONFIG_CGROUP_NUMA_STAT unsigned long numa_faults_locality[3 ]; +#else +unsigned long numa_faults_locality[5 ]; +#endif unsigned long numa_pages_migrated;#endif /* CONFIG_NUMA_BALANCING */
include/linux/sched/sysctl.h +6 -0
@@ -102,4 +102,10 @@ extern int sched_energy_aware_handler(struct ctl_table *table, int write, loff_t *ppos);#endif +#ifdef CONFIG_CGROUP_NUMA_STAT +extern int sysctl_cg_numa_stat (struct ctl_table *table,int write, +void __user *buffer,size_t *lenp, +loff_t *ppos); +#endif +#endif /* _LINUX_SCHED_SYSCTL_H */
init/Kconfig +9 -0
@@ -817,6 +817,15 @@ config NUMA_BALANCING_DEFAULT_ENABLED If set, automatic NUMA balancing will be enabled if running on a NUMA machine. +config CGROUP_NUMA_STAT + bool "Advanced per-cgroup NUMA statistics" + default n + depends on CGROUP_SCHED && NUMA_BALANCING + help + This option adds support for per-cgroup NUMA locality/execution + statistics, for monitoring NUMA efficiency of per-cgroup workloads + on NUMA platforms with NUMA Balancing enabled. + menuconfig CGROUPS bool "Control Group support" select KERNFS
kernel/sched/core.c +91 -0
109 lines not on this page · raw message
kernel/sched/fair.c +33 -0
@@ -2465,6 +2465,18 @@ void task_numa_fault(int last_cpupid, int mem_node, int pages, int flags) p->numa_faults[task_faults_idx (NUMA_MEMBUF , mem_node, priv)] += pages; p->numa_faults[task_faults_idx (NUMA_CPUBUF , cpu_node, priv)] += pages; p->numa_faults_locality[local] += pages; + +#ifdef CONFIG_CGROUP_NUMA_STAT +if (!static_branch_unlikely (&sched_cg_numa_stat)) +return ; + +/* +* We want to record the real local/remote page access statistic +* here, so use 'mem_node' which is the real residential node of +* page after migrate_misplaced_page(). +*/ + p->numa_faults_locality[3 + !!(mem_node ==numa_node_id ())] += pages; +#endif }static void reset_ptenuma_scan (struct task_struct *p)
@@ -4285,6 +4297,23 @@ static void put_prev_entity(struct cfs_rq *cfs_rq, struct sched_entity *prev) cfs_rq->curr =NULL ; } +#ifdef CONFIG_CGROUP_NUMA_STAT +static void update_numa_statistics (struct cfs_rq *cfs_rq) +{ +int idx; +unsigned long remote = current->numa_faults_locality[3 ]; +unsigned long local = current->numa_faults_locality[4 ]; + + cfs_rq->nstat.jiffies++; + +if (!remote && !local) +return ; + + idx = (NR_NL_INTERVAL -1 ) * local / (remote + local); + cfs_rq->nstat.locality[idx]++; +} +#endif +static void entity_tick (struct cfs_rq *cfs_rq,struct sched_entity *curr,int queued) {
@@ -4298,6 +4327,10 @@ entity_tick(struct cfs_rq *cfs_rq, struct sched_entity *curr, int queued)*/ update_load_avg (cfs_rq, curr,UPDATE_TG );update_cfs_group (curr); +#ifdef CONFIG_CGROUP_NUMA_STAT +if (static_branch_unlikely (&sched_cg_numa_stat)) +update_numa_statistics (cfs_rq); +#endif #ifdef CONFIG_SCHED_HRTICK /*
kernel/sched/sched.h +17 -0
@@ -486,6 +486,16 @@ struct cfs_bandwidth { };#endif /* CONFIG_CGROUP_SCHED */ +#ifdef CONFIG_CGROUP_NUMA_STAT +/* NUMA Locality Interval, 7 buckets for cache align */ +#define NR_NL_INTERVAL 7 + +struct numa_statistics { +u64 jiffies; +u64 locality[NR_NL_INTERVAL ]; +}; +#endif +/* CFS-related fields in a runqueue */ struct cfs_rq {struct load_weight load;
@@ -575,6 +585,9 @@ struct cfs_rq {struct list_head throttled_list;#endif /* CONFIG_CFS_BANDWIDTH */ #endif /* CONFIG_FAIR_GROUP_SCHED */ +#ifdef CONFIG_CGROUP_NUMA_STAT +struct numa_statistics nstat____cacheline_aligned ; +#endif };static inline int rt_bandwidth_enabled (void )
@@ -1601,6 +1614,10 @@ static const_debug __maybe_unused unsigned int sysctl_sched_features =extern struct static_key_false sched_numa_balancing;extern struct static_key_false sched_schedstats; +#ifdef CONFIG_CGROUP_NUMA_STAT +extern struct static_key_false sched_cg_numa_stat; +#endif +static inline u64 global_rt_period (void ) {return (u64 )sysctl_sched_rt_period *NSEC_PER_USEC ;
kernel/sysctl.c +11 -0
@@ -428,6 +428,17 @@ static struct ctl_table kern_table[] = { .extra2 = SYSCTL_ONE, }, #endif /* CONFIG_NUMA_BALANCING */ +#ifdef CONFIG_CGROUP_NUMA_STAT + { + .procname = "cg_numa_stat", + .data = NULL, /* filled in by handler */ + .maxlen = sizeof(unsigned int), + .mode = 0644, + .proc_handler = sysctl_cg_numa_stat, + .extra1 = SYSCTL_ZERO, + .extra2 = SYSCTL_ONE, + }, +#endif /* CONFIG_CGROUP_NUMA_STAT */ #endif /* CONFIG_SCHED_DEBUG */ { .procname = "sched_rt_period_us",
Signature · 1 line
2.14.4.44.g2045bb6
Mel Gorman
reviewerRe: [PATCH v2 1/3] sched/numa: advanced per-cgroup numa statistic
Quoted 7 lines · ??????
Currently there are no good approach to monitoring the per-cgroup numa efficiency, this could be a trouble especially when groups are sharing CPUs, it's impossible to tell which one caused the remote-memory access by reading hardware counter since multiple workloads could sharing the same CPU, which make it painful when one want to find out the root cause and fix the issue.
It's already possible to identify specific tasks triggering PMU events so this is not exactly true.
Quoted 135 lines
In order to address this, we introduced new per-cgroup statistic for numa:
* the numa locality to imply the numa balancing efficiency
* the numa execution time on each nodeThe task locality is the local page accessing ratio traced on numa balancing PF, and the group locality is the topology of task execution time, sectioned by the locality into 7 regions.
For example the new entry 'cpu.numa_stat' show:
locality 39541 60962 36842 72519 118605 721778 946553 exectime 1220127 1458684Here we know the workloads in hierarchy executed 1220127ms on
node_0and 1458684ms onnode_1in total, tasks with locality around 0~13% executed for 39541 ms, and tasks with locality around 86~100% executed for 946553 ms, which imply most of the memory access are local access.By monitoring the new statistic, we will be able to know the numa efficiency of each per-cgroup workloads on machine, whatever they sharing the CPUs or not, we will be able to find out which one introduced the remote access mostly.
Besides, per-node memory topology from 'memory.numa_stat' become more useful when we have the per-node execution time, workloads always executing on
node_0while it's memory is all onnode_1is usually a bad case.Cc Mel Gorman <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Michal Koutný <[email protected]>Signed-off-by Michael Wang <[email protected]>--- include/linux/sched.h | 18 ++++++++- include/linux/sched/sysctl.h | 6 +++ init/Kconfig | 9 +++++ kernel/sched/core.c | 91 ++++++++++++++++++++++++++++++++++++++++++++ kernel/sched/fair.c | 33 ++++++++++++++++ kernel/sched/sched.h | 17 +++++++++ kernel/sysctl.c | 11 ++++++ 7 files changed, 184 insertions(+), 1 deletion(-)include/linux/sched.h +17
-1@@ -1118,9 +1118,25 @@ struct task_struct {* numa_faults_locality tracks if faults recorded during the last * scan window were remote/local or failed to migrate. The task scan * period is adapted based on the locality of the faults with different -* weights depending on whether they were shared or private faults +* weights depending on whether they were shared or private faults. +* +* Counter id stand for: +* 0 -- remote faults +* 1 -- local faults +* 2 -- page migration failure +* +* Extra counters when CONFIG_CGROUP_NUMA_STAT enabled: +* 3 -- remote page accessing +* 4 -- local page accessing +* +* The 'remote/local faults' records the cpu-page relationship before +* page migration, while the 'remote/local page accessing' is after. */ +#ifndef CONFIG_CGROUP_NUMA_STAT unsigned long numa_faults_locality[3 ]; +#else +unsigned long numa_faults_locality[5 ]; +#endif unsigned long numa_pages_migrated;#endif /* CONFIG_NUMA_BALANCING */ include/linux/sched/sysctl.h +6
-0@@ -102,4 +102,10 @@ extern int sched_energy_aware_handler(struct ctl_table *table, int write, loff_t *ppos);#endif +#ifdef CONFIG_CGROUP_NUMA_STAT +extern int sysctl_cg_numa_stat (struct ctl_table *table,int write, +void __user *buffer,size_t *lenp, +loff_t *ppos); +#endif +#endif /* _LINUX_SCHED_SYSCTL_H */ init/Kconfig +9
-0@@ -817,6 +817,15 @@ config NUMA_BALANCING_DEFAULT_ENABLED If set, automatic NUMA balancing will be enabled if running on a NUMA machine. +config CGROUP_NUMA_STAT + bool "Advanced per-cgroup NUMA statistics" + default n + depends on CGROUP_SCHED && NUMA_BALANCING + help + This option adds support for per-cgroup NUMA locality/execution + statistics, for monitoring NUMA efficiency of per-cgroup workloads + on NUMA platforms with NUMA Balancing enabled. + menuconfig CGROUPS bool "Control Group support" select KERNFSkernel/sched/core.c +19
-0@@ -7657,6 +7657,84 @@ static u64 cpu_rt_period_read_uint(struct cgroup_subsys_state *css, }#endif /* CONFIG_RT_GROUP_SCHED */ +#ifdef CONFIG_CGROUP_NUMA_STAT +DEFINE_STATIC_KEY_FALSE(sched_cg_numa_stat); + +#ifdef CONFIG_PROC_SYSCTL +int sysctl_cg_numa_stat(struct ctl_table *table, int write, + void __user *buffer, size_t *lenp, loff_t *ppos) +{ + struct ctl_table t; + int err; + int state = static_branch_likely(&sched_cg_numa_stat); + + if (write && !capable(CAP_SYS_ADMIN)) + return -EPERM; + + t = *table; + t.data = &state; + err = proc_dointvec_minmax(&t, write, buffer, lenp, ppos); + if (err < 0 || !write) + return err;
kernel/sched/core.c static u64 cpu_rt_period_read_uint(struct cgroup_subsys_state *css, · line 7688
Quoted 10 lines
kernel/sched/core.c +10
-0+ +if (state) +static_branch_enable (&sched_cg_numa_stat); +else +static_branch_disable (&sched_cg_numa_stat); + + return err; +} +#endif +
Why is this implemented as a toggle? I'm finding it hard to make sense of this. The numa_stat should not even exist if the feature is disabled.
Assuming that is fixed then the runtime overhead is fine but the same issues with the quality of the information relying on NUMA balancing limits the usefulness of this. Disabling NUMA balancing or the scan rate dropping to a very low frequency would lead in misleading conclusions as well as false positives if the CPU and memory policies force remote memory usage. Similarly, the timing of the information available is variable du to how numa_faults_locality gets reset so sometimes the information is fine-grained and sometimes it's coarse grained. It will also pretend to display useful information even if NUMA balancing is disabled.
I find it hard to believe it would be useful in practice and I think users would have real trouble interpreting the data given how much it relies on internal implementation details of NUMA balancing. I cannot be certain as clearly something motivated the creation of this patch although it's unclear if it has ever been used to debug and fix an actual problem in the field. Hence, I'm neutral on the patch and will neither ack or nack it and will defer to the scheduler maintainers but if I was pushed on it, I would be disinclined to merge the patch due to the potential confusion caused by users who believe it provides accurate information when at best it gives a rough approximation with variable granularity.
Signature · 2 lines
Mel Gorman SUSE Labs
Re: [PATCH v2 1/3] sched/numa: advanced per-cgroup numa statistic
Quoted 10 lines · Mel Gorman
Quoted 6 lines · ??????
Currently there are no good approach to monitoring the per-cgroup numa efficiency, this could be a trouble especially when groups are sharing CPUs, it's impossible to tell which one caused the remote-memory access by reading hardware counter since multiple workloads could sharing the same CPU, which make it painful when one want to find out the root cause and fix the issue>>
It's already possible to identify specific tasks triggering PMU events so this is not exactly true.
Should fix the description regarding this...
I think you mean tools like numatop which showing per task local/remote accessing info from PMU, correct?
It's a good one for debugging, but when we talking about monitoring over cluster sharing by multiple users, still not very practical... compared to the workloads classified historical data.
I'm not sure about the overhead and limitation of this PMU approach, or whether there are any platform it's not yet supported, worth a survey.
Quoted 6 lines
Quoted 6 lines
In order to address this, we introduced new per-cgroup statistic for numa:
* the numa locality to imply the numa balancing efficiency
* the numa execution time on each node
[snip]
Quoted 21 lines
Quoted 21 lines
kernel/sched/core.c +21
-0+#ifdef CONFIG_PROC_SYSCTL +int sysctl_cg_numa_stat (struct ctl_table *table,int write, +void __user *buffer,size_t *lenp,loff_t *ppos) +{ +struct ctl_table t; +int err; +int state =static_branch_likely (&sched_cg_numa_stat); + +if (write && !capable (CAP_SYS_ADMIN )) +return -EPERM ; + + t = *table; + t.data = &state; + err =proc_dointvec_minmax (&t, write, buffer, lenp, ppos); +if (err <0 || !write) +return err; + +if (state) +static_branch_enable (&sched_cg_numa_stat); +else +static_branch_disable (&sched_cg_numa_stat);
Quoted 8 lines
kernel/sched/core.c static u64 cpu_rt_period_read_uint(struct cgroup_subsys_state *css, · line 7688
Quoted 5 lines
kernel/sched/core.c +5
-0+ + return err; +} +#endif +Why is this implemented as a toggle? I'm finding it hard to make sense of this. The
numa_statshould not even exist if the feature is disabled.
numa_stat will not exist if CONFIG is not enabled, do you mean it should also disappear when dynamically turn off?
Quoted 10 lines
Assuming that is fixed then the runtime overhead is fine but the same issues with the quality of the information relying on NUMA balancing limits the usefulness of this. Disabling NUMA balancing or the scan rate dropping to a very low frequency would lead in misleading conclusions as well as false positives if the CPU and memory policies force remote memory usage. Similarly, the timing of the information available is variable du to how
numa_faults_localitygets reset so sometimes the information is fine-grained and sometimes it's coarse grained. It will also pretend to display useful information even if NUMA balancing is disabled.
The data just represent what we traced on NUMA balancing PF, so yes folks need some understanding on NUMA balancing to figure out the real meaning behind locality.
We want it to tell the real story, if NUMA balancing disabled or scan rate dropped very low, the locality increments should be very small, when it keep failing for memory policy or CPU binding reason, we want it to tell how bad it is, locality just show us how NUMA Balancing is performing, the data could contains many information since how OS dealing with NUMA could be complicated...
Quoted 11 lines
I find it hard to believe it would be useful in practice and I think users would have real trouble interpreting the data given how much it relies on internal implementation details of NUMA balancing. I cannot be certain as clearly something motivated the creation of this patch although it's unclear if it has ever been used to debug and fix an actual problem in the field. Hence, I'm neutral on the patch and will neither ack or nack it and will defer to the scheduler maintainers but if I was pushed on it, I would be disinclined to merge the patch due to the potential confusion caused by users who believe it provides accurate information when at best it gives a rough approximation with variable granularity.
We have our cluster enabled this feature already, an old version though but still helpful, when we want to debug NUMA issues, this could give good hints.
Consider it as load_1/5/15 which not accurate but tell the trend of system behavior, locality giving the trend of NUMA Balancing as long as it's working, when increasing slowly it means locality already good enough or no more memory to adjust, and that's fine, for those who disabled the NUMA Balancing, they do their own NUMA optimization and find their own ways to estimate the results.
Anyway, we thanks for all those good inputs from your side :-)
Regards,
Michael Wang
Re: [PATCH v2 1/3] sched/numa: advanced per-cgroup numa statistic
Hello.
My primary concern is still the measuring of per-NUMA node execution time.
First, I think exposing the aggregated data into the numa_stat file is loss of information. The data are collected per-CPU and then summed over NUMA nodes -- this could be easily done by the userspace consumer of the data, keeping the per-CPU data available.
Second, comparing with the cpuacct implementation, yours has only jiffy granularity (I may have overlooked something or I miss some context, then it's a non-concern).
IOW, to me it sounds like duplicating cpuacct job and if that is deemed useful for cgroup v2, I think it should be done (only once) and at proper place (i.e. how cputime is measured in the default hierarchy).
The previous two are design/theoretical remarks, however, your patch misses measuring of other than fair_sched_class policy tasks. Is that intentional?
My last two comments are to locality measurement but are based on no experience or specific knowledge.
The seven percentile groups seem quite arbitrary to me, I find it strange that the ratio of cache-line size and u64 leaks and is fixed in the generally visible file. Wouldn't such a form be better hidden under a _DEBUG config option?
Quoted 1 line · 王贇
Consider it as load_1/5/15 which not accurate but tell the trend of system
I understood your patchset provides cumulative data over time, i.e. if a user wants to see an immediate trend, they have to calculate differences. Have I overlooked some back-off or regular zeroing?
Michal
Re: [PATCH v2 1/3] sched/numa: advanced per-cgroup numa statistic
Quoted 5 lines · Michal Koutný
Hello.
My primary concern is still the measuring of per-NUMA node execution time.
Quoted 8 lines
First, I think exposing the aggregated data into the
numa_statfile is loss of information. The data are collected per-CPU and then summed over NUMA nodes -- this could be easily done by the userspace consumer of the data, keeping the per-CPU data available.Second, comparing with the cpuacct implementation, yours has only jiffy granularity (I may have overlooked something or I miss some context, then it's a non-concern).
There are used to be a discussion on this, Peter mentioned we no longer expose raw ticks into userspace and micro seconds could be fine.
Basically we use this to calculate percentages, for which jiffy could be accurate enough :-)
Quoted 4 lines
IOW, to me it sounds like duplicating cpuacct job and if that is deemed useful for cgroup v2, I think it should be done (only once) and at proper place (i.e. how cputime is measured in the default hierarchy).
But still, what if folks don't use v2... any good suggestions?
Quoted 4 lines
The previous two are design/theoretical remarks, however, your patch misses measuring of other than
fair_sched_classpolicy tasks. Is that intentional?
Yes, since they don't have NUMA balancing to do optimization, and generally they are not that much.
Quoted 8 lines
My last two comments are to locality measurement but are based on no experience or specific knowledge.
The seven percentile groups seem quite arbitrary to me, I find it strange that the ratio of cache-line size and u64 leaks and is fixed in the generally visible file. Wouldn't such a form be better hidden under a
_DEBUGconfig option?
Sorry but I don't get it... at first it was 10 regions, as Peter suggested we pick 8, but now to insert member 'jiffies' it become 7, the address of 'jiffies' is cache aligned, so we pick u64 * 8 == 64Bytes to make sure the whole thing could be load in cache once a time, or did I misunderstand something?
Quoted 7 lines · 王贇
Quoted 1 line
Consider it as load_1/5/15 which not accurate but tell the trend of system
I understood your patchset provides cumulative data over time, i.e. if a user wants to see an immediate trend, they have to calculate differences. Have I overlooked some back-off or regular zeroing?
Yes, here what I try to highlight is the similar usage, but not the way of monitoring ;-) as the docs tell, we monitoring increments.
Regards,
Michale Wang
Quoted 3 lines
Michal
Re: [PATCH v2 1/3] sched/numa: advanced per-cgroup numa statistic
Quoted 2 lines · 王贇
There are used to be a discussion on this, Peter mentioned we no longer expose raw ticks into userspace and micro seconds could be fine.
I don't mean the unit presented but the precision.
Quoted 2 lines
Basically we use this to calculate percentages, for which jiffy could be accurate enough :-)
You also report the raw times.
Ad percentages (or raw times precision), on average, it should be fine but can't there be any "aliasing" artifacts when only an unimportant task is regularly sampled, hence not capturing the real pattern on the CPU? (Again, I'm not confident I'm not missing anything that prevents that behavior.)
Quoted 1 line
But still, what if folks don't use v2... any good suggestions?
(Note this applies to exectimes not locality.) On v1, they can add up per CPU values from cpuacct. (So it's v2 that's missing the records.)
Quoted 2 lines
Yes, since they don't have NUMA balancing to do optimization, and generally they are not that much.
Aha, I didn't realize that.
Quoted 2 lines
Sorry but I don't get it... at first it was 10 regions, as Peter suggested we pick 8, but now to insert member 'jiffies' it become 7,
See, there are various arguments for different values :-)
I meant that the currently chosen one is imprinted into the API file. That is IMO fixable by documenting (e.g. the number of bands may change, assume uniform division) or making all this just a debug API. Or, see below.
Quoted 2 lines
Yes, here what I try to highlight is the similar usage, but not the way of monitoring ;-) as the docs tell, we monitoring increments.
I see, the docs give me an idea what's the supposed use case.
What about exposing only the counters for local, remote and let the user do their monitoring based on Δlocal/(Δlocal + Δremote)?
That would avoid the partitioning question completely, exposed values would be simple numbers and provided information should be equal. A drawback is that such a sampling would be slower (but sufficient for the illustrating example).
Michal
Re: [PATCH v2 1/3] sched/numa: advanced per-cgroup numa statistic
Quoted 5 lines · Michal Koutný
Quoted 2 lines · 王贇
There are used to be a discussion on this, Peter mentioned we no longer expose raw ticks into userspace and micro seconds could be fine.
I don't mean the unit presented but the precision.
Quoted 8 lines
Quoted 2 lines
Basically we use this to calculate percentages, for which jiffy could be accurate enough :-)
You also report the raw times.>
Ad percentages (or raw times precision), on average, it should be fine but can't there be any "aliasing" artifacts when only an unimportant task is regularly sampled, hence not capturing the real pattern on the CPU? (Again, I'm not confident I'm not missing anything that prevents that behavior.)
Hmm.. I think I get your point now, so the concern is about the missing situation between each ticks, correct?
It could be, like one tick hit task A running, then A switched to B, B switched back to A before next tick, then we missing the exectime of B in next tick, since it hit A again.
Actually we have the same issue for those data in /proc/stat too, don't we? The user, sys, iowait was sampled in the similar way.
So if we have to pick a precision, I may still pick jiffy since the exectime is some thing similar to user/sys time IMHO.
Quoted 4 lines
Quoted 2 lines
But still, what if folks don't use v2... any good suggestions?
(Note this applies to exectimes not locality.) On v1, they can add up per CPU values from cpuacct. (So it's v2 that's missing the records.)
Whatabout move the whole stuff into cpuacct cgroup?
I'm not sure but maybe we could use some data there to save the sample of jiffies, for those v1 user who need these statistics, they should have cpuacct enabled.
Quoted 19 lines
Quoted 4 lines
Yes, since they don't have NUMA balancing to do optimization, and generally they are not that much.
Aha, I didn't realize that.
Quoted 2 lines
Sorry but I don't get it... at first it was 10 regions, as Peter suggested we pick 8, but now to insert member 'jiffies' it become 7,
See, there are various arguments for different values :-)
I meant that the currently chosen one is imprinted into the API file. That is IMO fixable by documenting (e.g. the number of bands may change, assume uniform division) or making all this just a debug API. Or, see below.
Quoted 2 lines
Yes, here what I try to highlight is the similar usage, but not the way of monitoring ;-) as the docs tell, we monitoring increments.
I see, the docs give me an idea what's the supposed use case.
Quoted 7 lines
What about exposing only the counters for local, remote and let the user do their monitoring based on Δlocal/(Δlocal + Δremote)?
That would avoid the partitioning question completely, exposed values would be simple numbers and provided information should be equal. A drawback is that such a sampling would be slower (but sufficient for the illustrating example).
You mean the cgroup numa stat just give the accumulated local/remote access?
As long as the counter won't overflow, maybe... sounds easier to explain too.
So user tracing locality will then get just one percentage (calculated on their own) from a cgroup, but one should be enough to represent the situation.
Sounds like a good idea to me :-) will try to do that in next version.
Regards,
Michael Wang
Quoted 3 lines
Michal
Re: [PATCH v2 1/3] sched/numa: advanced per-cgroup numa statistic
On 2019/11/29 上午9:52, 王贇 wrote:
[snip]
Quoted 5 lines
Quoted 4 lines
That would avoid the partitioning question completely, exposed values would be simple numbers and provided information should be equal. A drawback is that such a sampling would be slower (but sufficient for the illustrating example).
Quoted 8 lines
You mean the cgroup numa stat just give the accumulated local/remote access?
As long as the counter won't overflow, maybe... sounds easier to explain too.
So user tracing locality will then get just one percentage (calculated on their own) from a cgroup, but one should be enough to represent the situation.
Sounds like a good idea to me :-) will try to do that in next version.
I did some research regarding cpuacct, and find cpuacct_charge() is a good place to do hierarchical update, however, what we get there is the execution time delta since last update_curr().
I'm afraid we can't just do local/remote accumulation since the sample period now is changing, still have to accumulate the execution time into locality regions.
While at least we should be able to address your concern regarding exectime collection :-)
Regards,
Michael Wang
Quoted 7 lines
Regards,
Michael WangQuoted 3 lines
Michal
Re: [PATCH v2 1/3] sched/numa: advanced per-cgroup numa statistic
Quoted 3 lines · 王贇
I did some research regarding cpuacct, and find
cpuacct_charge()is a good place to do hierarchical update, however, what we get there is the execution time delta since lastupdate_curr().
I wouldn't extend cpuacct, I'd like to look into using the rstat mechanism for per-CPU runtime collection. (Most certainly I won't get down to this until mid December though.)
Quoted 3 lines
I'm afraid we can't just do local/remote accumulation since the sample period now is changing, still have to accumulate the execution time into locality regions.
My idea was to decouple time from the locality counters completely. It'd be up to the monitoring application to normalize differences wrt sampling rate (and handle wrap arounds).
Michal
Re: [PATCH v2 1/3] sched/numa: advanced per-cgroup numa statistic
Quoted 8 lines · Michal Koutný
Quoted 3 lines · 王贇
I did some research regarding cpuacct, and find
cpuacct_charge()is a good place to do hierarchical update, however, what we get there is the execution time delta since lastupdate_curr().I wouldn't extend cpuacct, I'd like to look into using the rstat mechanism for per-CPU runtime collection. (Most certainly I won't get down to this until mid December though.)
Quoted 6 lines
Quoted 3 lines
I'm afraid we can't just do local/remote accumulation since the sample period now is changing, still have to accumulate the execution time into locality regions.y
My idea was to decouple time from the locality counters completely. It'd be up to the monitoring application to normalize differences wrt sampling rate (and handle wrap arounds).
I see, basically I understand your proposal as utilize cpuacct's runtime and only expose per-cgroup local/remote counters, I'm not sure if the locality still helpful after decouple time factor from it, both need some investigation, anyway, once I could convince myself it's working, I'll be happy to make things simple ;-)
Regards,
Michael Wang
Quoted 4 lines
Michal
PATCH v2 2/3 sched/numa: expose per-task pages-migration-failure
In reply to 王贇NUMA balancing will try to migrate pages between nodes, which could caused by memory policy or numa group aggregation, while the page migration could failed too for eg when the target node run out of memory.
Since this is critical to the performance, admin should know how serious the problem is, and take actions before it causing too much performance damage, thus this patch expose the counter as 'migfailed' in '/proc/PID/sched'.
--- kernel/sched/debug.c | 1 + 1 file changed, 1 insertion(+)
kernel/sched/debug.c +1 -0
@@ -848,6 +848,7 @@ static void sched_show_numa(struct task_struct *p, struct seq_file *m)P (total_numa_faults);SEQ_printf (m,"current_node=%d, numa_group_id=%d\n" ,task_node (p),task_numa_group_id (p)); +SEQ_printf (m,"migfailed=%lu\n" , p->numa_faults_locality[2 ]);show_numa_stats (p, m);mpol_put (pol);#endif
Signature · 1 line
2.14.4.44.g2045bb6
Re: [PATCH v2 2/3] sched/numa: expose per-task pages-migration-failure
Quoted 10 lines · ??????
NUMA balancing will try to migrate pages between nodes, which could caused by memory policy or numa group aggregation, while the page migration could failed too for eg when the target node run out of memory.
Since this is critical to the performance, admin should know how serious the problem is, and take actions before it causing too much performance damage, thus this patch expose the counter as 'migfailed' in '
/proc/PID/sched'.
Quoted 4 lines
Cc Peter Zijlstra <[email protected]>Cc Michal Koutný <[email protected]>Suggested-by Mel Gorman <[email protected]>Signed-off-by Michael Wang <[email protected]>
This patch can be treated independently of the rest of the series as it's not directly related.
Signature · 2 lines
Mel Gorman SUSE Labs
Re: [PATCH v2 2/3] sched/numa: expose per-task pages-migration-failure
In reply to 王贇Hi, Peter,
This has been acked by Mel Gorman, since it is not much related with the rest patches, would you like to pick this one now?
Regards,
Michael Wang
Quoted 31 lines · 王贇
NUMA balancing will try to migrate pages between nodes, which could caused by memory policy or numa group aggregation, while the page migration could failed too for eg when the target node run out of memory.
Since this is critical to the performance, admin should know how serious the problem is, and take actions before it causing too much performance damage, thus this patch expose the counter as 'migfailed' in '
/proc/PID/sched'.Cc Peter Zijlstra <[email protected]>Cc Michal Koutný <[email protected]>Suggested-by Mel Gorman <[email protected]>Signed-off-by Michael Wang <[email protected]>--- kernel/sched/debug.c | 1 + 1 file changed, 1 insertion(+)kernel/sched/debug.c +1
-0@@ -848,6 +848,7 @@ static void sched_show_numa(struct task_struct *p, struct seq_file *m)P (total_numa_faults);SEQ_printf (m,"current_node=%d, numa_group_id=%d\n" ,task_node (p),task_numa_group_id (p)); +SEQ_printf (m,"migfailed=%lu\n" , p->numa_faults_locality[2 ]);show_numa_stats (p, m);mpol_put (pol);#endif
PATCH v2 3/3 sched/numa: documentation for per-cgroup numa stat
In reply to 王贇Since v1:
* thanks to Iurii for the better sentence
* thanks to Jonathan for the better format
Add the description for 'cg_numa_stat', also a new doc to explain the details on how to deal with the per-cgroup numa statistics.
--- Documentation/admin-guide/cg-numa-stat.rst | 163 ++++++++++++++++++++++++ Documentation/admin-guide/index.rst | 1 + Documentation/admin-guide/kernel-parameters.txt | 4 + Documentation/admin-guide/sysctl/kernel.rst | 9 ++ 4 files changed, 177 insertions(+) create mode 100644 Documentation/admin-guide/cg-numa-stat.rst
Documentation/admin-guide/cg-numa-stat.rst new file +163 -0
@@ -0,0 +1,163 @@ +=============================== +Per-cgroup NUMA statistics +=============================== + +Background +---------- + +On NUMA platforms, remote memory accessing always has a performance penalty, +although we have NUMA balancing working hard to maximize the access locality, +there are still situations it can't help. + +This could happen in modern production environment. When a large number of +cgroups are used to classify and control resources, this creates a complex +configuration for memory policy, CPUs and NUMA nodes. In such cases NUMA +balancing could end up with the wrong memory policy or exhausted local NUMA +node, which would lead to low percentage of local page accesses. + +We need to detect such cases, figure out which workloads from which cgroup +has introduced the issues, then we get chance to do adjustment to avoid +performance degradation. + +However, there are no hardware counters for per-task local/remote accessing +info, we don't know how many remote page accesses have occurred for a +particular task. + +Statistics +---------- + +Fortunately, we have NUMA Balancing which scans task's mapping and triggers PF +periodically, gives us the opportunity to record per-task page accessing info. + +By "echo 1 > /proc/sys/kernel/cg_numa_stat" at runtime or adding boot parameter +'cg_numa_stat', we will enable the accounting of per-cgroup numa statistics, +the 'cpu.numa_stat' entry of CPU cgroup will show statistics:: + + locality -- execution time sectioned by task NUMA locality (in ms) + exectime -- execution time sectioned by NUMA node (in ms) + +We define 'task NUMA locality' as:: + + nr_local_page_access * 100 / (nr_local_page_access + nr_remote_page_access) + +this per-task percentage value will be updated on the ticks for current task, +and the access counter will be updated on task's NUMA balancing PF, so only +the pages which NUMA Balancing paid attention to will be accounted. + +On each tick, we acquire the locality of current task on that CPU, accumulating +the ticks into the counter of corresponding locality region, tasks from the +same group sharing the counters, becoming the group locality. + +Similarly, we acquire the NUMA node of current CPU where the current task is +executing on, accumulating the ticks into the counter of corresponding node, +becoming the per-cgroup node execution time. + +Note that the accounting is hierarchical, which means the numa statistics for +a given group represents not only the workload of this group, but also the +workloads of all it's descendants. + +For example the 'cpu.numa_stat' show:: + + locality 39541 60962 36842 72519 118605 721778 946553 + exectime 1220127 1458684 + +The locality is sectioned into 7 regions, approximately as:: + + 0-13% 14-27% 28-42% 43-56% 57-71% 72-85% 86-100% + +And exectime is sectioned into 2 nodes, 0 and 1 in this case. + +Thus we know the workload of this group and it's descendants have totally +executed 1220127ms on node_0 and 1458684ms on node_1, tasks with locality +around 0~13% executed for 39541 ms, and tasks with locality around 87~100% +executed for 946553 ms, which imply most of the memory access are local. + +Monitoring +---------- + +By monitoring the increments of these statistics, we can easily know whether +NUMA balancing is working well for a particular workload. + +For example we take a 5 secs sample period, and consider locality under 27% +is bad, then on each sampling we have:: + + region_bad = region_1 + region_2 + region_all = region_1 + region_2 + ... + region_7 + +and we have the increments as:: + + region_bad_diff = region_bad - last_region_bad + region_all_diff = region_all - last_region_all + +which finally become:: + + region_bad_percent = region_bad_diff * 100 / region_all_diff + +we can plot a line for region_bad_percent, when the line close to 0 things +are good, when getting close to 100% something is wrong, we can pick a proper +watermark to trigger warning message. + +You may want to drop the data if the region_all is too small, which implies +there are not many available pages for NUMA Balancing, ignoring would be fine +since most likely the workload is insensitive to NUMA. + +Monitoring root group helps you control the overall situation, while you may +also want to monitor all the leaf groups which contain the workloads, this +helps to catch the mouse. + +The exectime could be useful when NUMA Balancing is disabled, or when locality +becomes too small, for NUMA node X we have:: + + exectime_X_diff = exectime_X - last_exectime_X + exectime_all_diff = exectime_all - last_exectime_all + +try to put your workload into a memory cgroup which providing per-node memory +consumption by 'memory.numa_stat' entry, then we could get:: + + memory_percent_X = memory_X * 100 / memory_all + exectime_percent_X = exectime_X_diff * 100 / exectime_all_diff + +These two percentages are usually matched on each node, workload should execute +mostly on the node contain most of it's memory, but it's not guaranteed. + +The workload may only access a small part of it's memory, in such cases although +the majority of memory are remotely, locality could still be good. + +Thus to tell if things are fine or not depends on the understanding of system +resource deployment, however, if you find node X got 100% memory percent but 0% +exectime percent, definitely something is wrong. + +Troubleshooting +--------------- + +After identifying which workload introduced the bad locality, check: + +1). Is the workload bound to a particular NUMA node? +2). Has any NUMA node run out of resources? + +There are several ways to bind task's memory with a NUMA node, the strict way +like the MPOL_BIND memory policy or 'cpuset.mems' will limiting the memory +node where to allocate pages, in this situation, admin should make sure the +task is allowed to run on the CPUs of that NUMA node, and make sure there are +available CPU resource there. + +There are also ways to bind task's CPU with a NUMA node, like 'cpuset.cpus' or +sched_setaffinity() syscall, in this situation, NUMA Balancing help to migrate +pages into that node, admin should make sure there are available memory there. + +Admin could try rebind or unbind the NUMA node to erase the damage, make a +change then observe the statistics see if things get better until the situation +is acceptable. + +Highlights +---------- + +For some tasks, NUMA Balancing may found no necessary to scan pages, and +locality could always be 0 or small number, don't pay attention to them +since they most likely insensitive to NUMA. + +There are no accounting until the option turned on, so enable it in advance +if you want to have the whole history. + +We have per-task migfailed counter to tell how many page migration has been +failed for a particular task, you will find it in /proc/PID/sched entry.
Documentation/admin-guide/index.rst +1 -0
@@ -112,6 +112,7 @@ configure specific aspects of kernel behavior to your liking. video-output wimax/index xfs + cg-numa-stat .. only:: subproject and html
Documentation/admin-guide/kernel-parameters.txt +4 -0
@@ -3227,6 +3227,10 @@ numa_balancing= [KNL,X86] Enable or disable automatic NUMA balancing. Allowed values are enable and disable + cg_numa_atat [KNL] Enable advanced per-cgroup numa statistics. + Useful to debug NUMA efficiency problems when there are + lots of per-cgroup workloads. + numa_zonelist_order= [KNL, BOOT] Select zonelist order for NUMA. 'node', 'default' can be specified This can be set from sysctl after boot.
Documentation/admin-guide/sysctl/kernel.rst +9 -0
@@ -572,6 +572,15 @@ rate for each task. numa_balancing_scan_size_mb is how many megabytes worth of pages are scanned for a given scan. +cg_numa_stat: +============= + +Enables/disables advanced per-cgroup NUMA statistic. + +0: disabled (default). +1: enabled. + +Check Documentation/admin-guide/cg-numa-stat.rst for details. osrelease, ostype & version: ============================
Signature · 1 line
2.14.4.44.g2045bb6
Randy Dunlap
reviewerRe: [PATCH v2 3/3] sched/numa: documentation for per-cgroup numa stat
Quoted 7 lines · 王贇
Since v1:
* thanks to Iurii for the better sentence
* thanks to Jonathan for the better formatAdd the description for '
cg_numa_stat', also a new doc to explain the details on how to deal with the per-cgroup numa statistics.
Quoted 6 lines
Cc Peter Zijlstra <[email protected]>Cc Michal Koutný <[email protected]>Cc Mel Gorman <[email protected]>Cc Jonathan Corbet <[email protected]>Cc Iurii Zaikin <[email protected]>Signed-off-by Michael Wang <[email protected]>
Hi,
I have a few comments/corrections. Please see below.
Quoted 14 lines
--- Documentation/admin-guide/cg-numa-stat.rst | 163 ++++++++++++++++++++++++ Documentation/admin-guide/index.rst | 1 + Documentation/admin-guide/kernel-parameters.txt | 4 + Documentation/admin-guide/sysctl/kernel.rst | 9 ++ 4 files changed, 177 insertions(+) create mode 100644 Documentation/admin-guide/cg-numa-stat.rstDocumentation/admin-guide/cg-numa-stat.rst new file +0
-0
Documentation/admin-guide/cg-numa-stat.rst line 8
Quoted 8 lines
Documentation/admin-guide/cg-numa-stat.rst new file +8
-0@@ -0,0 +1,163 @@ +=============================== +Per-cgroup NUMA statistics +=============================== + +Background +---------- + +On NUMA platforms, remote memory accessing always has a performance penalty,
penalty.
Documentation/admin-guide/cg-numa-stat.rst line 9
Quoted 1 line
Documentation/admin-guide/cg-numa-stat.rst new file +1
-0+although we have NUMA balancing working hard to maximize the access locality,
Although
Documentation/admin-guide/cg-numa-stat.rst line 19
Quoted 10 lines
Documentation/admin-guide/cg-numa-stat.rst new file +10
-0+there are still situations it can't help. + +This could happen in modern production environment. When a large number of +cgroups are used to classify and control resources, this creates a complex +configuration for memory policy, CPUs and NUMA nodes. In such cases NUMA +balancing could end up with the wrong memory policy or exhausted local NUMA +node, which would lead to low percentage of local page accesses. + +We need to detect such cases, figure out which workloads from which cgroup +has introduced the issues, then we get chance to do adjustment to avoid
have
Documentation/admin-guide/cg-numa-stat.rst line 30
Quoted 11 lines
Documentation/admin-guide/cg-numa-stat.rst new file +11
-0+performance degradation. + +However, there are no hardware counters for per-task local/remote accessing +info, we don't know how many remote page accesses have occurred for a +particular task. + +Statistics +---------- + +Fortunately, we have NUMA Balancing which scans task's mapping and triggers PF +periodically, gives us the opportunity to record per-task page accessing info.
giving
Documentation/admin-guide/cg-numa-stat.rst line 33
Quoted 3 lines
Documentation/admin-guide/cg-numa-stat.rst new file +3
-0+ +By "echo 1 > /proc/sys/kernel/cg_numa_stat" at runtime or adding boot parameter +'cg_numa_stat', we will enable the accounting of per-cgroup numa statistics,
NUMA
Documentation/admin-guide/cg-numa-stat.rst line 43
Quoted 10 lines
Documentation/admin-guide/cg-numa-stat.rst new file +10
-0+the 'cpu.numa_stat' entry of CPU cgroup will show statistics:: + + locality -- execution time sectioned by task NUMA locality (in ms) + exectime -- execution time sectioned by NUMA node (in ms) + +We define 'task NUMA locality' as:: + + nr_local_page_access * 100 / (nr_local_page_access + nr_remote_page_access) + +this per-task percentage value will be updated on the ticks for current task,
This
Documentation/admin-guide/cg-numa-stat.rst line 55
Quoted 12 lines
Documentation/admin-guide/cg-numa-stat.rst new file +12
-0+and the access counter will be updated on task's NUMA balancing PF, so only +the pages which NUMA Balancing paid attention to will be accounted. + +On each tick, we acquire the locality of current task on that CPU, accumulating +the ticks into the counter of corresponding locality region, tasks from the +same group sharing the counters, becoming the group locality. + +Similarly, we acquire the NUMA node of current CPU where the current task is +executing on, accumulating the ticks into the counter of corresponding node, +becoming the per-cgroup node execution time. + +Note that the accounting is hierarchical, which means the numa statistics for
NUMA
Documentation/admin-guide/cg-numa-stat.rst line 56
Quoted 1 line
Documentation/admin-guide/cg-numa-stat.rst new file +1
-0+a given group represents not only the workload of this group, but also the
represent
Documentation/admin-guide/cg-numa-stat.rst line 57
Quoted 1 line
Documentation/admin-guide/cg-numa-stat.rst new file +1
-0+workloads of all it's descendants.
its
Documentation/admin-guide/cg-numa-stat.rst line 70
Quoted 13 lines
Documentation/admin-guide/cg-numa-stat.rst new file +13
-0+ +For example the 'cpu.numa_stat' show:: + + locality 39541 60962 36842 72519 118605 721778 946553 + exectime 1220127 1458684 + +The locality is sectioned into 7 regions, approximately as:: + + 0-13% 14-27% 28-42% 43-56% 57-71% 72-85% 86-100% + +And exectime is sectioned into 2 nodes, 0 and 1 in this case. + +Thus we know the workload of this group and it's descendants have totally
its
Documentation/admin-guide/cg-numa-stat.rst line 81
Quoted 11 lines
Documentation/admin-guide/cg-numa-stat.rst new file +11
-0+executed 1220127ms on node_0 and 1458684ms on node_1, tasks with locality +around 0~13% executed for 39541 ms, and tasks with locality around 87~100% +executed for 946553 ms, which imply most of the memory access are local. + +Monitoring +---------- + +By monitoring the increments of these statistics, we can easily know whether +NUMA balancing is working well for a particular workload. + +For example we take a 5 secs sample period, and consider locality under 27%
seconds
Quoted 5 lines
Documentation/admin-guide/cg-numa-stat.rst new file +5
-0+is bad, then on each sampling we have:: + + region_bad = region_1 + region_2 + region_all = region_1 + region_2 + ... + region_7 +
Documentation/admin-guide/cg-numa-stat.rst line 96
Quoted 10 lines
Documentation/admin-guide/cg-numa-stat.rst new file +10
-0+and we have the increments as:: + + region_bad_diff = region_bad - last_region_bad + region_all_diff = region_all - last_region_all + +which finally become:: + + region_bad_percent = region_bad_diff * 100 / region_all_diff + +we can plot a line for region_bad_percent, when the line close to 0 things
We
Documentation/admin-guide/cg-numa-stat.rst line 109
Quoted 13 lines
Documentation/admin-guide/cg-numa-stat.rst new file +13
-0+are good, when getting close to 100% something is wrong, we can pick a proper +watermark to trigger warning message. + +You may want to drop the data if the region_all is too small, which implies +there are not many available pages for NUMA Balancing, ignoring would be fine +since most likely the workload is insensitive to NUMA. + +Monitoring root group helps you control the overall situation, while you may +also want to monitor all the leaf groups which contain the workloads, this +helps to catch the mouse. + +The exectime could be useful when NUMA Balancing is disabled, or when locality +becomes too small, for NUMA node X we have::
small. For
Documentation/admin-guide/cg-numa-stat.rst line 114
Quoted 5 lines
Documentation/admin-guide/cg-numa-stat.rst new file +5
-0+ + exectime_X_diff = exectime_X - last_exectime_X + exectime_all_diff = exectime_all - last_exectime_all + +try to put your workload into a memory cgroup which providing per-node memory
Try provides
Documentation/admin-guide/cg-numa-stat.rst line 121
Quoted 7 lines
Documentation/admin-guide/cg-numa-stat.rst new file +7
-0+consumption by 'memory.numa_stat' entry, then we could get:: + + memory_percent_X = memory_X * 100 / memory_all + exectime_percent_X = exectime_X_diff * 100 / exectime_all_diff + +These two percentages are usually matched on each node, workload should execute +mostly on the node contain most of it's memory, but it's not guaranteed.
node that contains most of its
Documentation/admin-guide/cg-numa-stat.rst line 123
Quoted 2 lines
Documentation/admin-guide/cg-numa-stat.rst new file +2
-0+ +The workload may only access a small part of it's memory, in such cases although
its
Quoted 6 lines
Documentation/admin-guide/cg-numa-stat.rst new file +6
-0+the majority of memory are remotely, locality could still be good. + +Thus to tell if things are fine or not depends on the understanding of system +resource deployment, however, if you find node X got 100% memory percent but 0% +exectime percent, definitely something is wrong. +
Documentation/admin-guide/cg-numa-stat.rst line 139
Quoted 10 lines
Documentation/admin-guide/cg-numa-stat.rst new file +10
-0+Troubleshooting +--------------- + +After identifying which workload introduced the bad locality, check: + +1). Is the workload bound to a particular NUMA node? +2). Has any NUMA node run out of resources? + +There are several ways to bind task's memory with a NUMA node, the strict way +like the MPOL_BIND memory policy or 'cpuset.mems' will limiting the memory
will limit
Documentation/admin-guide/cg-numa-stat.rst line 140
Quoted 1 line
Documentation/admin-guide/cg-numa-stat.rst new file +1
-0+node where to allocate pages, in this situation, admin should make sure the
pages. In
Documentation/admin-guide/cg-numa-stat.rst line 145
Quoted 5 lines
Documentation/admin-guide/cg-numa-stat.rst new file +5
-0+task is allowed to run on the CPUs of that NUMA node, and make sure there are +available CPU resource there. + +There are also ways to bind task's CPU with a NUMA node, like 'cpuset.cpus' or +sched_setaffinity() syscall, in this situation, NUMA Balancing help to migrate
syscall. In
Documentation/admin-guide/cg-numa-stat.rst line 148
Quoted 3 lines
Documentation/admin-guide/cg-numa-stat.rst new file +3
-0+pages into that node, admin should make sure there are available memory there. + +Admin could try rebind or unbind the NUMA node to erase the damage, make a
try to
Documentation/admin-guide/cg-numa-stat.rst line 149
Quoted 1 line
Documentation/admin-guide/cg-numa-stat.rst new file +1
-0+change then observe the statistics see if things get better until the situation
observe the statistics to see if
Documentation/admin-guide/cg-numa-stat.rst line 159
Quoted 10 lines
Documentation/admin-guide/cg-numa-stat.rst new file +10
-0+is acceptable. + +Highlights +---------- + +For some tasks, NUMA Balancing may found no necessary to scan pages, and +locality could always be 0 or small number, don't pay attention to them +since they most likely insensitive to NUMA. + +There are no accounting until the option turned on, so enable it in advance
is no accounting until the option is turned on,
Documentation/admin-guide/cg-numa-stat.rst line 162
Quoted 3 lines
Documentation/admin-guide/cg-numa-stat.rst new file +3
-0+if you want to have the whole history. + +We have per-task migfailed counter to tell how many page migration has been
I can't find any occurrence of 'migfailed' in the entire kernel source tree. Maybe it is misspelled?
Documentation/admin-guide/cg-numa-stat.rst line 163
Quoted 1 line
Documentation/admin-guide/cg-numa-stat.rst new file +1
-0+failed for a particular task, you will find it in /proc/PID/sched entry.
HTH.
Signature · 1 line
~Randy
Re: [PATCH v2 3/3] sched/numa: documentation for per-cgroup numa stat
Hi, Randy
Quoted 15 lines · Randy Dunlap
Quoted 7 lines · 王贇
Since v1:
* thanks to Iurii for the better sentence
* thanks to Jonathan for the better formatAdd the description for '
cg_numa_stat', also a new doc to explain the details on how to deal with the per-cgroup numa statistics.Quoted 6 lines
Cc Peter Zijlstra <[email protected]>Cc Michal Koutný <[email protected]>Cc Mel Gorman <[email protected]>Cc Jonathan Corbet <[email protected]>Cc Iurii Zaikin <[email protected]>Signed-off-by Michael Wang <[email protected]>
Quoted 2 lines
Hi,
I have a few comments/corrections. Please see below.
Thanks for the comments :-) will apply them all in next version.
Quoted 3 lines
Quoted 3 lines
--- Documentation/admin-guide/cg-numa-stat.rst | 163
[snip]
Quoted 6 lines
Documentation/admin-guide/cg-numa-stat.rst line 162
Quoted 3 lines
Documentation/admin-guide/cg-numa-stat.rst new file +3
-0+if you want to have the whole history. + +We have per-task migfailed counter to tell how many page migration has beenI can't find any occurrence of 'migfailed' in the entire kernel source tree. Maybe it is misspelled?
This one is added by the secondary patch:
[PATCH v2 2/3] sched/numa: expose per-task pages-migration-failure
As suggested by Mel.
Regards,
Michael Wang
Quoted 6 lines
Quoted 2 lines
+failed for a particular task, you will find it in
/proc/PID/schedentry.HTH.
v3 cover sched/numa: introduce numa locality
In reply to 王贇Since last patch set:
Because the locality region concept is too complicated, we tried to decouple the time factor from it now as Michal commented.
Now the numa_stat just expose the local/remote page accessing counter , gathering from all the tasks in hierarchy. This should be much more easier to understand, also the meaning of counter is straightforward.
Now we have just one locality percentage for each cgroup, to represent how NUMA Balancing is working and imply NUMA efficiency.
Modern production environment could use hundreds of cgroup to control the resources for different workloads, along with the complicated resource binding.
On NUMA platforms where we have multiple nodes, things become even more complicated, we hope there are more local memory access to improve the performance, and NUMA Balancing keep working hard to achieve that, however, wrong memory policy or node binding could easily waste the effort, result a lot of remote page accessing.
We need to notice such problems, then we got chance to fix it before there are too much damages, however, there are no good monitoring approach yet to help catch the mouse who introduced the remote access.
This patch set is trying to fill in the missing pieces, by introduce the per-cgroup NUMA locality info, with this new statistics, we could achieve the daily monitoring on NUMA efficiency, to give warning when things going too wrong.
Please check the second patch for more details.
Michael Wang (2):
sched/numa: introduce per-cgroup NUMA locality info sched/numa: documentation for per-cgroup numa statistics
Documentation/admin-guide/cg-numa-stat.rst | 176 ++++++++++++++++++++++++ Documentation/admin-guide/index.rst | 1 + Documentation/admin-guide/kernel-parameters.txt | 4 + Documentation/admin-guide/sysctl/kernel.rst | 9 ++ include/linux/sched.h | 15 ++ include/linux/sched/sysctl.h | 6 + init/Kconfig | 11 ++ kernel/sched/core.c | 75 ++++++++++ kernel/sched/fair.c | 62 +++++++++ kernel/sched/sched.h | 12 ++ kernel/sysctl.c | 11 ++ 11 files changed, 382 insertions(+) create mode 100644 Documentation/admin-guide/cg-numa-stat.rst
Signature · 1 line
2.14.4.44.g2045bb6
PATCH v3 1/2 sched/numa: introduce per-cgroup NUMA locality info
Currently there are no good approach to monitoring the per-cgroup NUMA efficiency, this could be a trouble especially when groups are sharing CPUs, we don't know which one introduced remote-memory accessing.
Although the per-task NUMA accessing info from PMU is good for further debuging, but not light enough for daily monitoring, especial on a box with thousands of tasks.
Fortunately, when NUMA Balancing enabled, it will periodly trigger page fault and try to increase the NUMA locality, by tracing the results we will be able to estimate the NUMA efficiency.
On each page fault of NUMA Balancing, when task's executing CPU is from the same node of pages, we call this a local page accessing, otherwise a remote page accessing.
By updating task's accessing counter into it's cgroup on ticks, we get the per-cgroup numa locality info.
For example the new entry 'cpu.numa_stat' show:
page_access local=1231412 remote=53453
Here we know the workloads in hierarchy have totally been traced 1284865 times of page accessing, and 1231412 of them are local page access, which imply a good NUMA efficiency.
By monitoring the increments, we will be able to locate the per-cgroup workload which NUMA Balancing can't helpwith (usually caused by wrong CPU and memory node bindings), then we got chance to fix that in time.
--- include/linux/sched.h | 15 +++++++++ include/linux/sched/sysctl.h | 6 ++++ init/Kconfig | 9 ++++++ kernel/sched/core.c | 75 ++++++++++++++++++++++++++++++++++++++++++++ kernel/sched/fair.c | 62 ++++++++++++++++++++++++++++++++++++ kernel/sched/sched.h | 12 +++++++ kernel/sysctl.c | 11 +++++++ 7 files changed, 190 insertions(+)
include/linux/sched.h +15 -0
@@ -1125,6 +1125,21 @@ struct task_struct {unsigned long numa_pages_migrated;#endif /* CONFIG_NUMA_BALANCING */ +#ifdef CONFIG_CGROUP_NUMA_LOCALITY +/* +* Counter index stand for: +* 0 -- remote page accessing +* 1 -- local page accessing +* 2 -- remote page accessing updated +* 3 -- local page accessing updated +* +* We record the counter in task_numa_fault(), this is based on the +* fact that after page fault is handled, the task will access the +* page on the CPU where it triggered PF. +*/ +unsigned long numa_page_access[4 ]; +#endif +#ifdef CONFIG_RSEQ struct rseq __user *rseq;u32 rseq_sig;
include/linux/sched/sysctl.h +6 -0
@@ -102,4 +102,10 @@ extern int sched_energy_aware_handler(struct ctl_table *table, int write, loff_t *ppos);#endif +#ifdef CONFIG_CGROUP_NUMA_LOCALITY +extern int sysctl_numa_locality (struct ctl_table *table,int write, +void __user *buffer,size_t *lenp, +loff_t *ppos); +#endif +#endif /* _LINUX_SCHED_SYSCTL_H */
init/Kconfig +9 -0
@@ -817,6 +817,15 @@ config NUMA_BALANCING_DEFAULT_ENABLED If set, automatic NUMA balancing will be enabled if running on a NUMA machine. +config CGROUP_NUMA_LOCALITY + bool "The per-cgroup NUMA Locality" + default n + depends on CGROUP_SCHED && NUMA_BALANCING + help + This option enable the collection of per-cgroup NUMA locality info, + to tell whether NUMA Balancing is working well for a particular + workload. + menuconfig CGROUPS bool "Control Group support" select KERNFS
kernel/sched/core.c +75 -0
93 lines not on this page · raw message
kernel/sched/fair.c +62 -0
86 lines not on this page · raw message
kernel/sched/sched.h +12 -0
@@ -575,6 +575,14 @@ struct cfs_rq {struct list_head throttled_list;#endif /* CONFIG_CFS_BANDWIDTH */ #endif /* CONFIG_FAIR_GROUP_SCHED */ +#ifdef CONFIG_CGROUP_NUMA_LOCALITY +/* +* The local/remote page access info collected from all +* the tasks in hierarchy. +*/ +u64 local_page_access; +u64 remote_page_access; +#endif };static inline int rt_bandwidth_enabled (void )
@@ -1601,6 +1609,10 @@ static const_debug __maybe_unused unsigned int sysctl_sched_features =extern struct static_key_false sched_numa_balancing;extern struct static_key_false sched_schedstats; +#ifdef CONFIG_CGROUP_NUMA_LOCALITY +extern struct static_key_false sched_numa_locality; +#endif +static inline u64 global_rt_period (void ) {return (u64 )sysctl_sched_rt_period *NSEC_PER_USEC ;
kernel/sysctl.c +11 -0
@@ -428,6 +428,17 @@ static struct ctl_table kern_table[] = { .extra2 = SYSCTL_ONE, }, #endif /* CONFIG_NUMA_BALANCING */ +#ifdef CONFIG_CGROUP_NUMA_LOCALITY + { + .procname = "numa_locality", + .data = NULL, /* filled in by handler */ + .maxlen = sizeof(unsigned int), + .mode = 0644, + .proc_handler = sysctl_numa_locality, + .extra1 = SYSCTL_ZERO, + .extra2 = SYSCTL_ONE, + }, +#endif /* CONFIG_CGROUP_NUMA_LOCALITY */ #endif /* CONFIG_SCHED_DEBUG */ { .procname = "sched_rt_period_us",
Signature · 1 line
2.14.4.44.g2045bb6
Randy Dunlap
reviewerRe: [PATCH v3 1/2] sched/numa: introduce per-cgroup NUMA locality info
init/Kconfig config NUMA_BALANCING_DEFAULT_ENABLED · line 821
Quoted 10 lines · 王贇
init/Kconfig +2
-0@@ -817,6 +817,15 @@ config NUMA_BALANCING_DEFAULT_ENABLED If set, automatic NUMA balancing will be enabled if running on a NUMA machine. +config CGROUP_NUMA_LOCALITY + bool "The per-cgroup NUMA Locality"
I would drop "The".
init/Kconfig config NUMA_BALANCING_DEFAULT_ENABLED · line 825
Quoted 4 lines
init/Kconfig +4
-0+ default n + depends on CGROUP_SCHED && NUMA_BALANCING + help + This option enable the collection of per-cgroup NUMA locality info,
enables
Quoted 6 lines
init/Kconfig +3
-0+ to tell whether NUMA Balancing is working well for a particular + workload. + menuconfig CGROUPS bool "Control Group support" select KERNFS
Signature · 2 lines
~Randy Reported-by: Randy Dunlap <[email protected]>
Re: [PATCH v3 1/2] sched/numa: introduce per-cgroup NUMA locality info
Quoted 14 lines · Randy Dunlap
init/Kconfig config NUMA_BALANCING_DEFAULT_ENABLED · line 821
Quoted 10 lines · 王贇
init/Kconfig +2
-0@@ -817,6 +817,15 @@ config NUMA_BALANCING_DEFAULT_ENABLED If set, automatic NUMA balancing will be enabled if running on a NUMA machine. +config CGROUP_NUMA_LOCALITY + bool "The per-cgroup NUMA Locality"I would drop "The".
Quoted 6 lines
init/Kconfig config NUMA_BALANCING_DEFAULT_ENABLED · line 825
Quoted 4 lines
init/Kconfig +4
-0+ default n + depends on CGROUP_SCHED && NUMA_BALANCING + help + This option enable the collection of per-cgroup NUMA locality info,enables
Will fix them in next version too~
Regards,
Michael Wang
Quoted 9 lines
Quoted 7 lines
init/Kconfig +3
-0+ to tell whether NUMA Balancing is working well for a particular + workload. + menuconfig CGROUPS bool "Control Group support" select KERNFS
PATCH v3 2/2 sched/numa: documentation for per-cgroup numa statistics
In reply to 王贇Add the description for 'numa_locality', also a new doc to explain the details on how to deal with the per-cgroup numa statistics.
--- Documentation/admin-guide/cg-numa-stat.rst | 176 ++++++++++++++++++++++++ Documentation/admin-guide/index.rst | 1 + Documentation/admin-guide/kernel-parameters.txt | 4 + Documentation/admin-guide/sysctl/kernel.rst | 9 ++ include/linux/sched.h | 10 +- init/Kconfig | 4 +- kernel/sched/fair.c | 4 +- 7 files changed, 200 insertions(+), 8 deletions(-) create mode 100644 Documentation/admin-guide/cg-numa-stat.rst
Documentation/admin-guide/cg-numa-stat.rst new file +176 -0
@@ -0,0 +1,176 @@ +=============================== +Per-cgroup NUMA statistics +=============================== + +Background +---------- + +On NUMA platforms, remote memory accessing always has a performance penalty. +Although we have NUMA balancing working hard to maximize the access locality, +there are still situations it can't help. + +This could happen in modern production environment. When a large number of +cgroups are used to classify and control resources, this creates a complex +configuration for memory policy, CPUs and NUMA nodes. In such cases NUMA +balancing could end up with the wrong memory policy or exhausted local NUMA +node, which would lead to low percentage of local page accesses. + +We need to detect such cases, figure out which workloads from which cgroup +have introduced the issues, then we get chance to do adjustment to avoid +performance degradation. + +However, there are no hardware counters for per-task local/remote accessing +info, we don't know how many remote page accesses have occurred for a +particular task. + +NUMA Locality +------------- + +Fortunately, we have NUMA Balancing which scans task's mapping and triggers +page fault periodically, giving us the opportunity to record per-task page +accessing info, when the CPU fall into PF is from the same node of pages, we +consider task as doing local page accessing, otherwise the remote page +accessing, we call these two counter the locality info. + +On each tick, we acquire the locality info of current task on that CPU, update +the increments into it's cgroup, becoming the group locality info. + +By "echo 1 > /proc/sys/kernel/numa_locality" at runtime or adding boot parameter +'numa_locality', we will enable the accounting of per-cgroup NUMA locality info, +the 'cpu.numa_stat' entry of CPU cgroup will show statistics:: + + page_access local=NR_LOCAL_PAGE_ACCESS remote=NR_REMOTE_PAGE_ACCESS + +We define 'NUMA locality' as:: + + NR_LOCAL_PAGE_ACCESS * 100 / (NR_LOCAL_PAGE_ACCESS + NR_REMOTE_PAGE_ACCESS) + +This per-cgroup percentage number help to represent the NUMA Balancing behavior. + +Note that the accounting is hierarchical, which means the NUMA locality info for +a given group represent not only the workload of this group, but also the +workloads of all its descendants. + +For example the 'cpu.numa_stat' show:: + + page_access local=129909383 remote=18265810 + +The NUMA locality calculated as:: + + 129909383 * 100 / (129909383 + 18265810) = 87.67 + +Thus we know the workload of this group and its descendants have totally done +129909383 times of local page accessing and 18265810 times of remotes, locality +is 87.67% which imply most of the memory access are local. + +NUMA Consumption +---------------- + +There are also other cgroup entry help us to estimate NUMA efficiency, which is +'cpuacct.usage_percpu' and 'memory.numa_stat'. + +By reading 'cpuacct.usage_percpu' we will get per-cpu runtime (in nanoseconds) +info (in hierarchy) as:: + + CPU_0_RUNTIME CPU_1_RUNTIME CPU_2_RUNTIME ... CPU_X_RUNTIME + +Combined with the info from:: + + cat /sys/devices/system/node/nodeX/cpulist + +We would be able to accumulate the runtime of CPUs into NUMA nodes, to get the +per-cgroup node runtime info. + +By reading 'memory.numa_stat' we will get per-cgroup node memory consumption +info as:: + + total=TOTAL_MEM N0=MEM_ON_NODE0 N1=MEM_ON_NODE1 ... NX=MEM_ON_NODEX + +Together we call these the per-cgroup NUMA consumption info, tell us how many +resources a particular workload has consumed, on a particular NUMA node. + +Monitoring +---------- + +By monitoring the increments of locality info, we can easily know whether NUMA +Balancing is working well for a particular workload. + +For example we take a 5 seconds sample period, then on each sampling we have:: + + local_diff = last_nr_local_page_access - nr_local_page_access + remote_diff = last_nr_remote_page_access - nr_remote_page_access + +and we get the locality in this period as:: + + locality = local_diff * 100 / (local_diff + remote_diff) + +We can plot a line for locality, when the line close to 100% things are good, +when getting close to 0% something is wrong, we can pick a proper watermark to +trigger warning message. + +You may want to drop the data if the local/remote_diff is too small, which +implies there are not many available pages for NUMA Balancing to scan, ignoring +would be fine since most likely the workload is insensitive to NUMA, or the +memory topology is already good enough. + +Monitoring root group helps you control the overall situation, while you may +also want to monitor all the leaf groups which contain the workloads, this +helps to catch the mouse. + +Try to put your workload into also the cpuacct & memory cgroup, when NUMA +Balancing is disabled or locality becomes too small, we may want to monitoring +the per-node runtime & memory info to see if the node consumption meet the +requirements. + +For NUMA node X on each sampling we have:: + + runtime_X_diff = runtime_X - last_runtime_X + runtime_all_diff = runtime_all - last_runtime_all + + runtime_percent_X = runtime_X_diff * 100 / runtime_all_diff + memory_percent_X = memory_X * 100 / memory_all + +These two percentages are usually matched on each node, workload should execute +mostly on the node that contains most of its memory, but it's not guaranteed. + +The workload may only access a small part of its memory, in such cases although +the majority of memory are remotely, locality could still be good. + +Thus to tell if things are fine or not depends on the understanding of system +resource deployment, however, if you find node X got 100% memory percent but 0% +runtime percent, definitely something is wrong. + +Troubleshooting +--------------- + +After identifying which workload introduced the bad locality, check: + +1). Is the workload bound to a particular NUMA node? +2). Has any NUMA node run out of resources? + +There are several ways to bind task's memory with a NUMA node, the strict way +like the MPOL_BIND memory policy or 'cpuset.mems' will limit the memory +node where to allocate pages. In this situation, admin should make sure the +task is allowed to run on the CPUs of that NUMA node, and make sure there are +available CPU resource there. + +There are also ways to bind task's CPU with a NUMA node, like 'cpuset.cpus' or +sched_setaffinity() syscall. In this situation, NUMA Balancing help to migrate +pages into that node, admin should make sure there are available memory there. + +Admin could try to rebind or unbind the NUMA node to erase the damage, make a +change then observe the statistics to see if things get better until the +situation is acceptable. + +Highlights +---------- + +For some tasks, NUMA Balancing may found no necessary to scan pages, and +locality could always be 0 or small number, don't pay attention to them +since they most likely insensitive to NUMA. + +There is no accounting until the option is turned on, so enable it in advance +if you want to have the whole history. + +We have per-task migfailed counter to tell how many page migration has been +failed for a particular task, you will find it in /proc/PID/sched entry.
Documentation/admin-guide/index.rst +1 -0
@@ -112,6 +112,7 @@ configure specific aspects of kernel behavior to your liking. video-output wimax/index xfs + cg-numa-stat .. only:: subproject and html
Documentation/admin-guide/kernel-parameters.txt +4 -0
@@ -3227,6 +3227,10 @@ numa_balancing= [KNL,X86] Enable or disable automatic NUMA balancing. Allowed values are enable and disable + numa_locality [KNL] Enable per-cgroup numa locality info. + Useful to debug NUMA efficiency problems when there are + lots of per-cgroup workloads. + numa_zonelist_order= [KNL, BOOT] Select zonelist order for NUMA. 'node', 'default' can be specified This can be set from sysctl after boot.
Documentation/admin-guide/sysctl/kernel.rst +9 -0
@@ -572,6 +572,15 @@ rate for each task. numa_balancing_scan_size_mb is how many megabytes worth of pages are scanned for a given scan. +numa_locality: +============= + +Enables/disables per-cgroup NUMA locality info. + +0: disabled (default). +1: enabled. + +Check Documentation/admin-guide/cg-numa-stat.rst for details. osrelease, ostype & version: ============================
Signature · 1 line
2.14.4.44.g2045bb6
Jonathan Corbet
maintainerRe: [PATCH v3 2/2] sched/numa: documentation for per-cgroup numa statistics
Quoted 27 lines · On Tue, 3 Dec 2019 14:02:18 +0800 王贇 <[email protected]> wrote:
Add the description for '
numa_locality', also a new doc to explain the details on how to deal with the per-cgroup numa statistics.Cc Peter Zijlstra <[email protected]>Cc Michal Koutný <[email protected]>Cc Mel Gorman <[email protected]>Cc Jonathan Corbet <[email protected]>Cc Iurii Zaikin <[email protected]>Cc Randy Dunlap <[email protected]>Signed-off-by Michael Wang <[email protected]>--- Documentation/admin-guide/cg-numa-stat.rst | 176 ++++++++++++++++++++++++ Documentation/admin-guide/index.rst | 1 + Documentation/admin-guide/kernel-parameters.txt | 4 + Documentation/admin-guide/sysctl/kernel.rst | 9 ++ include/linux/sched.h | 10 +- init/Kconfig | 4 +- kernel/sched/fair.c | 4 +- 7 files changed, 200 insertions(+), 8 deletions(-) create mode 100644 Documentation/admin-guide/cg-numa-stat.rstDocumentation/admin-guide/cg-numa-stat.rst new file +0
-0
Documentation/admin-guide/cg-numa-stat.rst line 3
Quoted 3 lines
Documentation/admin-guide/cg-numa-stat.rst new file +3
-0@@ -0,0 +1,176 @@ +=============================== +Per-cgroup NUMA statistics +===============================
One small request: can we get an SPDX line at the beginning of that new file?
Thanks,
jon
Re: [PATCH v3 2/2] sched/numa: documentation for per-cgroup numa statistics
Quoted 1 line · Jonathan Corbet
On Tue, 3 Dec 2019 14:02:18 +0800
[snip]
Quoted 4 lines
Quoted 4 lines
Documentation/admin-guide/cg-numa-stat.rst new file +0
-1--- /dev/null
Quoted 8 lines
Documentation/admin-guide/cg-numa-stat.rst line 3
Quoted 5 lines
+++
b/Documentation/admin-guide/cg-numa-stat.rstDocumentation/admin-guide/cg-numa-stat.rst new file +3
-0@@ -0,0 +1,176 @@ +=============================== +Per-cgroup NUMA statistics +===============================One small request: can we get an SPDX line at the beginning of that new file?
Certainly, will be in next version :-)
Regards,
Michael Wang
Quoted 5 lines
Thanks,
jon
v4 cover sched/numa: introduce numa locality
In reply to 王贇Since v3:
* fix comments and improved documentation
Since v2:
* simplified the locality concept & implementation
Since v1:
* improved documentation
Modern production environment could use hundreds of cgroup to control the resources for different workloads, along with the complicated resource binding.
On NUMA platforms where we have multiple nodes, things become even more complicated, we hope there are more local memory access to improve the performance, and NUMA Balancing keep working hard to achieve that, however, wrong memory policy or node binding could easily waste the effort, result a lot of remote page accessing.
We need to notice such problems, then we got chance to fix it before there are too much damages, however, there are no good monitoring approach yet to help catch the mouse who introduced the remote access.
This patch set is trying to fill in the missing pieces, by introduce the per-cgroup NUMA locality info, with this new statistics, we could achieve the daily monitoring on NUMA efficiency, to give warning when things going too wrong.
Please check the second patch for more details. Michael Wang (2):
sched/numa: introduce per-cgroup NUMA locality info sched/numa: documentation for per-cgroup numa statistics
Documentation/admin-guide/cg-numa-stat.rst | 178 ++++++++++++++++++++++++ Documentation/admin-guide/index.rst | 1 + Documentation/admin-guide/kernel-parameters.txt | 4 + Documentation/admin-guide/sysctl/kernel.rst | 9 ++ include/linux/sched.h | 15 ++ include/linux/sched/sysctl.h | 6 + init/Kconfig | 11 ++ kernel/sched/core.c | 75 ++++++++++ kernel/sched/fair.c | 62 +++++++++ kernel/sched/sched.h | 12 ++ kernel/sysctl.c | 11 ++ 11 files changed, 384 insertions(+) create mode 100644 Documentation/admin-guide/cg-numa-stat.rst
Signature · 1 line
2.14.4.44.g2045bb6
PATCH v4 1/2 sched/numa: introduce per-cgroup NUMA locality info
Currently there are no good approach to monitoring the per-cgroup NUMA efficiency, this could be a trouble especially when groups are sharing CPUs, we don't know which one introduced remote-memory accessing.
Although the per-task NUMA accessing info from PMU is good for further debuging, but not light enough for daily monitoring, especial on a box with thousands of tasks.
Fortunately, when NUMA Balancing enabled, it will periodly trigger page fault and try to increase the NUMA locality, by tracing the results we will be able to estimate the NUMA efficiency.
On each page fault of NUMA Balancing, when task's executing CPU is from the same node of pages, we call this a local page accessing, otherwise a remote page accessing.
By updating task's accessing counter into it's cgroup on ticks, we get the per-cgroup numa locality info.
For example the new entry 'cpu.numa_stat' show:
page_access local=1231412 remote=53453
Here we know the workloads in hierarchy have totally been traced 1284865 times of page accessing, and 1231412 of them are local page access, which imply a good NUMA efficiency.
By monitoring the increments, we will be able to locate the per-cgroup workload which NUMA Balancing can't helpwith (usually caused by wrong CPU and memory node bindings), then we got chance to fix that in time.
--- include/linux/sched.h | 15 +++++++++ include/linux/sched/sysctl.h | 6 ++++ init/Kconfig | 9 ++++++ kernel/sched/core.c | 75 ++++++++++++++++++++++++++++++++++++++++++++ kernel/sched/fair.c | 62 ++++++++++++++++++++++++++++++++++++ kernel/sched/sched.h | 12 +++++++ kernel/sysctl.c | 11 +++++++ 7 files changed, 190 insertions(+)
include/linux/sched.h +15 -0
@@ -1125,6 +1125,21 @@ struct task_struct {unsigned long numa_pages_migrated;#endif /* CONFIG_NUMA_BALANCING */ +#ifdef CONFIG_CGROUP_NUMA_LOCALITY +/* +* Counter index stand for: +* 0 -- remote page accessing +* 1 -- local page accessing +* 2 -- remote page accessing updated to cgroup +* 3 -- local page accessing updated to cgroup +* +* We record the counter before the end of task_numa_fault(), this +* is based on the fact that after page fault is handled, the task +* will access the page on the CPU where it triggered the PF. +*/ +unsigned long numa_page_access[4 ]; +#endif +#ifdef CONFIG_RSEQ struct rseq __user *rseq;u32 rseq_sig;
include/linux/sched/sysctl.h +6 -0
@@ -102,4 +102,10 @@ extern int sched_energy_aware_handler(struct ctl_table *table, int write, loff_t *ppos);#endif +#ifdef CONFIG_CGROUP_NUMA_LOCALITY +extern int sysctl_numa_locality (struct ctl_table *table,int write, +void __user *buffer,size_t *lenp, +loff_t *ppos); +#endif +#endif /* _LINUX_SCHED_SYSCTL_H */
init/Kconfig +9 -0
@@ -817,6 +817,15 @@ config NUMA_BALANCING_DEFAULT_ENABLED If set, automatic NUMA balancing will be enabled if running on a NUMA machine. +config CGROUP_NUMA_LOCALITY + bool "The per-cgroup NUMA Locality" + default n + depends on CGROUP_SCHED && NUMA_BALANCING + help + This option enable the collection of per-cgroup NUMA locality info, + to tell whether NUMA Balancing is working well for a particular + workload, also imply the NUMA efficiency. + menuconfig CGROUPS bool "Control Group support" select KERNFS
kernel/sched/core.c +75 -0
93 lines not on this page · raw message
kernel/sched/fair.c +62 -0
86 lines not on this page · raw message
kernel/sched/sched.h +12 -0
@@ -575,6 +575,14 @@ struct cfs_rq {struct list_head throttled_list;#endif /* CONFIG_CFS_BANDWIDTH */ #endif /* CONFIG_FAIR_GROUP_SCHED */ +#ifdef CONFIG_CGROUP_NUMA_LOCALITY +/* +* The local/remote page access info collected from all +* the tasks in hierarchy. +*/ +u64 local_page_access; +u64 remote_page_access; +#endif };static inline int rt_bandwidth_enabled (void )
@@ -1601,6 +1609,10 @@ static const_debug __maybe_unused unsigned int sysctl_sched_features =extern struct static_key_false sched_numa_balancing;extern struct static_key_false sched_schedstats; +#ifdef CONFIG_CGROUP_NUMA_LOCALITY +extern struct static_key_false sched_numa_locality; +#endif +static inline u64 global_rt_period (void ) {return (u64 )sysctl_sched_rt_period *NSEC_PER_USEC ;
kernel/sysctl.c +11 -0
@@ -428,6 +428,17 @@ static struct ctl_table kern_table[] = { .extra2 = SYSCTL_ONE, }, #endif /* CONFIG_NUMA_BALANCING */ +#ifdef CONFIG_CGROUP_NUMA_LOCALITY + { + .procname = "numa_locality", + .data = NULL, /* filled in by handler */ + .maxlen = sizeof(unsigned int), + .mode = 0644, + .proc_handler = sysctl_numa_locality, + .extra1 = SYSCTL_ZERO, + .extra2 = SYSCTL_ONE, + }, +#endif /* CONFIG_CGROUP_NUMA_LOCALITY */ #endif /* CONFIG_SCHED_DEBUG */ { .procname = "sched_rt_period_us",
Signature · 1 line
2.14.4.44.g2045bb6
Randy Dunlap
reviewerRe: [PATCH v4 1/2] sched/numa: introduce per-cgroup NUMA locality info
Hi,
It seems that you missed my previous comments...
init/Kconfig config NUMA_BALANCING_DEFAULT_ENABLED · line 821
Quoted 10 lines · 王贇
init/Kconfig +2
-0@@ -817,6 +817,15 @@ config NUMA_BALANCING_DEFAULT_ENABLED If set, automatic NUMA balancing will be enabled if running on a NUMA machine. +config CGROUP_NUMA_LOCALITY + bool "The per-cgroup NUMA Locality"
Drop "The"
init/Kconfig config NUMA_BALANCING_DEFAULT_ENABLED · line 825
Quoted 4 lines
init/Kconfig +4
-0+ default n + depends on CGROUP_SCHED && NUMA_BALANCING + help + This option enable the collection of per-cgroup NUMA locality info,
enables
init/Kconfig config NUMA_BALANCING_DEFAULT_ENABLED · line 831
Quoted 6 lines
init/Kconfig +3
-0+ to tell whether NUMA Balancing is working well for a particular + workload, also imply the NUMA efficiency. + menuconfig CGROUPS bool "Control Group support" select KERNFS
thanks.
Signature · 1 line
~Randy
Randy Dunlap
reviewerRe: [PATCH v4 1/2] sched/numa: introduce per-cgroup NUMA locality info
Quoted 26 lines · Randy Dunlap
Hi,
It seems that you missed my previous comments...
init/Kconfig config NUMA_BALANCING_DEFAULT_ENABLED · line 821
Quoted 10 lines · 王贇
init/Kconfig +2
-0@@ -817,6 +817,15 @@ config NUMA_BALANCING_DEFAULT_ENABLED If set, automatic NUMA balancing will be enabled if running on a NUMA machine. +config CGROUP_NUMA_LOCALITY + bool "The per-cgroup NUMA Locality"Drop "The"
init/Kconfig config NUMA_BALANCING_DEFAULT_ENABLED · line 825
Quoted 4 lines
init/Kconfig +4
-0+ default n + depends on CGROUP_SCHED && NUMA_BALANCING + help + This option enable the collection of per-cgroup NUMA locality info,enables
Quoted 10 lines
init/Kconfig config NUMA_BALANCING_DEFAULT_ENABLED · line 831
Quoted 6 lines
init/Kconfig +3
-0+ to tell whether NUMA Balancing is working well for a particular + workload, also imply the NUMA efficiency. + menuconfig CGROUPS bool "Control Group support" select KERNFSthanks.
Ah, the changes are in patch 2/2/ for some reason. OK, thanks.
Signature · 1 line
~Randy
Re: [PATCH v4 1/2] sched/numa: introduce per-cgroup NUMA locality info
Quoted 38 lines · Randy Dunlap
Quoted 26 lines · Randy Dunlap
Hi,
It seems that you missed my previous comments...
init/Kconfig config NUMA_BALANCING_DEFAULT_ENABLED · line 821
Quoted 10 lines · 王贇
init/Kconfig +2
-0@@ -817,6 +817,15 @@ config NUMA_BALANCING_DEFAULT_ENABLED If set, automatic NUMA balancing will be enabled if running on a NUMA machine. +config CGROUP_NUMA_LOCALITY + bool "The per-cgroup NUMA Locality"Drop "The"
init/Kconfig config NUMA_BALANCING_DEFAULT_ENABLED · line 825
Quoted 4 lines
init/Kconfig +4
-0+ default n + depends on CGROUP_SCHED && NUMA_BALANCING + help + This option enable the collection of per-cgroup NUMA locality info,enables
Quoted 10 lines
init/Kconfig config NUMA_BALANCING_DEFAULT_ENABLED · line 831
Quoted 6 lines
init/Kconfig +3
-0+ to tell whether NUMA Balancing is working well for a particular + workload, also imply the NUMA efficiency. + menuconfig CGROUPS bool "Control Group support" select KERNFSthanks.
Quoted 1 line
Ah, the changes are in patch 2/2/ for some reason. OK, thanks.
My bad, let's move them to 1/2 then, also will apply the comments you sent for 2/2 in next version ;-)
Regards,
Michael Wang
Quoted 1 line
PATCH v4 2/2 sched/numa: documentation for per-cgroup numa statistics
In reply to 王贇Add the description for 'numa_locality', also a new doc to explain the details on how to deal with the per-cgroup numa statistics.
--- Documentation/admin-guide/cg-numa-stat.rst | 178 ++++++++++++++++++++++++ Documentation/admin-guide/index.rst | 1 + Documentation/admin-guide/kernel-parameters.txt | 4 + Documentation/admin-guide/sysctl/kernel.rst | 9 ++ init/Kconfig | 6 +- 5 files changed, 196 insertions(+), 2 deletions(-) create mode 100644 Documentation/admin-guide/cg-numa-stat.rst
Documentation/admin-guide/cg-numa-stat.rst new file +178 -0
@@ -0,0 +1,178 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=============================== +Per-cgroup NUMA statistics +=============================== + +Background +---------- + +On NUMA platforms, remote memory accessing always has a performance penalty. +Although we have NUMA balancing working hard to maximize the access locality, +there are still situations it can't help. + +This could happen in modern production environment. When a large number of +cgroups are used to classify and control resources, this creates a complex +configuration for memory policy, CPUs and NUMA nodes. In such cases NUMA +balancing could end up with the wrong memory policy or exhausted local NUMA +node, which would lead to low percentage of local page accesses. + +We need to detect such cases, figure out which workloads from which cgroup +have introduced the issues, then we get chance to do adjustment to avoid +performance degradation. + +However, there are no hardware counters for per-task local/remote accessing +info, we don't know how many remote page accesses have occurred for a +particular task. + +NUMA Locality +------------- + +Fortunately, we have NUMA Balancing which scans task's mapping and triggers +page fault periodically, giving us the opportunity to record per-task page +accessing info, when the CPU fall into PF is from the same node of pages, we +consider task as doing local page accessing, otherwise the remote page +accessing, we call these two counter the locality info. + +On each tick, we acquire the locality info of current task on that CPU, update +the increments into it's cgroup, becoming the group locality info. + +By "echo 1 > /proc/sys/kernel/numa_locality" at runtime or adding boot parameter +'numa_locality', we will enable the accounting of per-cgroup NUMA locality info, +the 'cpu.numa_stat' entry of CPU cgroup will show statistics:: + + page_access local=NR_LOCAL_PAGE_ACCESS remote=NR_REMOTE_PAGE_ACCESS + +We define 'NUMA locality' as:: + + NR_LOCAL_PAGE_ACCESS * 100 / (NR_LOCAL_PAGE_ACCESS + NR_REMOTE_PAGE_ACCESS) + +This per-cgroup percentage number help to represent the NUMA Balancing behavior. + +Note that the accounting is hierarchical, which means the NUMA locality info for +a given group represent not only the workload of this group, but also the +workloads of all its descendants. + +For example the 'cpu.numa_stat' show:: + + page_access local=129909383 remote=18265810 + +The NUMA locality calculated as:: + + 129909383 * 100 / (129909383 + 18265810) = 87.67 + +Thus we know the workload of this group and its descendants have totally done +129909383 times of local page accessing and 18265810 times of remotes, locality +is 87.67% which imply most of the memory access are local. + +NUMA Consumption +---------------- + +There are also other cgroup entry help us to estimate NUMA efficiency, which is +'cpuacct.usage_percpu' and 'memory.numa_stat'. + +By reading 'cpuacct.usage_percpu' we will get per-cpu runtime (in nanoseconds) +info (in hierarchy) as:: + + CPU_0_RUNTIME CPU_1_RUNTIME CPU_2_RUNTIME ... CPU_X_RUNTIME + +Combined with the info from:: + + cat /sys/devices/system/node/nodeX/cpulist + +We would be able to accumulate the runtime of CPUs into NUMA nodes, to get the +per-cgroup node runtime info. + +By reading 'memory.numa_stat' we will get per-cgroup node memory consumption +info as:: + + total=TOTAL_MEM N0=MEM_ON_NODE0 N1=MEM_ON_NODE1 ... NX=MEM_ON_NODEX + +Together we call these the per-cgroup NUMA consumption info, tell us how many +resources a particular workload has consumed, on a particular NUMA node. + +Monitoring +---------- + +By monitoring the increments of locality info, we can easily know whether NUMA +Balancing is working well for a particular workload. + +For example we take a 5 seconds sample period, then on each sampling we have:: + + local_diff = last_nr_local_page_access - nr_local_page_access + remote_diff = last_nr_remote_page_access - nr_remote_page_access + +and we get the locality in this period as:: + + locality = local_diff * 100 / (local_diff + remote_diff) + +We can plot a line for locality, when the line close to 100% things are good, +when getting close to 0% something is wrong, we can pick a proper watermark to +trigger warning message. + +You may want to drop the data if the local/remote_diff is too small, which +implies there are not many available pages for NUMA Balancing to scan, ignoring +would be fine since most likely the workload is insensitive to NUMA, or the +memory topology is already good enough. + +Monitoring root group helps you control the overall situation, while you may +also want to monitor all the leaf groups which contain the workloads, this +helps to catch the mouse. + +Try to put your workload into also the cpuacct & memory cgroup, when NUMA +Balancing is disabled or locality becomes too small, we may want to monitoring +the per-node runtime & memory info to see if the node consumption meet the +requirements. + +For NUMA node X on each sampling we have:: + + runtime_X_diff = runtime_X - last_runtime_X + runtime_all_diff = runtime_all - last_runtime_all + + runtime_percent_X = runtime_X_diff * 100 / runtime_all_diff + memory_percent_X = memory_X * 100 / memory_all + +These two percentages are usually matched on each node, workload should execute +mostly on the node that contains most of its memory, but it's not guaranteed. + +The workload may only access a small part of its memory, in such cases although +the majority of memory are remotely, locality could still be good. + +Thus to tell if things are fine or not depends on the understanding of system +resource deployment, however, if you find node X got 100% memory percent but 0% +runtime percent, definitely something is wrong. + +Troubleshooting +--------------- + +After identifying which workload introduced the bad locality, check: + +1). Is the workload bound to a particular NUMA node? +2). Has any NUMA node run out of resources? + +There are several ways to bind task's memory with a NUMA node, the strict way +like the MPOL_BIND memory policy or 'cpuset.mems' will limit the memory +node where to allocate pages. In this situation, admin should make sure the +task is allowed to run on the CPUs of that NUMA node, and make sure there are +available CPU resource there. + +There are also ways to bind task's CPU with a NUMA node, like 'cpuset.cpus' or +sched_setaffinity() syscall. In this situation, NUMA Balancing help to migrate +pages into that node, admin should make sure there are available memory there. + +Admin could try to rebind or unbind the NUMA node to erase the damage, make a +change then observe the statistics to see if things get better until the +situation is acceptable. + +Highlights +---------- + +For some tasks, NUMA Balancing may found no necessary to scan pages, and +locality could always be 0 or small number, don't pay attention to them +since they most likely insensitive to NUMA. + +There is no accounting until the option is turned on, so enable it in advance +if you want to have the whole history. + +We have per-task migfailed counter to tell how many page migration has been +failed for a particular task, you will find it in /proc/PID/sched entry.
Documentation/admin-guide/index.rst +1 -0
@@ -112,6 +112,7 @@ configure specific aspects of kernel behavior to your liking. video-output wimax/index xfs + cg-numa-stat .. only:: subproject and html
Documentation/admin-guide/kernel-parameters.txt +4 -0
@@ -3227,6 +3227,10 @@ numa_balancing= [KNL,X86] Enable or disable automatic NUMA balancing. Allowed values are enable and disable + numa_locality [KNL] Enable per-cgroup numa locality info. + Useful to debug NUMA efficiency problems when there are + lots of per-cgroup workloads. + numa_zonelist_order= [KNL, BOOT] Select zonelist order for NUMA. 'node', 'default' can be specified This can be set from sysctl after boot.
Documentation/admin-guide/sysctl/kernel.rst +9 -0
@@ -572,6 +572,15 @@ rate for each task. numa_balancing_scan_size_mb is how many megabytes worth of pages are scanned for a given scan. +numa_locality: +============= + +Enables/disables per-cgroup NUMA locality info. + +0: disabled (default). +1: enabled. + +Check Documentation/admin-guide/cg-numa-stat.rst for details. osrelease, ostype & version: ============================
init/Kconfig +4 -2
@@ -818,13 +818,15 @@ config NUMA_BALANCING_DEFAULT_ENABLED machine. config CGROUP_NUMA_LOCALITY - bool "The per-cgroup NUMA Locality" + bool "per-cgroup NUMA Locality" default n depends on CGROUP_SCHED && NUMA_BALANCING help - This option enable the collection of per-cgroup NUMA locality info, + This option enables the collection of per-cgroup NUMA locality info, to tell whether NUMA Balancing is working well for a particular workload, also imply the NUMA efficiency. + See + - Documentation/admin-guide/cg-numa-stat.rst menuconfig CGROUPS bool "Control Group support"
Signature · 1 line
2.14.4.44.g2045bb6
Randy Dunlap
reviewerRe: [PATCH v4 2/2] sched/numa: documentation for per-cgroup numa statistics
Quoted 53 lines · 王贇
Add the description for '
numa_locality', also a new doc to explain the details on how to deal with the per-cgroup numa statistics.Cc Peter Zijlstra <[email protected]>Cc Michal Koutný <[email protected]>Cc Mel Gorman <[email protected]>Cc Jonathan Corbet <[email protected]>Cc Iurii Zaikin <[email protected]>Cc Randy Dunlap <[email protected]>Signed-off-by Michael Wang <[email protected]>--- Documentation/admin-guide/cg-numa-stat.rst | 178 ++++++++++++++++++++++++ Documentation/admin-guide/index.rst | 1 + Documentation/admin-guide/kernel-parameters.txt | 4 + Documentation/admin-guide/sysctl/kernel.rst | 9 ++ init/Kconfig | 6 +- 5 files changed, 196 insertions(+), 2 deletions(-) create mode 100644 Documentation/admin-guide/cg-numa-stat.rstDocumentation/admin-guide/cg-numa-stat.rst new file +28
-0@@ -0,0 +1,178 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=============================== +Per-cgroup NUMA statistics +=============================== + +Background +---------- + +On NUMA platforms, remote memory accessing always has a performance penalty. +Although we have NUMA balancing working hard to maximize the access locality, +there are still situations it can't help. + +This could happen in modern production environment. When a large number of +cgroups are used to classify and control resources, this creates a complex +configuration for memory policy, CPUs and NUMA nodes. In such cases NUMA +balancing could end up with the wrong memory policy or exhausted local NUMA +node, which would lead to low percentage of local page accesses. + +We need to detect such cases, figure out which workloads from which cgroup +have introduced the issues, then we get chance to do adjustment to avoid +performance degradation. + +However, there are no hardware counters for per-task local/remote accessing +info, we don't know how many remote page accesses have occurred for a +particular task. + +NUMA Locality
Documentation/admin-guide/cg-numa-stat.rst line 38
Quoted 10 lines
Documentation/admin-guide/cg-numa-stat.rst new file +10
-0+------------- + +Fortunately, we have NUMA Balancing which scans task's mapping and triggers +page fault periodically, giving us the opportunity to record per-task page +accessing info, when the CPU fall into PF is from the same node of pages, we +consider task as doing local page accessing, otherwise the remote page +accessing, we call these two counter the locality info. + +On each tick, we acquire the locality info of current task on that CPU, update +the increments into it's cgroup, becoming the group locality info.
its
(it's means it is, which is not correct here)
Documentation/admin-guide/cg-numa-stat.rst line 50
Quoted 12 lines
Documentation/admin-guide/cg-numa-stat.rst new file +12
-0+ +By "echo 1 > /proc/sys/kernel/numa_locality" at runtime or adding boot parameter +'numa_locality', we will enable the accounting of per-cgroup NUMA locality info, +the 'cpu.numa_stat' entry of CPU cgroup will show statistics:: + + page_access local=NR_LOCAL_PAGE_ACCESS remote=NR_REMOTE_PAGE_ACCESS + +We define 'NUMA locality' as:: + + NR_LOCAL_PAGE_ACCESS * 100 / (NR_LOCAL_PAGE_ACCESS + NR_REMOTE_PAGE_ACCESS) + +This per-cgroup percentage number help to represent the NUMA Balancing behavior.
helps
Documentation/admin-guide/cg-numa-stat.rst line 56
Quoted 6 lines
Documentation/admin-guide/cg-numa-stat.rst new file +6
-0+ +Note that the accounting is hierarchical, which means the NUMA locality info for +a given group represent not only the workload of this group, but also the +workloads of all its descendants. + +For example the 'cpu.numa_stat' show::
shows::
Quoted 57 lines
Documentation/admin-guide/cg-numa-stat.rst new file +57
-0+ + page_access local=129909383 remote=18265810 + +The NUMA locality calculated as:: + + 129909383 * 100 / (129909383 + 18265810) = 87.67 + +Thus we know the workload of this group and its descendants have totally done +129909383 times of local page accessing and 18265810 times of remotes, locality +is 87.67% which imply most of the memory access are local. + +NUMA Consumption +---------------- + +There are also other cgroup entry help us to estimate NUMA efficiency, which is +'cpuacct.usage_percpu' and 'memory.numa_stat'. + +By reading 'cpuacct.usage_percpu' we will get per-cpu runtime (in nanoseconds) +info (in hierarchy) as:: + + CPU_0_RUNTIME CPU_1_RUNTIME CPU_2_RUNTIME ... CPU_X_RUNTIME + +Combined with the info from:: + + cat /sys/devices/system/node/nodeX/cpulist + +We would be able to accumulate the runtime of CPUs into NUMA nodes, to get the +per-cgroup node runtime info. + +By reading 'memory.numa_stat' we will get per-cgroup node memory consumption +info as:: + + total=TOTAL_MEM N0=MEM_ON_NODE0 N1=MEM_ON_NODE1 ... NX=MEM_ON_NODEX + +Together we call these the per-cgroup NUMA consumption info, tell us how many +resources a particular workload has consumed, on a particular NUMA node. + +Monitoring +---------- + +By monitoring the increments of locality info, we can easily know whether NUMA +Balancing is working well for a particular workload. + +For example we take a 5 seconds sample period, then on each sampling we have:: + + local_diff = last_nr_local_page_access - nr_local_page_access + remote_diff = last_nr_remote_page_access - nr_remote_page_access + +and we get the locality in this period as:: + + locality = local_diff * 100 / (local_diff + remote_diff) + +We can plot a line for locality, when the line close to 100% things are good, +when getting close to 0% something is wrong, we can pick a proper watermark to +trigger warning message. + +You may want to drop the data if the local/remote_diff is too small, which
Documentation/admin-guide/cg-numa-stat.rst line 123
Quoted 10 lines
Documentation/admin-guide/cg-numa-stat.rst new file +10
-0+implies there are not many available pages for NUMA Balancing to scan, ignoring +would be fine since most likely the workload is insensitive to NUMA, or the +memory topology is already good enough. + +Monitoring root group helps you control the overall situation, while you may +also want to monitor all the leaf groups which contain the workloads, this +helps to catch the mouse. + +Try to put your workload into also the cpuacct & memory cgroup, when NUMA +Balancing is disabled or locality becomes too small, we may want to monitoring
to monitor
Quoted 37 lines
Documentation/admin-guide/cg-numa-stat.rst new file +37
-0+the per-node runtime & memory info to see if the node consumption meet the +requirements. + +For NUMA node X on each sampling we have:: + + runtime_X_diff = runtime_X - last_runtime_X + runtime_all_diff = runtime_all - last_runtime_all + + runtime_percent_X = runtime_X_diff * 100 / runtime_all_diff + memory_percent_X = memory_X * 100 / memory_all + +These two percentages are usually matched on each node, workload should execute +mostly on the node that contains most of its memory, but it's not guaranteed. + +The workload may only access a small part of its memory, in such cases although +the majority of memory are remotely, locality could still be good. + +Thus to tell if things are fine or not depends on the understanding of system +resource deployment, however, if you find node X got 100% memory percent but 0% +runtime percent, definitely something is wrong. + +Troubleshooting +--------------- + +After identifying which workload introduced the bad locality, check: + +1). Is the workload bound to a particular NUMA node? +2). Has any NUMA node run out of resources? + +There are several ways to bind task's memory with a NUMA node, the strict way +like the MPOL_BIND memory policy or 'cpuset.mems' will limit the memory +node where to allocate pages. In this situation, admin should make sure the +task is allowed to run on the CPUs of that NUMA node, and make sure there are +available CPU resource there. + +There are also ways to bind task's CPU with a NUMA node, like 'cpuset.cpus' or +sched_setaffinity() syscall. In this situation, NUMA Balancing help to migrate
Documentation/admin-guide/cg-numa-stat.rst line 170
Quoted 10 lines
Documentation/admin-guide/cg-numa-stat.rst new file +10
-0+pages into that node, admin should make sure there are available memory there. + +Admin could try to rebind or unbind the NUMA node to erase the damage, make a +change then observe the statistics to see if things get better until the +situation is acceptable. + +Highlights +---------- + +For some tasks, NUMA Balancing may found no necessary to scan pages, and
may be found to be unnecessary
Documentation/admin-guide/cg-numa-stat.rst line 178
Quoted 8 lines
Documentation/admin-guide/cg-numa-stat.rst new file +8
-0+locality could always be 0 or small number, don't pay attention to them +since they most likely insensitive to NUMA. + +There is no accounting until the option is turned on, so enable it in advance +if you want to have the whole history. + +We have per-task migfailed counter to tell how many page migration has been +failed for a particular task, you will find it in /proc/PID/sched entry.
HTH.
Signature · 1 line
~Randy
v5 cover sched/numa: introduce numa locality
In reply to 王贇Since v4:
* improved documentation
Since v3:
* fix comments and improved documentation
Since v2:
* simplified the locality concept & implementation
Since v1:
* improved documentation
Modern production environment could use hundreds of cgroup to control the resources for different workloads, along with the complicated resource binding.
On NUMA platforms where we have multiple nodes, things become even more complicated, we hope there are more local memory access to improve the performance, and NUMA Balancing keep working hard to achieve that, however, wrong memory policy or node binding could easily waste the effort, result a lot of remote page accessing.
We need to notice such problems, then we got chance to fix it before there are too much damages, however, there are no good monitoring approach yet to help catch the mouse who introduced the remote access.
This patch set is trying to fill in the missing pieces, by introduce the per-cgroup NUMA locality info, with this new statistics, we could achieve the daily monitoring on NUMA efficiency, to give warning when things going too wrong.
Please check the second patch for more details.
Michael Wang (2):
sched/numa: introduce per-cgroup NUMA locality info sched/numa: documentation for per-cgroup numa statistics
Documentation/admin-guide/cg-numa-stat.rst | 178 ++++++++++++++++++++++++ Documentation/admin-guide/index.rst | 1 + Documentation/admin-guide/kernel-parameters.txt | 4 + Documentation/admin-guide/sysctl/kernel.rst | 9 ++ include/linux/sched.h | 15 ++ include/linux/sched/sysctl.h | 6 + init/Kconfig | 11 ++ kernel/sched/core.c | 75 ++++++++++ kernel/sched/fair.c | 62 +++++++++ kernel/sched/sched.h | 12 ++ kernel/sysctl.c | 11 ++ 11 files changed, 384 insertions(+) create mode 100644 Documentation/admin-guide/cg-numa-stat.rst
Signature · 1 line
2.14.4.44.g2045bb6
PATCH v5 1/2 sched/numa: introduce per-cgroup NUMA locality info
Currently there are no good approach to monitoring the per-cgroup NUMA efficiency, this could be a trouble especially when groups are sharing CPUs, we don't know which one introduced remote-memory accessing.
Although the per-task NUMA accessing info from PMU is good for further debuging, but not light enough for daily monitoring, especial on a box with thousands of tasks.
Fortunately, when NUMA Balancing enabled, it will periodly trigger page fault and try to increase the NUMA locality, by tracing the results we will be able to estimate the NUMA efficiency.
On each page fault of NUMA Balancing, when task's executing CPU is from the same node of pages, we call this a local page accessing, otherwise a remote page accessing.
By updating task's accessing counter into it's cgroup on ticks, we get the per-cgroup numa locality info.
For example the new entry 'cpu.numa_stat' show:
page_access local=1231412 remote=53453
Here we know the workloads in hierarchy have totally been traced 1284865 times of page accessing, and 1231412 of them are local page access, which imply a good NUMA efficiency.
By monitoring the increments, we will be able to locate the per-cgroup workload which NUMA Balancing can't helpwith (usually caused by wrong CPU and memory node bindings), then we got chance to fix that in time.
--- include/linux/sched.h | 15 +++++++++ include/linux/sched/sysctl.h | 6 ++++ init/Kconfig | 9 ++++++ kernel/sched/core.c | 75 ++++++++++++++++++++++++++++++++++++++++++++ kernel/sched/fair.c | 62 ++++++++++++++++++++++++++++++++++++ kernel/sched/sched.h | 12 +++++++ kernel/sysctl.c | 11 +++++++ 7 files changed, 190 insertions(+)
include/linux/sched.h +15 -0
@@ -1125,6 +1125,21 @@ struct task_struct {unsigned long numa_pages_migrated;#endif /* CONFIG_NUMA_BALANCING */ +#ifdef CONFIG_CGROUP_NUMA_LOCALITY +/* +* Counter index stand for: +* 0 -- remote page accessing +* 1 -- local page accessing +* 2 -- remote page accessing updated to cgroup +* 3 -- local page accessing updated to cgroup +* +* We record the counter before the end of task_numa_fault(), this +* is based on the fact that after page fault is handled, the task +* will access the page on the CPU where it triggered the PF. +*/ +unsigned long numa_page_access[4 ]; +#endif +#ifdef CONFIG_RSEQ struct rseq __user *rseq;u32 rseq_sig;
include/linux/sched/sysctl.h +6 -0
@@ -102,4 +102,10 @@ extern int sched_energy_aware_handler(struct ctl_table *table, int write, loff_t *ppos);#endif +#ifdef CONFIG_CGROUP_NUMA_LOCALITY +extern int sysctl_numa_locality (struct ctl_table *table,int write, +void __user *buffer,size_t *lenp, +loff_t *ppos); +#endif +#endif /* _LINUX_SCHED_SYSCTL_H */
init/Kconfig +9 -0
@@ -817,6 +817,15 @@ config NUMA_BALANCING_DEFAULT_ENABLED If set, automatic NUMA balancing will be enabled if running on a NUMA machine. +config CGROUP_NUMA_LOCALITY + bool "per-cgroup NUMA Locality" + default n + depends on CGROUP_SCHED && NUMA_BALANCING + help + This option enables the collection of per-cgroup NUMA locality info, + to tell whether NUMA Balancing is working well for a particular + workload, also imply the NUMA efficiency. + menuconfig CGROUPS bool "Control Group support" select KERNFS
kernel/sched/core.c +75 -0
93 lines not on this page · raw message
kernel/sched/fair.c +62 -0
86 lines not on this page · raw message
kernel/sched/sched.h +12 -0
@@ -575,6 +575,14 @@ struct cfs_rq {struct list_head throttled_list;#endif /* CONFIG_CFS_BANDWIDTH */ #endif /* CONFIG_FAIR_GROUP_SCHED */ +#ifdef CONFIG_CGROUP_NUMA_LOCALITY +/* +* The local/remote page access info collected from all +* the tasks in hierarchy. +*/ +u64 local_page_access; +u64 remote_page_access; +#endif };static inline int rt_bandwidth_enabled (void )
@@ -1601,6 +1609,10 @@ static const_debug __maybe_unused unsigned int sysctl_sched_features =extern struct static_key_false sched_numa_balancing;extern struct static_key_false sched_schedstats; +#ifdef CONFIG_CGROUP_NUMA_LOCALITY +extern struct static_key_false sched_numa_locality; +#endif +static inline u64 global_rt_period (void ) {return (u64 )sysctl_sched_rt_period *NSEC_PER_USEC ;
kernel/sysctl.c +11 -0
@@ -428,6 +428,17 @@ static struct ctl_table kern_table[] = { .extra2 = SYSCTL_ONE, }, #endif /* CONFIG_NUMA_BALANCING */ +#ifdef CONFIG_CGROUP_NUMA_LOCALITY + { + .procname = "numa_locality", + .data = NULL, /* filled in by handler */ + .maxlen = sizeof(unsigned int), + .mode = 0644, + .proc_handler = sysctl_numa_locality, + .extra1 = SYSCTL_ZERO, + .extra2 = SYSCTL_ONE, + }, +#endif /* CONFIG_CGROUP_NUMA_LOCALITY */ #endif /* CONFIG_SCHED_DEBUG */ { .procname = "sched_rt_period_us",
Signature · 1 line
2.14.4.44.g2045bb6
PATCH v5 2/2 sched/numa: documentation for per-cgroup numa, statistics
In reply to 王贇Add the description for 'numa_locality', also a new doc to explain the details on how to deal with the per-cgroup numa statistics.
--- Documentation/admin-guide/cg-numa-stat.rst | 178 ++++++++++++++++++++++++ Documentation/admin-guide/index.rst | 1 + Documentation/admin-guide/kernel-parameters.txt | 4 + Documentation/admin-guide/sysctl/kernel.rst | 9 ++ init/Kconfig | 2 + 5 files changed, 194 insertions(+) create mode 100644 Documentation/admin-guide/cg-numa-stat.rst
Documentation/admin-guide/cg-numa-stat.rst new file +178 -0
@@ -0,0 +1,178 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=============================== +Per-cgroup NUMA statistics +=============================== + +Background +---------- + +On NUMA platforms, remote memory accessing always has a performance penalty. +Although we have NUMA balancing working hard to maximize the access locality, +there are still situations it can't help. + +This could happen in modern production environment. When a large number of +cgroups are used to classify and control resources, this creates a complex +configuration for memory policy, CPUs and NUMA nodes. In such cases NUMA +balancing could end up with the wrong memory policy or exhausted local NUMA +node, which would lead to low percentage of local page accesses. + +We need to detect such cases, figure out which workloads from which cgroup +have introduced the issues, then we get chance to do adjustment to avoid +performance degradation. + +However, there are no hardware counters for per-task local/remote accessing +info, we don't know how many remote page accesses have occurred for a +particular task. + +NUMA Locality +------------- + +Fortunately, we have NUMA Balancing which scans task's mapping and triggers +page fault periodically, giving us the opportunity to record per-task page +accessing info, when the CPU fall into PF is from the same node of pages, we +consider task as doing local page accessing, otherwise the remote page +accessing, we call these two counter the locality info. + +On each tick, we acquire the locality info of current task on that CPU, update +the increments into its cgroup, becoming the group locality info. + +By "echo 1 > /proc/sys/kernel/numa_locality" at runtime or adding boot parameter +'numa_locality', we will enable the accounting of per-cgroup NUMA locality info, +the 'cpu.numa_stat' entry of CPU cgroup will show statistics:: + + page_access local=NR_LOCAL_PAGE_ACCESS remote=NR_REMOTE_PAGE_ACCESS + +We define 'NUMA locality' as:: + + NR_LOCAL_PAGE_ACCESS * 100 / (NR_LOCAL_PAGE_ACCESS + NR_REMOTE_PAGE_ACCESS) + +This per-cgroup percentage number helps to represent the NUMA Balancing behavior. + +Note that the accounting is hierarchical, which means the NUMA locality info for +a given group represent not only the workload of this group, but also the +workloads of all its descendants. + +For example the 'cpu.numa_stat' shows:: + + page_access local=129909383 remote=18265810 + +The NUMA locality calculated as:: + + 129909383 * 100 / (129909383 + 18265810) = 87.67 + +Thus we know the workload of this group and its descendants have totally done +129909383 times of local page accessing and 18265810 times of remotes, locality +is 87.67% which imply most of the memory access are local. + +NUMA Consumption +---------------- + +There are also other cgroup entry help us to estimate NUMA efficiency, which is +'cpuacct.usage_percpu' and 'memory.numa_stat'. + +By reading 'cpuacct.usage_percpu' we will get per-cpu runtime (in nanoseconds) +info (in hierarchy) as:: + + CPU_0_RUNTIME CPU_1_RUNTIME CPU_2_RUNTIME ... CPU_X_RUNTIME + +Combined with the info from:: + + cat /sys/devices/system/node/nodeX/cpulist + +We would be able to accumulate the runtime of CPUs into NUMA nodes, to get the +per-cgroup node runtime info. + +By reading 'memory.numa_stat' we will get per-cgroup node memory consumption +info as:: + + total=TOTAL_MEM N0=MEM_ON_NODE0 N1=MEM_ON_NODE1 ... NX=MEM_ON_NODEX + +Together we call these the per-cgroup NUMA consumption info, tell us how many +resources a particular workload has consumed, on a particular NUMA node. + +Monitoring +---------- + +By monitoring the increments of locality info, we can easily know whether NUMA +Balancing is working well for a particular workload. + +For example we take a 5 seconds sample period, then on each sampling we have:: + + local_diff = last_nr_local_page_access - nr_local_page_access + remote_diff = last_nr_remote_page_access - nr_remote_page_access + +and we get the locality in this period as:: + + locality = local_diff * 100 / (local_diff + remote_diff) + +We can plot a line for locality, when the line close to 100% things are good, +when getting close to 0% something is wrong, we can pick a proper watermark to +trigger warning message. + +You may want to drop the data if the local/remote_diff is too small, which +implies there are not many available pages for NUMA Balancing to scan, ignoring +would be fine since most likely the workload is insensitive to NUMA, or the +memory topology is already good enough. + +Monitoring root group helps you control the overall situation, while you may +also want to monitor all the leaf groups which contain the workloads, this +helps to catch the mouse. + +Try to put your workload into also the cpuacct & memory cgroup, when NUMA +Balancing is disabled or locality becomes too small, we may want to monitor +the per-node runtime & memory info to see if the node consumption meet the +requirements. + +For NUMA node X on each sampling we have:: + + runtime_X_diff = runtime_X - last_runtime_X + runtime_all_diff = runtime_all - last_runtime_all + + runtime_percent_X = runtime_X_diff * 100 / runtime_all_diff + memory_percent_X = memory_X * 100 / memory_all + +These two percentages are usually matched on each node, workload should execute +mostly on the node that contains most of its memory, but it's not guaranteed. + +The workload may only access a small part of its memory, in such cases although +the majority of memory are remotely, locality could still be good. + +Thus to tell if things are fine or not depends on the understanding of system +resource deployment, however, if you find node X got 100% memory percent but 0% +runtime percent, definitely something is wrong. + +Troubleshooting +--------------- + +After identifying which workload introduced the bad locality, check: + +1). Is the workload bound to a particular NUMA node? +2). Has any NUMA node run out of resources? + +There are several ways to bind task's memory with a NUMA node, the strict way +like the MPOL_BIND memory policy or 'cpuset.mems' will limit the memory +node where to allocate pages. In this situation, admin should make sure the +task is allowed to run on the CPUs of that NUMA node, and make sure there are +available CPU resource there. + +There are also ways to bind task's CPU with a NUMA node, like 'cpuset.cpus' or +sched_setaffinity() syscall. In this situation, NUMA Balancing help to migrate +pages into that node, admin should make sure there are available memory there. + +Admin could try to rebind or unbind the NUMA node to erase the damage, make a +change then observe the statistics to see if things get better until the +situation is acceptable. + +Highlights +---------- + +For some tasks, NUMA Balancing may be found to be unnecessary to scan pages, +and locality could always be 0 or small number, don't pay attention to them +since they most likely insensitive to NUMA. + +There is no accounting until the option is turned on, so enable it in advance +if you want to have the whole history. + +We have per-task migfailed counter to tell how many page migration has been +failed for a particular task, you will find it in /proc/PID/sched entry.
Documentation/admin-guide/index.rst +1 -0
@@ -112,6 +112,7 @@ configure specific aspects of kernel behavior to your liking. video-output wimax/index xfs + cg-numa-stat .. only:: subproject and html
Documentation/admin-guide/kernel-parameters.txt +4 -0
@@ -3227,6 +3227,10 @@ numa_balancing= [KNL,X86] Enable or disable automatic NUMA balancing. Allowed values are enable and disable + numa_locality [KNL] Enable per-cgroup numa locality info. + Useful to debug NUMA efficiency problems when there are + lots of per-cgroup workloads. + numa_zonelist_order= [KNL, BOOT] Select zonelist order for NUMA. 'node', 'default' can be specified This can be set from sysctl after boot.
Documentation/admin-guide/sysctl/kernel.rst +9 -0
@@ -572,6 +572,15 @@ rate for each task. numa_balancing_scan_size_mb is how many megabytes worth of pages are scanned for a given scan. +numa_locality: +============= + +Enables/disables per-cgroup NUMA locality info. + +0: disabled (default). +1: enabled. + +Check Documentation/admin-guide/cg-numa-stat.rst for details. osrelease, ostype & version: ============================
init/Kconfig +2 -0
@@ -825,6 +825,8 @@ config CGROUP_NUMA_LOCALITY This option enables the collection of per-cgroup NUMA locality info, to tell whether NUMA Balancing is working well for a particular workload, also imply the NUMA efficiency. + See + - Documentation/admin-guide/cg-numa-stat.rst menuconfig CGROUPS bool "Control Group support"
Signature · 1 line
2.14.4.44.g2045bb6
Re: [PATCH v5 0/2] sched/numa: introduce numa locality
In reply to 王贇Hi Peter, Ingo
We have reformed the implementation for several times, now it's very simple and easy to use, there are also a document to guide admin on how to use not only the NUMA locality, but also other per-cgroup NUMA statistics, we hope this could make things easier for other NUMA users.
As now there are no more comments, would you please take a look at this patch set, see if it's good enough to be picked?
Regards,
Michael Wang
Quoted 48 lines · 王贇
Since v4:
* improved documentation
Since v3:
* fix comments and improved documentation
Since v2:
* simplified the locality concept & implementation
Since v1:
* improved documentationModern production environment could use hundreds of cgroup to control the resources for different workloads, along with the complicated resource binding.
On NUMA platforms where we have multiple nodes, things become even more complicated, we hope there are more local memory access to improve the performance, and NUMA Balancing keep working hard to achieve that, however, wrong memory policy or node binding could easily waste the effort, result a lot of remote page accessing.
We need to notice such problems, then we got chance to fix it before there are too much damages, however, there are no good monitoring approach yet to help catch the mouse who introduced the remote access.
This patch set is trying to fill in the missing pieces, by introduce the per-cgroup NUMA locality info, with this new statistics, we could achieve the daily monitoring on NUMA efficiency, to give warning when things going too wrong.
Please check the second patch for more details.
Michael Wang (2):
sched/numa: introduce per-cgroup NUMA locality info sched/numa: documentation for per-cgroup numa statisticsDocumentation/admin-guide/cg-numa-stat.rst | 178 ++++++++++++++++++++++++ Documentation/admin-guide/index.rst | 1 + Documentation/admin-guide/kernel-parameters.txt | 4 + Documentation/admin-guide/sysctl/kernel.rst | 9 ++ include/linux/sched.h | 15 ++ include/linux/sched/sysctl.h | 6 + init/Kconfig | 11 ++ kernel/sched/core.c | 75 ++++++++++ kernel/sched/fair.c | 62 +++++++++ kernel/sched/sched.h | 12 ++ kernel/sysctl.c | 11 ++ 11 files changed, 384 insertions(+) create mode 100644 Documentation/admin-guide/cg-numa-stat.rst
v6 cover sched/numa: introduce numa locality
In reply to 王贇Since v5:
* fix compile failure when NUMA disabled
Since v4:
* improved documentation
Since v3:
* fix comments and improved documentation
Since v2:
* simplified the locality concept & implementation
Since v1:
* improved documentation
Modern production environment could use hundreds of cgroup to control the resources for different workloads, along with the complicated resource binding.
On NUMA platforms where we have multiple nodes, things become even more complicated, we hope there are more local memory access to improve the performance, and NUMA Balancing keep working hard to achieve that, however, wrong memory policy or node binding could easily waste the effort, result a lot of remote page accessing.
We need to notice such problems, then we got chance to fix it before there are too much damages, however, there are no good monitoring approach yet to help catch the mouse who introduced the remote access.
This patch set is trying to fill in the missing pieces, by introduce the per-cgroup NUMA locality info, with this new statistics, we could achieve the daily monitoring on NUMA efficiency, to give warning when things going too wrong.
Please check the second patch for more details.
Michael Wang (2):
sched/numa: introduce per-cgroup NUMA locality info sched/numa: documentation for per-cgroup numa statistics
Documentation/admin-guide/cg-numa-stat.rst | 178 ++++++++++++++++++++++++ Documentation/admin-guide/index.rst | 1 + Documentation/admin-guide/kernel-parameters.txt | 4 + Documentation/admin-guide/sysctl/kernel.rst | 9 ++ include/linux/sched.h | 15 ++ include/linux/sched/sysctl.h | 6 + init/Kconfig | 11 ++ kernel/sched/core.c | 75 ++++++++++ kernel/sched/fair.c | 62 +++++++++ kernel/sched/sched.h | 12 ++ kernel/sysctl.c | 11 ++ 11 files changed, 384 insertions(+) create mode 100644 Documentation/admin-guide/cg-numa-stat.rst
Signature · 1 line
2.14.4.44.g2045bb6
PATCH v6 1/2 sched/numa: introduce per-cgroup NUMA locality info
Currently there are no good approach to monitoring the per-cgroup NUMA efficiency, this could be a trouble especially when groups are sharing CPUs, we don't know which one introduced remote-memory accessing.
Although the per-task NUMA accessing info from PMU is good for further debuging, but not light enough for daily monitoring, especial on a box with thousands of tasks.
Fortunately, when NUMA Balancing enabled, it will periodly trigger page fault and try to increase the NUMA locality, by tracing the results we will be able to estimate the NUMA efficiency.
On each page fault of NUMA Balancing, when task's executing CPU is from the same node of pages, we call this a local page accessing, otherwise a remote page accessing.
By updating task's accessing counter into it's cgroup on ticks, we get the per-cgroup numa locality info.
For example the new entry 'cpu.numa_stat' show:
page_access local=1231412 remote=53453
Here we know the workloads in hierarchy have totally been traced 1284865 times of page accessing, and 1231412 of them are local page access, which imply a good NUMA efficiency.
By monitoring the increments, we will be able to locate the per-cgroup workload which NUMA Balancing can't helpwith (usually caused by wrong CPU and memory node bindings), then we got chance to fix that in time.
--- include/linux/sched.h | 15 +++++++++ include/linux/sched/sysctl.h | 6 ++++ init/Kconfig | 9 ++++++ kernel/sched/core.c | 75 ++++++++++++++++++++++++++++++++++++++++++++ kernel/sched/fair.c | 62 ++++++++++++++++++++++++++++++++++++ kernel/sched/sched.h | 12 +++++++ kernel/sysctl.c | 11 +++++++ 7 files changed, 190 insertions(+)
include/linux/sched.h +15 -0
@@ -1125,6 +1125,21 @@ struct task_struct {unsigned long numa_pages_migrated;#endif /* CONFIG_NUMA_BALANCING */ +#ifdef CONFIG_CGROUP_NUMA_LOCALITY +/* +* Counter index stand for: +* 0 -- remote page accessing +* 1 -- local page accessing +* 2 -- remote page accessing updated to cgroup +* 3 -- local page accessing updated to cgroup +* +* We record the counter before the end of task_numa_fault(), this +* is based on the fact that after page fault is handled, the task +* will access the page on the CPU where it triggered the PF. +*/ +unsigned long numa_page_access[4 ]; +#endif +#ifdef CONFIG_RSEQ struct rseq __user *rseq;u32 rseq_sig;
include/linux/sched/sysctl.h +6 -0
@@ -102,4 +102,10 @@ extern int sched_energy_aware_handler(struct ctl_table *table, int write, loff_t *ppos);#endif +#ifdef CONFIG_CGROUP_NUMA_LOCALITY +extern int sysctl_numa_locality (struct ctl_table *table,int write, +void __user *buffer,size_t *lenp, +loff_t *ppos); +#endif +#endif /* _LINUX_SCHED_SYSCTL_H */
init/Kconfig +9 -0
@@ -817,6 +817,15 @@ config NUMA_BALANCING_DEFAULT_ENABLED If set, automatic NUMA balancing will be enabled if running on a NUMA machine. +config CGROUP_NUMA_LOCALITY + bool "per-cgroup NUMA Locality" + default n + depends on CGROUP_SCHED && NUMA_BALANCING + help + This option enables the collection of per-cgroup NUMA locality info, + to tell whether NUMA Balancing is working well for a particular + workload, also imply the NUMA efficiency. + menuconfig CGROUPS bool "Control Group support" select KERNFS
kernel/sched/core.c +75 -0
93 lines not on this page · raw message
kernel/sched/fair.c +62 -0
87 lines not on this page · raw message
kernel/sched/sched.h +12 -0
@@ -575,6 +575,14 @@ struct cfs_rq {struct list_head throttled_list;#endif /* CONFIG_CFS_BANDWIDTH */ #endif /* CONFIG_FAIR_GROUP_SCHED */ +#ifdef CONFIG_CGROUP_NUMA_LOCALITY +/* +* The local/remote page access info collected from all +* the tasks in hierarchy. +*/ +u64 local_page_access; +u64 remote_page_access; +#endif };static inline int rt_bandwidth_enabled (void )
@@ -1601,6 +1609,10 @@ static const_debug __maybe_unused unsigned int sysctl_sched_features =extern struct static_key_false sched_numa_balancing;extern struct static_key_false sched_schedstats; +#ifdef CONFIG_CGROUP_NUMA_LOCALITY +extern struct static_key_false sched_numa_locality; +#endif +static inline u64 global_rt_period (void ) {return (u64 )sysctl_sched_rt_period *NSEC_PER_USEC ;
kernel/sysctl.c +11 -0
@@ -428,6 +428,17 @@ static struct ctl_table kern_table[] = { .extra2 = SYSCTL_ONE, }, #endif /* CONFIG_NUMA_BALANCING */ +#ifdef CONFIG_CGROUP_NUMA_LOCALITY + { + .procname = "numa_locality", + .data = NULL, /* filled in by handler */ + .maxlen = sizeof(unsigned int), + .mode = 0644, + .proc_handler = sysctl_numa_locality, + .extra1 = SYSCTL_ZERO, + .extra2 = SYSCTL_ONE, + }, +#endif /* CONFIG_CGROUP_NUMA_LOCALITY */ #endif /* CONFIG_SCHED_DEBUG */ { .procname = "sched_rt_period_us",
Signature · 1 line
2.14.4.44.g2045bb6
Re: [PATCH v6 1/2] sched/numa: introduce per-cgroup NUMA locality info
Hi.
Quoted 3 lines · 王贇
By monitoring the increments, we will be able to locate the per-cgroup workload which NUMA Balancing can't helpwith (usually caused by wrong CPU and memory node bindings), then we got chance to fix that in time.
I just wonder do the data based on increments match with those you obtained previously?
kernel/sched/fair.c update_stats_curr_start(struct cfs_rq *cfs_rq, struct sched_entity *se) · line 1069
Quoted 11 lines
kernel/sched/fair.c +11
-0+static inline void +update_task_locality (struct task_struct *p,int pnid,int cnid,int pages) +{ +if (!static_branch_unlikely (&sched_numa_locality)) +return ; + +/* +* pnid != cnid --> remote idx 0 +* pnid == cnid --> local idx 1 +*/ + p->numa_page_access[!!(pnid == cnid)] += pages;
If the per-task information isn't used anywhere, why not accumulate directly into task's cfs_rq->{local,remote}_page_access?
kernel/sched/fair.c entity_tick(struct cfs_rq *cfs_rq, struct sched_entity *curr, int queued) · line 4362
Quoted 5 lines
kernel/sched/fair.c +1
-0@@ -4298,6 +4359,7 @@ entity_tick(struct cfs_rq *cfs_rq, struct sched_entity *curr, int queued)*/ update_load_avg (cfs_rq, curr,UPDATE_TG );update_cfs_group (curr); +update_group_locality (cfs_rq);
With the per-NUMA node time tracked separately, isn't it unnecessary doing group updates inside entity_tick?
Regards,
Michal
Re: [PATCH v6 1/2] sched/numa: introduce per-cgroup NUMA locality info
Quoted 8 lines · Michal Koutný
Hi.
Quoted 3 lines · 王贇
By monitoring the increments, we will be able to locate the per-cgroup workload which NUMA Balancing can't helpwith (usually caused by wrong CPU and memory node bindings), then we got chance to fix that in time.
I just wonder do the data based on increments match with those you obtained previously?
They have different meaning, since now it's just the accumulation of local/remote page access counter, we have to increasing the sample period into the maximum NUMA balancing scan period, to my system it's 1 minute.
We still get useful information from the increments, for example:
local 100 remote 1000 <-- bad locality in last period local 0 remote 0 <-- no scan or NUMA PF happened in last period local 100 remote 0 <-- good locality but not much PF happened
So I won't say they are matched, they tell the story in different way :-P
Quoted 15 lines
kernel/sched/fair.c update_stats_curr_start(struct cfs_rq *cfs_rq, struct sched_entity *se) · line 1069
Quoted 12 lines
kernel/sched/fair.c +11
-0+static inline void +update_task_locality (struct task_struct *p,int pnid,int cnid,int pages) +{ +if (!static_branch_unlikely (&sched_numa_locality)) +return ; + +/* +* pnid != cnid --> remote idx 0 +* pnid == cnid --> local idx 1 +*/ + p->numa_page_access[!!(pnid == cnid)] += pages;If the per-task information isn't used anywhere, why not accumulate directly into task's cfs_rq->{local,remote}_page_access?
This is try to avoid hierarchy update in each PF, accumulate the counter and update together should cost less.
Besides, as they won't be reset now, maybe we could expose them too.
Quoted 7 lines
kernel/sched/fair.c entity_tick(struct cfs_rq *cfs_rq, struct sched_entity *curr, int queued) · line 4362
Quoted 5 lines
kernel/sched/fair.c +1
-0@@ -4298,6 +4359,7 @@ entity_tick(struct cfs_rq *cfs_rq, struct sched_entity *curr, int queued)*/ update_load_avg (cfs_rq, curr,UPDATE_TG );update_cfs_group (curr); +update_group_locality (cfs_rq);With the per-NUMA node time tracked separately, isn't it unnecessary doing group updates inside
entity_tick?
The hierarchy update can't be saved, and this is a good place where we already holding rq lock, iterate cfs_rq in hierarchy for current task.
Regards,
Michael Wang
Quoted 5 lines
Regards,
Michal
PATCH v6 2/2 sched/numa: documentation for per-cgroup numa
In reply to 王贇Add the description for 'numa_locality', also a new doc to explain the details on how to deal with the per-cgroup numa statistics.
--- Documentation/admin-guide/cg-numa-stat.rst | 178 ++++++++++++++++++++++++ Documentation/admin-guide/index.rst | 1 + Documentation/admin-guide/kernel-parameters.txt | 4 + Documentation/admin-guide/sysctl/kernel.rst | 9 ++ init/Kconfig | 2 + 5 files changed, 194 insertions(+) create mode 100644 Documentation/admin-guide/cg-numa-stat.rst
Documentation/admin-guide/cg-numa-stat.rst new file +178 -0
@@ -0,0 +1,178 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=============================== +Per-cgroup NUMA statistics +=============================== + +Background +---------- + +On NUMA platforms, remote memory accessing always has a performance penalty. +Although we have NUMA balancing working hard to maximize the access locality, +there are still situations it can't help. + +This could happen in modern production environment. When a large number of +cgroups are used to classify and control resources, this creates a complex +configuration for memory policy, CPUs and NUMA nodes. In such cases NUMA +balancing could end up with the wrong memory policy or exhausted local NUMA +node, which would lead to low percentage of local page accesses. + +We need to detect such cases, figure out which workloads from which cgroup +have introduced the issues, then we get chance to do adjustment to avoid +performance degradation. + +However, there are no hardware counters for per-task local/remote accessing +info, we don't know how many remote page accesses have occurred for a +particular task. + +NUMA Locality +------------- + +Fortunately, we have NUMA Balancing which scans task's mapping and triggers +page fault periodically, giving us the opportunity to record per-task page +accessing info, when the CPU fall into PF is from the same node of pages, we +consider task as doing local page accessing, otherwise the remote page +accessing, we call these two counter the locality info. + +On each tick, we acquire the locality info of current task on that CPU, update +the increments into its cgroup, becoming the group locality info. + +By "echo 1 > /proc/sys/kernel/numa_locality" at runtime or adding boot parameter +'numa_locality', we will enable the accounting of per-cgroup NUMA locality info, +the 'cpu.numa_stat' entry of CPU cgroup will show statistics:: + + page_access local=NR_LOCAL_PAGE_ACCESS remote=NR_REMOTE_PAGE_ACCESS + +We define 'NUMA locality' as:: + + NR_LOCAL_PAGE_ACCESS * 100 / (NR_LOCAL_PAGE_ACCESS + NR_REMOTE_PAGE_ACCESS) + +This per-cgroup percentage number helps to represent the NUMA Balancing behavior. + +Note that the accounting is hierarchical, which means the NUMA locality info for +a given group represent not only the workload of this group, but also the +workloads of all its descendants. + +For example the 'cpu.numa_stat' shows:: + + page_access local=129909383 remote=18265810 + +The NUMA locality calculated as:: + + 129909383 * 100 / (129909383 + 18265810) = 87.67 + +Thus we know the workload of this group and its descendants have totally done +129909383 times of local page accessing and 18265810 times of remotes, locality +is 87.67% which imply most of the memory access are local. + +NUMA Consumption +---------------- + +There are also other cgroup entry help us to estimate NUMA efficiency, which is +'cpuacct.usage_percpu' and 'memory.numa_stat'. + +By reading 'cpuacct.usage_percpu' we will get per-cpu runtime (in nanoseconds) +info (in hierarchy) as:: + + CPU_0_RUNTIME CPU_1_RUNTIME CPU_2_RUNTIME ... CPU_X_RUNTIME + +Combined with the info from:: + + cat /sys/devices/system/node/nodeX/cpulist + +We would be able to accumulate the runtime of CPUs into NUMA nodes, to get the +per-cgroup node runtime info. + +By reading 'memory.numa_stat' we will get per-cgroup node memory consumption +info as:: + + total=TOTAL_MEM N0=MEM_ON_NODE0 N1=MEM_ON_NODE1 ... NX=MEM_ON_NODEX + +Together we call these the per-cgroup NUMA consumption info, tell us how many +resources a particular workload has consumed, on a particular NUMA node. + +Monitoring +---------- + +By monitoring the increments of locality info, we can easily know whether NUMA +Balancing is working well for a particular workload. + +For example we take a 5 seconds sample period, then on each sampling we have:: + + local_diff = last_nr_local_page_access - nr_local_page_access + remote_diff = last_nr_remote_page_access - nr_remote_page_access + +and we get the locality in this period as:: + + locality = local_diff * 100 / (local_diff + remote_diff) + +We can plot a line for locality, when the line close to 100% things are good, +when getting close to 0% something is wrong, we can pick a proper watermark to +trigger warning message. + +You may want to drop the data if the local/remote_diff is too small, which +implies there are not many available pages for NUMA Balancing to scan, ignoring +would be fine since most likely the workload is insensitive to NUMA, or the +memory topology is already good enough. + +Monitoring root group helps you control the overall situation, while you may +also want to monitor all the leaf groups which contain the workloads, this +helps to catch the mouse. + +Try to put your workload into also the cpuacct & memory cgroup, when NUMA +Balancing is disabled or locality becomes too small, we may want to monitor +the per-node runtime & memory info to see if the node consumption meet the +requirements. + +For NUMA node X on each sampling we have:: + + runtime_X_diff = runtime_X - last_runtime_X + runtime_all_diff = runtime_all - last_runtime_all + + runtime_percent_X = runtime_X_diff * 100 / runtime_all_diff + memory_percent_X = memory_X * 100 / memory_all + +These two percentages are usually matched on each node, workload should execute +mostly on the node that contains most of its memory, but it's not guaranteed. + +The workload may only access a small part of its memory, in such cases although +the majority of memory are remotely, locality could still be good. + +Thus to tell if things are fine or not depends on the understanding of system +resource deployment, however, if you find node X got 100% memory percent but 0% +runtime percent, definitely something is wrong. + +Troubleshooting +--------------- + +After identifying which workload introduced the bad locality, check: + +1). Is the workload bound to a particular NUMA node? +2). Has any NUMA node run out of resources? + +There are several ways to bind task's memory with a NUMA node, the strict way +like the MPOL_BIND memory policy or 'cpuset.mems' will limit the memory +node where to allocate pages. In this situation, admin should make sure the +task is allowed to run on the CPUs of that NUMA node, and make sure there are +available CPU resource there. + +There are also ways to bind task's CPU with a NUMA node, like 'cpuset.cpus' or +sched_setaffinity() syscall. In this situation, NUMA Balancing help to migrate +pages into that node, admin should make sure there are available memory there. + +Admin could try to rebind or unbind the NUMA node to erase the damage, make a +change then observe the statistics to see if things get better until the +situation is acceptable. + +Highlights +---------- + +For some tasks, NUMA Balancing may be found to be unnecessary to scan pages, +and locality could always be 0 or small number, don't pay attention to them +since they most likely insensitive to NUMA. + +There is no accounting until the option is turned on, so enable it in advance +if you want to have the whole history. + +We have per-task migfailed counter to tell how many page migration has been +failed for a particular task, you will find it in /proc/PID/sched entry.
Documentation/admin-guide/index.rst +1 -0
@@ -112,6 +112,7 @@ configure specific aspects of kernel behavior to your liking. video-output wimax/index xfs + cg-numa-stat .. only:: subproject and html
Documentation/admin-guide/kernel-parameters.txt +4 -0
@@ -3227,6 +3227,10 @@ numa_balancing= [KNL,X86] Enable or disable automatic NUMA balancing. Allowed values are enable and disable + numa_locality [KNL] Enable per-cgroup numa locality info. + Useful to debug NUMA efficiency problems when there are + lots of per-cgroup workloads. + numa_zonelist_order= [KNL, BOOT] Select zonelist order for NUMA. 'node', 'default' can be specified This can be set from sysctl after boot.
Documentation/admin-guide/sysctl/kernel.rst +9 -0
@@ -572,6 +572,15 @@ rate for each task. numa_balancing_scan_size_mb is how many megabytes worth of pages are scanned for a given scan. +numa_locality: +============= + +Enables/disables per-cgroup NUMA locality info. + +0: disabled (default). +1: enabled. + +Check Documentation/admin-guide/cg-numa-stat.rst for details. osrelease, ostype & version: ============================
init/Kconfig +2 -0
@@ -825,6 +825,8 @@ config CGROUP_NUMA_LOCALITY This option enables the collection of per-cgroup NUMA locality info, to tell whether NUMA Balancing is working well for a particular workload, also imply the NUMA efficiency. + See + - Documentation/admin-guide/cg-numa-stat.rst menuconfig CGROUPS bool "Control Group support"
Signature · 1 line
2.14.4.44.g2045bb6
Re: [PATCH v6 0/2] sched/numa: introduce numa locality
In reply to 王贇Hi folks, is there any more comments?
Regards,
Michael Wang
Quoted 50 lines · 王贇
Since v5:
* fix compile failure when NUMA disabled
Since v4:
* improved documentation
Since v3:
* fix comments and improved documentation
Since v2:
* simplified the locality concept & implementation
Since v1:
* improved documentationModern production environment could use hundreds of cgroup to control the resources for different workloads, along with the complicated resource binding.
On NUMA platforms where we have multiple nodes, things become even more complicated, we hope there are more local memory access to improve the performance, and NUMA Balancing keep working hard to achieve that, however, wrong memory policy or node binding could easily waste the effort, result a lot of remote page accessing.
We need to notice such problems, then we got chance to fix it before there are too much damages, however, there are no good monitoring approach yet to help catch the mouse who introduced the remote access.
This patch set is trying to fill in the missing pieces, by introduce the per-cgroup NUMA locality info, with this new statistics, we could achieve the daily monitoring on NUMA efficiency, to give warning when things going too wrong.
Please check the second patch for more details.
Michael Wang (2):
sched/numa: introduce per-cgroup NUMA locality info sched/numa: documentation for per-cgroup numa statisticsDocumentation/admin-guide/cg-numa-stat.rst | 178 ++++++++++++++++++++++++ Documentation/admin-guide/index.rst | 1 + Documentation/admin-guide/kernel-parameters.txt | 4 + Documentation/admin-guide/sysctl/kernel.rst | 9 ++ include/linux/sched.h | 15 ++ include/linux/sched/sysctl.h | 6 + init/Kconfig | 11 ++ kernel/sched/core.c | 75 ++++++++++ kernel/sched/fair.c | 62 +++++++++ kernel/sched/sched.h | 12 ++ kernel/sysctl.c | 11 ++ 11 files changed, 384 insertions(+) create mode 100644 Documentation/admin-guide/cg-numa-stat.rst
Re: [PATCH v6 0/2] sched/numa: introduce numa locality
In reply to 王贇Dear folks,
During our testing, we found in some cases the NUMA Balancing is not helping improving locality, that is the memory writing inside a virtual machine.
The VM is created by docker kata-runtime, inside guest the container executed several tasks to malloc memory and keep writing in page size, then report the time cost after finished 1G writing.
The result is not as good as runc, and we found the locality is not growing in kata cases, with some debugging we located the reason.
Those vcpu threads created by VM is rarely exit into userspace in this case, they just stay in kernel after calling ioctl(KVM_RUN), while NUMA Balancing work is done with task_work_run(), which is handled together with signal handling before exit to usermode.
So the situation is, for these vcpu threads, NUMA Balancing work was queued with task_work_add(), but never got chance to finish.
Now the question is, is this by designed or not?
BTW, we also passed the NUMA topology into VM, but still the result is not as good as runc, seems like the effect of NUMA Balancing on host is far more better than inside guest.
Regards,
Michael Wang
Quoted 50 lines · 王贇
Since v5:
* fix compile failure when NUMA disabled
Since v4:
* improved documentation
Since v3:
* fix comments and improved documentation
Since v2:
* simplified the locality concept & implementation
Since v1:
* improved documentationModern production environment could use hundreds of cgroup to control the resources for different workloads, along with the complicated resource binding.
On NUMA platforms where we have multiple nodes, things become even more complicated, we hope there are more local memory access to improve the performance, and NUMA Balancing keep working hard to achieve that, however, wrong memory policy or node binding could easily waste the effort, result a lot of remote page accessing.
We need to notice such problems, then we got chance to fix it before there are too much damages, however, there are no good monitoring approach yet to help catch the mouse who introduced the remote access.
This patch set is trying to fill in the missing pieces, by introduce the per-cgroup NUMA locality info, with this new statistics, we could achieve the daily monitoring on NUMA efficiency, to give warning when things going too wrong.
Please check the second patch for more details.
Michael Wang (2):
sched/numa: introduce per-cgroup NUMA locality info sched/numa: documentation for per-cgroup numa statisticsDocumentation/admin-guide/cg-numa-stat.rst | 178 ++++++++++++++++++++++++ Documentation/admin-guide/index.rst | 1 + Documentation/admin-guide/kernel-parameters.txt | 4 + Documentation/admin-guide/sysctl/kernel.rst | 9 ++ include/linux/sched.h | 15 ++ include/linux/sched/sysctl.h | 6 + init/Kconfig | 11 ++ kernel/sched/core.c | 75 ++++++++++ kernel/sched/fair.c | 62 +++++++++ kernel/sched/sched.h | 12 ++ kernel/sysctl.c | 11 ++ 11 files changed, 384 insertions(+) create mode 100644 Documentation/admin-guide/cg-numa-stat.rst
v7 cover sched/numa: introduce numa locality
In reply to 王贇Since v6:
* rebased on latest linux-next
Since v5:
* fix compile failure when NUMA disabled
Since v4:
* improved documentation
Since v3:
* fix comments and improved documentation
Since v2:
* simplified the locality concept & implementation
Since v1:
* improved documentation
Modern production environment could use hundreds of cgroup to control the resources for different workloads, along with the complicated resource binding.
On NUMA platforms where we have multiple nodes, things become even more complicated, we hope there are more local memory access to improve the performance, and NUMA Balancing keep working hard to achieve that, however, wrong memory policy or node binding could easily waste the effort, result a lot of remote page accessing.
We need to notice such problems, then we got chance to fix it before there are too much damages, however, there are no good monitoring approach yet to help catch the mouse who introduced the remote access.
This patch set is trying to fill in the missing pieces, by introduce the per-cgroup NUMA locality info, with this new statistics, we could achieve the daily monitoring on NUMA efficiency, to give warning when things going too wrong.
Please check the second patch for more details.
Michael Wang (2):
sched/numa: introduce per-cgroup NUMA locality info sched/numa: documentation for per-cgroup numa statistics
Documentation/admin-guide/cg-numa-stat.rst | 178 ++++++++++++++++++++++++ Documentation/admin-guide/index.rst | 1 + Documentation/admin-guide/kernel-parameters.txt | 4 + Documentation/admin-guide/sysctl/kernel.rst | 9 ++ include/linux/sched.h | 15 ++ include/linux/sched/sysctl.h | 6 + init/Kconfig | 11 ++ kernel/sched/core.c | 75 ++++++++++ kernel/sched/fair.c | 62 +++++++++ kernel/sched/sched.h | 12 ++ kernel/sysctl.c | 11 ++ 11 files changed, 384 insertions(+) create mode 100644 Documentation/admin-guide/cg-numa-stat.rst
Signature · 1 line
2.14.4.44.g2045bb6
PATCH v7 1/2 sched/numa: introduce per-cgroup NUMA locality info
Currently there are no good approach to monitoring the per-cgroup NUMA efficiency, this could be a trouble especially when groups are sharing CPUs, we don't know which one introduced remote-memory accessing.
Although the per-task NUMA accessing info from PMU is good for further debuging, but not light enough for daily monitoring, especial on a box with thousands of tasks.
Fortunately, when NUMA Balancing enabled, it will periodly trigger page fault and try to increase the NUMA locality, by tracing the results we will be able to estimate the NUMA efficiency.
On each page fault of NUMA Balancing, when task's executing CPU is from the same node of pages, we call this a local page accessing, otherwise a remote page accessing.
By updating task's accessing counter into it's cgroup on ticks, we get the per-cgroup numa locality info.
For example the new entry 'cpu.numa_stat' show:
page_access local=1231412 remote=53453
Here we know the workloads in hierarchy have totally been traced 1284865 times of page accessing, and 1231412 of them are local page access, which imply a good NUMA efficiency.
By monitoring the increments, we will be able to locate the per-cgroup workload which NUMA Balancing can't helpwith (usually caused by wrong CPU and memory node bindings), then we got chance to fix that in time.
--- include/linux/sched.h | 15 +++++++++ include/linux/sched/sysctl.h | 6 ++++ init/Kconfig | 9 ++++++ kernel/sched/core.c | 75 ++++++++++++++++++++++++++++++++++++++++++++ kernel/sched/fair.c | 62 ++++++++++++++++++++++++++++++++++++ kernel/sched/sched.h | 12 +++++++ kernel/sysctl.c | 11 +++++++ 7 files changed, 190 insertions(+)
include/linux/sched.h +15 -0
@@ -1128,6 +1128,21 @@ struct task_struct {unsigned long numa_pages_migrated;#endif /* CONFIG_NUMA_BALANCING */ +#ifdef CONFIG_CGROUP_NUMA_LOCALITY +/* +* Counter index stand for: +* 0 -- remote page accessing +* 1 -- local page accessing +* 2 -- remote page accessing updated to cgroup +* 3 -- local page accessing updated to cgroup +* +* We record the counter before the end of task_numa_fault(), this +* is based on the fact that after page fault is handled, the task +* will access the page on the CPU where it triggered the PF. +*/ +unsigned long numa_page_access[4 ]; +#endif +#ifdef CONFIG_RSEQ struct rseq __user *rseq;u32 rseq_sig;
include/linux/sched/sysctl.h +6 -0
@@ -101,4 +101,10 @@ extern int sched_energy_aware_handler(struct ctl_table *table, int write, loff_t *ppos);#endif +#ifdef CONFIG_CGROUP_NUMA_LOCALITY +extern int sysctl_numa_locality (struct ctl_table *table,int write, +void __user *buffer,size_t *lenp, +loff_t *ppos); +#endif +#endif /* _LINUX_SCHED_SYSCTL_H */
init/Kconfig +9 -0
@@ -813,6 +813,15 @@ config NUMA_BALANCING_DEFAULT_ENABLED If set, automatic NUMA balancing will be enabled if running on a NUMA machine. +config CGROUP_NUMA_LOCALITY + bool "per-cgroup NUMA Locality" + default n + depends on CGROUP_SCHED && NUMA_BALANCING + help + This option enables the collection of per-cgroup NUMA locality info, + to tell whether NUMA Balancing is working well for a particular + workload, also imply the NUMA efficiency. + menuconfig CGROUPS bool "Control Group support" select KERNFS
kernel/sched/core.c +75 -0
93 lines not on this page · raw message
kernel/sched/fair.c +62 -0
87 lines not on this page · raw message
kernel/sched/sched.h +12 -0
@@ -575,6 +575,14 @@ struct cfs_rq {struct list_head throttled_list;#endif /* CONFIG_CFS_BANDWIDTH */ #endif /* CONFIG_FAIR_GROUP_SCHED */ +#ifdef CONFIG_CGROUP_NUMA_LOCALITY +/* +* The local/remote page access info collected from all +* the tasks in hierarchy. +*/ +u64 local_page_access; +u64 remote_page_access; +#endif };static inline int rt_bandwidth_enabled (void )
@@ -1601,6 +1609,10 @@ static const_debug __maybe_unused unsigned int sysctl_sched_features =extern struct static_key_false sched_numa_balancing;extern struct static_key_false sched_schedstats; +#ifdef CONFIG_CGROUP_NUMA_LOCALITY +extern struct static_key_false sched_numa_locality; +#endif +static inline u64 global_rt_period (void ) {return (u64 )sysctl_sched_rt_period *NSEC_PER_USEC ;
kernel/sysctl.c +11 -0
@@ -428,6 +428,17 @@ static struct ctl_table kern_table[] = { .extra2 = SYSCTL_ONE, }, #endif /* CONFIG_NUMA_BALANCING */ +#ifdef CONFIG_CGROUP_NUMA_LOCALITY + { + .procname = "numa_locality", + .data = NULL, /* filled in by handler */ + .maxlen = sizeof(unsigned int), + .mode = 0644, + .proc_handler = sysctl_numa_locality, + .extra1 = SYSCTL_ZERO, + .extra2 = SYSCTL_ONE, + }, +#endif /* CONFIG_CGROUP_NUMA_LOCALITY */ #endif /* CONFIG_SCHED_DEBUG */ { .procname = "sched_rt_period_us",
Signature · 1 line
2.14.4.44.g2045bb6
PATCH v7 2/2 sched/numa: documentation for per-cgroup numa, statistics
In reply to 王贇Add the description for 'numa_locality', also a new doc to explain the details on how to deal with the per-cgroup numa statistics.
--- Documentation/admin-guide/cg-numa-stat.rst | 178 ++++++++++++++++++++++++ Documentation/admin-guide/index.rst | 1 + Documentation/admin-guide/kernel-parameters.txt | 4 + Documentation/admin-guide/sysctl/kernel.rst | 9 ++ init/Kconfig | 2 + 5 files changed, 194 insertions(+) create mode 100644 Documentation/admin-guide/cg-numa-stat.rst
Documentation/admin-guide/cg-numa-stat.rst new file +178 -0
@@ -0,0 +1,178 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=============================== +Per-cgroup NUMA statistics +=============================== + +Background +---------- + +On NUMA platforms, remote memory accessing always has a performance penalty. +Although we have NUMA balancing working hard to maximize the access locality, +there are still situations it can't help. + +This could happen in modern production environment. When a large number of +cgroups are used to classify and control resources, this creates a complex +configuration for memory policy, CPUs and NUMA nodes. In such cases NUMA +balancing could end up with the wrong memory policy or exhausted local NUMA +node, which would lead to low percentage of local page accesses. + +We need to detect such cases, figure out which workloads from which cgroup +have introduced the issues, then we get chance to do adjustment to avoid +performance degradation. + +However, there are no hardware counters for per-task local/remote accessing +info, we don't know how many remote page accesses have occurred for a +particular task. + +NUMA Locality +------------- + +Fortunately, we have NUMA Balancing which scans task's mapping and triggers +page fault periodically, giving us the opportunity to record per-task page +accessing info, when the CPU fall into PF is from the same node of pages, we +consider task as doing local page accessing, otherwise the remote page +accessing, we call these two counter the locality info. + +On each tick, we acquire the locality info of current task on that CPU, update +the increments into its cgroup, becoming the group locality info. + +By "echo 1 > /proc/sys/kernel/numa_locality" at runtime or adding boot parameter +'numa_locality', we will enable the accounting of per-cgroup NUMA locality info, +the 'cpu.numa_stat' entry of CPU cgroup will show statistics:: + + page_access local=NR_LOCAL_PAGE_ACCESS remote=NR_REMOTE_PAGE_ACCESS + +We define 'NUMA locality' as:: + + NR_LOCAL_PAGE_ACCESS * 100 / (NR_LOCAL_PAGE_ACCESS + NR_REMOTE_PAGE_ACCESS) + +This per-cgroup percentage number helps to represent the NUMA Balancing behavior. + +Note that the accounting is hierarchical, which means the NUMA locality info for +a given group represent not only the workload of this group, but also the +workloads of all its descendants. + +For example the 'cpu.numa_stat' shows:: + + page_access local=129909383 remote=18265810 + +The NUMA locality calculated as:: + + 129909383 * 100 / (129909383 + 18265810) = 87.67 + +Thus we know the workload of this group and its descendants have totally done +129909383 times of local page accessing and 18265810 times of remotes, locality +is 87.67% which imply most of the memory access are local. + +NUMA Consumption +---------------- + +There are also other cgroup entry help us to estimate NUMA efficiency, which is +'cpuacct.usage_percpu' and 'memory.numa_stat'. + +By reading 'cpuacct.usage_percpu' we will get per-cpu runtime (in nanoseconds) +info (in hierarchy) as:: + + CPU_0_RUNTIME CPU_1_RUNTIME CPU_2_RUNTIME ... CPU_X_RUNTIME + +Combined with the info from:: + + cat /sys/devices/system/node/nodeX/cpulist + +We would be able to accumulate the runtime of CPUs into NUMA nodes, to get the +per-cgroup node runtime info. + +By reading 'memory.numa_stat' we will get per-cgroup node memory consumption +info as:: + + total=TOTAL_MEM N0=MEM_ON_NODE0 N1=MEM_ON_NODE1 ... NX=MEM_ON_NODEX + +Together we call these the per-cgroup NUMA consumption info, tell us how many +resources a particular workload has consumed, on a particular NUMA node. + +Monitoring +---------- + +By monitoring the increments of locality info, we can easily know whether NUMA +Balancing is working well for a particular workload. + +For example we take a 5 seconds sample period, then on each sampling we have:: + + local_diff = last_nr_local_page_access - nr_local_page_access + remote_diff = last_nr_remote_page_access - nr_remote_page_access + +and we get the locality in this period as:: + + locality = local_diff * 100 / (local_diff + remote_diff) + +We can plot a line for locality, when the line close to 100% things are good, +when getting close to 0% something is wrong, we can pick a proper watermark to +trigger warning message. + +You may want to drop the data if the local/remote_diff is too small, which +implies there are not many available pages for NUMA Balancing to scan, ignoring +would be fine since most likely the workload is insensitive to NUMA, or the +memory topology is already good enough. + +Monitoring root group helps you control the overall situation, while you may +also want to monitor all the leaf groups which contain the workloads, this +helps to catch the mouse. + +Try to put your workload into also the cpuacct & memory cgroup, when NUMA +Balancing is disabled or locality becomes too small, we may want to monitor +the per-node runtime & memory info to see if the node consumption meet the +requirements. + +For NUMA node X on each sampling we have:: + + runtime_X_diff = runtime_X - last_runtime_X + runtime_all_diff = runtime_all - last_runtime_all + + runtime_percent_X = runtime_X_diff * 100 / runtime_all_diff + memory_percent_X = memory_X * 100 / memory_all + +These two percentages are usually matched on each node, workload should execute +mostly on the node that contains most of its memory, but it's not guaranteed. + +The workload may only access a small part of its memory, in such cases although +the majority of memory are remotely, locality could still be good. + +Thus to tell if things are fine or not depends on the understanding of system +resource deployment, however, if you find node X got 100% memory percent but 0% +runtime percent, definitely something is wrong. + +Troubleshooting +--------------- + +After identifying which workload introduced the bad locality, check: + +1). Is the workload bound to a particular NUMA node? +2). Has any NUMA node run out of resources? + +There are several ways to bind task's memory with a NUMA node, the strict way +like the MPOL_BIND memory policy or 'cpuset.mems' will limit the memory +node where to allocate pages. In this situation, admin should make sure the +task is allowed to run on the CPUs of that NUMA node, and make sure there are +available CPU resource there. + +There are also ways to bind task's CPU with a NUMA node, like 'cpuset.cpus' or +sched_setaffinity() syscall. In this situation, NUMA Balancing help to migrate +pages into that node, admin should make sure there are available memory there. + +Admin could try to rebind or unbind the NUMA node to erase the damage, make a +change then observe the statistics to see if things get better until the +situation is acceptable. + +Highlights +---------- + +For some tasks, NUMA Balancing may be found to be unnecessary to scan pages, +and locality could always be 0 or small number, don't pay attention to them +since they most likely insensitive to NUMA. + +There is no accounting until the option is turned on, so enable it in advance +if you want to have the whole history. + +We have per-task migfailed counter to tell how many page migration has been +failed for a particular task, you will find it in /proc/PID/sched entry.
Documentation/admin-guide/index.rst +1 -0
@@ -114,6 +114,7 @@ configure specific aspects of kernel behavior to your liking. video-output wimax/index xfs + cg-numa-stat .. only:: subproject and html
Documentation/admin-guide/kernel-parameters.txt +4 -0
@@ -3249,6 +3249,10 @@ numa_balancing= [KNL,X86] Enable or disable automatic NUMA balancing. Allowed values are enable and disable + numa_locality [KNL] Enable per-cgroup numa locality info. + Useful to debug NUMA efficiency problems when there are + lots of per-cgroup workloads. + numa_zonelist_order= [KNL, BOOT] Select zonelist order for NUMA. 'node', 'default' can be specified This can be set from sysctl after boot.
Documentation/admin-guide/sysctl/kernel.rst +9 -0
@@ -556,6 +556,15 @@ rate for each task. numa_balancing_scan_size_mb is how many megabytes worth of pages are scanned for a given scan. +numa_locality: +============= + +Enables/disables per-cgroup NUMA locality info. + +0: disabled (default). +1: enabled. + +Check Documentation/admin-guide/cg-numa-stat.rst for details. osrelease, ostype & version: ============================
init/Kconfig +2 -0
@@ -821,6 +821,8 @@ config CGROUP_NUMA_LOCALITY This option enables the collection of per-cgroup NUMA locality info, to tell whether NUMA Balancing is working well for a particular workload, also imply the NUMA efficiency. + See + - Documentation/admin-guide/cg-numa-stat.rst menuconfig CGROUPS bool "Control Group support"
Signature · 1 line
2.14.4.44.g2045bb6
Randy Dunlap
reviewerRe: [PATCH v7 2/2] sched/numa: documentation for per-cgroup numa, statistics
Hi,
Documentation edits below...
Quoted 50 lines · 王贇
Add the description for '
numa_locality', also a new doc to explain the details on how to deal with the per-cgroup numa statistics.Cc Peter Zijlstra <[email protected]>Cc Michal Koutný <[email protected]>Cc Mel Gorman <[email protected]>Cc Jonathan Corbet <[email protected]>Cc Iurii Zaikin <[email protected]>Cc Randy Dunlap <[email protected]>Signed-off-by Michael Wang <[email protected]>--- Documentation/admin-guide/cg-numa-stat.rst | 178 ++++++++++++++++++++++++ Documentation/admin-guide/index.rst | 1 + Documentation/admin-guide/kernel-parameters.txt | 4 + Documentation/admin-guide/sysctl/kernel.rst | 9 ++ init/Kconfig | 2 + 5 files changed, 194 insertions(+) create mode 100644 Documentation/admin-guide/cg-numa-stat.rstDocumentation/admin-guide/cg-numa-stat.rst new file +25
-0@@ -0,0 +1,178 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=============================== +Per-cgroup NUMA statistics +=============================== + +Background +---------- + +On NUMA platforms, remote memory accessing always has a performance penalty. +Although we have NUMA balancing working hard to maximize the access locality, +there are still situations it can't help. + +This could happen in modern production environment. When a large number of +cgroups are used to classify and control resources, this creates a complex +configuration for memory policy, CPUs and NUMA nodes. In such cases NUMA +balancing could end up with the wrong memory policy or exhausted local NUMA +node, which would lead to low percentage of local page accesses. + +We need to detect such cases, figure out which workloads from which cgroup +have introduced the issues, then we get chance to do adjustment to avoid +performance degradation. + +However, there are no hardware counters for per-task local/remote accessing +info, we don't know how many remote page accesses have occurred for a
Documentation/admin-guide/cg-numa-stat.rst line 35
Quoted 10 lines
Documentation/admin-guide/cg-numa-stat.rst new file +10
-0+particular task. + +NUMA Locality +------------- + +Fortunately, we have NUMA Balancing which scans task's mapping and triggers +page fault periodically, giving us the opportunity to record per-task page +accessing info, when the CPU fall into PF is from the same node of pages, we +consider task as doing local page accessing, otherwise the remote page +accessing, we call these two counter the locality info.
counters
Quoted 8 lines
Documentation/admin-guide/cg-numa-stat.rst new file +8
-0+ +On each tick, we acquire the locality info of current task on that CPU, update +the increments into its cgroup, becoming the group locality info. + +By "echo 1 > /proc/sys/kernel/numa_locality" at runtime or adding boot parameter +'numa_locality', we will enable the accounting of per-cgroup NUMA locality info, +the 'cpu.numa_stat' entry of CPU cgroup will show statistics:: +
Documentation/admin-guide/cg-numa-stat.rst line 53
Quoted 10 lines
Documentation/admin-guide/cg-numa-stat.rst new file +10
-0+ page_access local=NR_LOCAL_PAGE_ACCESS remote=NR_REMOTE_PAGE_ACCESS + +We define 'NUMA locality' as:: + + NR_LOCAL_PAGE_ACCESS * 100 / (NR_LOCAL_PAGE_ACCESS + NR_REMOTE_PAGE_ACCESS) + +This per-cgroup percentage number helps to represent the NUMA Balancing behavior. + +Note that the accounting is hierarchical, which means the NUMA locality info for +a given group represent not only the workload of this group, but also the
represents
Documentation/admin-guide/cg-numa-stat.rst line 66
Quoted 13 lines
Documentation/admin-guide/cg-numa-stat.rst new file +13
-0+workloads of all its descendants. + +For example the 'cpu.numa_stat' shows:: + + page_access local=129909383 remote=18265810 + +The NUMA locality calculated as:: + + 129909383 * 100 / (129909383 + 18265810) = 87.67 + +Thus we know the workload of this group and its descendants have totally done +129909383 times of local page accessing and 18265810 times of remotes, locality +is 87.67% which imply most of the memory access are local.
implies
Documentation/admin-guide/cg-numa-stat.rst line 71
Quoted 5 lines
Documentation/admin-guide/cg-numa-stat.rst new file +5
-0+ +NUMA Consumption +---------------- + +There are also other cgroup entry help us to estimate NUMA efficiency, which is
entries which help us to estimate NUMA efficiency. They are
Quoted 10 lines
Documentation/admin-guide/cg-numa-stat.rst new file +10
-0+'cpuacct.usage_percpu' and 'memory.numa_stat'. + +By reading 'cpuacct.usage_percpu' we will get per-cpu runtime (in nanoseconds) +info (in hierarchy) as:: + + CPU_0_RUNTIME CPU_1_RUNTIME CPU_2_RUNTIME ... CPU_X_RUNTIME + +Combined with the info from:: + + cat /sys/devices/system/node/nodeX/cpulist
Documentation/admin-guide/cg-numa-stat.rst line 91
Quoted 10 lines
Documentation/admin-guide/cg-numa-stat.rst new file +10
-0+ +We would be able to accumulate the runtime of CPUs into NUMA nodes, to get the +per-cgroup node runtime info. + +By reading 'memory.numa_stat' we will get per-cgroup node memory consumption +info as:: + + total=TOTAL_MEM N0=MEM_ON_NODE0 N1=MEM_ON_NODE1 ... NX=MEM_ON_NODEX + +Together we call these the per-cgroup NUMA consumption info, tell us how many
telling us
Quoted 8 lines
Documentation/admin-guide/cg-numa-stat.rst new file +8
-0+resources a particular workload has consumed, on a particular NUMA node. + +Monitoring +---------- + +By monitoring the increments of locality info, we can easily know whether NUMA +Balancing is working well for a particular workload. +
Documentation/admin-guide/cg-numa-stat.rst line 109
Quoted 10 lines
Documentation/admin-guide/cg-numa-stat.rst new file +10
-0+For example we take a 5 seconds sample period, then on each sampling we have:: + + local_diff = last_nr_local_page_access - nr_local_page_access + remote_diff = last_nr_remote_page_access - nr_remote_page_access + +and we get the locality in this period as:: + + locality = local_diff * 100 / (local_diff + remote_diff) + +We can plot a line for locality, when the line close to 100% things are good,
locality. When the line is close to 100%, things are good;
Documentation/admin-guide/cg-numa-stat.rst line 110
Quoted 1 line
Documentation/admin-guide/cg-numa-stat.rst new file +1
-0+when getting close to 0% something is wrong, we can pick a proper watermark to
wrong. We can pick
Quoted 19 lines
Documentation/admin-guide/cg-numa-stat.rst new file +19
-0+trigger warning message. + +You may want to drop the data if the local/remote_diff is too small, which +implies there are not many available pages for NUMA Balancing to scan, ignoring +would be fine since most likely the workload is insensitive to NUMA, or the +memory topology is already good enough. + +Monitoring root group helps you control the overall situation, while you may +also want to monitor all the leaf groups which contain the workloads, this +helps to catch the mouse. + +Try to put your workload into also the cpuacct & memory cgroup, when NUMA +Balancing is disabled or locality becomes too small, we may want to monitor +the per-node runtime & memory info to see if the node consumption meet the +requirements. + +For NUMA node X on each sampling we have:: + + runtime_X_diff = runtime_X - last_runtime_X
Documentation/admin-guide/cg-numa-stat.rst line 139
Quoted 10 lines
Documentation/admin-guide/cg-numa-stat.rst new file +10
-0+ runtime_all_diff = runtime_all - last_runtime_all + + runtime_percent_X = runtime_X_diff * 100 / runtime_all_diff + memory_percent_X = memory_X * 100 / memory_all + +These two percentages are usually matched on each node, workload should execute +mostly on the node that contains most of its memory, but it's not guaranteed. + +The workload may only access a small part of its memory, in such cases although +the majority of memory are remotely, locality could still be good.
are remote,
Quoted 8 lines
Documentation/admin-guide/cg-numa-stat.rst new file +8
-0+ +Thus to tell if things are fine or not depends on the understanding of system +resource deployment, however, if you find node X got 100% memory percent but 0% +runtime percent, definitely something is wrong. + +Troubleshooting +--------------- +
Documentation/admin-guide/cg-numa-stat.rst line 157
Quoted 10 lines
Documentation/admin-guide/cg-numa-stat.rst new file +10
-0+After identifying which workload introduced the bad locality, check: + +1). Is the workload bound to a particular NUMA node? +2). Has any NUMA node run out of resources? + +There are several ways to bind task's memory with a NUMA node, the strict way +like the MPOL_BIND memory policy or 'cpuset.mems' will limit the memory +node where to allocate pages. In this situation, admin should make sure the +task is allowed to run on the CPUs of that NUMA node, and make sure there are +available CPU resource there.
resources
Documentation/admin-guide/cg-numa-stat.rst line 160
Quoted 3 lines
Documentation/admin-guide/cg-numa-stat.rst new file +3
-0+ +There are also ways to bind task's CPU with a NUMA node, like 'cpuset.cpus' or +sched_setaffinity() syscall. In this situation, NUMA Balancing help to migrate
helps
Documentation/admin-guide/cg-numa-stat.rst line 161
Quoted 1 line
Documentation/admin-guide/cg-numa-stat.rst new file +1
-0+pages into that node, admin should make sure there are available memory there.
is
Quoted 6 lines
Documentation/admin-guide/cg-numa-stat.rst new file +6
-0+ +Admin could try to rebind or unbind the NUMA node to erase the damage, make a +change then observe the statistics to see if things get better until the +situation is acceptable. + +Highlights
Documentation/admin-guide/cg-numa-stat.rst line 177
Quoted 10 lines
Documentation/admin-guide/cg-numa-stat.rst new file +10
-0+---------- + +For some tasks, NUMA Balancing may be found to be unnecessary to scan pages, +and locality could always be 0 or small number, don't pay attention to them +since they most likely insensitive to NUMA. + +There is no accounting until the option is turned on, so enable it in advance +if you want to have the whole history. + +We have per-task migfailed counter to tell how many page migration has been
migrations have {drop: been}Documentation/admin-guide/cg-numa-stat.rst line 178
Quoted 1 line
Documentation/admin-guide/cg-numa-stat.rst new file +1
-0+failed for a particular task, you will find it in /proc/PID/sched entry.
task; you
HTH.
Signature · 1 line
~Randy
Re: [PATCH v7 2/2] sched/numa: documentation for per-cgroup numa, statistics
Quoted 4 lines · Randy Dunlap
Hi,
Documentation edits below...
Thx Randy :-) I've send v8 which should have included all the edits below.
Regards,
Michael Wang
Quoted 246 lines · 王贇
Quoted 50 lines
Add the description for '
numa_locality', also a new doc to explain the details on how to deal with the per-cgroup numa statistics.Cc Peter Zijlstra <[email protected]>Cc Michal Koutný <[email protected]>Cc Mel Gorman <[email protected]>Cc Jonathan Corbet <[email protected]>Cc Iurii Zaikin <[email protected]>Cc Randy Dunlap <[email protected]>Signed-off-by Michael Wang <[email protected]>--- Documentation/admin-guide/cg-numa-stat.rst | 178 ++++++++++++++++++++++++ Documentation/admin-guide/index.rst | 1 + Documentation/admin-guide/kernel-parameters.txt | 4 + Documentation/admin-guide/sysctl/kernel.rst | 9 ++ init/Kconfig | 2 + 5 files changed, 194 insertions(+) create mode 100644 Documentation/admin-guide/cg-numa-stat.rstDocumentation/admin-guide/cg-numa-stat.rst new file +25
-0@@ -0,0 +1,178 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=============================== +Per-cgroup NUMA statistics +=============================== + +Background +---------- + +On NUMA platforms, remote memory accessing always has a performance penalty. +Although we have NUMA balancing working hard to maximize the access locality, +there are still situations it can't help. + +This could happen in modern production environment. When a large number of +cgroups are used to classify and control resources, this creates a complex +configuration for memory policy, CPUs and NUMA nodes. In such cases NUMA +balancing could end up with the wrong memory policy or exhausted local NUMA +node, which would lead to low percentage of local page accesses. + +We need to detect such cases, figure out which workloads from which cgroup +have introduced the issues, then we get chance to do adjustment to avoid +performance degradation. + +However, there are no hardware counters for per-task local/remote accessing +info, we don't know how many remote page accesses have occurred for aDocumentation/admin-guide/cg-numa-stat.rst line 35
Quoted 10 lines
Documentation/admin-guide/cg-numa-stat.rst new file +10
-0+particular task. + +NUMA Locality +------------- + +Fortunately, we have NUMA Balancing which scans task's mapping and triggers +page fault periodically, giving us the opportunity to record per-task page +accessing info, when the CPU fall into PF is from the same node of pages, we +consider task as doing local page accessing, otherwise the remote page +accessing, we call these two counter the locality info.counters
Quoted 8 lines
Documentation/admin-guide/cg-numa-stat.rst new file +8
-0+ +On each tick, we acquire the locality info of current task on that CPU, update +the increments into its cgroup, becoming the group locality info. + +By "echo 1 > /proc/sys/kernel/numa_locality" at runtime or adding boot parameter +'numa_locality', we will enable the accounting of per-cgroup NUMA locality info, +the 'cpu.numa_stat' entry of CPU cgroup will show statistics:: +Documentation/admin-guide/cg-numa-stat.rst line 53
Quoted 10 lines
Documentation/admin-guide/cg-numa-stat.rst new file +10
-0+ page_access local=NR_LOCAL_PAGE_ACCESS remote=NR_REMOTE_PAGE_ACCESS + +We define 'NUMA locality' as:: + + NR_LOCAL_PAGE_ACCESS * 100 / (NR_LOCAL_PAGE_ACCESS + NR_REMOTE_PAGE_ACCESS) + +This per-cgroup percentage number helps to represent the NUMA Balancing behavior. + +Note that the accounting is hierarchical, which means the NUMA locality info for +a given group represent not only the workload of this group, but also therepresents
Documentation/admin-guide/cg-numa-stat.rst line 66
Quoted 13 lines
Documentation/admin-guide/cg-numa-stat.rst new file +13
-0+workloads of all its descendants. + +For example the 'cpu.numa_stat' shows:: + + page_access local=129909383 remote=18265810 + +The NUMA locality calculated as:: + + 129909383 * 100 / (129909383 + 18265810) = 87.67 + +Thus we know the workload of this group and its descendants have totally done +129909383 times of local page accessing and 18265810 times of remotes, locality +is 87.67% which imply most of the memory access are local.implies
Documentation/admin-guide/cg-numa-stat.rst line 71
Quoted 5 lines
Documentation/admin-guide/cg-numa-stat.rst new file +5
-0+ +NUMA Consumption +---------------- + +There are also other cgroup entry help us to estimate NUMA efficiency, which isentries which help us to estimate NUMA efficiency. They are
Quoted 10 lines
Documentation/admin-guide/cg-numa-stat.rst new file +10
-0+'cpuacct.usage_percpu' and 'memory.numa_stat'. + +By reading 'cpuacct.usage_percpu' we will get per-cpu runtime (in nanoseconds) +info (in hierarchy) as:: + + CPU_0_RUNTIME CPU_1_RUNTIME CPU_2_RUNTIME ... CPU_X_RUNTIME + +Combined with the info from:: + + cat /sys/devices/system/node/nodeX/cpulistDocumentation/admin-guide/cg-numa-stat.rst line 91
Quoted 10 lines
Documentation/admin-guide/cg-numa-stat.rst new file +10
-0+ +We would be able to accumulate the runtime of CPUs into NUMA nodes, to get the +per-cgroup node runtime info. + +By reading 'memory.numa_stat' we will get per-cgroup node memory consumption +info as:: + + total=TOTAL_MEM N0=MEM_ON_NODE0 N1=MEM_ON_NODE1 ... NX=MEM_ON_NODEX + +Together we call these the per-cgroup NUMA consumption info, tell us how manytelling us
Quoted 8 lines
Documentation/admin-guide/cg-numa-stat.rst new file +8
-0+resources a particular workload has consumed, on a particular NUMA node. + +Monitoring +---------- + +By monitoring the increments of locality info, we can easily know whether NUMA +Balancing is working well for a particular workload. +Documentation/admin-guide/cg-numa-stat.rst line 109
Quoted 10 lines
Documentation/admin-guide/cg-numa-stat.rst new file +10
-0+For example we take a 5 seconds sample period, then on each sampling we have:: + + local_diff = last_nr_local_page_access - nr_local_page_access + remote_diff = last_nr_remote_page_access - nr_remote_page_access + +and we get the locality in this period as:: + + locality = local_diff * 100 / (local_diff + remote_diff) + +We can plot a line for locality, when the line close to 100% things are good,locality. When the line is close to 100%, things are good;Documentation/admin-guide/cg-numa-stat.rst line 110
Quoted 1 line
Documentation/admin-guide/cg-numa-stat.rst new file +1
-0+when getting close to 0% something is wrong, we can pick a proper watermark towrong. We can pick
Quoted 19 lines
Documentation/admin-guide/cg-numa-stat.rst new file +19
-0+trigger warning message. + +You may want to drop the data if the local/remote_diff is too small, which +implies there are not many available pages for NUMA Balancing to scan, ignoring +would be fine since most likely the workload is insensitive to NUMA, or the +memory topology is already good enough. + +Monitoring root group helps you control the overall situation, while you may +also want to monitor all the leaf groups which contain the workloads, this +helps to catch the mouse. + +Try to put your workload into also the cpuacct & memory cgroup, when NUMA +Balancing is disabled or locality becomes too small, we may want to monitor +the per-node runtime & memory info to see if the node consumption meet the +requirements. + +For NUMA node X on each sampling we have:: + + runtime_X_diff = runtime_X - last_runtime_XDocumentation/admin-guide/cg-numa-stat.rst line 139
Quoted 10 lines
Documentation/admin-guide/cg-numa-stat.rst new file +10
-0+ runtime_all_diff = runtime_all - last_runtime_all + + runtime_percent_X = runtime_X_diff * 100 / runtime_all_diff + memory_percent_X = memory_X * 100 / memory_all + +These two percentages are usually matched on each node, workload should execute +mostly on the node that contains most of its memory, but it's not guaranteed. + +The workload may only access a small part of its memory, in such cases although +the majority of memory are remotely, locality could still be good.are remote,
Quoted 8 lines
Documentation/admin-guide/cg-numa-stat.rst new file +8
-0+ +Thus to tell if things are fine or not depends on the understanding of system +resource deployment, however, if you find node X got 100% memory percent but 0% +runtime percent, definitely something is wrong. + +Troubleshooting +--------------- +Documentation/admin-guide/cg-numa-stat.rst line 157
Quoted 10 lines
Documentation/admin-guide/cg-numa-stat.rst new file +10
-0+After identifying which workload introduced the bad locality, check: + +1). Is the workload bound to a particular NUMA node? +2). Has any NUMA node run out of resources? + +There are several ways to bind task's memory with a NUMA node, the strict way +like the MPOL_BIND memory policy or 'cpuset.mems' will limit the memory +node where to allocate pages. In this situation, admin should make sure the +task is allowed to run on the CPUs of that NUMA node, and make sure there are +available CPU resource there.resources
Documentation/admin-guide/cg-numa-stat.rst line 160
Quoted 3 lines
Documentation/admin-guide/cg-numa-stat.rst new file +3
-0+ +There are also ways to bind task's CPU with a NUMA node, like 'cpuset.cpus' or +sched_setaffinity() syscall. In this situation, NUMA Balancing help to migratehelps
Documentation/admin-guide/cg-numa-stat.rst line 161
Quoted 1 line
Documentation/admin-guide/cg-numa-stat.rst new file +1
-0+pages into that node, admin should make sure there are available memory there.is
Quoted 6 lines
Documentation/admin-guide/cg-numa-stat.rst new file +6
-0+ +Admin could try to rebind or unbind the NUMA node to erase the damage, make a +change then observe the statistics to see if things get better until the +situation is acceptable. + +HighlightsDocumentation/admin-guide/cg-numa-stat.rst line 177
Quoted 10 lines
Documentation/admin-guide/cg-numa-stat.rst new file +10
-0+---------- + +For some tasks, NUMA Balancing may be found to be unnecessary to scan pages, +and locality could always be 0 or small number, don't pay attention to them +since they most likely insensitive to NUMA. + +There is no accounting until the option is turned on, so enable it in advance +if you want to have the whole history. + +We have per-task migfailed counter to tell how many page migration has beenmigrations have {drop: been}Documentation/admin-guide/cg-numa-stat.rst line 178
Quoted 1 line
Documentation/admin-guide/cg-numa-stat.rst new file +1
-0+failed for a particular task, you will find it in /proc/PID/sched entry.task; you
HTH.
v8 cover sched/numa: introduce numa locality
In reply to 王贇v8:
* document edited
v7:
* rebased on latest linux-next
v6:
* fix compile failure when NUMA disabled
v5:
* improved documentation
v4:
* fix comments and improved documentation
v3:
* simplified the locality concept & implementation
v2:
* improved documentation
Modern production environment could use hundreds of cgroup to control the resources for different workloads, along with the complicated resource binding.
On NUMA platforms where we have multiple nodes, things become even more complicated, we hope there are more local memory access to improve the performance, and NUMA Balancing keep working hard to achieve that, however, wrong memory policy or node binding could easily waste the effort, result a lot of remote page accessing.
We need to notice such problems, then we got chance to fix it before there are too much damages, however, there are no good monitoring approach yet to help catch the mouse who introduced the remote access.
This patch set is trying to fill in the missing pieces, by introduce the per-cgroup NUMA locality info, with this new statistics, we could achieve the daily monitoring on NUMA efficiency, to give warning when things going too wrong.
Please check the second patch for more details.
Michael Wang (2):
sched/numa: introduce per-cgroup NUMA locality info sched/numa: documentation for per-cgroup numa statistics
Documentation/admin-guide/cg-numa-stat.rst | 178 ++++++++++++++++++++++++ Documentation/admin-guide/index.rst | 1 + Documentation/admin-guide/kernel-parameters.txt | 4 + Documentation/admin-guide/sysctl/kernel.rst | 9 ++ include/linux/sched.h | 15 ++ include/linux/sched/sysctl.h | 6 + init/Kconfig | 11 ++ kernel/sched/core.c | 75 ++++++++++ kernel/sched/fair.c | 62 +++++++++ kernel/sched/sched.h | 12 ++ kernel/sysctl.c | 11 ++ 11 files changed, 384 insertions(+) create mode 100644 Documentation/admin-guide/cg-numa-stat.rst
Signature · 1 line
2.14.4.44.g2045bb6
PATCH v8 1/2 sched/numa: introduce per-cgroup NUMA locality info
Currently there are no good approach to monitoring the per-cgroup NUMA efficiency, this could be a trouble especially when groups are sharing CPUs, we don't know which one introduced remote-memory accessing.
Although the per-task NUMA accessing info from PMU is good for further debuging, but not light enough for daily monitoring, especial on a box with thousands of tasks.
Fortunately, when NUMA Balancing enabled, it will periodly trigger page fault and try to increase the NUMA locality, by tracing the results we will be able to estimate the NUMA efficiency.
On each page fault of NUMA Balancing, when task's executing CPU is from the same node of pages, we call this a local page accessing, otherwise a remote page accessing.
By updating task's accessing counter into it's cgroup on ticks, we get the per-cgroup numa locality info.
For example the new entry 'cpu.numa_stat' show:
page_access local=1231412 remote=53453
Here we know the workloads in hierarchy have totally been traced 1284865 times of page accessing, and 1231412 of them are local page access, which imply a good NUMA efficiency.
By monitoring the increments, we will be able to locate the per-cgroup workload which NUMA Balancing can't helpwith (usually caused by wrong CPU and memory node bindings), then we got chance to fix that in time.
--- include/linux/sched.h | 15 +++++++++ include/linux/sched/sysctl.h | 6 ++++ init/Kconfig | 9 ++++++ kernel/sched/core.c | 75 ++++++++++++++++++++++++++++++++++++++++++++ kernel/sched/fair.c | 62 ++++++++++++++++++++++++++++++++++++ kernel/sched/sched.h | 12 +++++++ kernel/sysctl.c | 11 +++++++ 7 files changed, 190 insertions(+)
include/linux/sched.h +15 -0
@@ -1128,6 +1128,21 @@ struct task_struct {unsigned long numa_pages_migrated;#endif /* CONFIG_NUMA_BALANCING */ +#ifdef CONFIG_CGROUP_NUMA_LOCALITY +/* +* Counter index stand for: +* 0 -- remote page accessing +* 1 -- local page accessing +* 2 -- remote page accessing updated to cgroup +* 3 -- local page accessing updated to cgroup +* +* We record the counter before the end of task_numa_fault(), this +* is based on the fact that after page fault is handled, the task +* will access the page on the CPU where it triggered the PF. +*/ +unsigned long numa_page_access[4 ]; +#endif +#ifdef CONFIG_RSEQ struct rseq __user *rseq;u32 rseq_sig;
include/linux/sched/sysctl.h +6 -0
@@ -101,4 +101,10 @@ extern int sched_energy_aware_handler(struct ctl_table *table, int write, loff_t *ppos);#endif +#ifdef CONFIG_CGROUP_NUMA_LOCALITY +extern int sysctl_numa_locality (struct ctl_table *table,int write, +void __user *buffer,size_t *lenp, +loff_t *ppos); +#endif +#endif /* _LINUX_SCHED_SYSCTL_H */
init/Kconfig +9 -0
@@ -813,6 +813,15 @@ config NUMA_BALANCING_DEFAULT_ENABLED If set, automatic NUMA balancing will be enabled if running on a NUMA machine. +config CGROUP_NUMA_LOCALITY + bool "per-cgroup NUMA Locality" + default n + depends on CGROUP_SCHED && NUMA_BALANCING + help + This option enables the collection of per-cgroup NUMA locality info, + to tell whether NUMA Balancing is working well for a particular + workload, also imply the NUMA efficiency. + menuconfig CGROUPS bool "Control Group support" select KERNFS
kernel/sched/core.c +75 -0
93 lines not on this page · raw message
kernel/sched/fair.c +62 -0
87 lines not on this page · raw message
kernel/sched/sched.h +12 -0
@@ -575,6 +575,14 @@ struct cfs_rq {struct list_head throttled_list;#endif /* CONFIG_CFS_BANDWIDTH */ #endif /* CONFIG_FAIR_GROUP_SCHED */ +#ifdef CONFIG_CGROUP_NUMA_LOCALITY +/* +* The local/remote page access info collected from all +* the tasks in hierarchy. +*/ +u64 local_page_access; +u64 remote_page_access; +#endif };static inline int rt_bandwidth_enabled (void )
@@ -1601,6 +1609,10 @@ static const_debug __maybe_unused unsigned int sysctl_sched_features =extern struct static_key_false sched_numa_balancing;extern struct static_key_false sched_schedstats; +#ifdef CONFIG_CGROUP_NUMA_LOCALITY +extern struct static_key_false sched_numa_locality; +#endif +static inline u64 global_rt_period (void ) {return (u64 )sysctl_sched_rt_period *NSEC_PER_USEC ;
kernel/sysctl.c +11 -0
@@ -428,6 +428,17 @@ static struct ctl_table kern_table[] = { .extra2 = SYSCTL_ONE, }, #endif /* CONFIG_NUMA_BALANCING */ +#ifdef CONFIG_CGROUP_NUMA_LOCALITY + { + .procname = "numa_locality", + .data = NULL, /* filled in by handler */ + .maxlen = sizeof(unsigned int), + .mode = 0644, + .proc_handler = sysctl_numa_locality, + .extra1 = SYSCTL_ZERO, + .extra2 = SYSCTL_ONE, + }, +#endif /* CONFIG_CGROUP_NUMA_LOCALITY */ #endif /* CONFIG_SCHED_DEBUG */ { .procname = "sched_rt_period_us",
Signature · 1 line
2.14.4.44.g2045bb6
PATCH v8 2/2 sched/numa: documentation for per-cgroup numa, statistics
In reply to 王贇Add the description for 'numa_locality', also a new doc to explain the details on how to deal with the per-cgroup numa statistics.
--- Documentation/admin-guide/cg-numa-stat.rst | 178 ++++++++++++++++++++++++ Documentation/admin-guide/index.rst | 1 + Documentation/admin-guide/kernel-parameters.txt | 4 + Documentation/admin-guide/sysctl/kernel.rst | 9 ++ init/Kconfig | 2 + 5 files changed, 194 insertions(+) create mode 100644 Documentation/admin-guide/cg-numa-stat.rst
Documentation/admin-guide/cg-numa-stat.rst new file +178 -0
@@ -0,0 +1,178 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=============================== +Per-cgroup NUMA statistics +=============================== + +Background +---------- + +On NUMA platforms, remote memory accessing always has a performance penalty. +Although we have NUMA balancing working hard to maximize the access locality, +there are still situations it can't help. + +This could happen in modern production environment. When a large number of +cgroups are used to classify and control resources, this creates a complex +configuration for memory policy, CPUs and NUMA nodes. In such cases NUMA +balancing could end up with the wrong memory policy or exhausted local NUMA +node, which would lead to low percentage of local page accesses. + +We need to detect such cases, figure out which workloads from which cgroup +have introduced the issues, then we get chance to do adjustment to avoid +performance degradation. + +However, there are no hardware counters for per-task local/remote accessing +info, we don't know how many remote page accesses have occurred for a +particular task. + +NUMA Locality +------------- + +Fortunately, we have NUMA Balancing which scans task's mapping and triggers +page fault periodically, giving us the opportunity to record per-task page +accessing info, when the CPU fall into PF is from the same node of pages, we +consider task as doing local page accessing, otherwise the remote page +accessing, we call these two counters the locality info. + +On each tick, we acquire the locality info of current task on that CPU, update +the increments into its cgroup, becoming the group locality info. + +By "echo 1 > /proc/sys/kernel/numa_locality" at runtime or adding boot parameter +'numa_locality', we will enable the accounting of per-cgroup NUMA locality info, +the 'cpu.numa_stat' entry of CPU cgroup will show statistics:: + + page_access local=NR_LOCAL_PAGE_ACCESS remote=NR_REMOTE_PAGE_ACCESS + +We define 'NUMA locality' as:: + + NR_LOCAL_PAGE_ACCESS * 100 / (NR_LOCAL_PAGE_ACCESS + NR_REMOTE_PAGE_ACCESS) + +This per-cgroup percentage number helps to represent the NUMA Balancing behavior. + +Note that the accounting is hierarchical, which means the NUMA locality info for +a given group represents not only the workload of this group, but also the +workloads of all its descendants. + +For example the 'cpu.numa_stat' shows:: + + page_access local=129909383 remote=18265810 + +The NUMA locality calculated as:: + + 129909383 * 100 / (129909383 + 18265810) = 87.67 + +Thus we know the workload of this group and its descendants have totally done +129909383 times of local page accessing and 18265810 times of remotes, locality +is 87.67% which implies most of the memory access are local. + +NUMA Consumption +---------------- + +There are also other cgroup entries which help us to estimate NUMA efficiency. +They are 'cpuacct.usage_percpu' and 'memory.numa_stat'. + +By reading 'cpuacct.usage_percpu' we will get per-cpu runtime (in nanoseconds) +info (in hierarchy) as:: + + CPU_0_RUNTIME CPU_1_RUNTIME CPU_2_RUNTIME ... CPU_X_RUNTIME + +Combined with the info from:: + + cat /sys/devices/system/node/nodeX/cpulist + +We would be able to accumulate the runtime of CPUs into NUMA nodes, to get the +per-cgroup node runtime info. + +By reading 'memory.numa_stat' we will get per-cgroup node memory consumption +info as:: + + total=TOTAL_MEM N0=MEM_ON_NODE0 N1=MEM_ON_NODE1 ... NX=MEM_ON_NODEX + +Together we call these the per-cgroup NUMA consumption info, telling us how many +resources a particular workload has consumed, on a particular NUMA node. + +Monitoring +---------- + +By monitoring the increments of locality info, we can easily know whether NUMA +Balancing is working well for a particular workload. + +For example we take a 5 seconds sample period, then on each sampling we have:: + + local_diff = last_nr_local_page_access - nr_local_page_access + remote_diff = last_nr_remote_page_access - nr_remote_page_access + +and we get the locality in this period as:: + + locality = local_diff * 100 / (local_diff + remote_diff) + +We can plot a line for locality. When the line is close to 100%, things are +good; when getting close to 0% something is wrong. We can pick a proper +watermark to trigger warning message. + +You may want to drop the data if the local/remote_diff is too small, which +implies there are not many available pages for NUMA Balancing to scan, ignoring +would be fine since most likely the workload is insensitive to NUMA, or the +memory topology is already good enough. + +Monitoring root group helps you control the overall situation, while you may +also want to monitor all the leaf groups which contain the workloads, this +helps to catch the mouse. + +Try to put your workload into also the cpuacct & memory cgroup, when NUMA +Balancing is disabled or locality becomes too small, we may want to monitor +the per-node runtime & memory info to see if the node consumption meet the +requirements. + +For NUMA node X on each sampling we have:: + + runtime_X_diff = runtime_X - last_runtime_X + runtime_all_diff = runtime_all - last_runtime_all + + runtime_percent_X = runtime_X_diff * 100 / runtime_all_diff + memory_percent_X = memory_X * 100 / memory_all + +These two percentages are usually matched on each node, workload should execute +mostly on the node that contains most of its memory, but it's not guaranteed. + +The workload may only access a small part of its memory, in such cases although +the majority of memory are remote, locality could still be good. + +Thus to tell if things are fine or not depends on the understanding of system +resource deployment, however, if you find node X got 100% memory percent but 0% +runtime percent, definitely something is wrong. + +Troubleshooting +--------------- + +After identifying which workload introduced the bad locality, check: + +1). Is the workload bound to a particular NUMA node? +2). Has any NUMA node run out of resources? + +There are several ways to bind task's memory with a NUMA node, the strict way +like the MPOL_BIND memory policy or 'cpuset.mems' will limit the memory +node where to allocate pages. In this situation, admin should make sure the +task is allowed to run on the CPUs of that NUMA node, and make sure there are +available CPU resources there. + +There are also ways to bind task's CPU with a NUMA node, like 'cpuset.cpus' or +sched_setaffinity() syscall. In this situation, NUMA Balancing helps to migrate +pages into that node, admin should make sure there is available memory there. + +Admin could try to rebind or unbind the NUMA node to erase the damage, make a +change then observe the statistics to see if things get better until the +situation is acceptable. + +Highlights +---------- + +For some tasks, NUMA Balancing may be found to be unnecessary to scan pages, +and locality could always be 0 or small number, don't pay attention to them +since they most likely insensitive to NUMA. + +There is no accounting until the option is turned on, so enable it in advance +if you want to have the whole history. + +We have per-task migfailed counter to tell how many page migrations have +failed for a particular task; you will find it in /proc/PID/sched entry.
Documentation/admin-guide/index.rst +1 -0
@@ -114,6 +114,7 @@ configure specific aspects of kernel behavior to your liking. video-output wimax/index xfs + cg-numa-stat .. only:: subproject and html
Documentation/admin-guide/kernel-parameters.txt +4 -0
@@ -3249,6 +3249,10 @@ numa_balancing= [KNL,X86] Enable or disable automatic NUMA balancing. Allowed values are enable and disable + numa_locality [KNL] Enable per-cgroup numa locality info. + Useful to debug NUMA efficiency problems when there are + lots of per-cgroup workloads. + numa_zonelist_order= [KNL, BOOT] Select zonelist order for NUMA. 'node', 'default' can be specified This can be set from sysctl after boot.
Documentation/admin-guide/sysctl/kernel.rst +9 -0
@@ -556,6 +556,15 @@ rate for each task. numa_balancing_scan_size_mb is how many megabytes worth of pages are scanned for a given scan. +numa_locality: +============= + +Enables/disables per-cgroup NUMA locality info. + +0: disabled (default). +1: enabled. + +Check Documentation/admin-guide/cg-numa-stat.rst for details. osrelease, ostype & version: ============================
init/Kconfig +2 -0
@@ -821,6 +821,8 @@ config CGROUP_NUMA_LOCALITY This option enables the collection of per-cgroup NUMA locality info, to tell whether NUMA Balancing is working well for a particular workload, also imply the NUMA efficiency. + See + - Documentation/admin-guide/cg-numa-stat.rst menuconfig CGROUPS bool "Control Group support"
Signature · 1 line
2.14.4.44.g2045bb6
Re: [PATCH v8 2/2] sched/numa: documentation for per-cgroup numa, statistics
Quoted 10 lines · 王贇
Add the description for '
numa_locality', also a new doc to explain the details on how to deal with the per-cgroup numa statistics.Cc Peter Zijlstra <[email protected]>Cc Michal Koutný <[email protected]>Cc Mel Gorman <[email protected]>Cc Jonathan Corbet <[email protected]>Cc Iurii Zaikin <[email protected]>Cc Randy Dunlap <[email protected]>Signed-off-by Michael Wang <[email protected]>
Thanks for the updates.
Quoted 193 lines
--- Documentation/admin-guide/cg-numa-stat.rst | 178 ++++++++++++++++++++++++ Documentation/admin-guide/index.rst | 1 + Documentation/admin-guide/kernel-parameters.txt | 4 + Documentation/admin-guide/sysctl/kernel.rst | 9 ++ init/Kconfig | 2 + 5 files changed, 194 insertions(+) create mode 100644 Documentation/admin-guide/cg-numa-stat.rstDocumentation/admin-guide/cg-numa-stat.rst new file +178
-0@@ -0,0 +1,178 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=============================== +Per-cgroup NUMA statistics +=============================== + +Background +---------- + +On NUMA platforms, remote memory accessing always has a performance penalty. +Although we have NUMA balancing working hard to maximize the access locality, +there are still situations it can't help. + +This could happen in modern production environment. When a large number of +cgroups are used to classify and control resources, this creates a complex +configuration for memory policy, CPUs and NUMA nodes. In such cases NUMA +balancing could end up with the wrong memory policy or exhausted local NUMA +node, which would lead to low percentage of local page accesses. + +We need to detect such cases, figure out which workloads from which cgroup +have introduced the issues, then we get chance to do adjustment to avoid +performance degradation. + +However, there are no hardware counters for per-task local/remote accessing +info, we don't know how many remote page accesses have occurred for a +particular task. + +NUMA Locality +------------- + +Fortunately, we have NUMA Balancing which scans task's mapping and triggers +page fault periodically, giving us the opportunity to record per-task page +accessing info, when the CPU fall into PF is from the same node of pages, we +consider task as doing local page accessing, otherwise the remote page +accessing, we call these two counters the locality info. + +On each tick, we acquire the locality info of current task on that CPU, update +the increments into its cgroup, becoming the group locality info. + +By "echo 1 > /proc/sys/kernel/numa_locality" at runtime or adding boot parameter +'numa_locality', we will enable the accounting of per-cgroup NUMA locality info, +the 'cpu.numa_stat' entry of CPU cgroup will show statistics:: + + page_access local=NR_LOCAL_PAGE_ACCESS remote=NR_REMOTE_PAGE_ACCESS + +We define 'NUMA locality' as:: + + NR_LOCAL_PAGE_ACCESS * 100 / (NR_LOCAL_PAGE_ACCESS + NR_REMOTE_PAGE_ACCESS) + +This per-cgroup percentage number helps to represent the NUMA Balancing behavior. + +Note that the accounting is hierarchical, which means the NUMA locality info for +a given group represents not only the workload of this group, but also the +workloads of all its descendants. + +For example the 'cpu.numa_stat' shows:: + + page_access local=129909383 remote=18265810 + +The NUMA locality calculated as:: + + 129909383 * 100 / (129909383 + 18265810) = 87.67 + +Thus we know the workload of this group and its descendants have totally done +129909383 times of local page accessing and 18265810 times of remotes, locality +is 87.67% which implies most of the memory access are local. + +NUMA Consumption +---------------- + +There are also other cgroup entries which help us to estimate NUMA efficiency. +They are 'cpuacct.usage_percpu' and 'memory.numa_stat'. + +By reading 'cpuacct.usage_percpu' we will get per-cpu runtime (in nanoseconds) +info (in hierarchy) as:: + + CPU_0_RUNTIME CPU_1_RUNTIME CPU_2_RUNTIME ... CPU_X_RUNTIME + +Combined with the info from:: + + cat /sys/devices/system/node/nodeX/cpulist + +We would be able to accumulate the runtime of CPUs into NUMA nodes, to get the +per-cgroup node runtime info. + +By reading 'memory.numa_stat' we will get per-cgroup node memory consumption +info as:: + + total=TOTAL_MEM N0=MEM_ON_NODE0 N1=MEM_ON_NODE1 ... NX=MEM_ON_NODEX + +Together we call these the per-cgroup NUMA consumption info, telling us how many +resources a particular workload has consumed, on a particular NUMA node. + +Monitoring +---------- + +By monitoring the increments of locality info, we can easily know whether NUMA +Balancing is working well for a particular workload. + +For example we take a 5 seconds sample period, then on each sampling we have:: + + local_diff = last_nr_local_page_access - nr_local_page_access + remote_diff = last_nr_remote_page_access - nr_remote_page_access + +and we get the locality in this period as:: + + locality = local_diff * 100 / (local_diff + remote_diff) + +We can plot a line for locality. When the line is close to 100%, things are +good; when getting close to 0% something is wrong. We can pick a proper +watermark to trigger warning message. + +You may want to drop the data if the local/remote_diff is too small, which +implies there are not many available pages for NUMA Balancing to scan, ignoring +would be fine since most likely the workload is insensitive to NUMA, or the +memory topology is already good enough. + +Monitoring root group helps you control the overall situation, while you may +also want to monitor all the leaf groups which contain the workloads, this +helps to catch the mouse. + +Try to put your workload into also the cpuacct & memory cgroup, when NUMA +Balancing is disabled or locality becomes too small, we may want to monitor +the per-node runtime & memory info to see if the node consumption meet the +requirements. + +For NUMA node X on each sampling we have:: + + runtime_X_diff = runtime_X - last_runtime_X + runtime_all_diff = runtime_all - last_runtime_all + + runtime_percent_X = runtime_X_diff * 100 / runtime_all_diff + memory_percent_X = memory_X * 100 / memory_all + +These two percentages are usually matched on each node, workload should execute +mostly on the node that contains most of its memory, but it's not guaranteed. + +The workload may only access a small part of its memory, in such cases although +the majority of memory are remote, locality could still be good. + +Thus to tell if things are fine or not depends on the understanding of system +resource deployment, however, if you find node X got 100% memory percent but 0% +runtime percent, definitely something is wrong. + +Troubleshooting +--------------- + +After identifying which workload introduced the bad locality, check: + +1). Is the workload bound to a particular NUMA node? +2). Has any NUMA node run out of resources? + +There are several ways to bind task's memory with a NUMA node, the strict way +like the MPOL_BIND memory policy or 'cpuset.mems' will limit the memory +node where to allocate pages. In this situation, admin should make sure the +task is allowed to run on the CPUs of that NUMA node, and make sure there are +available CPU resources there. + +There are also ways to bind task's CPU with a NUMA node, like 'cpuset.cpus' or +sched_setaffinity() syscall. In this situation, NUMA Balancing helps to migrate +pages into that node, admin should make sure there is available memory there. + +Admin could try to rebind or unbind the NUMA node to erase the damage, make a +change then observe the statistics to see if things get better until the +situation is acceptable. + +Highlights +---------- + +For some tasks, NUMA Balancing may be found to be unnecessary to scan pages, +and locality could always be 0 or small number, don't pay attention to them +since they most likely insensitive to NUMA. + +There is no accounting until the option is turned on, so enable it in advance +if you want to have the whole history. + +We have per-task migfailed counter to tell how many page migrations have +failed for a particular task; you will find it in /proc/PID/sched entry.
Re: [PATCH v8 0/2] sched/numa: introduce numa locality
In reply to 王贇Hi, Peter, Ingo
Could you give some comments please?
As Mel replied previously, he won't disagree the idea, so we're looking forward the opinion from the maintainers.
Please allow me to highlight the necessary of monitoring NUMA Balancing again, this feature is critical to the performance on NUMA platform, it cost and benefit -- lot or less, however there are not enough information for an admin to analysis the trade-off, while locality could be the missing piece.
Regards,
Michael Wang
Quoted 54 lines · 王贇
v8:
* document edited
v7:
* rebased on latest linux-next
v6:
* fix compile failure when NUMA disabled
v5:
* improved documentation
v4:
* fix comments and improved documentation
v3:
* simplified the locality concept & implementation
v2:
* improved documentationModern production environment could use hundreds of cgroup to control the resources for different workloads, along with the complicated resource binding.
On NUMA platforms where we have multiple nodes, things become even more complicated, we hope there are more local memory access to improve the performance, and NUMA Balancing keep working hard to achieve that, however, wrong memory policy or node binding could easily waste the effort, result a lot of remote page accessing.
We need to notice such problems, then we got chance to fix it before there are too much damages, however, there are no good monitoring approach yet to help catch the mouse who introduced the remote access.
This patch set is trying to fill in the missing pieces, by introduce the per-cgroup NUMA locality info, with this new statistics, we could achieve the daily monitoring on NUMA efficiency, to give warning when things going too wrong.
Please check the second patch for more details.
Michael Wang (2):
sched/numa: introduce per-cgroup NUMA locality info sched/numa: documentation for per-cgroup numa statisticsDocumentation/admin-guide/cg-numa-stat.rst | 178 ++++++++++++++++++++++++ Documentation/admin-guide/index.rst | 1 + Documentation/admin-guide/kernel-parameters.txt | 4 + Documentation/admin-guide/sysctl/kernel.rst | 9 ++ include/linux/sched.h | 15 ++ include/linux/sched/sysctl.h | 6 + init/Kconfig | 11 ++ kernel/sched/core.c | 75 ++++++++++ kernel/sched/fair.c | 62 +++++++++ kernel/sched/sched.h | 12 ++ kernel/sysctl.c | 11 ++ 11 files changed, 384 insertions(+) create mode 100644 Documentation/admin-guide/cg-numa-stat.rst
Steven Rostedt
reviewerRe: [PATCH v8 0/2] sched/numa: introduce numa locality
Quoted 3 lines · On Fri, 7 Feb 2020 09:10:33 +0800 王贇 <[email protected]> wrote:
Hi, Peter, Ingo
Could you give some comments please?
A little word of advice. When sending new versions of a patch. Don't send them as a reply to the previous version. Some developers (and I believe Peter is one of them), wont look for new patches in threads, and this may never be seen by him.
New versions of patches (v8 in this case) need to start a new thread and be at the top level. It's hard to manage patches when a thread series in embedded in another thread series.
-- Steve
Re: [PATCH v8 0/2] sched/numa: introduce numa locality
Quoted 7 lines · Steven Rostedt
Quoted 3 lines · On Fri, 7 Feb 2020 09:10:33 +0800 王贇 <[email protected]> wrote:
Hi, Peter, Ingo
Could you give some comments please?
Quoted 8 lines
A little word of advice. When sending new versions of a patch. Don't send them as a reply to the previous version. Some developers (and I believe Peter is one of them), wont look for new patches in threads, and this may never be seen by him.
New versions of patches (v8 in this case) need to start a new thread and be at the top level. It's hard to manage patches when a thread series in embedded in another thread series.
Aha, I do believe that's the situation...
I'll resend the v8 with the Ack from Randy, thanks for the advice :-)
Regards,
Michael Wang
Quoted 3 lines
-- Steve
v8 cover sched/numa: introduce numa locality
In reply to 王贇v8:
* document edited
v7:
* rebased on latest linux-next
v6:
* fix compile failure when NUMA disabled
v5:
* improved documentation
v4:
* fix comments and improved documentation
v3:
* simplified the locality concept & implementation
v2:
* improved documentation
Modern production environment could use hundreds of cgroup to control the resources for different workloads, along with the complicated resource binding.
On NUMA platforms where we have multiple nodes, things become even more complicated, we hope there are more local memory access to improve the performance, and NUMA Balancing keep working hard to achieve that, however, wrong memory policy or node binding could easily waste the effort, result a lot of remote page accessing.
We need to notice such problems, then we got chance to fix it before there are too much damages, however, there are no good monitoring approach yet to help catch the mouse who introduced the remote access.
This patch set is trying to fill in the missing pieces, by introduce the per-cgroup NUMA locality info, with this new statistics, we could achieve the daily monitoring on NUMA efficiency, to give warning when things going too wrong.
Please check the second patch for more details.
Michael Wang (2):
sched/numa: introduce per-cgroup NUMA locality info sched/numa: documentation for per-cgroup numa statistics
Documentation/admin-guide/cg-numa-stat.rst | 178 ++++++++++++++++++++++++ Documentation/admin-guide/index.rst | 1 + Documentation/admin-guide/kernel-parameters.txt | 4 + Documentation/admin-guide/sysctl/kernel.rst | 9 ++ include/linux/sched.h | 15 ++ include/linux/sched/sysctl.h | 6 + init/Kconfig | 11 ++ kernel/sched/core.c | 75 ++++++++++ kernel/sched/fair.c | 62 +++++++++ kernel/sched/sched.h | 12 ++ kernel/sysctl.c | 11 ++ 11 files changed, 384 insertions(+) create mode 100644 Documentation/admin-guide/cg-numa-stat.rst
Signature · 1 line
2.14.4.44.g2045bb6