I am currently working on a NUMA system with two CPUs. The memory access time is not the same for the two CPUs.
I have used PTHREAD_SETAFFINITY_NP
to assign threads to specific CPUs:
int stick_this_thread_to_core(int core_id) {
int num_cores = sysconf(_SC_NPROCESSORS_ONLN);//number of processors
if (core_id < 0 || core_id >= num_cores)
return EINVAL;
cpu_set_t mask;
CPU_ZERO(&mask);
CPU_SET(core_id, &mask);
pthread_t current_thread = pthread_self();
return pthread_setaffinity_np(current_thread, sizeof(cpu_set_t), &mask);
}
My question is, does it also restrict the memory allocation of the thread? For example, if I malloc
in the thread running in CPU-1, will the memory be allocated in memories of CPU-1 only?