Can I get a NUMA node from a pointer address (in C on Linux)?

I installed my code to carefully download and process data locally on my NUMA system. I think. That is, for debugging purposes, I really would like to use the addresses of pointers that refer to a specific function that were set by many other functions to directly identify the NUMA node (s) that the memory is indicating what is located, so I can verify that everything is located where it should be located. Is it possible?

I found this query in msdn http://social.msdn.microsoft.com/Forums/en-US/parallelcppnative/thread/37a02e17-e160-48d9-8625-871ff6b21f72 for the same, but the answer uses QueryWorkingSetEx () which looks like windows. Can this be done on Linux? I am on Debian Squeeze, to be precise.

Thanks.

+8
c multithreading linux memory numa
source share
2 answers

-lnuma has a move_pages function: http://linux.die.net/man/2/move_pages

which can report the current state of the address (page) in the mapping node:

nodes can also be NULL, in which case move_pages () does not move any pages, but instead returns node, where each page is in this state, in an array of states. Obtaining the status of each page may be required to determine the pages to be migrated.

So the call could be like this:

  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); 
+17
source share

Alternatively, there is a get_mempolicy function in -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. 

Thus, the numa node of the page ptr points to is marked:

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

All Articles