4 ms·
Ah, I see--it's all mapped pages, not all pages as irishsultan's comment says. That makes a lot more sense, thanks!
by wolfgang42 8y ago
Ah, I see--it's all mapped pages, not all pages as
irishsultan's comment says. That makes a lot more sense, thanks!
- rkeene2 8y agoAfter some experimenting it will fault all the mapped pages, causing the VM subsystem to try to back them. In Linux 4.4+ there is an a flag to `mlockall(2)` called "MCL_ONFAULT" which does not do that and instead locks the pages as they become backed. $ cat wheres-the-ram.c #! /home/rkeene/bin/c #include <sys/mman.h> #include <stdlib.h> #include <stdio.h> int main(int argc, char **argv) { unsigned char *buffer; int mla_ret; mla_ret = mlockall(MCL_CURRENT | MCL_FUTURE | MCL_ONFAULT); if (mla_ret != 0) { perror("mlockall"); return(1); } buffer = malloc(1024LLU * 1024LLU * 1024LLU * 32LLU); if (!buffer) { perror("malloc"); return(1); } buffer[0] = 1; buffer[1] = buffer[0]; buffer[2] = buffer[3]; puts("Success !"); return(0); } $ sudo ./wheres-the-ram.c Success ! $ free -g total used free shared buff/cache available Mem: 14 1 5 0 7 13 Swap: 0 0 0 $
- dullgiulio 8y agoNever seen someone "execute C" before. You are never done learning apparently obvious things...
- riking 8y agoThe canonical shebang line to do this is '/usr/bin/tcc -r' - the Tiny C Compiler in "run" mode.