3

次のように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のステータスは「ページが存在しない」ことを意味すると記載されています。

numa_alloc_onnode()を通常のmalloc()に置き換えると、正常に機能します。ノード番号を取得します。

ここで何が起こっているのか誰かが知っていますか?

前もって感謝します。

4

1 に答える 1

4

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.

これは、カーネルが実際にページを提供する前に、新しく割り当てられたページに何かを格納する必要があるということですか?

于 2011-11-12T01:15:29.113 に答える