From owner-svn-src-head@FreeBSD.ORG Wed Dec 29 12:53:54 2010 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1E755106566C; Wed, 29 Dec 2010 12:53:54 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 0CDDE8FC14; Wed, 29 Dec 2010 12:53:54 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id oBTCrrmi001328; Wed, 29 Dec 2010 12:53:53 GMT (envelope-from kib@svn.freebsd.org) Received: (from kib@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id oBTCrr7G001325; Wed, 29 Dec 2010 12:53:53 GMT (envelope-from kib@svn.freebsd.org) Message-Id: <201012291253.oBTCrr7G001325@svn.freebsd.org> From: Konstantin Belousov Date: Wed, 29 Dec 2010 12:53:53 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r216799 - head/sys/vm X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 29 Dec 2010 12:53:54 -0000 Author: kib Date: Wed Dec 29 12:53:53 2010 New Revision: 216799 URL: http://svn.freebsd.org/changeset/base/216799 Log: Move the increment of vm object generation count into vm_object_set_writeable_dirty(). Fix an issue where restart of the scan in vm_object_page_clean() did not removed write permissions for newly added pages or, if the mapping for some already scanned page changed to writeable due to fault. Merge the two loops in vm_object_page_clean(), doing the remove of write permission and cleaning in the same loop. The restart of the loop then correctly downgrade writeable mappings. Fix an issue where a second caller to msync() might actually return before the first caller had actually completed flushing the pages. Clear the OBJ_MIGHTBEDIRTY flag after the cleaning loop, not before. Calls to pmap_is_modified() are not needed after pmap_remove_write() there. Proposed, reviewed and tested by: alc MFC after: 1 week Modified: head/sys/vm/vm_object.c head/sys/vm/vm_page.c Modified: head/sys/vm/vm_object.c ============================================================================== --- head/sys/vm/vm_object.c Wed Dec 29 12:31:18 2010 (r216798) +++ head/sys/vm/vm_object.c Wed Dec 29 12:53:53 2010 (r216799) @@ -101,7 +101,9 @@ SYSCTL_INT(_vm, OID_AUTO, old_msync, CTL "Use old (insecure) msync behavior"); static int vm_object_page_collect_flush(vm_object_t object, vm_page_t p, - int pagerflags); + int pagerflags, int flags, int *clearobjflags); +static boolean_t vm_object_page_remove_write(vm_page_t p, int flags, + int *clearobjflags); static void vm_object_qcollapse(vm_object_t object); static void vm_object_vndeallocate(vm_object_t object); @@ -753,6 +755,24 @@ vm_object_terminate(vm_object_t object) vm_object_destroy(object); } +static boolean_t +vm_object_page_remove_write(vm_page_t p, int flags, int *clearobjflags) +{ + + /* + * If we have been asked to skip nosync pages and this is a + * nosync page, skip it. Note that the object flags were not + * cleared in this case so we do not have to set them. + */ + if ((flags & OBJPC_NOSYNC) != 0 && (p->oflags & VPO_NOSYNC) != 0) { + *clearobjflags = 0; + return (FALSE); + } else { + pmap_remove_write(p); + return (p->dirty != 0); + } +} + /* * vm_object_page_clean * @@ -799,17 +819,6 @@ vm_object_page_clean(vm_object_t object, * object flags. */ clearobjflags = 1; - for (p = vm_page_find_least(object, start); - p != NULL && p->pindex < tend; p = TAILQ_NEXT(p, listq)) { - if ((flags & OBJPC_NOSYNC) != 0 && - (p->oflags & VPO_NOSYNC) != 0) - clearobjflags = 0; - else - pmap_remove_write(p); - } - - if (clearobjflags && (start == 0) && (tend == object->size)) - vm_object_clear_flag(object, OBJ_MIGHTBEDIRTY); rescan: curgeneration = object->generation; @@ -827,20 +836,11 @@ rescan: np = vm_page_find_least(object, pi); continue; } - vm_page_test_dirty(p); - if (p->dirty == 0) + if (!vm_object_page_remove_write(p, flags, &clearobjflags)) continue; - /* - * If we have been asked to skip nosync pages and this is a - * nosync page, skip it. Note that the object flags were - * not cleared in this case so we do not have to set them. - */ - if ((flags & OBJPC_NOSYNC) != 0 && - (p->oflags & VPO_NOSYNC) != 0) - continue; - - n = vm_object_page_collect_flush(object, p, pagerflags); + n = vm_object_page_collect_flush(object, p, pagerflags, + flags, &clearobjflags); if (object->generation != curgeneration) goto rescan; np = vm_page_find_least(object, pi + n); @@ -850,10 +850,13 @@ rescan: #endif vm_object_clear_flag(object, OBJ_CLEANING); + if (clearobjflags && start == 0 && tend == object->size) + vm_object_clear_flag(object, OBJ_MIGHTBEDIRTY); } static int -vm_object_page_collect_flush(vm_object_t object, vm_page_t p, int pagerflags) +vm_object_page_collect_flush(vm_object_t object, vm_page_t p, int pagerflags, + int flags, int *clearobjflags) { vm_page_t ma[vm_pageout_page_count], p_first, tp; int count, i, mreq, runlen; @@ -869,8 +872,7 @@ vm_object_page_collect_flush(vm_object_t tp = vm_page_next(tp); if (tp == NULL || tp->busy != 0 || (tp->oflags & VPO_BUSY) != 0) break; - vm_page_test_dirty(tp); - if (tp->dirty == 0) + if (!vm_object_page_remove_write(tp, flags, clearobjflags)) break; } @@ -878,8 +880,7 @@ vm_object_page_collect_flush(vm_object_t tp = vm_page_prev(p_first); if (tp == NULL || tp->busy != 0 || (tp->oflags & VPO_BUSY) != 0) break; - vm_page_test_dirty(tp); - if (tp->dirty == 0) + if (!vm_object_page_remove_write(tp, flags, clearobjflags)) break; p_first = tp; mreq++; @@ -1985,8 +1986,10 @@ vm_object_set_writeable_dirty(vm_object_ { VM_OBJECT_LOCK_ASSERT(object, MA_OWNED); - if (object->type != OBJT_VNODE || - (object->flags & OBJ_MIGHTBEDIRTY) != 0) + if (object->type != OBJT_VNODE) + return; + object->generation++; + if ((object->flags & OBJ_MIGHTBEDIRTY) != 0) return; vm_object_set_flag(object, OBJ_MIGHTBEDIRTY); } Modified: head/sys/vm/vm_page.c ============================================================================== --- head/sys/vm/vm_page.c Wed Dec 29 12:31:18 2010 (r216798) +++ head/sys/vm/vm_page.c Wed Dec 29 12:53:53 2010 (r216799) @@ -811,7 +811,6 @@ vm_page_insert(vm_page_t m, vm_object_t } } object->root = m; - object->generation++; /* * show that the object has one more resident page.