Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 23 Apr 2004 00:30:34 -0700 (PDT)
From:      Julian Elischer <julian@elischer.org>
To:        Matthew Dillon <dillon@apollo.backplane.com>
Cc:        Stephan Uphoff <ups@tree.com>
Subject:   Re: how to flush out cache.? 
Message-ID:  <Pine.BSF.4.21.0404230028570.826-100000@InterJet.elischer.org>
In-Reply-To: <200404230211.i3N2Bwh6004161@apollo.backplane.com>

next in thread | previous in thread | raw e-mail | index | archive | help


On Thu, 22 Apr 2004, Matthew Dillon wrote:

>     Sigh.  Run this program.  Note that the file contains an 'A' in the
>     first byte after you run it (hexdump -C test.dat).  Thus, msync()
>     is not destroying the page until AFTER it finishes flushing it to
>     disk.
> 
> /*
>  * x.c
>  */
> #include <sys/types.h>
> #include <sys/mman.h>
> #include <stdio.h>
> #include <unistd.h>
> #include <fcntl.h>
> 
> int
> main(int ac, char **av)
> {
>     int fd;
>     char *ptr;
> 
>     fd = open("test.dat", O_RDWR|O_CREAT|O_TRUNC, 0666);
>     ftruncate(fd, 4096);
>     ptr = mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
>     *ptr = 'A';
>     msync(ptr, 4096, MS_INVALIDATE);
>     return(0);
> }
> 
>     Now run this program.  Note that the file still contains an 'A'
>     after you run it.  Thus, again, msync() is not destroying the page
>     until after it has been synchronized with the file.
> 
>     I also added some additional code to re-read *ptr after the msync
>     and observed the I/O go through to the disk, so it does appear to
>     be destroying the page.  But it is definitely flushing it to disk
>     first.
> 
>     If you can demonstrate a case where the page is being destroying
>     when it shouldn't be, then there's a bug that needs fixing.  Right
>     now though it seems to operate as expected.

But this is exactly what I want..

I want any unwrittendata to be written out, and pages containing written
out data to be discarded so that a reread is forced to go to disk.


> 
> 						-Matt
> 
> /*
>  * y.c
>  */
> #include <sys/types.h>
> #include <sys/mman.h>
> #include <stdio.h>
> #include <unistd.h>
> #include <fcntl.h>
> 
> int
> main(int ac, char **av)
> {
>     int fd;
>     char *ptr;
> 
>     fd = open("test.dat", O_RDWR|O_CREAT|O_TRUNC, 0666);
>     ftruncate(fd, 4096);
>     ptr = mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
>     *ptr = 'A';
>     munmap(ptr, 4096);
>     ptr = mmap(NULL, 4096, PROT_READ, MAP_SHARED, fd, 0);
>     msync(ptr, 4096, MS_INVALIDATE);
>     return(0);
> }
> 
> 
> 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0404230028570.826-100000>