/* * In the split VM code in 2.6.25-rc3-mm1 and later, we see PG_mlock * pages freed from the exit/exit_mmap path. This test case creates * a process, forks it, mlocks, touches some memory and exits, to * try and trigger the bug - Rik van Riel, Mar 2008 */ #include #include #include #include #include #include #define NUMFORKS 1 #define MEMSIZE 1024*1024 void child(void) { char * mem; int i; mem = malloc(MEMSIZE); if (!mem) { printf("child could not allocate memory\n"); exit(2); } /* Touch the memory so the kernel allocates actual pages. */ for (i = 0; i < MEMSIZE; i++) mem[i] = i; /* This is where we can trigger the oops. */ exit(0); } int main(int argc, char *argv) { int i; int status; pid_t pid; int err; err = mlockall(MCL_CURRENT|MCL_FUTURE); if (err < 0) { printf("parent mlock failed\n"); exit(1); } pid = getpid(); printf("parent pid = %d\n", pid); for (i = 0; i < NUMFORKS ; i++) { pid = fork(); if (!pid) child(); /* does not return */ else if (pid > 0) wait(&status); else { printf("fork failed\n"); exit(1); } } }