• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

How to allocate a stack on a specific NUMA node?

Genie86

Junior Member
I would like to know if there is a way to create the stack of a thread on a specific NUMA node. I have written this code but i'm not sure if it does the trick or not.

Code:
pthread_t thread1;

int main(int argc, char**argv) {        
  pthread_attr_t attr;
  pthread_attr_init(&attr);

  char** stackarray;
  int numanode = 1;

  stackarray = (char**) numa_alloc_onnode(sizeof(char*), numanode);
  // considering that the newly 
  // created thread will be running on a core on node1

  pthread_attr_setstack(&attr, stackarray[0], 1000000);
  pthread create(&thread1, NULL, function, (void*)0);

  ...
  ...
}
Thanks
 
1. You probably want to allocate more than one pointer's worth of memory for a stack, say, 64KB instead. You're also telling pthread_attr_setstack the stack size is 1 million bytes, but you're only allocating ~8. (though numa_alloc_onnode rounds up to the page size).

2. No need to indirect though char**:
Code:
void* stack_location = numa_alloc_onnode(64*1024, numa_node);
if (NULL == stack_location) {
  ... // failure
}
if (0 == pthread_attr_setstack(&attr, stack_location, 64*1024)) {
  ... // success
} else {
  ... // failure
}
 
Back
Top