Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

mmap is not swap. It's using the same virtual memory mechanisms to load/dump pages to disk. The policy for when to read and write those pages is completely different.


When the room for memory mapped files gets low enough you get bad thrashing anyway, so the policy difference isn't that important.

Having no swap limits how much you can overburden your computer, but you also hit problems earlier. Here's some example numbers for 64GB of memory: With swap you can go up to 62GB of active program data (85GB allocated and used) before you have performance issues. Without swap you can go up to 45GB of active program data (63GB allocated and used) before you hit a brick wall of either thrashing or killing processes. The no-swap version is better at maintaining snappiness within its happy range, but it's a tradeoff.


It is doing exactly what swap is doing. That it's swap with a different policy doesn't make it not-swap.

Also, that separate policy shouldn't even exist. For LRU/active-list/inactive-list purposes, why does it matter whether a page is anonymous or file-backed? If you need it, you need it, and if you don't, you don't. No reason for anonymous and file-backed memory to be separate sub-sub-systems under vm.


Anonymous memory and files have different access patterns. Files are frequently read sequentially and only once, so there is no need to keep them in memory. When files are read, cached memory pages are put into inactive file LRU first and promoted to active LRU only on the second access.


It is possible to unify things behind a single mechanism, yet apply different policies to different instances of this mechanism depending on circumstances and heuristics. We do not need almost entirely disjoint paging systems in the Linux kernel to notice that some kinds of memory have access patterns different from other kinds of memory. Instead of guessing based on whether someone used MAP_ANONYMOUS, we should observe what a program is actually doing.


All LRUs, file-backend and anonymous are handled by the same code. There are some conditionals here and there - executable pages are promoted to active LRU on the first access, locked pages (if I remember correctly) too, but all pages go through the same cycle. See this Linux Plumbers conference presentation https://www.youtube.com/watch?v=0bnWQF7WQP0 with the following slides https://d3s.mff.cuni.cz/files/teaching/nswi161/2023_24/08_li...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: