// This program is a pointless memory hog to induce swapping. // Build with -m64 for the 64-bit memory model. // #include #include #include int main() { // mlockall(MCL_FUTURE); int cnt = 0; void *addr; while(1){ addr = mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0); if(addr==MAP_FAILED){ perror("mmap failed: "); return -1; } printf("allocated %p\n", addr); *(unsigned long*)addr = 0xdeadbeef; // what happens without this write? if( cnt++ % 10000 == 0 ) sleep(1); } return 0; }