2011-11-02 9 views
8

Ho impostato il mio codice per caricare ed elaborare i dati in modo locale sul mio sistema NUMA. Credo. Cioè, per scopi di debug mi piacerebbe davvero essere in grado di utilizzare gli indirizzi puntatore a cui si accede all'interno di una particolare funzione, che sono state impostate da molte altre funzioni, per identificare direttamente i nodi NUMA che la memoria indicava è residente, quindi posso verificare che tutto si trovi dove dovrebbe essere localizzato. È possibile?Posso ottenere il nodo NUMA da un indirizzo puntatore (in C su Linux)?

Ho trovato questa richiesta su msdn http://social.msdn.microsoft.com/Forums/en-US/parallelcppnative/thread/37a02e17-e160-48d9-8625-871ff6b21f72 per la stessa cosa, ma la risposta utilizza QueryWorkingSetEx() che sembra essere specifica di Windows. Questo può essere fatto su Linux? Sono su Debian Squeeze, per essere precisi.

Grazie.

risposta

16

C'è una funzione move_pages in -lnuma: http://linux.die.net/man/2/move_pages

che può segnalare lo stato attuale delle indirizzo (pagina) per nodo mappature:

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.

Quindi, chiamata può essere come:

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); 
+0

Utilizzando la risposta ottengo "fatale errore: numaif.h: No such file or directory". Hai un'idea di cosa c'è che non va? – klm123

+1

Ok. Capito. L'intestazione non è inclusa con glibc, ma richiede l'installazione di libnuma-devel o di un pacchetto simile. – klm123

6

In alternativa, c'è una funzione get_mempolicy 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. 

Così, il nodo NUMA di una pagina che è puntato da ptr viene controllata con:

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