Skip to content

Instantly share code, notes, and snippets.

@eerpini
Created February 18, 2015 21:53
Show Gist options
  • Save eerpini/b724820e5c3b02bfcc77 to your computer and use it in GitHub Desktop.
Save eerpini/b724820e5c3b02bfcc77 to your computer and use it in GitHub Desktop.
Get the memory at each node in a NUMA system.
#include <numa.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv){
long free;
int num_cpus = 4;
long node_size = -1L;
int i;
if(numa_available() == -1){
printf("ERROR : Numa not available on the system\n");
return EXIT_FAILURE;
}
num_cpus = numa_num_configured_cpus();
if(numa_num_configured_nodes() != num_cpus){
printf("INFO : The number of thread nodes [%d] is different from the number of thread CPUs [%d]\n",
numa_num_configured_nodes(),
num_cpus);
} else {
printf("INFO : The number of thread nodes and thread CPUs is [%d]\n",
num_cpus);
}
for(i=0;i<num_cpus; i++){
node_size = numa_node_size(i, &amp;free);
printf("INFO : CPU [%d] : Memory Available [%ld] MB, Free Memory [%ld] MB\n",
i, node_size/(1024*1024), free/(1024*1024));
}
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment