DF-0946 / pressure_amp.c
/* * DF-0946 — swap pressure amplifier. * Allocates a large chunk to force the kernel to swap, then exits. * Intended to run as a background process alongside swap_meta_race. */ #include <sys/mman.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> int main(int argc, char **argv) { size_t mb = (argc > 1) ? atol(argv[1]) : 3072; size_t sz = mb * 1024UL * 1024; char *p = malloc(sz); if (!p) { perror("malloc"); return 1; } /* touch every page to force allocation, then leave resident */ long pg = sysconf(_SC_PAGESIZE); for (size_t i = 0; i < sz; i += pg) p[i] = (char)i; printf("[*] pressure amp: %zuMB resident, pid %d, sleeping 60s\n", mb, (int)getpid()); fflush(stdout); sleep(60); free(p); return 0; } |