nanovms / nanos

A kernel designed to run one and only one application in a virtualized environment
https://nanos.org
Apache License 2.0
2.66k stars 137 forks source link

Memory mapping: add support for Transparent Huge Pages (THP) #2037

Closed francescolavra closed 3 months ago

francescolavra commented 4 months ago

Memory areas mapped in the user process virtual address space are paged on-demand when the process causes a page fault by de-referencing a virtual address. In the existing implementation, a single 4-KB memory page is allocated and mapped after a page fault; with THP, memory pages belonging to anonymous mappings can be allocated and mapped using larger sizes (up to 2 MB); this decreases the number of page faults triggered when the process accesses a large memory area, resulting in improved performance. In addition, by allowing user pages to be mapped at a block level (i.e. in 2MB chunks) instead of being limited to page-level mappings (i.e. 4KB chunks), TLB usage is optimized and TLB hit rates are increased.

The THP feature is enabled by default in memory areas mapped via the mmap() syscall, and can be enabled and disabled dynamically for an arbitrary (non-file-backed) memory area via the newly implemented madvise() syscall, by using the MADV_HUGEPAGE and MADV_NOHUGEPAGE advice values.