From owner-freebsd-fs@FreeBSD.ORG Fri Sep 18 17:57:11 2009 Return-Path: Delivered-To: freebsd-fs@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E54901065670 for ; Fri, 18 Sep 2009 17:57:10 +0000 (UTC) (envelope-from gleb.kurtsou@gmail.com) Received: from fg-out-1718.google.com (fg-out-1718.google.com [72.14.220.153]) by mx1.freebsd.org (Postfix) with ESMTP id 75B8D8FC19 for ; Fri, 18 Sep 2009 17:57:10 +0000 (UTC) Received: by fg-out-1718.google.com with SMTP id 16so502212fgg.13 for ; Fri, 18 Sep 2009 10:57:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:from:to:cc:subject :message-id:mime-version:content-type:content-disposition:user-agent; bh=MOXvSDyQ0R08x+JzI2vqJgVIOOtDYws5AuI91kn8FEo=; b=wDCn1ppEU30t5OWr99ANBTLyRo+I9HQ6SXvKvtC+xwaHf4j/xTNXpynP1hMpA9u6V9 GAwW91++w/4W5e+bSrgaKuLXs7in6ce9V+B1l1EAXWcsXmeNydZWCGSAJaTrlOdV9MRJ UxTgpAH71QiTbyIaaxzO21sAxy/+2Wke+vnD8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:mime-version:content-type :content-disposition:user-agent; b=lbOgeBRP4RDrl68JfkCH2owuKQX9yKd+K7WVExnPj9fjYXROTjzXw3b0ENzqZ3bTri kOyqCTsg7WUrXg+oXjMlV89ZrMtqwOym0tpv6Zqlonz7UfnyX1pqTq/4Z/xmLS21Iznc kFMC5uX38RPceUZLsDTsBSZ/j1HYHF31jbP7s= Received: by 10.86.18.34 with SMTP id 34mr2007250fgr.2.1253294914345; Fri, 18 Sep 2009 10:28:34 -0700 (PDT) Received: from localhost (lan-78-157-90-54.vln.skynet.lt [78.157.90.54]) by mx.google.com with ESMTPS id l12sm111061fgb.20.2009.09.18.10.28.33 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 18 Sep 2009 10:28:33 -0700 (PDT) Date: Fri, 18 Sep 2009 20:28:16 +0300 From: Gleb Kurtsou To: freebsd-fs@freebsd.org Message-ID: <20090918172816.GA1449@tops> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="Qxx1br4bt0+wmkIi" Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) Cc: Pawel Jakub Dawidek Subject: [patch] tmpfs mmap sync bug fix X-BeenThere: freebsd-fs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Filesystems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Sep 2009 17:57:11 -0000 --Qxx1br4bt0+wmkIi Content-Type: text/plain; charset=utf-8 Content-Disposition: inline [ pjd@ CCed to make sure it doesn't apply to zfs ] Mmaped pages can get out of sync in tmpfs. The bug is 100% reproducible by: # fsx -S 125 -d /tmpfs/file It breaks at operation 42. Fix is inspired by zfs, it calls vm_page_cache_free(). Reading zfs sources, it looks like it doesn't check v_object->cache, but never the less bug never shows up on there. Probably it's because of zfs using VOP_BMAP to do page mapping. tmpfs uses default vop_getpages/vop_putpages which invokes vop_read/vop_write accordingly. Removing v_object->cache == NULL checks breaks things again. I'm not entirely sure if it's correct fix and would appreciate vm guru having a look at it, because I do the same thing in my pefs filesystem and It works as expected for me: http://blogs.freebsdish.org/gleb/2009/09/16/pefs-benchmark/ Thank, Gleb. --Qxx1br4bt0+wmkIi Content-Type: text/plain; charset=utf-8 Content-Disposition: attachment; filename="tmpfs-mmap-sync.patch.txt" diff --git a/sys/fs/tmpfs/tmpfs_vnops.c b/sys/fs/tmpfs/tmpfs_vnops.c index db8ceea..59d94d7 100644 --- a/sys/fs/tmpfs/tmpfs_vnops.c +++ b/sys/fs/tmpfs/tmpfs_vnops.c @@ -444,7 +444,8 @@ tmpfs_mappedread(vm_object_t vobj, vm_object_t tobj, size_t len, struct uio *uio offset = addr & PAGE_MASK; tlen = MIN(PAGE_SIZE - offset, len); - if ((vobj == NULL) || (vobj->resident_page_count == 0)) + if ((vobj == NULL) || + (vobj->resident_page_count == 0 && vobj->cache == NULL)) goto nocache; VM_OBJECT_LOCK(vobj); @@ -555,7 +556,8 @@ tmpfs_mappedwrite(vm_object_t vobj, vm_object_t tobj, size_t len, struct uio *ui offset = addr & PAGE_MASK; tlen = MIN(PAGE_SIZE - offset, len); - if ((vobj == NULL) || (vobj->resident_page_count == 0)) { + if ((vobj == NULL) || + (vobj->resident_page_count == 0 && vobj->cache == NULL)) { vpg = NULL; goto nocache; } @@ -573,6 +575,8 @@ lookupvpg: VM_OBJECT_UNLOCK(vobj); error = uiomove_fromphys(&vpg, offset, tlen, uio); } else { + if (__predict_false(vobj->cache != NULL)) + vm_page_cache_free(vobj, idx, idx + 1); VM_OBJECT_UNLOCK(vobj); vpg = NULL; } --Qxx1br4bt0+wmkIi--