Conversation

Is there a way to tell kernels “I’m done with this addr space, don’t recycle it and fault me if I access it, but don’t actually keep the page around”? Maybe madvise+mprotect? It would make for cheap use-after-free detection at the cost of eventually running out of address space.
10
28
I think it's significantly cheaper to use mmap with MAP_FIXED. 2 system calls and mprotect still grabs mmap_sem write lock and MADV_DONTNEED grabs the read lock. End result is also actually slightly different. It would only be cheaper if you used MADV_FREE for lazy free.
1
1
And really, if you are never going to use it again, MADV_DONTNEED is better than MADV_FREE. You are going to pay the cost of dropping and zeroing the pages anyway, and you don't take advantage of not needing to fault them in again when reusing before memory pressure wipes it out.
1
This Tweet was deleted by the Tweet author. Learn more
I don't really think of the slab quarantine as a valuable feature since it doesn't happen reliably. The way it actually works for small allocations is the small allocation quarantine. They're zeroed on free and it can check for the zeroing on allocation when reusing the memory.
1
These 3 quarantines (small allocations in slabs, slabs - when pushed out of cache, large) are a bit like ASan using a FIFO queue but it also borrows the random swap with a slot in an array approach used by OpenBSD malloc for small allocations, to make reuse unpredictable.
1
This Tweet was deleted by the Tweet author. Learn more
This Tweet was deleted by the Tweet author. Learn more
Show replies