Skip to contentSkip to conversation

Framework for accurate node based statistics

RFC In review Christoph Lameter 5 participants 21 messages Dec 6, 2005 – Dec 8, 2005

Subsystems (10)
lore
Share & tools
lore
#0 lore raw

RFC 1/3 Framework for accurate node based statistics

[RFC] Framework for accurate node based statistics

Currently we have various vm counters that are split per cpu. This arrangement does not allow access to per node statistics that are important to optimize VM behavior for NUMA architectures. All one can say from the per_cpu differential variables is how much a certain variable was changed by this cpu without being able to deduce how many pages in each node are of a certain type.

This patch introduces a generic framework to allow accurate per node vm statistics through a large per node and per cpu array. The numbers are consolidated when the slab drainer runs (every 3 seconds or so) into global and per node counters. VM functions can then check these statistics by simply accessing the node specific or global counter.

A significant problem with this approach is that the statistics are only accumulated every 3 seconds or so. I have tried various other approaches but they typically end up with having to add atomic variables to critical VM paths. I'd be glad if someone else had a bright idea on how to improve the situation.

There are two patches following that convert two important counters to work per node but there may be many more that may be useful in the future.

mm/page_alloc.c +27 -0
Index: linux-2.6.15-rc3/mm/page_alloc.c
===================================================================
@@ -557,6 +557,33 @@ static int rmqueue_bulk(struct zone *zon
 }
 
 #ifdef CONFIG_NUMA
+static spinlock_t node_stat_lock;
+unsigned long vm_stat_global[NR_STAT_ITEMS];
+unsigned long vm_stat_node[MAX_NUMNODES][NR_STAT_ITEMS];
+int vm_stat_diff[NR_CPUS][MAX_NUMNODES][NR_STAT_ITEMS];
+
+void refresh_vm_stats(void) {
+	int cpu;
+	int node;
+	int i;
+
+	spin_lock(&node_stat_lock);
+
+	cpu = get_cpu();
+	for_each_online_node(node)
+		for(i = 0; i < NR_STAT_ITEMS; i++) {
+			int * p = vm_stat_diff[cpu][node]+i;
+			if (*p) {
+				vm_stat_node[node][i] += *p;
+				vm_stat_global[i] += *p;
+				*p = 0;
+			}
+		}
+	put_cpu();
+
+	spin_unlock(&node_stat_lock);
+}
+
 /* Called from the slab reaper to drain remote pagesets */
 void drain_remote_pages(void)
 {
include/linux/page-flags.h +21 -0
Index: linux-2.6.15-rc3/include/linux/page-flags.h
===================================================================
@@ -163,6 +163,27 @@ extern void __mod_page_state(unsigned lo
 	} while (0)
 
 /*
+ * Node based accounting with per cpu differentials.
+ */
+enum node_stat_item { };
+#define NR_STAT_ITEMS 0
+
+extern unsigned long vm_stat_global[NR_STAT_ITEMS];
+extern unsigned long vm_stat_node[MAX_NUMNODES][NR_STAT_ITEMS];
+extern int vm_stat_diff[NR_CPUS][MAX_NUMNODES][NR_STAT_ITEMS];
+
+static inline void mod_node_page_state(int node, enum node_stat_item item, int delta)
+{
+	vm_stat_diff[get_cpu()][node][item] += delta;
+	put_cpu();
+}
+
+#define inc_node_page_state(node, item) mod_node_page_state(node, item, 1)
+#define dec_node_page_state(node, item) mod_node_page_state(node, item, -1)
+#define add_node_page_state(node, item) mod_node_page_state(node, item, delta)
+#define sub_node_page_state(node, item) mod_node_page_state(node, item, -(delta))
+
+/*
  * Manipulation of page state flags
  */
 #define PageLocked(page)		\
include/linux/gfp.h +2 -0
Index: linux-2.6.15-rc3/include/linux/gfp.h
===================================================================
@@ -153,8 +153,10 @@ extern void FASTCALL(free_cold_page(stru
 void page_alloc_init(void);
 #ifdef CONFIG_NUMA
 void drain_remote_pages(void);
+void refresh_vm_stats(void);
 #else
 static inline void drain_remote_pages(void) { };
+static inline void refresh_vm_stats(void) { }
 #endif
 
 #endif /* __LINUX_GFP_H */
mm/slab.c +1 -0
Index: linux-2.6.15-rc3/mm/slab.c
===================================================================
@@ -3359,6 +3359,7 @@ next:
 	check_irq_on();
 	up(&cache_chain_sem);
 	drain_remote_pages();
+	refresh_vm_stats();
 	/* Setup the next iteration */
 	schedule_delayed_work(&__get_cpu_var(reap_work), REAPTIMEOUT_CPUC);
 }

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#1 lore raw

RFC 2/3 Make nr_mapped a per node counter

Make nr_mapped a per node counter

The per cpu nr_mapped counter is important because it allows a determination how many pages of a node are not mapped, which would allow a more effiecient means of determining when a node should reclaim memory.

include/linux/page-flags.h +2 -3
Index: linux-2.6.15-rc3/include/linux/page-flags.h
===================================================================
@@ -85,7 +85,6 @@ struct page_state {
 	unsigned long nr_writeback;	/* Pages under writeback */
 	unsigned long nr_unstable;	/* NFS unstable pages */
 	unsigned long nr_page_table_pages;/* Pages used for pagetables */
-	unsigned long nr_mapped;	/* mapped into pagetables */
 	unsigned long nr_slab;		/* In slab */
 #define GET_PAGE_STATE_LAST nr_slab
 
@@ -165,8 +164,8 @@ extern void __mod_page_state(unsigned lo
 /*
  * Node based accounting with per cpu differentials.
  */
-enum node_stat_item { };
-#define NR_STAT_ITEMS 0
+enum node_stat_item { NR_MAPPED };
+#define NR_STAT_ITEMS 1
 
 extern unsigned long vm_stat_global[NR_STAT_ITEMS];
 extern unsigned long vm_stat_node[MAX_NUMNODES][NR_STAT_ITEMS];
drivers/base/node.c +1 -3
Index: linux-2.6.15-rc3/drivers/base/node.c
===================================================================
@@ -53,8 +53,6 @@ static ssize_t node_read_meminfo(struct 
 		ps.nr_dirty = 0;
 	if ((long)ps.nr_writeback < 0)
 		ps.nr_writeback = 0;
-	if ((long)ps.nr_mapped < 0)
-		ps.nr_mapped = 0;
 	if ((long)ps.nr_slab < 0)
 		ps.nr_slab = 0;
 
@@ -83,7 +81,7 @@ static ssize_t node_read_meminfo(struct 
 		       nid, K(i.freeram - i.freehigh),
 		       nid, K(ps.nr_dirty),
 		       nid, K(ps.nr_writeback),
-		       nid, K(ps.nr_mapped),
+		       nid, K(vm_stat_node[nid][NR_MAPPED]),
 		       nid, K(ps.nr_slab));
 	n += hugetlb_report_node_meminfo(nid, buf + n);
 	return n;
fs/proc/proc_misc.c +1 -1
Index: linux-2.6.15-rc3/fs/proc/proc_misc.c
===================================================================
@@ -190,7 +190,7 @@ static int meminfo_read_proc(char *page,
 		K(i.freeswap),
 		K(ps.nr_dirty),
 		K(ps.nr_writeback),
-		K(ps.nr_mapped),
+		K(vm_stat_global[NR_MAPPED]),
 		K(ps.nr_slab),
 		K(allowed),
 		K(committed),
mm/vmscan.c +3 -3
Index: linux-2.6.15-rc3/mm/vmscan.c
===================================================================
@@ -967,7 +967,7 @@ int try_to_free_pages(struct zone **zone
 	}
 
 	for (priority = DEF_PRIORITY; priority >= 0; priority--) {
-		sc.nr_mapped = read_page_state(nr_mapped);
+		sc.nr_mapped = vm_stat_global[NR_MAPPED];
 		sc.nr_scanned = 0;
 		sc.nr_reclaimed = 0;
 		sc.priority = priority;
@@ -1056,7 +1056,7 @@ loop_again:
 	sc.gfp_mask = GFP_KERNEL;
 	sc.may_writepage = 0;
 	sc.may_swap = 1;
-	sc.nr_mapped = read_page_state(nr_mapped);
+	sc.nr_mapped = vm_stat_global[NR_MAPPED];
 
 	inc_page_state(pageoutrun);
 
@@ -1373,7 +1373,7 @@ int zone_reclaim(struct zone *zone, gfp_
 	sc.gfp_mask = gfp_mask;
 	sc.may_writepage = 0;
 	sc.may_swap = 0;
-	sc.nr_mapped = read_page_state(nr_mapped);
+	sc.nr_mapped = vm_stat_global[NR_MAPPED];
 	sc.nr_scanned = 0;
 	sc.nr_reclaimed = 0;
 	/* scan at the highest priority */
mm/page-writeback.c +1 -1
Index: linux-2.6.15-rc3/mm/page-writeback.c
===================================================================
@@ -111,7 +111,7 @@ static void get_writeback_state(struct w
 {
 	wbs->nr_dirty = read_page_state(nr_dirty);
 	wbs->nr_unstable = read_page_state(nr_unstable);
-	wbs->nr_mapped = read_page_state(nr_mapped);
+	wbs->nr_mapped = vm_stat_global[NR_MAPPED];
 	wbs->nr_writeback = read_page_state(nr_writeback);
 }
 
mm/page_alloc.c +1 -1
Index: linux-2.6.15-rc3/mm/page_alloc.c
===================================================================
@@ -1400,7 +1400,7 @@ void show_free_areas(void)
 		ps.nr_unstable,
 		nr_free_pages(),
 		ps.nr_slab,
-		ps.nr_mapped,
+		vm_stat_global[NR_MAPPED],
 		ps.nr_page_table_pages);
 
 	for_each_zone(zone) {
mm/rmap.c +3 -3
Index: linux-2.6.15-rc3/mm/rmap.c
===================================================================
@@ -454,7 +454,7 @@ void page_add_anon_rmap(struct page *pag
 
 		page->index = linear_page_index(vma, address);
 
-		inc_page_state(nr_mapped);
+		inc_node_page_state(page_to_nid(page), NR_MAPPED);
 	}
 	/* else checking page index and mapping is racy */
 }
@@ -471,7 +471,7 @@ void page_add_file_rmap(struct page *pag
 	BUG_ON(!pfn_valid(page_to_pfn(page)));
 
 	if (atomic_inc_and_test(&page->_mapcount))
-		inc_page_state(nr_mapped);
+		inc_node_page_state(page_to_nid(page), NR_MAPPED);
 }
 
 /**
@@ -495,7 +495,7 @@ void page_remove_rmap(struct page *page)
 		 */
 		if (page_test_and_clear_dirty(page))
 			set_page_dirty(page);
-		dec_page_state(nr_mapped);
+		dec_node_page_state(page_to_nid(page), NR_MAPPED);
 	}
 }
 

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#2 lore raw

Re: [RFC 2/3] Make nr_mapped a per node counter

Quoted 80 lines · Christoph Lameter

Make nr_mapped a per node counter

The per cpu nr_mapped counter is important because it allows a determination how many pages of a node are not mapped, which would allow a more effiecient means of determining when a node should reclaim memory.

Index: linux-2.6.15-rc3/include/linux/page-flags.h
===================================================================

include/linux/page-flags.h +2 -3
@@ -85,7 +85,6 @@ struct page_state {
 	unsigned long nr_writeback;	/* Pages under writeback */
 	unsigned long nr_unstable;	/* NFS unstable pages */
 	unsigned long nr_page_table_pages;/* Pages used for pagetables */
-	unsigned long nr_mapped;	/* mapped into pagetables */
 	unsigned long nr_slab;		/* In slab */
 #define GET_PAGE_STATE_LAST nr_slab
 
@@ -165,8 +164,8 @@ extern void __mod_page_state(unsigned lo
 /*
  * Node based accounting with per cpu differentials.
  */
-enum node_stat_item { };
-#define NR_STAT_ITEMS 0
+enum node_stat_item { NR_MAPPED };
+#define NR_STAT_ITEMS 1
 
 extern unsigned long vm_stat_global[NR_STAT_ITEMS];
 extern unsigned long vm_stat_node[MAX_NUMNODES][NR_STAT_ITEMS];

Index: linux-2.6.15-rc3/drivers/base/node.c
===================================================================

drivers/base/node.c +1 -3
@@ -53,8 +53,6 @@ static ssize_t node_read_meminfo(struct 
 		ps.nr_dirty = 0;
 	if ((long)ps.nr_writeback < 0)
 		ps.nr_writeback = 0;
-	if ((long)ps.nr_mapped < 0)
-		ps.nr_mapped = 0;
 	if ((long)ps.nr_slab < 0)
 		ps.nr_slab = 0;
 
@@ -83,7 +81,7 @@ static ssize_t node_read_meminfo(struct 
 		       nid, K(i.freeram - i.freehigh),
 		       nid, K(ps.nr_dirty),
 		       nid, K(ps.nr_writeback),
-		       nid, K(ps.nr_mapped),
+		       nid, K(vm_stat_node[nid][NR_MAPPED]),
 		       nid, K(ps.nr_slab));
 	n += hugetlb_report_node_meminfo(nid, buf + n);
 	return n;

Index: linux-2.6.15-rc3/fs/proc/proc_misc.c
===================================================================

fs/proc/proc_misc.c +1 -1
@@ -190,7 +190,7 @@ static int meminfo_read_proc(char *page,
 		K(i.freeswap),
 		K(ps.nr_dirty),
 		K(ps.nr_writeback),
-		K(ps.nr_mapped),
+		K(vm_stat_global[NR_MAPPED]),
 		K(ps.nr_slab),
 		K(allowed),
 		K(committed),

Index: linux-2.6.15-rc3/mm/vmscan.c
===================================================================

mm/vmscan.c +1 -1
@@ -967,7 +967,7 @@ int try_to_free_pages(struct zone **zone
 	}
 
 	for (priority = DEF_PRIORITY; priority >= 0; priority--) {
-		sc.nr_mapped = read_page_state(nr_mapped);
+		sc.nr_mapped = vm_stat_global[NR_MAPPED];
 		sc.nr_scanned = 0;
 		sc.nr_reclaimed = 0;
 		sc.priority = priority;

mm/vmscan.c loop_again: · line 1060

Quoted 6 lines
mm/vmscan.c +1 -1
@@ -1056,7 +1056,7 @@ loop_again:
 	sc.gfp_mask = GFP_KERNEL;
 	sc.may_writepage = 0;
 	sc.may_swap = 1;
-	sc.nr_mapped = read_page_state(nr_mapped);
+	sc.nr_mapped = vm_stat_global[NR_MAPPED];
 

Any chance you can wrap these in macros? (something like read_page_node_state())

I gather Andrew did this so that they can easily be defined out for things that don't want them (maybe, embedded systems).

Signature · 9 lines
SUSE Labs, Novell Inc.

Send instant messages to your online friends http://au.messenger.yahoo.com 

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#3 lore raw

RFC 3/3 Make nr_pagecache a per node counter

In reply to Christoph Lameter

Make nr_pagecache a per node variable

The nr_pagecache atomic variable is a particular ugly spot in the VM right now. We ultimately need a sortof accurate value. This patch makes nr_pagecache conform to the other VM statistics

include/linux/page-flags.h +2 -2
Index: linux-2.6.15-rc5/include/linux/page-flags.h
===================================================================
@@ -164,8 +164,8 @@ extern void __mod_page_state(unsigned lo
 /*
  * Node based accounting with per cpu differentials.
  */
-enum node_stat_item { NR_MAPPED };
-#define NR_STAT_ITEMS 1
+enum node_stat_item { NR_MAPPED, NR_PAGECACHE };
+#define NR_STAT_ITEMS 2
 
 extern unsigned long vm_stat_global[NR_STAT_ITEMS];
 extern unsigned long vm_stat_node[MAX_NUMNODES][NR_STAT_ITEMS];
include/linux/pagemap.h +1 -41

50 lines not on this page · raw message

mm/swap_state.c +2 -2
Index: linux-2.6.15-rc5/mm/swap_state.c
===================================================================
@@ -84,7 +84,7 @@ static int __add_to_swap_cache(struct pa
 			SetPageSwapCache(page);
 			set_page_private(page, entry.val);
 			total_swapcache_pages++;
-			pagecache_acct(1);
+			inc_node_page_state(page_to_nid(page), NR_PAGECACHE);
 		}
 		write_unlock_irq(&swapper_space.tree_lock);
 		radix_tree_preload_end();
@@ -129,7 +129,7 @@ void __delete_from_swap_cache(struct pag
 	set_page_private(page, 0);
 	ClearPageSwapCache(page);
 	total_swapcache_pages--;
-	pagecache_acct(-1);
+	dec_node_page_state(page_to_nid(page), NR_PAGECACHE);
 	INC_CACHE_INFO(del_total);
 }
 
mm/filemap.c +2 -2
Index: linux-2.6.15-rc5/mm/filemap.c
===================================================================
@@ -115,7 +115,7 @@ void __remove_from_page_cache(struct pag
 	radix_tree_delete(&mapping->page_tree, page->index);
 	page->mapping = NULL;
 	mapping->nrpages--;
-	pagecache_acct(-1);
+	dec_node_page_state(page_to_nid(page), NR_PAGECACHE);
 }
 
 void remove_from_page_cache(struct page *page)
@@ -390,7 +390,7 @@ int add_to_page_cache(struct page *page,
 			page->mapping = mapping;
 			page->index = offset;
 			mapping->nrpages++;
-			pagecache_acct(1);
+			inc_node_page_state(page_to_nid(page), NR_PAGECACHE);
 		}
 		write_unlock_irq(&mapping->tree_lock);
 		radix_tree_preload_end();

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#4 lore raw
In reply to Christoph Lameter

include/linux/page-flags.h extern void __mod_page_state(unsigned lo · line 178

Quoted 4 lines
include/linux/page-flags.h +4 -0
+static inline void mod_node_page_state(int node, enum node_stat_item item, int delta)
+{
+	vm_stat_diff[get_cpu()][node][item] += delta;
+	put_cpu();

Instead of get/put_cpu I would use a local_t. This would give much better code on i386/x86-64. I have some plans to port over all the MM statistics counters over to local_t, still stuck, but for new code it should be definitely done.

-Andi

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#5 lore raw
Quoted 8 lines · Andi Kleen

include/linux/page-flags.h extern void __mod_page_state(unsigned lo · line 178

Quoted 4 lines
include/linux/page-flags.h +4 -0
+static inline void mod_node_page_state(int node, enum node_stat_item item, int delta)
+{
+	vm_stat_diff[get_cpu()][node][item] += delta;
+	put_cpu();

Instead of get/put_cpu I would use a local_t. This would give much better code on i386/x86-64. I have some plans to port over all the MM statistics counters over to local_t, still stuck, but for new code it should be definitely done.

Yuck. That code uses atomic operations and is not aware of atomic64_t.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#6 lore raw
Quoted 11 lines · Christoph Lameter
Quoted 8 lines · Andi Kleen

include/linux/page-flags.h extern void __mod_page_state(unsigned lo · line 178

Quoted 4 lines
include/linux/page-flags.h +4 -0
+static inline void mod_node_page_state(int node, enum node_stat_item item, int delta)
+{
+	vm_stat_diff[get_cpu()][node][item] += delta;
+	put_cpu();

Instead of get/put_cpu I would use a local_t. This would give much better code on i386/x86-64. I have some plans to port over all the MM statistics counters over to local_t, still stuck, but for new code it should be definitely done.

Quoted 1 line

Yuck. That code uses atomic operations and is not aware of atomic64_t.

Hmm? What code are you looking at?

At least i386/x86-64/generic don't use any atomic operations, just normal non atomic on bus but atomic for interrupts local rmw.

Do you actually need 64bit?

-Andi

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#7 lore raw
Quoted 2 lines · Andi Kleen
Quoted 1 line

Yuck. That code uses atomic operations and is not aware of atomic64_t.

Hmm? What code are you looking at?

include/asm-generic/local.h. this is the default right? And include/asm-ia64/local.h.

Quoted 2 lines

At least i386/x86-64/generic don't use any atomic operations, just normal non atomic on bus but atomic for interrupts local rmw.

inc/dec are atomic by default on x86_64?

Quoted 1 line

Do you actually need 64bit?

32 bit limits us in the worst case to 8 Terabytes of RAM (assuming a very small page size of 4k and 31 bit available for an atomic variable [sparc]). SGI already has installations with 15 Terabytes of RAM.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#8 lore raw
Quoted 11 lines · Christoph Lameter
Quoted 2 lines · Andi Kleen
Quoted 1 line

Yuck. That code uses atomic operations and is not aware of atomic64_t.

Hmm? What code are you looking at?

include/asm-generic/local.h. this is the default right? And include/asm-ia64/local.h.

Quoted 2 lines

At least i386/x86-64/generic don't use any atomic operations, just normal non atomic on bus but atomic for interrupts local rmw.

inc/dec are atomic by default on x86_64?

They are atomic against interrupts on the same CPU. And on Linux also atomic against preempt moving you to another CPU. And all that without the cost of a bus lock. And that is what local_t is about.

Quoted 6 lines
Quoted 2 lines

Do you actually need 64bit?

32 bit limits us in the worst case to 8 Terabytes of RAM (assuming a very small page size of 4k and 31 bit available for an atomic variable [sparc]). SGI already has installations with 15 Terabytes of RAM.

Ok we'll need a local64_t then. No big deal - can be easily added. Or perhaps better a long_local_t so that 32bit doesn't need to pay the cost.

-Andi

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#9 lore raw
Quoted 3 lines · Andi Kleen

Ok we'll need a local64_t then. No big deal - can be easily added. Or perhaps better a long_local_t so that 32bit doesn't need to pay the cost.

I jusw saw that ia64 already has local_t as 64 bit, so that is no problem for us. Here is a patch that would convert the framework to use local_t. Is that okay?

The problem with this solution is that the use of local_t will lead to the use of atomic operations (in case the preemption status is unknown). It may be better to use atomic operations and simply drop the per_cpu stuff. That way the summing of the per cpu variables is avoided and the stats are accurate in real time.

Seems that local.h is rarely used. There was an obvious mistake in there for ia64.

Index: linux-2.6.15-rc5/mm/page_alloc.c
=================================--- linux-2.6.15-rc5.orig/mm/page_alloc.c 2005-12-06 10:13:49.000000000 -0800
+++ linux-2.6.15-rc5/mm/page_alloc.c 2005-12-06 14:43:41.000000000 -0800
@@ -560,26 +560,25 @@ static int rmqueue_bulk(struct zone *zon
static spinlock_t node_stat_lock;
unsigned long vm_stat_global[NR_STAT_ITEMS];
unsigned long vm_stat_node[MAX_NUMNODES][NR_STAT_ITEMS];
-int vm_stat_diff[NR_CPUS][MAX_NUMNODES][NR_STAT_ITEMS]; +DEFINE_PER_CPU(local_t [MAX_NUMNODES][NR_STAT_ITEMS], vm_stat_diff);

void refresh_vm_stats(void) {
- int cpu;
int node;
int i;

spin_lock(&node_stat_lock);

- cpu = get_cpu();
for_each_online_node(node)
for(i = 0; i < NR_STAT_ITEMS; i++) {
- int * p = vm_stat_diff[cpu][node]+i;
- if (*p) {
- vm_stat_node[node][i] += *p;
- vm_stat_global[i] += *p;
- *p = 0;
+ long v;
+
+ v = cpu_local_read(vm_stat_diff[node][i]);
+ if (v) {
+ vm_stat_node[node][i] += v;
+ vm_stat_global[i] += v;
+ cpu_local_set(vm_stat_diff[node][i], 0);
}
}
- put_cpu();

spin_unlock(&node_stat_lock);
}
Index: linux-2.6.15-rc5/include/linux/page-flags.h
=================================--- linux-2.6.15-rc5.orig/include/linux/page-flags.h 2005-12-06 10:15:59.000000000 -0800
+++ linux-2.6.15-rc5/include/linux/page-flags.h 2005-12-06 14:47:03.000000000 -0800
@@ -8,6 +8,7 @@
#include <linux/percpu.h>
#include <linux/cache.h>
#include <asm/pgtable.h>
+#include <asm/local.h>

/*
* Various page->flags bits:
@@ -169,12 +170,19 @@ enum node_stat_item { NR_MAPPED, NR_PAGE

extern unsigned long vm_stat_global[NR_STAT_ITEMS];
extern unsigned long vm_stat_node[MAX_NUMNODES][NR_STAT_ITEMS];
-extern int vm_stat_diff[NR_CPUS][MAX_NUMNODES][NR_STAT_ITEMS]; +DECLARE_PER_CPU(local_t [MAX_NUMNODES][NR_STAT_ITEMS], vm_stat_diff);

static inline void mod_node_page_state(int node, enum node_stat_item item, int delta) {
- vm_stat_diff[get_cpu()][node][item] += delta;
- put_cpu();
+ cpu_local_add(delta, vm_stat_diff[node][item]);
+}
+
+/*
+ * For use when we know that preemption is disabled. Avoids atomic operations.
+ */
+static inline void __mod_node_page_state(int node, enum node_stat_item item, int delta) +{
+ __local_add(delta, &__get_cpu_var(vm_stat_diff[node][item]));
}

#define inc_node_page_state(node, item) mod_node_page_state(node, item, 1)
Index: linux-2.6.15-rc5/include/asm-ia64/local.h
=================================--- linux-2.6.15-rc5.orig/include/asm-ia64/local.h 2005-12-03 21:10:42.000000000 -0800
+++ linux-2.6.15-rc5/include/asm-ia64/local.h 2005-12-06 14:39:47.000000000 -0800
@@ -17,7 +17,7 @@ typedef struct {
#define local_set(l, i) atomic64_set(&(l)->val, i)
#define local_inc(l) atomic64_inc(&(l)->val)
#define local_dec(l) atomic64_dec(&(l)->val)
-#define local_add(l) atomic64_add(&(l)->val)
+#define local_add(i, l) atomic64_add((i), &(l)->val)
#define local_sub(l) atomic64_sub(&(l)->val)

/* Non-atomic variants, i.e., preemption disabled and won't be touched in interrupt, etc. */

#10 lore raw
Quoted 1 line · Christoph Lameter

+DEFINE_PER_CPU(local_t [MAX_NUMNODES][NR_STAT_ITEMS], vm_stat_diff);

How big is that array going to get? The total per cpu data area is limited to 64K on IA64 and we already use at least 34K.

#11 lore raw
Quoted 6 lines · Keith Owens
Quoted 1 line · Christoph Lameter

+DEFINE_PER_CPU(local_t [MAX_NUMNODES][NR_STAT_ITEMS], vm_stat_diff);

How big is that array going to get? The total per cpu data area is limited to 64K on IA64 and we already use at least 34K.

Maximum around 1k nodes and I guess we may end up with 16 counters:

1024*16*8 = 131k ?

#12 lore raw
In reply to Christoph Lameter
Quoted 14 lines · Christoph Lameter

[RFC] Framework for accurate node based statistics

Currently we have various vm counters that are split per cpu. This arrangement does not allow access to per node statistics that are important to optimize VM behavior for NUMA architectures. All one can say from the per_cpu differential variables is how much a certain variable was changed by this cpu without being able to deduce how many pages in each node are of a certain type.

This patch introduces a generic framework to allow accurate per node vm statistics through a large per node and per cpu array. The numbers are consolidated when the slab drainer runs (every 3 seconds or so) into global and per node counters. VM functions can then check these statistics by simply accessing the node specific or global counter.

Quoted 6 lines

A significant problem with this approach is that the statistics are only accumulated every 3 seconds or so. I have tried various other approaches but they typically end up with having to add atomic variables to critical VM paths. I'd be glad if someone else had a bright idea on how to improve the situation.

Why not have per-node * per-cpu counters?

Or even use the current per-zone * per-cpu counters, and work out your node details from there?

Signature · 9 lines
SUSE Labs, Novell Inc.

Send instant messages to your online friends http://au.messenger.yahoo.com 

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#13 lore raw
Quoted 1 line · Nick Piggin

Why not have per-node * per-cpu counters?

Yes, that is exactly what this patch implements.

Quoted 2 lines

Or even use the current per-zone * per-cpu counters, and work out your node details from there?

I am not aware of any per-zone per cpu counters.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#14 lore raw
Quoted 1 line · Christoph Lameter

I am not aware of any per-zone per cpu counters.

Argh. Wrong. Yes there are counters in the per cpu structures for each zone. The pointers here could be folded into that and then would give us zone based statistics which may be better than per node statistics for decision making about memory in a zone.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#15 lore raw
In reply to Christoph Lameter
Quoted 8 lines · Christoph Lameter
Quoted 1 line · Nick Piggin

Why not have per-node * per-cpu counters?

Yes, that is exactly what this patch implements.

Sorry, I think I meant: why don't you just use the "add all counters from all per-cpu of the node" in order to find the node-statistic?

Ie. like the node based page_state statistics that we already have.

Signature · 9 lines
SUSE Labs, Novell Inc.

Send instant messages to your online friends http://au.messenger.yahoo.com 

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#17 lore raw
Quoted 9 lines · Christoph Lameter
Quoted 2 lines · Nick Piggin

Sorry, I think I meant: why don't you just use the "add all counters from all per-cpu of the node" in order to find the node-statistic?

which function is that?

I'm thinking of get_page_state_node... but that's not quite the same thing. I guess sum all per-CPU counters from all zones in the node, but that's going to be costly on big machines.

So I'm not sure, I guess I don't have any bright ideas... there is the batching approach used by current pagecache_acct - is something like that not sufficient either?

Signature · 9 lines
SUSE Labs, Novell Inc.

Send instant messages to your online friends http://au.messenger.yahoo.com 

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#18 lore raw
Quoted 10 lines · Nick Piggin
Quoted 5 lines · Christoph Lameter
Quoted 2 lines · Nick Piggin

Sorry, I think I meant: why don't you just use the "add all counters from all per-cpu of the node" in order to find the node-statistic?

which function is that?

I'm thinking of get_page_state_node... but that's not quite the same thing. I guess sum all per-CPU counters from all zones in the node, but that's going to be costly on big machines.

The per cpu counters count when a cpu did an allocation. They do not count on which node the allocation was done and are thereofre not useful to determine the memory use on one node.

Quoted 3 lines

So I'm not sure, I guess I don't have any bright ideas... there is the batching approach used by current pagecache_acct - is something like that not sufficient either?

The framework provides a similar approach by keeping differential counters for each processor.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#19 lore raw
Quoted 13 lines · Christoph Lameter
Quoted 10 lines · Nick Piggin
Quoted 7 lines · Christoph Lameter
Quoted 2 lines · Nick Piggin

Sorry, I think I meant: why don't you just use the "add all counters from all per-cpu of the node" in order to find the node-statistic?

which function is that?

Quoted 7 lines
Quoted 3 lines

I'm thinking of get_page_state_node... but that's not quite the same thing. I guess sum all per-CPU counters from all zones in the node, but that's going to be costly on big machines.

The per cpu counters count when a cpu did an allocation. They do not count on which node the allocation was done and are thereofre not useful to determine the memory use on one node.

Yes, not that exact function of course.

Quoted 8 lines
Quoted 4 lines

So I'm not sure, I guess I don't have any bright ideas... there is the batching approach used by current pagecache_acct - is something like that not sufficient either?

The framework provides a similar approach by keeping differential counters for each processor.

But the accounting delay has the unbounded error problem that the batching approach does not.

Signature · 9 lines
SUSE Labs, Novell Inc.

Send instant messages to your online friends http://au.messenger.yahoo.com 

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#20 lore raw
Quoted 4 lines · Nick Piggin
Quoted 2 lines

The framework provides a similar approach by keeping differential counters for each processor.

But the accounting delay has the unbounded error problem that the batching approach does not.

Ok. We could switch to batching in order to avoid using the slab reaper.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>