lkml.org 
[lkml]   [2000]   [Mar]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectBad FS behavior w/ testcase
Hello All,
I have found an annoying problem with the way linux handles dirty pages
of unlinked files. The attached testcase makes a file, unlinks it, and
dirties 64M of its pages. The program then prints a message and calls
_exit(). You will notice a long delay between this message appearing and
when you get your shell prompt back. AFAICT, this delay is due to the
process writting the dirty pages back to the file. Now since the file has
been unlinked there is no need to write these pages back, but it looks like
linux does not know this. Any comments?

Thanks,

Jim
#include <stdlib.h>
#include <stdio.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>

#define TESTSIZE (64*1024*1024)
#define FILENAME "my_tmp_file"

int main()
{
int fd = open(FILENAME, O_RDWR | O_CREAT | O_TRUNC, 0600);
if(fd>0) {
unlink(FILENAME); /* The file is gone */
if(lseek(fd, TESTSIZE, SEEK_SET)==TESTSIZE && write(fd, "x", 1)==1) {
int prot = PROT_READ|PROT_WRITE;
int flag = MAP_SHARED;
char *ptr = (char*) mmap(0, TESTSIZE, prot, flag, fd, 0);
if(ptr!=(char*)-1) {
int idx, lcnt;
close(fd);
/* Dirty the pages */
for(lcnt=0; lcnt<3; lcnt++) {
for(idx=0; idx<TESTSIZE; idx+=1024) ptr[idx] = 'A';
}

/* leave */
write(1, "Calling _exit()\n ", 16);
_exit(0);
}
}
}

perror("Test program failed:");
return -errno;
}
\
 
 \ /
  Last update: 2005-03-22 13:57    [W:0.025 / U:0.472 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site