2 ms·
It won't do that by default. You need to set some non-portable flags to get it to munmap things. Unmapping trashes page-map caches of other threads in the proc
by ncmncm 4y ago
It won't do that by default. You need to set some non-portable flags to get it to munmap things.
Unmapping trashes page-map caches of other threads in the process. That involves inter-core interrupts. Not pretty.
- yakubin 4y agoExample program: #include <stdlib.h> int main() { for (size_t i = 0; i < 4096*4096; i++) { void* p = malloc(i * 4096); free(p); } } Running strace on it gives me a whole spam of logs like: mmap(NULL, 139264, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f0e7d46f000 munmap(0x7f0e7d46f000, 139264) = 0 mmap(NULL, 143360, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f0e7d46e000 munmap(0x7f0e7d46e000, 143360) = 0 mmap(NULL, 147456, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f0e7d46d000 munmap(0x7f0e7d46d000, 147456) = 0 mmap(NULL, 151552, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f0e7d46c000 munmap(0x7f0e7d46c000, 151552) = 0 mmap(NULL, 155648, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f0e7d46b000 munmap(0x7f0e7d46b000, 155648) = 0 mmap(NULL, 159744, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f0e7d46a000 munmap(0x7f0e7d46a000, 159744) = 0 That was run under a standard Debian 11 installation.
- ncmncm 4y agoEek. I am corrected. Now I need to find the nonstandard flags to set to turn it off.