Hi all, I found THP can't correctly distinguish one anonymous hugepage map. 1. when /sys/kernel/mm/transparent_hugepage/enabled is 'always', the amount of THP always is one less. Testing code: ---- snip -------- unsigned long hugepagesize = (1UL << 21); int main() { void *addr; int i; printf("pid is %d\n", getpid()); for (i = 0; i < 5; i++) { addr = mmap(NULL, hugepagesize, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0); if (addr == MAP_FAILED) { perror("mmap"); return -1; } memset(addr, i, hugepagesize); } sleep(50); return 0; } ------ snip ---------- the /proc/[pid]/smaps show that Anonymous is 10240kB but AnonHugePages is 8192Kb, one THP less: ----- snip -------- 7f59ccc01000-7f59cd601000 rw-p 00000000 00:00 0 Size: 10240 kB Rss: 10240 kB Pss: 10240 kB Shared_Clean: 0 kB Shared_Dirty: 0 kB Private_Clean: 0 kB Private_Dirty: 10240 kB Referenced: 10240 kB Anonymous: 10240 kB AnonHugePages: 8192 kB Swap: 0 kB KernelPageSize: 4 kB MMUPageSize: 4 kB Locked: 0 kB VmFlags: rd wr mr mw me ac hg ------- sinp --------- 2. when /sys/kernel/mm/transparent_hugepage/enabled is 'madvise', THP can't distinguish any one anonymous hugepage size: Testing code: -------- snip -------- unsigned long hugepagesize = (1UL << 21); int main() { void *addr; int i; printf("pid is %d\n", getpid()); for (i = 0; i < 5; i++) { addr = mmap(NULL, hugepagesize, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0); if (addr == MAP_FAILED) { perror("mmap"); return -1; } if (madvise(addr, hugepagesize, MADV_HUGEPAGE) == -1) { perror("madvise"); return -1; } memset(addr, i, hugepagesize); } sleep(50); return 0; } --------- snip ---------- The result is that it can't find any AnonHugePages from /proc/[pid]/smaps : -------------- snip ------- 7f0b38cd0000-7f0b396d0000 rw-p 00000000 00:00 0 Size: 10240 kB Rss: 10240 kB Pss: 10240 kB Shared_Clean: 0 kB Shared_Dirty: 0 kB Private_Clean: 0 kB Private_Dirty: 10240 kB Referenced: 10240 kB Anonymous: 10240 kB AnonHugePages: 0 kB Swap: 0 kB KernelPageSize: 4 kB MMUPageSize: 4 kB Locked: 0 kB VmFlags: rd wr mr mw me ac ----------- snip ---------- 3. when I made the address aligned with HUGEPAGESIZE using 'posix_memalign()' instead of mmap(), THP perform good, and can distinguish all anonymous huge pages. my question is: 1. all the above behaviour is right? 2. why THP can't distinguish one naturally aligned huge page(generated by mmap())? -- Thanks, Zhouping -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@xxxxxxxxx. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@xxxxxxxxx"> email@xxxxxxxxx </a>