11

我已经设置了我的代码,以便在我的 NUMA 系统上小心地在本地加载和处理数据。我认为。也就是说,出于调试目的,我真的希望能够使用在特定函数内部访问的指针地址(由许多其他函数设置)来直接识别内存指向的 NUMA 节点居住在上面,所以我可以检查所有东西是否都位于它应该位于的位置。这可能吗?

我在 msdn http://social.msdn.microsoft.com/Forums/en-US/parallelcppnative/thread/37a02e17-e160-48d9-8625-871ff6b21f72上找到了这个请求,但答案使用的是 QueryWorkingSetEx()似乎是特定于 Windows 的。这可以在Linux上完成吗?准确地说,我正在使用 Debian Squeeze。

谢谢。

4

4 回答 4

21

有一个move_pages功能-lnuma: http: //linux.die.net/man/2/move_pages

它可以将地址(页面)的当前状态报告给节点映射:

nodes 也可以为 NULL,在这种情况下 move_pages() 不会移动任何页面,而是会在状态数组中返回每个页面当前所在的节点。可能需要获取每个页面的状态以确定需要移动的页面。

所以,调用可能是这样的:

 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);
于 2011-11-04T20:41:17.540 回答
11

或者,http: //linux.die.net/man/2/get_mempolicy中有一个get_mempolicy函数-lnuma:

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. 

ptr因此,通过以下方式检查所指向的页面的 numa 节点:

int numa_node = -1;
get_mempolicy(&numa_node, NULL, 0, (void*)ptr, MPOL_F_NODE | MPOL_F_ADDR);
return numa_node;
于 2013-06-07T08:25:10.763 回答
0

如果您知道 mmap 返回的地址,请尝试检查/proc/{pid}/numa_maps. 你会看到类似的东西

14ab47200000 interleave:2-3 anon=1171400 dirty=1171400 N2=585690 N3=585710 kernelpagesize_kB=4

这意味着 0x14ab47200000 地址交错到节点 2 和节点 3(N3)。查看https://linux.die.net/man/5/numa_maps了解详情。

于 2021-09-08T10:28:01.400 回答
0

在内核模式下,我们可以使用lookup_node().

于 2021-12-01T08:51:21.183 回答