Closed danielsn closed 4 years ago
munlock() unlocks pages in the address range starting at addr and continuing for len bytes. After this call, all pages that contain a part of the specified memory range can be moved to external swap space again by the kernel.
We only mlock on the size of the data, not the amount allocated (L72). So it seems like L118 is technically correct, but we should update mlock in s2n_realloc to reflect the new size of the data in this check: L93. Maybe either way works, because it might not be that big of a deal if we munlock more than we mlock.
Yeah, we can either munlock(blob->size)
, then mlock(newsize)
in the realloc function every time its called, or we could just mlock(allocated)
when memory is aquired, and munlock(allocated)
when its free. I personally find the second clearer, because then all our operations happen on page boundaries. But YMMV.
There is also possible a performance cost. Each mlock
or munlock
call requires a kernel call. So it may be expensive to do more than necessary. Profiling would be the best way to tell.
Problem:
https://github.com/awslabs/s2n/blob/master/utils/s2n_mem.c#L118 We leak locked pages, since the size may be less than the allocated bytes
Proposed Solution:
Use allocated here.