This patch allows the OS to free page and arena memory. This only happens in single objspace mode at the end of a major GC. There is still an empty_pages list per objspace, and this stays resident as before. Only pages previously munmapped pre-rlgc are madvised(DONTNEED)'d. We call these discarded pages. Once an arena (2MB) has all of its 32 pages (each 64K) discarded, we munmap the arena. At least 1 arena is kept mapped at all times.
The following fields are added to GC.stat for the default GC:
page_pool_arenas // number of mapped arenas
page_pool_arenas_freed // number of freed (unmapped) arenas
page_pool_total_pages // total pages in all arenas (arena_count * 32 currently)
page_pool_discarded_pages // number of madvise(DONTNEED) pages (they can still be mapped)
Future work:
* Reduce the amount of empty pages per objspace or get rid of objspace->empty_pages altogether and keep a certain amount of resident pages in the pool for all objspaces.
* Allow reclaiming memory when there are multiple Ractors.