为什么使用 numa_alloc_onnode() 进行分配会导致“页面不存在”?

发布于 2024-12-14 19:34:17 字数 1097 浏览 0 评论 0原文

当我使用 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() 替换 numa_alloc_onnode() ,它可以正常工作:我得到一个节点号。

有谁知道这里发生了什么事吗?

提前致谢。

When I allocate memory on a specific NUMA node using numa_alloc_onnode() like this :

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);
}

and then use move_pages() to try and confirm that the memory allocated is indeed on node 1 :

  printf("ptr is on node %d\n",get_node(ptr));

where

// 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]);

}

I get the answer "ptr is on node -2". From errno-base.h I find that 2 is ENOENT, and the move_pages() man page says that a status of -ENOENT in this context means "The page is not present".

If I replace numa_alloc_onnode() with ordinary malloc() it works fine : I get a node number.

Does anyone have any idea what's going on here?

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

郁金香雨 2024-12-21 19:34:17

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.

这是否意味着您需要在内核实际为您提供页面之前将某些内容存储到新分配的页面中?

numa_alloc_onnode(3) says:

   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.

Does this mean you need to store something into the newly-allocated page before the kernel actually gives you the page?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文