Re: Shared mmap write-out (was: Re: patch cow-swapin)-- 2.0, 2.1

Ion Badulescu (ionut@moisil.cs.columbia.edu)
Sun, 27 Sep 1998 21:51:09 -0400 (EDT)


On Sun, 27 Sep 1998, Andrea Arcangeli wrote:

> >No, I've no clue (yet) how to fix it, but ideas are always welcome. I don't
> >know if 2.1 has the same behavior -- no box is running 2.1 right now.
>
> Yes bo is full with 2.1 too, but I have not read your source and so I don'
> t know if this is the right behavior.

I just ran the same exact program on solaris 2.6, and sure enough solaris
does the right thing:

1. no fsync on open file descriptors when exec-ing
2. no multiple sync-ing of the same data in the children (tested by
replacing the execl() with a fsync(fd); exit(0); sequence).

FreeBSD 2.2.1-RELEASE does the same thing.

So I'm pretty sure at this point that the Linux behavior is not the right
one..

Here's the same program attached for those who didn't get it initially (my
newsreader screwed up and sent the message only to Andrea). I would
appreciate other opinions as well as results on other platforms. Just run
it in the background and then watch the "bo" column (or whatever it is
on that specific OS) of vmstat.

Thanks,
Ion

-- 
  It is better to keep your mouth shut and be thought a fool,
            than to open it and remove all doubt.
------------------------------------
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>

/* * file size, should be half of the size of the physical memory */ #define FILESIZE (32 * 1024 * 1024)

int main(void) { char *ptr; int fd, i; char c = 'A'; pid_t pid;

if ((fd = open("foo", O_RDWR | O_CREAT | O_TRUNC)) == -1) { perror("open"); exit(1); } lseek(fd, FILESIZE - 1, SEEK_SET); /* write one byte to extend the file */ write(fd, &fd, 1);

/* get a shared mapping */ ptr = mmap(0, FILESIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (ptr == NULL) { perror("mmap"); exit(1); }

/* touch all pages in the mapping */ for (i = 0; i < FILESIZE; i += 4096) ptr[i] = c;

while (1) { if ((pid = fork())) { /* parent, wait */ waitpid(pid, NULL, 0); } else { /* child, exec away */ #if 0 execl("/bin/echo", "echo", "blah"); #else fsync(fd); printf("blah\n"); exit(0); #endif } sleep(5); } }

- 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/