nanovms / nanos

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

Kernel heaps: add page heap #1994

Closed francescolavra closed 7 months ago

francescolavra commented 7 months ago

This new heap is a caching heap that allows allocating single memory pages, while avoiding complete exhaustion of physical memory and minimizing memory fragmentation. It is used by both the pagecache code (instead of a pagecache-specific caching heap) and the mmap code (instead of the page_backed heap), which now avoid accessing directly the physical heap. The page heap is drained by the MM service when the kernel is running out of memory. This change fixes a memory fragmentation issue that occurs when the user process makes heavy use of map() and unmap() system calls and may cause failure to allocate 2MB chunks of memory (https://github.com/nanovms/ops/issues/1570#issuecomment-1895947857).

The first 2 commits refactor the mmap code to remove code duplication, the third commit fixes a bug in the mmap code.