为什么使用numa“alloc”onnode()进行分配会导致;该页不存在;?
当我使用NUMA_alloc_onnode()在特定NUMA节点上分配内存时,如下所示:为什么使用numa“alloc”onnode()进行分配会导致;该页不存在;?,c,linux,multithreading,memory,numa,C,Linux,Multithreading,Memory,Numa,当我使用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上: p
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));
在哪里
我得到的答案是“ptr在节点-2上”。从errno base.h中,我发现2是enoint,move_pages()手册页说,在这个上下文中,-enoint的状态表示“页面不存在”
如果我用普通的malloc()替换numa_alloc_onnode(),效果很好:我得到一个节点号
有人知道这里发生了什么吗
提前感谢。numa\u alloc\u 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.
这是否意味着您需要在内核实际提供页面之前将某些内容存储到新分配的页面中?您是正确的。你赢了我12秒!事实证明,写入分配的空间(一个简单的ptr[0]=0;就可以)使上述代码按预期工作:它给我一个节点号。看来读书不算数。在我看来,这似乎与手册页相矛盾:这是一个numa_alloc_*函数,它不是自动处理的!如果相关的话,我正在使用Debian Squeeze。嘿,关于“自动”的那一点也让我感到困惑——但后来我记得它是由一位德国内核工程师写的,他可能想“自动设置页面错误机制”。)
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.