Skip to contentSkip to conversation

On numa interfaces and stuff

PATCH Peter Zijlstra 3 participants 3 messages Nov 17, 2011 – Jan 27, 2012

Subsystems (6)
lore
Share & tools
lore

Peter Zijlstra

author maintainer
#0 lore raw

Hi,

I promised to send this out way sooner, but here goes.

So the problem is that our current NUMA scheduling and control interfaces all suck. On the scheduling side we have no clue as to where our memory resides, esp. interesting for threaded applications.

For the control interfaces we only have stuff that allows hard pinning to physical topology, but nothing useful if you don't want to have to manage your applications by hand or have all applications talk to each other through some common middle-ware.

So there's two things we need to do, fix up our defaults, and the simple way to do this is by simply assigning a (mem) node to an application and when we find the tasks are predominantly running away from the home node migrate everything over to another node, including full memory migration.

We also need to provide a new NUMA interface that allows (threaded) applications to specify what they want. The below patch outlines such an interface although the patch is very much incomplete and uncompilable, I guess its complete enough to illustrate the idea.

The abstraction proposed is that of coupling threads (tasks) with virtual address ranges (vmas) and guaranteeing they are all located on the same node. This leaves the kernel in charge of where to place all that and gives it the freedom to move them around, as long as the threads and v-ranges stay together.

A typical use for this would be HPC where the compute threads and v-space want to stay on the node, but starting multiple jobs will allow the kernel to balance resources properly etc.

Another use-case would be kvm/qemu like things where you group vcpus and v-space to provide virtual numa nodes to the guest OS.

I spoke to a number of people in Prague and PJT wanted to merge the task grouping the below does into cgroups, preferably the cpu controller I think. The advantage of doing so is that it removes a duplicate layer of accounting, the dis-advantage however is that it entangles it with the cpu-controller in that you might not want the threads you group to be scheduled differently etc. Also it would restrict the functionality to a cgroup enabled kernel only.

AA mentioned wanting to run a pte scanner to dynamically find the numa distribution of tasks, although I think assigning them to a particular node and assuming they all end up there is simpler (and less overhead). If your application is large enough to not fit on a single node you've got to manually interfere anyway if you care about performance.

As to memory migration (and I think a comment in the below patch refers to it) we can unmap and lazy migrate on fault. Alternatively AA mentioned a background process that trickle migrates everything. I don't really like the latter option since it hides the work/overhead in yet another opaque kernel thread.

Anyway, there were plenty of ideas and I think we need to start forming a consensus as to what we want to do before we continue much further with writing code or so.. who knows. Then again, writing stuff to find out what doesn't work is useful too :-)

---
 include/linux/mempolicy.h |    8 +
 include/linux/memsched.h  |   27 ++
 include/linux/sched.h     |    5 +-
 kernel/exit.c             |    1 +
 kernel/fork.c             |    7 +-
 kernel/memsched.c         | 1003 +++++++++++++++++++++++++++++++++++++++++++++
 kernel/sched.c            |   16 +-
 kernel/sched_fair.c       |    8 +-
 kernel/sched_rt.c         |    1 +
 mm/mempolicy.c            |   14 +
 mm/mmap.c                 |   18 +-
 11 files changed, 1087 insertions(+), 21 deletions(-)
include/linux/mempolicy.h +8 -0
index 7978eec..26799c8 100644
@@ -68,6 +68,8 @@ enum mpol_rebind_step {
 #include <linux/spinlock.h>
 #include <linux/nodemask.h>
 #include <linux/pagemap.h>
+#include <linux/list.h>
+#include <linux/memsched.h>
 
 struct mm_struct;
 
@@ -99,6 +101,9 @@ struct mempolicy {
 	atomic_t refcnt;
 	unsigned short mode; 	/* See MPOL_* above */
 	unsigned short flags;	/* See set_mempolicy() MPOL_F_* above */
+	struct memsched_struct *memsched;
+	struct vm_area_struct *vma;
+	struct list_head memsched_entry;
 	union {
 		short 		 preferred_node; /* preferred */
 		nodemask_t	 nodes;		/* interleave/bind */
@@ -158,6 +163,8 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
 #define vma_policy(vma) ((vma)->vm_policy)
 #define vma_set_policy(vma, pol) ((vma)->vm_policy = (pol))
 
+int vma_dup_policy(struct vm_area_struct *new, struct vm_area_struct *old);
+
 static inline void mpol_get(struct mempolicy *pol)
 {
 	if (pol)
@@ -311,6 +318,7 @@ mpol_shared_policy_lookup(struct shared_policy *sp, unsigned long idx)
 
 #define vma_policy(vma) NULL
 #define vma_set_policy(vma, pol) do {} while(0)
+#define vma_dup_policy(new, old) (0)
 
 static inline void numa_policy_init(void)
 {
include/linux/memsched.h +27 -0
index e69de29..6a0fd5a 100644
@@ -0,0 +1,27 @@
+#ifndef _LINUX_MEMSCHED_H
+#define _LINUX_MEMSCHED_H
+
+struct task_struct;
+struct vm_area_struct;
+
+#ifdef CONFIG_NUMA
+
+extern void memsched_cpu_weight_update(struct task_struct *p, unsigned long);
+extern void memsched_cpu_acct_wait(struct task_struct *, u64, u64);
+extern void memsched_task_exit(struct task_struct *);
+extern void memsched_vma_link(struct vm_area_struct *, struct vm_area_struct *);
+extern void memsched_vma_adjust(struct vm_area_struct *, unsigned long, unsigned long);
+extern void memsched_vma_unlink(struct vm_area_struct *);
+
+#else /* CONFIG_NUMA */
+
+static inline void memsched_cpu_weight_update(struct task_struct *p, unsigned long) { };
+static inline void memsched_cpu_acct_wait(struct task_struct *, u64, u64) { };
+static inline void memsched_task_exit(struct task_struct *) { };
+static inline void memsched_vma_link(struct vm_area_struct *, struct vm_area_struct *) { };
+static inline void memsched_vma_adjust(struct vm_area_struct *, unsigned long, unsigned long) { };
+static inline void memsched_vma_unlink(struct vm_area_struct *) { };
+
+#endif /* CONFIG_NUMA */
+
+#endif /* _LINUX_MEMSCHED_H */
include/linux/sched.h +4 -1
index f3c5273..20c09e8 100644
@@ -1133,7 +1133,7 @@ struct load_weight {
 
 #ifdef CONFIG_SCHEDSTATS
 struct sched_statistics {
-	u64			wait_start;
+	u64			wait_start; // XXX kill me
 	u64			wait_max;
 	u64			wait_count;
 	u64			wait_sum;
@@ -1174,6 +1174,7 @@ struct sched_entity {
 	unsigned int		on_rq;
 
 	u64			exec_start;
+	u64			wait_start; // XXX remove statistics::wait_start
 	u64			sum_exec_runtime;
 	u64			vruntime;
 	u64			prev_sum_exec_runtime;
@@ -1512,6 +1513,8 @@ struct task_struct {
 	struct mempolicy *mempolicy;	/* Protected by alloc_lock */
 	short il_next;
 	short pref_node_fork;
+	struct list_entry memsched_entry;
+	struct memsched_struct *memsched;
 #endif
 	struct rcu_head rcu;
 
kernel/exit.c +1 -0
index 2913b35..aa07540 100644
@@ -1014,6 +1014,7 @@ NORET_TYPE void do_exit(long code)
 	mpol_put(tsk->mempolicy);
 	tsk->mempolicy = NULL;
 	task_unlock(tsk);
+	memsched_task_exit(tsk);
 #endif
 #ifdef CONFIG_FUTEX
 	if (unlikely(current->pi_state_cache))
kernel/fork.c +3 -4
index 8e6b6f4..21f4c20 100644
@@ -365,11 +365,9 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
 			goto fail_nomem;
 		*tmp = *mpnt;
 		INIT_LIST_HEAD(&tmp->anon_vma_chain);
-		pol = mpol_dup(vma_policy(mpnt));
-		retval = PTR_ERR(pol);
-		if (IS_ERR(pol))
+		retval = vma_dup_policy(tmp, mpnt);
+		if (retval)
 			goto fail_nomem_policy;
-		vma_set_policy(tmp, pol);
 		tmp->vm_mm = mm;
 		if (anon_vma_fork(tmp, mpnt))
 			goto fail_nomem_anon_vma_fork;
@@ -431,6 +429,7 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
 	up_write(&oldmm->mmap_sem);
 	return retval;
 fail_nomem_anon_vma_fork:
+	memsched_vma_unlink(tmp);
 	mpol_put(pol);
 fail_nomem_policy:
 	kmem_cache_free(vm_area_cachep, tmp);
kernel/memsched.c +1003 -0

1,003 lines not on this page · raw message

kernel/sched.c +10 -6
index 24637c7..38d603b 100644
@@ -71,6 +71,7 @@
 #include <linux/ctype.h>
 #include <linux/ftrace.h>
 #include <linux/slab.h>
+#include <linux/memsched.h>
 
 #include <asm/tlb.h>
 #include <asm/irq_regs.h>
@@ -1924,19 +1925,22 @@ static void dec_nr_running(struct rq *rq)
 static void set_load_weight(struct task_struct *p)
 {
 	int prio = p->static_prio - MAX_RT_PRIO;
-	struct load_weight *load = &p->se.load;
+	struct load_weight load;
 
 	/*
 	 * SCHED_IDLE tasks get minimal weight:
 	 */
 	if (p->policy == SCHED_IDLE) {
-		load->weight = scale_load(WEIGHT_IDLEPRIO);
-		load->inv_weight = WMULT_IDLEPRIO;
-		return;
+		load.weight = scale_load(WEIGHT_IDLEPRIO);
+		load.inv_weight = WMULT_IDLEPRIO;
+	} else {
+		load.weight = scale_load(prio_to_weight[prio]);
+		load.inv_weight = prio_to_wmult[prio];
 	}
 
-	load->weight = scale_load(prio_to_weight[prio]);
-	load->inv_weight = prio_to_wmult[prio];
+	memsched_cpu_weight_update(p, load.weight);
+
+       	p->se.load = load;
 }
 
 static void enqueue_task(struct rq *rq, struct task_struct *p, int flags)
kernel/sched_fair.c +6 -2
index 5c9e679..6201ea1 100644
@@ -598,6 +598,7 @@ static void update_curr(struct cfs_rq *cfs_rq)
 		trace_sched_stat_runtime(curtask, delta_exec, curr->vruntime);
 		cpuacct_charge(curtask, delta_exec);
 		account_group_exec_runtime(curtask, delta_exec);
+		memsched_cpu_acct(curtask, delta_exec);
 	}
 
 	account_cfs_rq_runtime(cfs_rq, delta_exec);
@@ -607,6 +608,7 @@ static inline void
 update_stats_wait_start(struct cfs_rq *cfs_rq, struct sched_entity *se)
 {
 	schedstat_set(se->statistics.wait_start, rq_of(cfs_rq)->clock);
+	se->wait_start = rq_of(cfs_rq)->clock_task;
 }
 
 /*
@@ -630,12 +632,14 @@ update_stats_wait_end(struct cfs_rq *cfs_rq, struct sched_entity *se)
 	schedstat_set(se->statistics.wait_count, se->statistics.wait_count + 1);
 	schedstat_set(se->statistics.wait_sum, se->statistics.wait_sum +
 			rq_of(cfs_rq)->clock - se->statistics.wait_start);
-#ifdef CONFIG_SCHEDSTATS
 	if (entity_is_task(se)) {
+#ifdef CONFIG_SCHEDSTATS
 		trace_sched_stat_wait(task_of(se),
 			rq_of(cfs_rq)->clock - se->statistics.wait_start);
-	}
 #endif
+		memsched_cpu_acct_wait(task_of(se), 
+				rq_of(cfs_rq)->clock_task, se->wait_start);
+	}
 	schedstat_set(se->statistics.wait_start, 0);
 }
 
kernel/sched_rt.c +1 -0
index 056cbd2..4a05003 100644
@@ -690,6 +690,7 @@ static void update_curr_rt(struct rq *rq)
 
 	curr->se.exec_start = rq->clock_task;
 	cpuacct_charge(curr, delta_exec);
+	memsched_cpu_acct(curr, delta_exec);
 
 	sched_rt_avg_update(rq, delta_exec);
 
mm/mempolicy.c +14 -0
index 9c51f9f..4c38c91 100644
@@ -623,6 +623,8 @@ static int policy_vma(struct vm_area_struct *vma, struct mempolicy *new)
 	if (!err) {
 		mpol_get(new);
 		vma->vm_policy = new;
+		memsched_vma_link(vma, NULL);
+		memsched_vma_unlink(old);
 		mpol_put(old);
 	}
 	return err;
@@ -1951,6 +1953,18 @@ struct mempolicy *__mpol_dup(struct mempolicy *old)
 	return new;
 }
 
+int vma_dup_policy(struct vm_area_struct *new, struct vm_area_struct *old)
+{
+	struct mempolicy *mpol;
+
+	mpol = mpol_dup(vma_policy(old));
+	if (IS_ERR(mpol))
+		return PTR_ERR(mpol);
+	vma_set_policy(new, mpol);
+	memsched_vma_link(new, old);
+	return 0;
+}
+
 /*
  * If *frompol needs [has] an extra ref, copy *frompol to *tompol ,
  * eliminate the * MPOL_F_* flags that require conditional ref and
mm/mmap.c +10 -8
index a65efd4..50e05f6 100644
@@ -235,6 +235,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
 		if (vma->vm_flags & VM_EXECUTABLE)
 			removed_exe_file_vma(vma->vm_mm);
 	}
+	memsched_vma_unlink(vma);
 	mpol_put(vma_policy(vma));
 	kmem_cache_free(vm_area_cachep, vma);
 	return next;
@@ -579,10 +580,13 @@ again:			remove_next = 1 + (end > next->vm_end);
 			vma_prio_tree_remove(next, root);
 	}
 
+	memsched_vma_adjust(vma, start, end);
 	vma->vm_start = start;
 	vma->vm_end = end;
 	vma->vm_pgoff = pgoff;
 	if (adjust_next) {
+		memsched_vma_adjust(vma, next->vm_start + (adjust_next << PAGE_SHIFT),
+					 next->vm_end);
 		next->vm_start += adjust_next << PAGE_SHIFT;
 		next->vm_pgoff += adjust_next;
 	}
@@ -625,6 +629,7 @@ again:			remove_next = 1 + (end > next->vm_end);
 		if (next->anon_vma)
 			anon_vma_merge(vma, next);
 		mm->map_count--;
+		memsched_vma_unlink(next);
 		mpol_put(vma_policy(next));
 		kmem_cache_free(vm_area_cachep, next);
 		/*
@@ -1953,12 +1958,9 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
 		new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
 	}
 
-	pol = mpol_dup(vma_policy(vma));
-	if (IS_ERR(pol)) {
-		err = PTR_ERR(pol);
+	err = vma_dup_policy(new, vma);
+	if (err)
 		goto out_free_vma;
-	}
-	vma_set_policy(new, pol);
 
 	if (anon_vma_clone(new, vma))
 		goto out_free_mpol;
@@ -1992,6 +1994,7 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
 	}
 	unlink_anon_vmas(new);
  out_free_mpol:
+	memsched_vma_unlock(new);
 	mpol_put(pol);
  out_free_vma:
 	kmem_cache_free(vm_area_cachep, new);
@@ -2344,13 +2347,11 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
 		new_vma = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
 		if (new_vma) {
 			*new_vma = *vma;
-			pol = mpol_dup(vma_policy(vma));
-			if (IS_ERR(pol))
+			if (vma_dup_policy(new_vma, vma))
 				goto out_free_vma;
 			INIT_LIST_HEAD(&new_vma->anon_vma_chain);
 			if (anon_vma_clone(new_vma, vma))
 				goto out_free_mempol;
-			vma_set_policy(new_vma, pol);
 			new_vma->vm_start = addr;
 			new_vma->vm_end = addr + len;
 			new_vma->vm_pgoff = pgoff;
@@ -2367,6 +2368,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
 	return new_vma;
 
  out_free_mempol:
+	memsched_vma_unlink(new_vma);
 	mpol_put(pol);
  out_free_vma:
 	kmem_cache_free(vm_area_cachep, new_vma);

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#1 lore raw
Quoted 5 lines · Peter Zijlstra

The abstraction proposed is that of coupling threads (tasks) with virtual address ranges (vmas) and guaranteeing they are all located on the same node. This leaves the kernel in charge of where to place all that and gives it the freedom to move them around, as long as the threads and v-ranges stay together.

I believe this abstraction makes sense.

Programs that are small enough to fit in one NUMA node do not need any modification, since the default could just be to keep all memory and threads together.

With unmap & migrate-on-fault, we can make a reasonable attempt at leaving behind the memory that is not part of the working set if the programs running on one NUMA node do not quite fit on that node memory-wise.

I expect we will always have some unbalance here, because we cannot expect memory and CPU use for programs to correspond in a predictable way. Some small programs may use lots of CPU, and some large memory programs may use less CPU.

Quoted 6 lines

A typical use for this would be HPC where the compute threads and v-space want to stay on the node, but starting multiple jobs will allow the kernel to balance resources properly etc.

Another use-case would be kvm/qemu like things where you group vcpus and v-space to provide virtual numa nodes to the guest OS.

Databases, Java and any other workload with long-running workloads are a good candidate, too.

Quoted 8 lines

I spoke to a number of people in Prague and PJT wanted to merge the task grouping the below does into cgroups, preferably the cpu controller I think. The advantage of doing so is that it removes a duplicate layer of accounting, the dis-advantage however is that it entangles it with the cpu-controller in that you might not want the threads you group to be scheduled differently etc. Also it would restrict the functionality to a cgroup enabled kernel only.

Quoted 7 lines

AA mentioned wanting to run a pte scanner to dynamically find the numa distribution of tasks, although I think assigning them to a particular node and assuming they all end up there is simpler (and less overhead).

If your application is large enough to not fit on a single node you've got to manually interfere anyway if you care about performance.

There are two cases here.

If the application is multi-threaded and needs more CPUs than what are available on one NUMA node, using your APIs to bind threads to memory areas is obviously the way to go.

For programs that do not use all their memory simultaneously and do not use as many CPUs, unmap & migrate-on-fault may well "catch" the working set on the same node where the threads are running, leaving less used memory elsewhere.

Quoted 5 lines

As to memory migration (and I think a comment in the below patch refers to it) we can unmap and lazy migrate on fault. Alternatively AA mentioned a background process that trickle migrates everything. I don't really like the latter option since it hides the work/overhead in yet another opaque kernel thread.

There's something to be said for both approaches.

On the one hand, doing unmap & migrate-on-fault with 2MB pages could be slow. Especially if memory on the destination side needs to be compacted/defragmented first!

Andrea and I talked about some ideas to reduce the latency of compacting memory. I will try those ideas out soon, to see if they are realistic and make enough of a difference.

On the other hand, moving the memory that is not in the working set is not only extra overhead, but it could even be counter-productive, since it can take away space from the memory that IS the working set.

Since most of the code will be the stuff that does the actual mechanism of migration, we should be able to just experiment with both for a while.

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#2 lore raw

AutoNUMA alpha3 microbench [Re: On numa interfaces and stuff]

In reply to Peter Zijlstra

Hi everyone,

Quoted 10 lines · Peter Zijlstra

We also need to provide a new NUMA interface that allows (threaded) applications to specify what they want. The below patch outlines such an interface although the patch is very much incomplete and uncompilable, I guess its complete enough to illustrate the idea.

The abstraction proposed is that of coupling threads (tasks) with virtual address ranges (vmas) and guaranteeing they are all located on the same node. This leaves the kernel in charge of where to place all that and gives it the freedom to move them around, as long as the threads and v-ranges stay together.

I think expecting all apps to be modified to run a syscall after every allocation to tell which thread will access which memory is unreasonable (and I'm hopeful that's not needed).

Also not sure what you will do when N threads are sharing the same memory and N is more than the CPUs in one node.

Another problem is that for the very large apps with tons of threads on very large systems, you risk to fragment the vma too much and get -ENOMEM, or in the best case slowdown the vma lookups significantly if you'll build up a zillon of vmas.

None of the above issues are a concern for qemu-kvm of course, but you still have to use the syscalls in guest or you're back to use cpusets or other forms of hard binds in guest. It may work for guests that fits in one node of course, but those are the easiest to get right for autonuma. If the guest fits in one node, syscalls or not syscalls is the same as you're back to square one: the syscall in that case would ask the kernel to keep all vcpus access all guest memory as the vtopology is the identity, so what's the point?

In the meantime I've got autonuma (total automatic NUMA scheduler and memory migration) fully working, to the point I'm quite happy about it (with what I tested so far at least...). I've yet to benchmark it extensively for mixed real life workloads but I tested it a lot on the microbenchmarks that tends to stress the NUMA effects in similar to real life scenarios (they however tends to trash the CPU caches much more than real life apps).

The code is still dirty so I just need to start cleaning it up (now that I'm happy about the math :), add sysfs, add native THP migration. At the moment THP is split, so it works fine and it's recreated by khugepaged, but I prefer not to split in the future. The benchmarks are run with THP off just in case (not necessairly because it was faster that way, I didn't bother to benchmark it with THP yet, I only verified it's stable).

Sharing code at this point while possible with a large raw diff, may not be so easy to read and it's still going to change significantly as I'm in the clean up process :). Reviewing it for bugs also not worth it at this point.

But I'd like to share at least the results I got so far and that makes me slightly optimistic that it can work well, especially if you will help me improve it over time. The testcases source is attached (not so clean too I know but they're just quick testcases..). They're tuned to run on 24-way 2 sockets 2 nodes with 8G per node.

Note that the hard bind case don't do any memory migration and allocates the memory in the right place immediately. autonuma is the only case where any memory migration happens in the benchmark, so it's immpossible for autonuma to perform exactly the same as hard bindings no matter what. (I also have an initial placement logic that gets us closer to hard bindings in the numa01 first bench, only if you disable -DNO_BIND_FORCE_SAME_NODE of course, but that logic is disabled in this benchmark because I feel it's not generic enough, and anyway I built numa01 with -DNO_BIND_FORCE_SAME_NODE to ensure to start with the worst possible memory placement even when I had that logic enabled, otherwise if the initial placement is right no memory migration would run anymore at all as autonuma would agree then)

I'm afraid my current implementation may not be too good if there's a ton of CPU overcommit, to avoid regressing the scheduler to O(N) (and to avoid being too intrusive on the scheduler code too) but that should be doable in the future. But note that the last bench has a x2 overcommit (48 threads on 24 CPUs) and it still does close to the hard bindings so it kind of works well there too. I suspect it'll gradually get worse if you overcommit 10 or 100 times every CPU (but ideally not worse than no autonuma).

When booted on not-NUMA systems the overhead (after I will clean it up) will become 1 pointer in mm_struct and 1 pointer in task_struct, and no more than that. On NUMA systems where it will activate, the memory overhead is still fairly low (comparable to memcg). It will also be possible to shut off all the runtime CPU overhead totally (freeing all memory at runtime it's a lot more tricky, booting with noautonuma will be possible to avoid the memory overhead though). The whole thing is activated a single knuma_scand damon, stop that and it runs identical to upstream.

If you modify the testcases to run your new NUMA affinity syscalls and compare your results that would be interesting to see. For example the numa01 benchmark compiled with -DNO_BIND_FORCE_SAME_NODE will allow you to first allocate all ram of both "mm" in the same node, then return to MPOL_DEFAULT and then run your syscalls to verify the performance of your memory migration and NUMA node scheduler placement vs mine. Of course for these benchmarks you want to keep it on the aggressive side so it will converge to the point where migration stops within 10-30 sec from startup (in real life the processes won't quit after a few min so the migration rate can be much lower).

http://www.kernel.org/pub/linux/kernel/people/andrea/autonuma/autonuma_bench-20120126.pdf

Thanks,
Andrea

/*
* Copyright (C) 2012 Red Hat, Inc.
*
* This work is licensed under the terms of the GNU GPL, version 2. See
* the COPYING file in the top-level directory.
*/

#define _GNU_SOURCE
#include <pthread.h>
#include <strings.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <numaif.h>
#include <sched.h>
#include <time.h>
#include <sys/wait.h>
#include <sys/file.h>

//#define KVM
#ifndef KVM
#define THREADS 12
#define SIZE (3UL*1024*1024*1024)
#else
#define THREADS 4
#define SIZE (200*1024*1024)
#endif
//#define THREAD_ALLOC
#ifdef THREAD_ALLOC
#define THREAD_SIZE (SIZE/THREADS)
#else
#define THREAD_SIZE SIZE
#endif
//#define HARD_BIND
//#define INVERSE_BIND
//#define NO_BIND_FORCE_SAME_NODE

static char *p_global;
static unsigned long nodemask_global;

void *thread(void * arg)

{
	char *p = arg;
	int i;
#ifndef KVM
#ifndef THREAD_ALLOC
	int nr = 50;
#else
	int nr = 1000;
#endif
#else
	int nr = 500;
#endif
#ifdef NO_BIND_FORCE_SAME_NODE
	if (set_mempolicy(MPOL_BIND, &nodemask_global, 3) < 0)
		perror("set_mempolicy"), printf("%lu\n", nodemask_global),
			exit(1);
#endif
	bzero(p_global, SIZE);
#ifdef NO_BIND_FORCE_SAME_NODE
	if (set_mempolicy(MPOL_DEFAULT, NULL, 3) < 0)
		perror("set_mempolicy"), exit(1);
#endif
	for (i = 0; i < nr; i++) {
#if 1
		bzero(p, THREAD_SIZE);
#else
		memcpy(p, p+THREAD_SIZE/2, THREAD_SIZE/2);
#endif
		asm volatile("" : : : "memory");
	}
	return NULL;
}

int main()

{
	int i;
	pthread_t pthread[THREADS];
	char *p;
	pid_t pid;
	cpu_set_t cpumask;
	int f;
	unsigned long nodemask;

	nodemask_global = (time(NULL) & 1) + 1;
	f = creat("lock", 0400);
	if (f < 0)
		perror("creat"), exit(1);
	if (unlink("lock") < 0)
		perror("unlink"), exit(1);

	if ((pid = fork()) < 0)
		perror("fork"), exit(1);

	p_global = p = malloc(SIZE);
	if (!p)
		perror("malloc"), exit(1);
	CPU_ZERO(&cpumask);
	if (!pid) {
		nodemask = 1;
		for (i = 0; i < 6; i++)
			CPU_SET(i, &cpumask);
#if 1
		for (i = 12; i < 18; i++)
			CPU_SET(i, &cpumask);
#else
		for (i = 6; i < 12; i++)
			CPU_SET(i, &cpumask);
#endif
	} else {
		nodemask = 2;
		for (i = 6; i < 12; i++)
			CPU_SET(i, &cpumask);
		for (i = 18; i < 24; i++)
			CPU_SET(i, &cpumask);
	}
#ifdef INVERSE_BIND
	if (nodemask == 1)
		nodemask = 2;
	else if (nodemask == 2)
		nodemask = 1;
#endif
#if 0
	if (pid)
		goto skip;
#endif
#ifdef HARD_BIND
	if (sched_setaffinity(0, sizeof(cpumask), &cpumask) < 0)
		perror("sched_setaffinity"), exit(1);
#endif
#ifdef HARD_BIND
	if (set_mempolicy(MPOL_BIND, &nodemask, 3) < 0)
		perror("set_mempolicy"), printf("%lu\n", nodemask), exit(1);
#endif
#if 0
	bzero(p, SIZE);
#endif
	for (i = 0; i < THREADS; i++) {
		char *_p = p;
#ifdef THREAD_ALLOC
		_p += THREAD_SIZE * i;
#endif
		if (pthread_create(&pthread[i], NULL, thread, _p) != 0)
			perror("pthread_create"), exit(1);
	}
	for (i = 0; i < THREADS; i++)
		if (pthread_join(pthread[i], NULL) != 0)
			perror("pthread_join"), exit(1);
#if 1
skip:
#endif
	if (pid)
		if (wait(NULL) < 0)
			perror("wait"), exit(1);
	return 0;
}

/*
* Copyright (C) 2012 Red Hat, Inc.
*
* This work is licensed under the terms of the GNU GPL, version 2. See
* the COPYING file in the top-level directory.
*/

#define _GNU_SOURCE
#include <pthread.h>
#include <strings.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <numaif.h>
#include <sched.h>
#include <sys/wait.h>
#include <sys/file.h>

#if 1
#define THREADS 24
#define SIZE (1UL*1024*1024*1024)
#else
#define THREADS 8
#define SIZE (500*1024*1024)
#endif
#define TOTALSIZE (4UL*1024*1024*1024*200)
#define THREAD_SIZE (SIZE/THREADS)
//#define HARD_BIND
//#define INVERSE_BIND

static void *thread(void * arg)

{
	char *p = arg;
	int i;
	for (i = 0; i < TOTALSIZE/SIZE; i++) {
		bzero(p, THREAD_SIZE);
		asm volatile("" : : : "memory");
	}
	return NULL;
}

#ifdef HARD_BIND
static void bind(int node)

{
	int i;
	unsigned long nodemask;
	cpu_set_t cpumask;
	CPU_ZERO(&cpumask);
	if (!node) {
		nodemask = 1;
		for (i = 0; i < 6; i++)
			CPU_SET(i, &cpumask);
		for (i = 12; i < 18; i++)
			CPU_SET(i, &cpumask);
	} else {
		nodemask = 2;
		for (i = 6; i < 12; i++)
			CPU_SET(i, &cpumask);
		for (i = 18; i < 24; i++)
			CPU_SET(i, &cpumask);
	}
	if (sched_setaffinity(0, sizeof(cpumask), &cpumask) < 0)
		perror("sched_setaffinity"), exit(1);
	if (set_mempolicy(MPOL_BIND, &nodemask, 3) < 0)
		perror("set_mempolicy"), printf("%lu\n", nodemask), exit(1);
}

#else
static void bind(int node) {}
#endif

int main()

{
	int i;
	pthread_t pthread[THREADS];
	char *p;
	pid_t pid;
	int f;

	p = malloc(SIZE);
	if (!p)
		perror("malloc"), exit(1);
	bind(0);
	bzero(p, SIZE/2);
	bind(1);
	bzero(p+SIZE/2, SIZE/2);
	for (i = 0; i < THREADS; i++) {
		char *_p = p + THREAD_SIZE * i;
#ifdef INVERSE_BIND
		bind(i < THREADS/2);
#else
		bind(i >= THREADS/2);
#endif
		if (pthread_create(&pthread[i], NULL, thread, _p) != 0)
			perror("pthread_create"), exit(1);
	}
	for (i = 0; i < THREADS; i++)
		if (pthread_join(pthread[i], NULL) != 0)
			perror("pthread_join"), exit(1);
	return 0;
}