Meta/Facebook engineers announced their work on THP Shrinker, a way to make Linux’s Transparent Pages (THP) work more efficiently, with the main principle being to avoid memory waste by removing underutilized transparent pages.
THP can be efficient for some workloads by reducing the unhit state of the TLB cache, but the 2MB vs. 4Kb page size can lead to significant memory waste if not utilized efficiently.
Facebook engineers found on one of their platforms that the THP was not being fully utilized, even leaving each machine with about 2.7GB of wasted memory.
The THP Shrinker mechanism Facebook is developing for the Linux kernel aims to address this waste while still enjoying the benefits of THP for CPU efficiency, with the THP Shrinker splitting the least utilized large memory pages.
THP Shrinker is designed to avoid wasting RAM and to make large memory pages as transparent and open to the public as possible, making them unconditionally enabled, thus replacing the madevise system call-based option.
Facebook engineers are working on adding additional tuning around this THP Shrinker and possibly tying it to CPU/IO/memory stress events. Eventually, the engineers hope that the THP shrinker will allow them to directly deprecate Linux’s madvise THP mode and switch to THP enabled for all applications.