Date: Fri, 18 Sep 2009 20:28:16 +0300 From: Gleb Kurtsou <gleb.kurtsou@gmail.com> To: freebsd-fs@freebsd.org Cc: Pawel Jakub Dawidek <pjd@FreeBSD.org> Subject: [patch] tmpfs mmap sync bug fix Message-ID: <20090918172816.GA1449@tops>
next in thread | raw e-mail | index | archive | help
--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--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20090918172816.GA1449>
