Skip to content

Commit 3a321d2

Browse files
Kemi Wangtorvalds
authored andcommitted
mm: change the call sites of numa statistics items
Patch series "Separate NUMA statistics from zone statistics", v2. Each page allocation updates a set of per-zone statistics with a call to zone_statistics(). As discussed in 2017 MM summit, these are a substantial source of overhead in the page allocator and are very rarely consumed. This significant overhead in cache bouncing caused by zone counters (NUMA associated counters) update in parallel in multi-threaded page allocation (pointed out by Dave Hansen). A link to the MM summit slides: http://people.netfilter.org/hawk/presentations/MM-summit2017/MM-summit2017-JesperBrouer.pdf To mitigate this overhead, this patchset separates NUMA statistics from zone statistics framework, and update NUMA counter threshold to a fixed size of MAX_U16 - 2, as a small threshold greatly increases the update frequency of the global counter from local per cpu counter (suggested by Ying Huang). The rationality is that these statistics counters don't need to be read often, unlike other VM counters, so it's not a problem to use a large threshold and make readers more expensive. With this patchset, we see 31.3% drop of CPU cycles(537-->369, see below) for per single page allocation and reclaim on Jesper's page_bench03 benchmark. Meanwhile, this patchset keeps the same style of virtual memory statistics with little end-user-visible effects (only move the numa stats to show behind zone page stats, see the first patch for details). I did an experiment of single page allocation and reclaim concurrently using Jesper's page_bench03 benchmark on a 2-Socket Broadwell-based server (88 processors with 126G memory) with different size of threshold of pcp counter. Benchmark provided by Jesper D Brouer(increase loop times to 10000000): https://github.com/netoptimizer/prototype-kernel/tree/master/kernel/mm/bench Threshold CPU cycles Throughput(88 threads) 32 799 241760478 64 640 301628829 125 537 358906028 <==> system by default 256 468 412397590 512 428 450550704 4096 399 482520943 20000 394 489009617 30000 395 488017817 65533 369(-31.3%) 521661345(+45.3%) <==> with this patchset N/A 342(-36.3%) 562900157(+56.8%) <==> disable zone_statistics This patch (of 3): In this patch, NUMA statistics is separated from zone statistics framework, all the call sites of NUMA stats are changed to use numa-stats-specific functions, it does not have any functionality change except that the number of NUMA stats is shown behind zone page stats when users *read* the zone info. E.g. cat /proc/zoneinfo ***Base*** ***With this patch*** nr_free_pages 3976 nr_free_pages 3976 nr_zone_inactive_anon 0 nr_zone_inactive_anon 0 nr_zone_active_anon 0 nr_zone_active_anon 0 nr_zone_inactive_file 0 nr_zone_inactive_file 0 nr_zone_active_file 0 nr_zone_active_file 0 nr_zone_unevictable 0 nr_zone_unevictable 0 nr_zone_write_pending 0 nr_zone_write_pending 0 nr_mlock 0 nr_mlock 0 nr_page_table_pages 0 nr_page_table_pages 0 nr_kernel_stack 0 nr_kernel_stack 0 nr_bounce 0 nr_bounce 0 nr_zspages 0 nr_zspages 0 numa_hit 0 *nr_free_cma 0* numa_miss 0 numa_hit 0 numa_foreign 0 numa_miss 0 numa_interleave 0 numa_foreign 0 numa_local 0 numa_interleave 0 numa_other 0 numa_local 0 *nr_free_cma 0* numa_other 0 ... ... vm stats threshold: 10 vm stats threshold: 10 ... ... The next patch updates the numa stats counter size and threshold. [akpm@linux-foundation.org: coding-style fixes] Link: http://lkml.kernel.org/r/1503568801-21305-2-git-send-email-kemi.wang@intel.com Signed-off-by: Kemi Wang <kemi.wang@intel.com> Reported-by: Jesper Dangaard Brouer <brouer@redhat.com> Acked-by: Mel Gorman <mgorman@techsingularity.net> Cc: Michal Hocko <mhocko@suse.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Christopher Lameter <cl@linux.com> Cc: Dave Hansen <dave.hansen@intel.com> Cc: Andi Kleen <andi.kleen@intel.com> Cc: Ying Huang <ying.huang@intel.com> Cc: Aaron Lu <aaron.lu@intel.com> Cc: Tim Chen <tim.c.chen@intel.com> Cc: Dave Hansen <dave.hansen@intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent fde26be commit 3a321d2

5 files changed

Lines changed: 220 additions & 27 deletions

File tree

‎drivers/base/node.c‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,12 @@ static ssize_t node_read_numastat(struct device *dev,
160160
"interleave_hit %lu\n"
161161
"local_node %lu\n"
162162
"other_node %lu\n",
163-
sum_zone_node_page_state(dev->id, NUMA_HIT),
164-
sum_zone_node_page_state(dev->id, NUMA_MISS),
165-
sum_zone_node_page_state(dev->id, NUMA_FOREIGN),
166-
sum_zone_node_page_state(dev->id, NUMA_INTERLEAVE_HIT),
167-
sum_zone_node_page_state(dev->id, NUMA_LOCAL),
168-
sum_zone_node_page_state(dev->id, NUMA_OTHER));
163+
sum_zone_numa_state(dev->id, NUMA_HIT),
164+
sum_zone_numa_state(dev->id, NUMA_MISS),
165+
sum_zone_numa_state(dev->id, NUMA_FOREIGN),
166+
sum_zone_numa_state(dev->id, NUMA_INTERLEAVE_HIT),
167+
sum_zone_numa_state(dev->id, NUMA_LOCAL),
168+
sum_zone_numa_state(dev->id, NUMA_OTHER));
169169
}
170170
static DEVICE_ATTR(numastat, S_IRUGO, node_read_numastat, NULL);
171171

@@ -181,9 +181,17 @@ static ssize_t node_read_vmstat(struct device *dev,
181181
n += sprintf(buf+n, "%s %lu\n", vmstat_text[i],
182182
sum_zone_node_page_state(nid, i));
183183

184-
for (i = 0; i < NR_VM_NODE_STAT_ITEMS; i++)
184+
#ifdef CONFIG_NUMA
185+
for (i = 0; i < NR_VM_NUMA_STAT_ITEMS; i++)
185186
n += sprintf(buf+n, "%s %lu\n",
186187
vmstat_text[i + NR_VM_ZONE_STAT_ITEMS],
188+
sum_zone_numa_state(nid, i));
189+
#endif
190+
191+
for (i = 0; i < NR_VM_NODE_STAT_ITEMS; i++)
192+
n += sprintf(buf+n, "%s %lu\n",
193+
vmstat_text[i + NR_VM_ZONE_STAT_ITEMS +
194+
NR_VM_NUMA_STAT_ITEMS],
187195
node_page_state(pgdat, i));
188196

189197
return n;

‎include/linux/mmzone.h‎

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,20 @@ struct zone_padding {
114114
#define ZONE_PADDING(name)
115115
#endif
116116

117+
#ifdef CONFIG_NUMA
118+
enum numa_stat_item {
119+
NUMA_HIT, /* allocated in intended node */
120+
NUMA_MISS, /* allocated in non intended node */
121+
NUMA_FOREIGN, /* was intended here, hit elsewhere */
122+
NUMA_INTERLEAVE_HIT, /* interleaver preferred this zone */
123+
NUMA_LOCAL, /* allocation from local node */
124+
NUMA_OTHER, /* allocation from other node */
125+
NR_VM_NUMA_STAT_ITEMS
126+
};
127+
#else
128+
#define NR_VM_NUMA_STAT_ITEMS 0
129+
#endif
130+
117131
enum zone_stat_item {
118132
/* First 128 byte cacheline (assuming 64 bit words) */
119133
NR_FREE_PAGES,
@@ -131,14 +145,6 @@ enum zone_stat_item {
131145
NR_BOUNCE,
132146
#if IS_ENABLED(CONFIG_ZSMALLOC)
133147
NR_ZSPAGES, /* allocated in zsmalloc */
134-
#endif
135-
#ifdef CONFIG_NUMA
136-
NUMA_HIT, /* allocated in intended node */
137-
NUMA_MISS, /* allocated in non intended node */
138-
NUMA_FOREIGN, /* was intended here, hit elsewhere */
139-
NUMA_INTERLEAVE_HIT, /* interleaver preferred this zone */
140-
NUMA_LOCAL, /* allocation from local node */
141-
NUMA_OTHER, /* allocation from other node */
142148
#endif
143149
NR_FREE_CMA_PAGES,
144150
NR_VM_ZONE_STAT_ITEMS };
@@ -276,6 +282,8 @@ struct per_cpu_pageset {
276282
struct per_cpu_pages pcp;
277283
#ifdef CONFIG_NUMA
278284
s8 expire;
285+
s8 numa_stat_threshold;
286+
s8 vm_numa_stat_diff[NR_VM_NUMA_STAT_ITEMS];
279287
#endif
280288
#ifdef CONFIG_SMP
281289
s8 stat_threshold;
@@ -496,6 +504,7 @@ struct zone {
496504
ZONE_PADDING(_pad3_)
497505
/* Zone statistics */
498506
atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
507+
atomic_long_t vm_numa_stat[NR_VM_NUMA_STAT_ITEMS];
499508
} ____cacheline_internodealigned_in_smp;
500509

501510
enum pgdat_flags {

‎include/linux/vmstat.h‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,33 @@ static inline void vm_events_fold_cpu(int cpu)
107107
* Zone and node-based page accounting with per cpu differentials.
108108
*/
109109
extern atomic_long_t vm_zone_stat[NR_VM_ZONE_STAT_ITEMS];
110+
extern atomic_long_t vm_numa_stat[NR_VM_NUMA_STAT_ITEMS];
110111
extern atomic_long_t vm_node_stat[NR_VM_NODE_STAT_ITEMS];
111112

113+
#ifdef CONFIG_NUMA
114+
static inline void zone_numa_state_add(long x, struct zone *zone,
115+
enum numa_stat_item item)
116+
{
117+
atomic_long_add(x, &zone->vm_numa_stat[item]);
118+
atomic_long_add(x, &vm_numa_stat[item]);
119+
}
120+
121+
static inline unsigned long global_numa_state(enum numa_stat_item item)
122+
{
123+
long x = atomic_long_read(&vm_numa_stat[item]);
124+
125+
return x;
126+
}
127+
128+
static inline unsigned long zone_numa_state(struct zone *zone,
129+
enum numa_stat_item item)
130+
{
131+
long x = atomic_long_read(&zone->vm_numa_stat[item]);
132+
133+
return x;
134+
}
135+
#endif /* CONFIG_NUMA */
136+
112137
static inline void zone_page_state_add(long x, struct zone *zone,
113138
enum zone_stat_item item)
114139
{
@@ -194,8 +219,10 @@ static inline unsigned long node_page_state_snapshot(pg_data_t *pgdat,
194219

195220

196221
#ifdef CONFIG_NUMA
222+
extern void __inc_numa_state(struct zone *zone, enum numa_stat_item item);
197223
extern unsigned long sum_zone_node_page_state(int node,
198-
enum zone_stat_item item);
224+
enum zone_stat_item item);
225+
extern unsigned long sum_zone_numa_state(int node, enum numa_stat_item item);
199226
extern unsigned long node_page_state(struct pglist_data *pgdat,
200227
enum node_stat_item item);
201228
#else

‎mm/page_alloc.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2741,18 +2741,18 @@ int __isolate_free_page(struct page *page, unsigned int order)
27412741
static inline void zone_statistics(struct zone *preferred_zone, struct zone *z)
27422742
{
27432743
#ifdef CONFIG_NUMA
2744-
enum zone_stat_item local_stat = NUMA_LOCAL;
2744+
enum numa_stat_item local_stat = NUMA_LOCAL;
27452745

27462746
if (z->node != numa_node_id())
27472747
local_stat = NUMA_OTHER;
27482748

27492749
if (z->node == preferred_zone->node)
2750-
__inc_zone_state(z, NUMA_HIT);
2750+
__inc_numa_state(z, NUMA_HIT);
27512751
else {
2752-
__inc_zone_state(z, NUMA_MISS);
2753-
__inc_zone_state(preferred_zone, NUMA_FOREIGN);
2752+
__inc_numa_state(z, NUMA_MISS);
2753+
__inc_numa_state(preferred_zone, NUMA_FOREIGN);
27542754
}
2755-
__inc_zone_state(z, local_stat);
2755+
__inc_numa_state(z, local_stat);
27562756
#endif
27572757
}
27582758

0 commit comments

Comments
 (0)