From owner-freebsd-hackers@FreeBSD.ORG Wed Mar 30 02:18:40 2005 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 C05B816A4CE; Wed, 30 Mar 2005 02:18:40 +0000 (GMT) Received: from VARK.MIT.EDU (VARK.MIT.EDU [18.95.3.179]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5712843D4C; Wed, 30 Mar 2005 02:18:40 +0000 (GMT) (envelope-from das@FreeBSD.ORG) Received: from VARK.MIT.EDU (localhost [127.0.0.1]) by VARK.MIT.EDU (8.13.3/8.13.1) with ESMTP id j2U2IWjc032980; Tue, 29 Mar 2005 21:18:32 -0500 (EST) (envelope-from das@FreeBSD.ORG) Received: (from das@localhost) by VARK.MIT.EDU (8.13.3/8.13.1/Submit) id j2U2IWr9032979; Tue, 29 Mar 2005 21:18:32 -0500 (EST) (envelope-from das@FreeBSD.ORG) Date: Tue, 29 Mar 2005 21:18:32 -0500 From: David Schultz To: Richard Sharpe Message-ID: <20050330021831.GA26006@VARK.MIT.EDU> Mail-Followup-To: Richard Sharpe , freebsd-hackers@FreeBSD.ORG, alc@FreeBSD.ORG References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: cc: alc@FreeBSD.ORG cc: freebsd-hackers@FreeBSD.ORG Subject: Re: Possible problems with mmap/munmap on FreeBSD ... 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: Wed, 30 Mar 2005 02:18:41 -0000 On Tue, Mar 29, 2005, Richard Sharpe wrote: > Hi, > > I am having some problems with the tdb package on FreeBSD 4.6.2 and 4.10. > > One of the things the above package does is: > > mmap the tdb file to a region of memory > store stuff in the region (memmov etc). > when it needs to extend the size of the region { > munmap the region > write data at the end of the file > mmap the region again with a larger size > } > > What I am seeing is that after the munmap the data written to the region > is gone. > > However, if I insert an msync before the munmap, everything is nicely > coherent. This seems odd (in the sense that it works without the msync > under Linux). > > The region is mmapped with: > > mmap(NULL, tdb->map_size, > PROT_READ|(tdb->read_only? 0:PROT_WRITE), > MAP_SHARED|MAP_FILE, tdb->fd, 0); > > What I notice is that all the calls to mmap return the same address. > > A careful reading of the man pages for mmap and munmap does not suggest > that I am doing anything wrong. > > Is it possible that FreeBSD is deferring flushing the dirty data, and then > forgets to do it when the same starting address is used etc? It looks like all of the underlying pages are getting invalidated in vm_object_page_remove(). This is clearly the right thing to do for private mappings, but it seems wrong for shared mappings. Perhaps Alan has some insight.