Ho eseguito il programma con privilegio di root ma continua a lamentarsi che mmap non può allocare memoria. Lo snippet di codice è qui sotto:Perché mmap non può allocare memoria?
#define PROTECTION (PROT_READ | PROT_WRITE)
#define LENGTH (4*1024)
#ifndef MAP_HUGETLB
#define MAP_HUGETLB 0x40000
#endif
#define ADDR (void *) (0x0UL)
#define FLAGS (MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB)
int main (int argc, char *argv[]){
...
// allocate a buffer with the same size as the LLC using huge pages
buf = mmap(ADDR, LENGTH, PROTECTION, FLAGS, 0, 0);
if (buf == MAP_FAILED) {
perror("mmap");
exit(1);
}
...}
Hardware: Ho 8G di RAM. Il processore è Ivybridge uscita
Uname:
Linux mymachine 3.13.0-43-generiC#72-Ubuntu SMP Mon Dec 8 19:35:06 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
EDIT 1: L'uscita del perror
mmap: Cannot allocate memory
aggiunto anche una linea per stampare errno
printf("something is wrong: %d\n", errno);
Ma l'output è:
something is wrong: 12
EDIT 2: L'enorme informazioni relative TLB da/proc/meminfo
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
hai controllato l'errore? [o] qual è l'output di 'perror()'? –
Nessun problema con il mio OSX. –
Sei sicuro del valore della tua costante 'MAP_HUGETLB'? –