Skip to contentSkip to conversation

cyclictest: touch threadstacks on numa to pre-fault them

PATCH In review Clark Williams 2 participants 2 messages Apr 24, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cyclictest: touch threadstacks on numa to pre-fault them

On a numa system we allocate a stack from the closest NUMA node for each measurement thread. We need to touch those stack pages to prevent them faulting when first run. Not a big deal on a system with just a few cores, but overhead adds up with 32+ cores.

---
 src/cyclictest/cyclictest.c | 3 +++
 1 file changed, 3 insertions(+)
src/cyclictest/cyclictest.c +3 -0
index 5e23fc58f602..49a81f168cdb 100644
@@ -2376,6 +2376,9 @@ int main(int argc, char **argv)
 			/*  allocate memory for a stack on appropriate node */
 			stack = rt_numa_numa_alloc_onnode(stksize, node, i);
 
+			/* touch the stack pages to pre-fault them in */
+			memset(stack, 0, stksize);
+
 			/* set the thread's stack */
 			if (pthread_attr_setstack(&attr, stack, stksize))
 				fatal("failed to set stack addr for thread %d to 0x%x\n",
Signature · 1 line
2.9.3
#1 lore raw
Quoted 28 lines · Clark Williams

On a numa system we allocate a stack from the closest NUMA node for each measurement thread. We need to touch those stack pages to prevent them faulting when first run. Not a big deal on a system with just a few cores, but overhead adds up with 32+ cores.

---
 src/cyclictest/cyclictest.c | 3 +++
 1 file changed, 3 insertions(+)
src/cyclictest/cyclictest.c +3 -0
index 5e23fc58f602..49a81f168cdb 100644
@@ -2376,6 +2376,9 @@ int main(int argc, char **argv)
 			/*  allocate memory for a stack on appropriate node */
 			stack = rt_numa_numa_alloc_onnode(stksize, node, i);
 
+			/* touch the stack pages to pre-fault them in */
+			memset(stack, 0, stksize);
+
 			/* set the thread's stack */
 			if (pthread_attr_setstack(&attr, stack, stksize))
 				fatal("failed to set stack addr for thread %d to 0x%x\n",
Signature · 3 lines
2.9.3

--