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/