当我使用numa_alloc_onnode()像这样在特定的NUMA节点上分配内存时:
char *ptr; if ((ptr = (char *) numa_alloc_onnode(1024,1)) == NULL) { fprintf(stderr,"Problem in %s line %d allocating memory\n",__FILE__,__LINE__); return(1); }
然后使用move_pages()来尝试确认分配的内存确实在节点1上:
printf("ptr is on node %d\n",get_node(ptr));
哪里
// This function returns the NUMA node that a pointer address resides on. int get_node(void *p) { int status[1]; void *pa; unsigned long a; // round p down to the nearest page boundary a = (unsigned long) p; a = a - (a % ((unsigned long) getpagesize())); pa = (void *) a; if (move_pages(0,1,&pa,NULL,status,0) != 0) { fprintf(stderr,"Problem in %s line %d calling move_pages()\n",__FILE__,__LINE__); abort(); } return(status[0]); }
我得到答案“ptr是在节点-2”。 从errno-base.h中,我发现2是ENOENT,而move_pages()手册页说在这种情况下-ENOENT的状态意味着“页面不存在”。
如果我用普通malloc()replacenuma_alloc_onnode()它工作正常:我得到一个节点号码。
有没有人知道这里发生了什么?
提前致谢。
numa_alloc_onnode(3)
说:
All numa memory allocation policy only takes effect when a page is actually faulted into the address space of a process by accessing it. The numa_alloc_* functions take care of this automatically.
这是否意味着你需要在内核实际给你的页面之前把东西存储到新分配的页面中?