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

后端 未结 2 1894
感情败类
感情败类 2020-12-01 11:48

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

2条回答
  •  醉梦人生
    2020-12-01 12:11

    There is an move_pages function in -lnuma: http://linux.die.net/man/2/move_pages

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

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

提交回复
热议问题