I have Linux THP enabled for all processes:
cat /sys/kernel/mm/transparent_hugepage/enabled
[always] madvise never
echo 1024 | tee /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages
But seems that my example code which allocetes and uses more than 100Mb (supposedly over 50 2MB huge pages) doesn't use huge pages at all and uses regular pages:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define SIZE 1024*1024*100
int main(void)
{
char *buf = malloc(SIZE);
memset(buf, 'A', SIZE);
for (;;) {
printf("%p\n", buf);
sleep(1);
}
}
Before and after starting this example I see the static picture wtih grep HugePages_ /proc/meminfo
:
HugePages_Total: 1024
HugePages_Free: 1023
HugePages_Rsvd: 0
HugePages_Surp: 0
But free
shows that over +100Mb are used while example is running.
What is the reason of Linux THP not working?