google / tcmalloc

Apache License 2.0
4.31k stars 463 forks source link

MADV_COLLAPSE #221

Closed ioworker0 closed 6 months ago

ioworker0 commented 7 months ago

MADV_COLLAPSE is a new madvise mode, that allows users to request a synchronous collapse of memory at their own expense.

commit: https://github.com/torvalds/linux/commit/7d8faaf155454f8798ec56404faca29a82689c77

MADV_COLLAPSE is no longer dependent on any sysfs setting under /sys/kernel/mm/transparent_hugepage.

One of the use cases for MADV_COLLAPSE is malloc() implementations that manage memory in hugepage-sized chunks, but sometimes subrelease memory back to the system in native-sized chunks via MADV_DONTNEED; zapping the pmd. Later, when the memory is hot, the implementation could madvise(MADV_COLLAPSE) to re-back the memory by THPs to regain hugepage coverage and dTLB performance.

The only thing to note is that MADV_COLLAPSE may result in directed reclaim and/or compaction, leading to unpredictable stalls.

Would you consider using MADV_COLLAPSE into tcmalloc?