From owner-freebsd-hackers@FreeBSD.ORG Fri Apr 23 00:30:38 2004 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 3DEFC16A4CE for ; Fri, 23 Apr 2004 00:30:38 -0700 (PDT) Received: from sccrmhc13.comcast.net (sccrmhc13.comcast.net [204.127.202.64]) by mx1.FreeBSD.org (Postfix) with ESMTP id E121643D45 for ; Fri, 23 Apr 2004 00:30:37 -0700 (PDT) (envelope-from julian@elischer.org) Received: from interjet.elischer.org ([24.7.73.28]) by comcast.net (sccrmhc13) with ESMTP id <2004042307303601600d1kcke>; Fri, 23 Apr 2004 07:30:37 +0000 Received: from localhost (localhost.elischer.org [127.0.0.1]) by InterJet.elischer.org (8.9.1a/8.9.1) with ESMTP id AAA00857; Fri, 23 Apr 2004 00:30:35 -0700 (PDT) Date: Fri, 23 Apr 2004 00:30:34 -0700 (PDT) From: Julian Elischer To: Matthew Dillon In-Reply-To: <200404230211.i3N2Bwh6004161@apollo.backplane.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII cc: hackers@freebsd.org cc: Stephan Uphoff Subject: Re: how to flush out cache.? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 23 Apr 2004 07:30:38 -0000 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 > #include > #include > #include > #include > > 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 > #include > #include > #include > #include > > 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); > } > > >