From owner-freebsd-questions@FreeBSD.ORG Tue Nov 22 12:48:03 2005 Return-Path: X-Original-To: questions@freebsd.org Delivered-To: freebsd-questions@FreeBSD.ORG Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 1188C16A41F for ; Tue, 22 Nov 2005 12:48:03 +0000 (GMT) (envelope-from mi+kde@aldan.algebra.com) Received: from aldan.algebra.com (aldan.algebra.com [216.254.65.224]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8547A43D78 for ; Tue, 22 Nov 2005 12:47:53 +0000 (GMT) (envelope-from mi+kde@aldan.algebra.com) Received: from aldan.algebra.com (blue [127.0.0.1]) by aldan.algebra.com (8.13.4/8.13.4) with ESMTP id jAMClpuD028473 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 22 Nov 2005 07:47:51 -0500 (EST) (envelope-from mi+kde@aldan.algebra.com) Received: from localhost (localhost [[UNIX: localhost]]) by aldan.algebra.com (8.13.4/8.13.4/Submit) id jAMClnI9028472; Tue, 22 Nov 2005 07:47:49 -0500 (EST) (envelope-from mi+kde@aldan.algebra.com) From: Mikhail Teterin To: Dan Nelson Date: Tue, 22 Nov 2005 07:47:48 -0500 User-Agent: KMail/1.8.2 References: <200511211650.08260.mi+mx@aldan.algebra.com> <20051122074559.GA6893@dan.emsphone.com> In-Reply-To: <20051122074559.GA6893@dan.emsphone.com> X-Face: %UW#n0|w>ydeGt/b@1-.UFP=K^~-:0f#O:D7whJ5G_<5143Bb3kOIs9XpX+"V+~$adGP:J|SLieM31VIhqXeLBli" Cc: questions@freebsd.org Subject: Re: some files written via mmap end up corrupted X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 Nov 2005 12:48:03 -0000 On Tuesday 22 November 2005 02:45 am, Dan Nelson wrote: = In the last episode (Nov 21), Mikhail Teterin said: = > I must not be using the API properly :-( = > = > The writes to the mmap-ed area and then fsync-s the opened file, = > munmaps it, and exits. = > = > Sometimes, the files end up corrupted at the end, however -- in about = > 10% of cases. = = What kind of corruption are you seeing? Blocks of zeroes? Hard to say -- the files are (supposed to be) gzip-ed at the end. But `gzip -t' detects corruption in some of them. = Maybe you need to call msync() before unmapping the region? Or call = munmap before fsync. mmap(2) page says, msync() is obsolete now, and that fsync(2) "will flush all dirty data and metadata associated with a file, including dirty NOSYNC VM data, to physical media" = Can't tell that for sure without seeing the code :) The ending sequence was fsync->close->munmap. I changed it to fsync->munmap->close (not that it should matter), and am going to try again now. mmap is such a beautiful interface, too bad people don't use it and it bitrots :-( Thanks! -mi