Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么使用numa“alloc”onnode()进行分配会导致;该页不存在;?_C_Linux_Multithreading_Memory_Numa - Fatal编程技术网

为什么使用numa“alloc”onnode()进行分配会导致;该页不存在;?

为什么使用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

当我使用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));
在哪里

我得到的答案是“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.