Date: Wed, 17 Nov 2010 18:21:29 +0000 (UTC) From: Alan Cox <alc@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org Subject: svn commit: r215433 - in stable/7/sys: kern vm Message-ID: <201011171821.oAHILTIO000236@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: alc Date: Wed Nov 17 18:21:29 2010 New Revision: 215433 URL: http://svn.freebsd.org/changeset/base/215433 Log: MFC r209407, r209648, r209650 Introduce and use vm_page_next() and vm_page_prev(). They provide both a simpler and faster interface for iterating over the pages of an object. Modified: stable/7/sys/kern/kern_exec.c stable/7/sys/vm/vm_fault.c stable/7/sys/vm/vm_page.c stable/7/sys/vm/vm_page.h stable/7/sys/vm/vm_pageout.c Directory Properties: stable/7/sys/ (props changed) stable/7/sys/cddl/contrib/opensolaris/ (props changed) stable/7/sys/contrib/dev/acpica/ (props changed) stable/7/sys/contrib/pf/ (props changed) Modified: stable/7/sys/kern/kern_exec.c ============================================================================== --- stable/7/sys/kern/kern_exec.c Wed Nov 17 18:09:02 2010 (r215432) +++ stable/7/sys/kern/kern_exec.c Wed Nov 17 18:21:29 2010 (r215433) @@ -884,7 +884,7 @@ exec_map_first_page(imgp) if (initial_pagein > object->size) initial_pagein = object->size; for (i = 1; i < initial_pagein; i++) { - if ((ma[i] = vm_page_lookup(object, i)) != NULL) { + if ((ma[i] = vm_page_next(ma[i - 1])) != NULL) { if (ma[i]->valid) break; if ((ma[i]->oflags & VPO_BUSY) || ma[i]->busy) Modified: stable/7/sys/vm/vm_fault.c ============================================================================== --- stable/7/sys/vm/vm_fault.c Wed Nov 17 18:09:02 2010 (r215432) +++ stable/7/sys/vm/vm_fault.c Wed Nov 17 18:21:29 2010 (r215433) @@ -214,7 +214,7 @@ vm_fault(vm_map_t map, vm_offset_t vaddr boolean_t growstack, wired; int map_generation; vm_object_t next_object; - vm_page_t marray[VM_FAULT_READ]; + vm_page_t marray[VM_FAULT_READ], mt, mt_prev; int hardfault; int faultcount; struct faultstate fs; @@ -487,12 +487,18 @@ readrest: fs.first_object->type != OBJT_DEVICE && fs.first_object->type != OBJT_PHYS && fs.first_object->type != OBJT_SG) { - vm_pindex_t firstpindex, tmppindex; + vm_pindex_t firstpindex; if (fs.first_pindex < 2 * VM_FAULT_READ) firstpindex = 0; else firstpindex = fs.first_pindex - 2 * VM_FAULT_READ; + mt = fs.first_object != fs.object ? + fs.first_m : fs.m; + KASSERT(mt != NULL, ("vm_fault: missing mt")); + KASSERT((mt->oflags & VPO_BUSY) != 0, + ("vm_fault: mt %p not busy", mt)); + mt_prev = vm_page_prev(mt); vm_page_lock_queues(); /* @@ -500,14 +506,10 @@ readrest: * included in the lookahead - NFS piecemeal * writes will barf on it badly. */ - for (tmppindex = fs.first_pindex - 1; - tmppindex >= firstpindex; - --tmppindex) { - vm_page_t mt; - - mt = vm_page_lookup(fs.first_object, tmppindex); - if (mt == NULL || (mt->valid != VM_PAGE_BITS_ALL)) - break; + while ((mt = mt_prev) != NULL && + mt->pindex >= firstpindex && + mt->valid == VM_PAGE_BITS_ALL) { + mt_prev = vm_page_prev(mt); if (mt->busy || (mt->oflags & VPO_BUSY) || mt->hold_count || Modified: stable/7/sys/vm/vm_page.c ============================================================================== --- stable/7/sys/vm/vm_page.c Wed Nov 17 18:09:02 2010 (r215432) +++ stable/7/sys/vm/vm_page.c Wed Nov 17 18:21:29 2010 (r215433) @@ -772,6 +772,42 @@ vm_page_lookup(vm_object_t object, vm_pi } /* + * Returns the given page's successor (by pindex) within the object if it is + * resident; if none is found, NULL is returned. + * + * The object must be locked. + */ +vm_page_t +vm_page_next(vm_page_t m) +{ + vm_page_t next; + + VM_OBJECT_LOCK_ASSERT(m->object, MA_OWNED); + if ((next = TAILQ_NEXT(m, listq)) != NULL && + next->pindex != m->pindex + 1) + next = NULL; + return (next); +} + +/* + * Returns the given page's predecessor (by pindex) within the object if it is + * resident; if none is found, NULL is returned. + * + * The object must be locked. + */ +vm_page_t +vm_page_prev(vm_page_t m) +{ + vm_page_t prev; + + VM_OBJECT_LOCK_ASSERT(m->object, MA_OWNED); + if ((prev = TAILQ_PREV(m, pglist, listq)) != NULL && + prev->pindex != m->pindex - 1) + prev = NULL; + return (prev); +} + +/* * vm_page_rename: * * Move the given memory entry from its Modified: stable/7/sys/vm/vm_page.h ============================================================================== --- stable/7/sys/vm/vm_page.h Wed Nov 17 18:09:02 2010 (r215432) +++ stable/7/sys/vm/vm_page.h Wed Nov 17 18:21:29 2010 (r215433) @@ -325,6 +325,8 @@ void vm_page_dontneed (register vm_page_ void vm_page_deactivate (vm_page_t); void vm_page_insert (vm_page_t, vm_object_t, vm_pindex_t); vm_page_t vm_page_lookup (vm_object_t, vm_pindex_t); +vm_page_t vm_page_next(vm_page_t m); +vm_page_t vm_page_prev(vm_page_t m); void vm_page_remove (vm_page_t); void vm_page_rename (vm_page_t, vm_object_t, vm_pindex_t); void vm_page_requeue(vm_page_t m); Modified: stable/7/sys/vm/vm_pageout.c ============================================================================== --- stable/7/sys/vm/vm_pageout.c Wed Nov 17 18:09:02 2010 (r215432) +++ stable/7/sys/vm/vm_pageout.c Wed Nov 17 18:21:29 2010 (r215433) @@ -281,7 +281,7 @@ vm_pageout_clean(m) vm_page_t m; { vm_object_t object; - vm_page_t mc[2*vm_pageout_page_count]; + vm_page_t mc[2*vm_pageout_page_count], pb, ps; int pageout_count; int ib, is, page_base; vm_pindex_t pindex = m->pindex; @@ -306,7 +306,7 @@ vm_pageout_clean(m) return 0; } - mc[vm_pageout_page_count] = m; + mc[vm_pageout_page_count] = pb = ps = m; pageout_count = 1; page_base = vm_pageout_page_count; ib = 1; @@ -341,11 +341,8 @@ more: break; } - if ((p = vm_page_lookup(object, pindex - ib)) == NULL) { - ib = 0; - break; - } - if ((p->oflags & VPO_BUSY) || p->busy) { + if ((p = vm_page_prev(pb)) == NULL || + (p->oflags & VPO_BUSY) != 0 || p->busy != 0) { ib = 0; break; } @@ -357,7 +354,7 @@ more: ib = 0; break; } - mc[--page_base] = p; + mc[--page_base] = pb = p; ++pageout_count; ++ib; /* @@ -372,11 +369,9 @@ more: pindex + is < object->size) { vm_page_t p; - if ((p = vm_page_lookup(object, pindex + is)) == NULL) + if ((p = vm_page_next(ps)) == NULL || + (p->oflags & VPO_BUSY) != 0 || p->busy != 0) break; - if ((p->oflags & VPO_BUSY) || p->busy) { - break; - } vm_page_test_dirty(p); if ((p->dirty & p->valid) == 0 || p->queue != PQ_INACTIVE || @@ -384,7 +379,7 @@ more: p->hold_count != 0) { /* may be undergoing I/O */ break; } - mc[page_base + pageout_count] = p; + mc[page_base + pageout_count] = ps = p; ++pageout_count; ++is; }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201011171821.oAHILTIO000236>