我可以从指针地址(在 Linux 上的 C 中)获取 NUMA 节点吗? [英] Can I get the NUMA node from a pointer address (in C on Linux)?

查看:28
本文介绍了我可以从指针地址(在 Linux 上的 C 中)获取 NUMA 节点吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设置了我的代码,以便在我的 NUMA 系统上本地加载和处理数据.我认为.也就是说,出于调试目的,我真的希望能够使用在特定函数内部访问的指针地址,这些地址已由许多其他函数设置,以直接识别内存指向的 NUMA 节点正在驻留,因此我可以检查所有内容是否都位于应位于的位置.这可能吗?

I've set up my code to carefully load and process data locally on my NUMA system. I think. That is, for debugging purposes I'd really like to be able to use the pointer addresses being accessed inside a particular function, which have been set up by many other functions, to directly identify the NUMA node(s) that the memory pointed at is residing on, so I can check that everything is located where it should be located. Is this possible?

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

I found this request on msdn http://social.msdn.microsoft.com/Forums/en-US/parallelcppnative/thread/37a02e17-e160-48d9-8625-871ff6b21f72 for the same thing, but the answer uses QueryWorkingSetEx() which appears to be Windows specific. Can this be done on Linux? I'm on Debian Squeeze, to be precise.

谢谢.

推荐答案

-lnuma中有一个move_pages函数:http://linux.die.net/man/2/move_pages

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

which can report current state of address(page) to node mappings:

nodes 也可以为 NULL,在这种情况下,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.

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

So, call may be like:

 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)
", ptr_to_check, status[0], ret_code);

这篇关于我可以从指针地址(在 Linux 上的 C 中)获取 NUMA 节点吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆