3 ms·
madvise( start, size, MADV_DONTNEED ); start must be page-aligned. size is in bytes, but if you take one byte of a page, you take the whole thing, so clip as a
by knome 7y ago
madvise( start, size, MADV_DONTNEED );
start must be page-aligned. size is in bytes, but if you take one byte of a page, you take the whole thing, so clip as appropriate.
this informs the kernel you're done with some part of the memory. mapped things will be re-read and others will act as if zero'd when later accessed. both can be safely dropped without taking space in the swap, instead being newly created when next needed.
- kevinoid 7y agoAlthough this is true on Linux, it's worth noting that this behavior doesn't match the specified behavior of posix_madvise.[1] It was also a subject of Bryan Cantril's hilarious "A crime against common sense" Surge 2015 talk (at ~1:06:50).[2] [1]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_madvise.html https://pubs.opengroup.org/onlinepubs/9699919799/functions/p... [2]: https://youtu.be/bg6-LVCHmGM?t=3518 https://youtu.be/bg6-LVCHmGM?t=3518