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

后端 未结 2 1915
感情败类
感情败类 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:12

    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 a page being pointed at by ptr is checked with:

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

提交回复
热议问题