3 ms·
There are usually very sound reasons not to release memory back to the OS, particularly in a multithreaded program. Each such release causes a "TLB shootdown",
by ncmncm 7y ago
There are usually very sound reasons not to release memory back to the OS, particularly in a multithreaded program. Each such release causes a "TLB shootdown", in which threads on other cores are blocked while the cores' "translation lookaside buffers", caches of page mappings, are cleared, and further stalls as their entries are re-filled.
This is another reason to prefer single-threaded processes, which are less subject to such shootdowns, and less-coupled forms of parallelism.
Besides the TLB potholes, releasing memory means that the next time memory is requested, the OS is obliged to zero it before the process gets to see it again. Furthermore, each page will be marked read-only, causing a trap the first time it is touched, and then zeroed lazily.
As a result, freeing memory to the OS should only be essayed with the support of a great deal of measurement of the consequences.