Skip to contentSkip to conversation

mm, sysctl: make NUMA stats configurable

PATCH New [email protected] 1 participant 1 message Nov 16, 2017

Subsystems (6)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

PATCH 115/131 mm, sysctl: make NUMA stats configurable

From: Kemi Wang <[email protected]>
Subject: mm, sysctl: make NUMA stats configurable

This is the second step which introduces a tunable interface that allow numa stats configurable for optimizing zone_statistics(), as suggested by Dave Hansen and Ying Huang.

=========================================================================

When page allocation performance becomes a bottleneck and you can tolerate some possible tool breakage and decreased numa counter precision, you can do:

echo 0 > /proc/sys/vm/numa_stat

In this case, numa counter update is ignored. We can see about *4.8%*(185->176) drop of cpu cycles per single page allocation and reclaim on Jesper's page_bench01 (single thread) and *8.1%*(343->315) drop of cpu cycles per single page allocation and reclaim on Jesper's page_bench03 (88 threads) running on a 2-Socket Broadwell-based server (88 threads, 126G memory).

Benchmark link provided by Jesper D Brouer(increase loop times to 10000000):
https://github.com/netoptimizer/prototype-kernel/tree/master/kernel/mm/
bench

=========================================================================

When page allocation performance is not a bottleneck and you want all tooling to work, you can do:

echo 1 > /proc/sys/vm/numa_stat

This is system default setting.

Many thanks to Michal Hocko, Dave Hansen, Ying Huang and Vlastimil Babka for comments to help improve the original patch.

---

 Documentation/sysctl/vm.txt |   16 +++++++
 include/linux/vmstat.h      |   10 ++++
 kernel/sysctl.c             |    9 ++++
 mm/mempolicy.c              |    3 +
 mm/page_alloc.c             |    6 ++
 mm/vmstat.c                 |   71 ++++++++++++++++++++++++++++++++++
 6 files changed, 115 insertions(+)
Documentation/sysctl/vm.txt renamed from Documentation/sysctl/vm.txt~mm-sysctl-make-numa-stats-configurable-v5 +16 -0
diff -puN Documentation/sysctl/vm.txt~mm-sysctl-make-numa-stats-configurable-v5 Documentation/sysctl/vm.txt
@@ -58,6 +58,7 @@ Currently, these files are in /proc/sys/
 - percpu_pagelist_fraction
 - stat_interval
 - stat_refresh
+- numa_stat
 - swappiness
 - user_reserve_kbytes
 - vfs_cache_pressure
@@ -799,6 +800,21 @@ with no ill effects: errors and warnings
 
 ==============================================================
 
+numa_stat
+
+This interface allows runtime configuration of numa statistics.
+
+When page allocation performance becomes a bottleneck and you can tolerate
+some possible tool breakage and decreased numa counter precision, you can
+do:
+	echo 0 > /proc/sys/vm/numa_stat
+
+When page allocation performance is not a bottleneck and you want all
+tooling to work, you can do:
+	echo 1 > /proc/sys/vm/numa_stat
+
+==============================================================
+
 swappiness
 
 This control is used to define how aggressive the kernel will swap
include/linux/vmstat.h renamed from include/linux/vmstat.h~mm-sysctl-make-numa-stats-configurable-v5 +10 -0
diff -puN include/linux/vmstat.h~mm-sysctl-make-numa-stats-configurable-v5 include/linux/vmstat.h
@@ -7,9 +7,19 @@
 #include <linux/mmzone.h>
 #include <linux/vm_event_item.h>
 #include <linux/atomic.h>
+#include <linux/static_key.h>
 
 extern int sysctl_stat_interval;
 
+#ifdef CONFIG_NUMA
+#define ENABLE_NUMA_STAT   1
+#define DISABLE_NUMA_STAT   0
+extern int sysctl_vm_numa_stat;
+DECLARE_STATIC_KEY_TRUE(vm_numa_stat_key);
+extern int sysctl_vm_numa_stat_handler(struct ctl_table *table,
+		int write, void __user *buffer, size_t *length, loff_t *ppos);
+#endif
+
 #ifdef CONFIG_VM_EVENT_COUNTERS
 /*
  * Light weight per cpu counter implementation.
kernel/sysctl.c renamed from kernel/sysctl.c~mm-sysctl-make-numa-stats-configurable-v5 +9 -0
diff -puN kernel/sysctl.c~mm-sysctl-make-numa-stats-configurable-v5 kernel/sysctl.c
@@ -1356,6 +1356,15 @@ static struct ctl_table vm_table[] = {
 		.mode           = 0644,
 		.proc_handler   = &hugetlb_mempolicy_sysctl_handler,
 	},
+	{
+		.procname		= "numa_stat",
+		.data			= &sysctl_vm_numa_stat,
+		.maxlen			= sizeof(int),
+		.mode			= 0644,
+		.proc_handler	= sysctl_vm_numa_stat_handler,
+		.extra1			= &zero,
+		.extra2			= &one,
+	},
 #endif
 	 {
 		.procname	= "hugetlb_shm_group",
mm/mempolicy.c renamed from mm/mempolicy.c~mm-sysctl-make-numa-stats-configurable-v5 +3 -0
diff -puN mm/mempolicy.c~mm-sysctl-make-numa-stats-configurable-v5 mm/mempolicy.c
@@ -1915,6 +1915,9 @@ static struct page *alloc_page_interleav
 	struct page *page;
 
 	page = __alloc_pages(gfp, order, nid);
+	/* skip NUMA_INTERLEAVE_HIT counter update if numa stats is disabled */
+	if (!static_branch_likely(&vm_numa_stat_key))
+		return page;
 	if (page && page_to_nid(page) == nid) {
 		preempt_disable();
 		__inc_numa_state(page_zone(page), NUMA_INTERLEAVE_HIT);
mm/page_alloc.c renamed from mm/page_alloc.c~mm-sysctl-make-numa-stats-configurable-v5 +6 -0
diff -puN mm/page_alloc.c~mm-sysctl-make-numa-stats-configurable-v5 mm/page_alloc.c
@@ -82,6 +82,8 @@ DEFINE_PER_CPU(int, numa_node);
 EXPORT_PER_CPU_SYMBOL(numa_node);
 #endif
 
+DEFINE_STATIC_KEY_TRUE(vm_numa_stat_key);
+
 #ifdef CONFIG_HAVE_MEMORYLESS_NODES
 /*
  * N.B., Do NOT reference the '_numa_mem_' per cpu variable directly.
@@ -2777,6 +2779,10 @@ static inline void zone_statistics(struc
 #ifdef CONFIG_NUMA
 	enum numa_stat_item local_stat = NUMA_LOCAL;
 
+	/* skip numa counters update if numa stats is disabled */
+	if (!static_branch_likely(&vm_numa_stat_key))
+		return;
+
 	if (z->node != numa_node_id())
 		local_stat = NUMA_OTHER;
 
mm/vmstat.c renamed from mm/vmstat.c~mm-sysctl-make-numa-stats-configurable-v5 +71 -0

77 lines not on this page · raw message

_