Transparent Huge Pages

From: Michael Tokarev
Date: Thu Feb 07 2013 - 11:33:07 EST


Hello.

I'm trying to understand how to use transparent huge pages
(currently in x86). Before I used "explicit" huge pages
alot (mostly about hugetlbfs), but it looked like THP should
be easier so I gave it a try.

This tiny program:

----- cut -----
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <errno.h>
#include <string.h>

int main(int argc, char **argv) {
void *ptr;
size_t len = argv[1] ? atoi(argv[1]) : 1024*1024*1024;
/* no error checking! */
posix_memalign(&ptr, 2048*1024, len);
madvise(ptr, len, MADV_HUGEPAGE);
memset(ptr, 0, len);
usleep(500); /* let khugepagesd do its work */
system("grep ^AnonHugePages: /proc/meminfo");
return 0;
}
----- cut -----

which just tries to allocate some amount of RAM (1Gb by default)
aligned to 2Mb, uses madvise(HUGEPAGE) on it, and checks
/proc/meminfo for AnonHugePages.

The problem is: I've never seen any value for AnonHugePages
larger than about 16Mb. Usually it is around 10Mb or 8Mb,
no matter how large the requested memory size is, including
the default 1Gb.

The question, obviously, is: why so small?

My system (which is a few years old now) has 6Gb of RAM,
it uses AMD Athlon II X2 260 CPU, and is running 3.2
kernel.

Original question comes from grounds of of QEMU, which is
supposed to use THP for guest memory, but it also does not
use more than these ~10Mb, when allocating 1Gb to the guest.

Thanks!

/mjt
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/