2011-11-12 26 views
3

當我使用numa_alloc_onnode()這樣一個特定的NUMA節點上分配內存:爲什麼使用numa_alloc_onnode()分配導致「頁面不存在」?

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(),它工作正常:我得到一個節點號。

有沒有人有任何想法這裏發生了什麼?

在此先感謝。

回答

3

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. 

這是否意味着你需要的東西存儲到新分配的頁內核之前,其實是給予你的頁面?

+0

你是對的。你打我12秒!事實證明,寫入分配空間(一個簡單的ptr [0] = 0;會這樣做)使上述代碼正常工作:它給了我一個節點號。看起來,閱讀不算數。在我看來,這與手冊頁相矛盾:這是一個numa_alloc_ *函數,並沒有自動處理!我在Debian Squeeze上,如果這是相關的。 –

+0

呵呵,那個'自動'讓我也困惑 - 但是後來我想起它是由一位德國內核工程師編寫的,他可能會考慮「自動設置頁面錯誤機制」。 :) – sarnold

+0

我認爲你是對的:) –

相關問題