/* * 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 1000 #define MEMSIZE 1024*1024 void child(void) { char * mem; int err; int i; err = mlockall(MCL_CURRENT|MCL_FUTURE); if (err < 0) { printf("child mlock failed\n"); exit(1); } 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; /* Avoids the oops? Nope ... :( */ munlockall(); /* This is where we can trigger the oops. */ exit(0); } int main(int argc, char *argv) { int i; int status; for (i = 0; i < NUMFORKS ; i++) { pid_t pid = fork(); if (!pid) child(); /* does not return */ else if (pid > 0) wait(&status); else { printf("fork failed\n"); exit(1); } } }