I/O slowdown + Testprogram

Jim Nance (jlnance@sailboat.mis.uncwil.edu)
Sat, 3 Jul 1999 07:40:46 -0400


Hello All,
I have attached a program which creates a file, mmaps the file,
and closes the file. It then dirties its pages, deletes the file, and
unmaps the file. When I run it under 2.2.10, I notice that it spends a LOT
of time in the munmap() system call. Since there will be no references to
the file after the munmap(), we should be able to throw all these pages away,
so I dont know what is taking it so long (hence this post).
If I run under 2.3.9 the munmap() is much faster. I dont know if this is
because the cause of the problem in 2.2.10 is gone, or if the page cache
changes just make the problem not take as long. If nothing else this program
does show off the new page cache stuff in the 2.3 kernels.

Any ideas?

Thanks,

Jim

PS: I ran this on a 133MHz Cyrix machine with IDE disk drives and 64M of
memory. The test were done on an idle machine.

PPS: Once when I ran it under 2.2.10 with some other large processes running
on the machine, it got killed by (I assume) the OOM killer. Since this
program effectivly provides its own private swap space it seems strange
that it should be chosen to die.

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/mman.h>

#define SEGSIZE (45*1024*1024)
#define FNAME "my_tmp_file"
#define DELT(E,B) ((E)->tv_sec-(B)->tv_sec + 1e-6*((E)->tv_usec-(B)->tv_usec))

void bye(char *str)
{
perror(str);
exit(-1);
}

int main()
{
struct timeval tstart, tstop;
char *filemap;
int fd;
int lcnt, idx;

gettimeofday(&tstart, NULL);
fd = open(FNAME, O_RDWR | O_TRUNC | O_CREAT, 0600);
if(fd<0) bye("open "FNAME);

/* Set the file size */
lseek(fd, SEGSIZE, SEEK_SET);
write(fd, '\0', 1);
filemap=mmap(NULL, SEGSIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);

if(filemap==(void*)-1) {bye("mmap "FNAME);}
close(fd); /* We dont need it anymore */
gettimeofday(&tstop, NULL);

printf("open/map/close time = %.3f seconds\n", DELT(&tstop, &tstart));

for(lcnt=0; lcnt<5; lcnt++) {
gettimeofday(&tstart, NULL);

for(idx=0; idx<SEGSIZE; idx+=2048) {
filemap[idx] = 1;
}

gettimeofday(&tstop, NULL);
printf("Pass %d time = %.3f seconds\n", lcnt, DELT(&tstop, &tstart));
}

gettimeofday(&tstart, NULL);
unlink(FNAME);
gettimeofday(&tstop, NULL);
printf("unlink time = %.3f seconds\n", DELT(&tstop, &tstart));

gettimeofday(&tstart, NULL);
munmap(filemap, SEGSIZE);
gettimeofday(&tstop, NULL);
printf("munmap time = %.3f seconds\n", DELT(&tstop, &tstart));
}

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/