2011-11-02 58 views
8

我已經設置了我的代碼,在我的NUMA系統上本地謹慎加載和處理數據。我認爲。也就是說,爲了調試的目的,我真的希望能夠使用指針地址在一個特定的函數中被訪問,這個函數已經被很多其他函數設置,以直接識別內存指向的NUMA節點正在居住,所以我可以檢查一切都位於它應該位於的地方。這可能嗎?我可以從指針地址(Linux上的C)獲取NUMA節點嗎?

我在msdn http://social.msdn.microsoft.com/Forums/en-US/parallelcppnative/thread/37a02e17-e160-48d9-8625-871ff6b21f72上發現了同樣的請求,但答案使用了QueryWorkingSetEx(),它似乎是Windows特有的。這可以在Linux上完成嗎?我在Debian Squeeze上,確切地說。

謝謝。

回答

16

有一個move_pages功能-lnumahttp://linux.die.net/man/2/move_pages

可舉報地址(頁)的當前狀態到節點的映射:

nodes can also be NULL, in which case move_pages() does not move any pages but instead will return the node where each page currently resides, in the status array. Obtaining the status of each page may be necessary to determine pages that need to be moved.

所以,呼叫可能是這樣:

void * ptr_to_check = your_address; 
/*here you should align ptr_to_check to page boundary */ 
int status[1]; 
int ret_code; 
status[0]=-1; 
ret_code=move_pages(0 /*self memory */, 1, &ptr_to_check, 
    NULL, status, 0); 
printf("Memory at %p is at %d node (retcode %d)\n", ptr_to_check, status[0], ret_code); 
+0

使用你的答案我碰到一個「致命的錯誤:numaif.h:沒有這樣的文件或目錄」。你知道什麼是錯的嗎? – klm123

+1

好的。我知道了。 glibc不包含頭文件,但需要安裝libnuma-devel或類似的軟件包。 – klm123

6

或者,get_mempolicy功能-lnuma:http://linux.die.net/man/2/get_mempolicy

If flags specifies both MPOL_F_NODE and MPOL_F_ADDR, get_mempolicy() will 
return the node ID of the node on which the address addr is allocated into 
the location pointed to by mode. If no page has yet been allocated for the 
specified address, get_mempolicy() will allocate a page as if the process had 
performed a read [load] access to that address, and return the ID of the node 
where that page was allocated. 

因此,一個頁面的NUMA節點正指向由ptr檢查有:

int numa_node = -1; 
get_mempolicy(&numa_node, NULL, 0, (void*)ptr, MPOL_F_NODE | MPOL_F_ADDR); 
return numa_node;