THP and Memory Bloat
Normally, the size of a Linux memory page is 4 KB. After THP is enabled, the kernel tries to combine 4 KB pages into 2 MB huge pages to reduce TLB misses and improve performance. Enabling THP for small objects may cause memory bloat (internal fragmentation) and increase the risk of OOM errors.
Causes of THP Memory Bloat
- Internal fragmentation
- Although only a small part of a 2 MB huge page is used by a process, the remaining space is also occupied by the process and cannot be used by other processes.
- Common small page: 8 KB of space is requested and two 4 KB pages are allocated and used. There is no waste.
- THP: 8 KB of space is requested. The kernel allocates a 2 MB huge page. Only 8 KB is used actually but the remaining space is also considered used.
- Although only a small part of a 2 MB huge page is used by a process, the remaining space is also occupied by the process and cannot be used by other processes.
- Large allocation granularity
- If THP is enabled, memory is allocated in the units of 2 MB, which easily causes high memory usage.
- Slow memory reclamation
- THP reclamation and migration are more complex than those of 4 KB pages. As a result, memory cannot be reclaimed in a timely manner, and the memory usage keeps increasing.
The bloated memory usage is not reflected in the top command's per-process statistics.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot