Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/uebayasi-xip]: src/sys Mark XIP pages as PG_CLEAN and/or PG_BUSY when ap...



details:   https://anonhg.NetBSD.org/src/rev/d25de79b9642
branches:  uebayasi-xip
changeset: 751737:d25de79b9642
user:      uebayasi <uebayasi%NetBSD.org@localhost>
date:      Fri Jul 09 12:49:21 2010 +0000

description:
Mark XIP pages as PG_CLEAN and/or PG_BUSY when appropriate.  Protect
vnode lock when vm_page::flags is manipulated.

diffstat:

 sys/miscfs/genfs/genfs_io.c |  39 ++++++++++++++++++++++++++++++---------
 sys/uvm/uvm_bio.c           |   9 ++++-----
 sys/uvm/uvm_fault.c         |  44 +++++++++++++++++++-------------------------
 sys/uvm/uvm_page.c          |   6 +++---
 4 files changed, 56 insertions(+), 42 deletions(-)

diffs (truncated from 301 to 300 lines):

diff -r 7fb09ab246c4 -r d25de79b9642 sys/miscfs/genfs/genfs_io.c
--- a/sys/miscfs/genfs/genfs_io.c       Thu Jul 08 07:47:37 2010 +0000
+++ b/sys/miscfs/genfs/genfs_io.c       Fri Jul 09 12:49:21 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: genfs_io.c,v 1.36.2.12 2010/07/07 14:29:39 uebayasi Exp $      */
+/*     $NetBSD: genfs_io.c,v 1.36.2.13 2010/07/09 12:49:21 uebayasi Exp $      */
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: genfs_io.c,v 1.36.2.12 2010/07/07 14:29:39 uebayasi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: genfs_io.c,v 1.36.2.13 2010/07/09 12:49:21 uebayasi Exp $");
 
 #include "opt_direct_page.h"
 #include "opt_xip.h"
@@ -816,8 +816,7 @@
 
        /* XXX optimize */
        off = offset;
-       i = 0;
-       while (i < npages) {
+       for (i = 0; i < npages; i++) {
                daddr_t lbn, blkno;
                int run;
                struct vnode *devvp;
@@ -842,6 +841,7 @@
                        pps[i] = xip_zero_page;
                } else {
                        struct vm_physseg *seg;
+                       struct vm_page *pg;
 
                        seg = devvp->v_physseg;
                        KASSERT(seg != NULL);
@@ -849,10 +849,11 @@
                        phys_addr = pmap_phys_address(seg->start) +
                            (blkno << dev_bshift) +
                            (off - (lbn << fs_bshift));
-                       pps[i] = seg->pgs +
+                       pg = seg->pgs +
                            ((phys_addr >> PAGE_SHIFT) - seg->start);
-                       KASSERT(pps[i]->phys_addr == phys_addr);
-                       KASSERT((pps[i]->flags & PG_DIRECT) != 0);
+                       KASSERT(pg->phys_addr == phys_addr);
+
+                       pps[i] = pg;
                }
 
                UVMHIST_LOG(ubchist, "xip pgs %d => phys_addr=0x%lx (%p)",
@@ -862,10 +863,30 @@
                        0);
 
                off += PAGE_SIZE;
-               i++;
        }
 
-       *npagesp = i;
+       if ((flags & PGO_LOCKED) == 0)
+               mutex_enter(&uobj->vmobjlock);
+       KASSERT(mutex_owned(&uobj->vmobjlock));
+
+       for (i = 0; i < npages; i++) {
+               struct vm_page *pg = pps[i];
+
+               if (pg == xip_zero_page) {
+               } else {
+                       KASSERT((pg->flags & PG_BUSY) == 0);
+                       KASSERT((pg->flags & PG_RDONLY) != 0);
+                       KASSERT((pg->flags & PG_CLEAN) != 0);
+                       KASSERT((pg->flags & PG_DIRECT) != 0);
+                       pg->flags |= PG_BUSY;
+                       pg->uobject = &vp->v_uobj;
+               }
+       }
+
+       if ((flags & PGO_LOCKED) == 0)
+               mutex_exit(&uobj->vmobjlock);
+
+       *npagesp = npages;
 
        return 0;
 }
diff -r 7fb09ab246c4 -r d25de79b9642 sys/uvm/uvm_bio.c
--- a/sys/uvm/uvm_bio.c Thu Jul 08 07:47:37 2010 +0000
+++ b/sys/uvm/uvm_bio.c Fri Jul 09 12:49:21 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uvm_bio.c,v 1.68.2.5 2010/07/08 06:55:13 uebayasi Exp $        */
+/*     $NetBSD: uvm_bio.c,v 1.68.2.6 2010/07/09 12:49:21 uebayasi Exp $        */
 
 /*
  * Copyright (c) 1998 Chuck Silvers.
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uvm_bio.c,v 1.68.2.5 2010/07/08 06:55:13 uebayasi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_bio.c,v 1.68.2.6 2010/07/09 12:49:21 uebayasi Exp $");
 
 #include "opt_uvmhist.h"
 #include "opt_ubc.h"
@@ -393,7 +393,6 @@
                    pg->offset < umap->writeoff ||
                    pg->offset + PAGE_SIZE > umap->writeoff + umap->writelen);
                mask = rdonly ? ~VM_PROT_WRITE : VM_PROT_ALL;
-
                error = pmap_enter(ufi->orig_map->pmap, va, VM_PAGE_TO_PHYS(pg),
                    prot & mask, PMAP_CANFAIL | (access_type & mask));
 
@@ -403,10 +402,10 @@
                mutex_enter(&uvm_pageqlock);
                uvm_pageactivate(pg);
                mutex_exit(&uvm_pageqlock);
+
+ubc_fault_done:
                pg->flags &= ~(PG_BUSY|PG_WANTED);
                UVM_PAGE_OWN(pg, NULL);
-
-ubc_fault_done:
                mutex_exit(&uobj->vmobjlock);
                if (error) {
                        UVMHIST_LOG(ubchist, "pmap_enter fail %d",
diff -r 7fb09ab246c4 -r d25de79b9642 sys/uvm/uvm_fault.c
--- a/sys/uvm/uvm_fault.c       Thu Jul 08 07:47:37 2010 +0000
+++ b/sys/uvm/uvm_fault.c       Fri Jul 09 12:49:21 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uvm_fault.c,v 1.166.2.12 2010/07/08 06:55:13 uebayasi Exp $    */
+/*     $NetBSD: uvm_fault.c,v 1.166.2.13 2010/07/09 12:49:21 uebayasi Exp $    */
 
 /*
  *
@@ -39,7 +39,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uvm_fault.c,v 1.166.2.12 2010/07/08 06:55:13 uebayasi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_fault.c,v 1.166.2.13 2010/07/09 12:49:21 uebayasi Exp $");
 
 #include "opt_uvmhist.h"
 #include "opt_xip.h"
@@ -574,8 +574,7 @@
 
        KASSERT(amap != NULL);
        KASSERT(uobjpage != NULL);
-       KASSERT(uobjpage == PGO_DONTCARE || uvm_pageisdirect_p(uobjpage) ||
-           (uobjpage->flags & PG_BUSY) != 0);
+       KASSERT(uobjpage == PGO_DONTCARE || (uobjpage->flags & PG_BUSY) != 0);
        KASSERT(mutex_owned(&amap->am_l));
        KASSERT(oanon == NULL || mutex_owned(&oanon->an_lock));
        KASSERT(uobj == NULL || mutex_owned(&uobj->vmobjlock));
@@ -1581,8 +1580,7 @@
        /* locked: maps(read), amap(if there), uobj(if !null), uobjpage(if !null) */
        KASSERT(amap == NULL || mutex_owned(&amap->am_l));
        KASSERT(uobj == NULL || mutex_owned(&uobj->vmobjlock));
-       KASSERT(uobjpage == NULL || uvm_pageisdirect_p(uobjpage) ||
-           (uobjpage->flags & PG_BUSY) != 0);
+       KASSERT(uobjpage == NULL || (uobjpage->flags & PG_BUSY) != 0);
 
        /*
         * note that at this point we are done with any front or back pages.
@@ -1601,8 +1599,7 @@
         */
        KASSERT(amap == NULL || mutex_owned(&amap->am_l));
        KASSERT(uobj == NULL || mutex_owned(&uobj->vmobjlock));
-       KASSERT(uobjpage == NULL || uvm_pageisdirect_p(uobjpage) ||
-           (uobjpage->flags & PG_BUSY) != 0);
+       KASSERT(uobjpage == NULL || (uobjpage->flags & PG_BUSY) != 0);
 
        /*
         * note that uobjpage can not be PGO_DONTCARE at this point.  we now
@@ -1645,8 +1642,7 @@
         */
        KASSERT(amap == NULL || mutex_owned(&amap->am_l));
        KASSERT(uobj == NULL || mutex_owned(&uobj->vmobjlock));
-       KASSERT(uobj == NULL || uvm_pageisdirect_p(uobjpage) ||
-           (uobjpage->flags & PG_BUSY) != 0);
+       KASSERT(uobj == NULL || (uobjpage->flags & PG_BUSY) != 0);
 
        /*
         * notes:
@@ -1656,10 +1652,8 @@
         *  - at this point uobjpage could be PG_WANTED (handle later)
         */
 
-       KASSERT(uobj == NULL || uvm_pageisdirect_p(uobjpage) ||
-           uobj == uobjpage->uobject);
-       KASSERT(uobj == NULL || uvm_pageisdirect_p(uobjpage) ||
-           !UVM_OBJ_IS_CLEAN(uobjpage->uobject) ||
+       KASSERT(uobj == NULL || uobj == uobjpage->uobject);
+       KASSERT(uobj == NULL || !UVM_OBJ_IS_CLEAN(uobjpage->uobject) ||
            (uobjpage->flags & PG_CLEAN) != 0);
 
        if (flt->promote == false) {
@@ -1718,7 +1712,7 @@
                if (curpg == NULL || curpg == PGO_DONTCARE) {
                        continue;
                }
-               KASSERT(uvm_pageisdirect_p(curpg) || curpg->uobject == uobj);
+               KASSERT(curpg->uobject == uobj);
 
                /*
                 * if center page is resident and not PG_BUSY|PG_RELEASED
@@ -1780,10 +1774,11 @@
        KASSERT((pg->flags & PG_WANTED) == 0);
        KASSERT(!UVM_OBJ_IS_CLEAN(pg->uobject) ||
            (pg->flags & PG_CLEAN) != 0);
+
+uvm_fault_lower_neighbor_enter:
        pg->flags &= ~(PG_BUSY);
        UVM_PAGE_OWN(pg, NULL);
 
-uvm_fault_lower_neighbor_enter:
        UVMHIST_LOG(maphist,
            "  MAPPING: n obj: pm=0x%x, va=0x%x, pg=0x%x",
            ufi->orig_map->pmap, currva, pg, 0);
@@ -2113,10 +2108,11 @@
                if (uobjpage->flags & PG_WANTED)
                        /* still have the obj lock */
                        wakeup(uobjpage);
+
+uvm_fault_lower_promote_done:
                uobjpage->flags &= ~(PG_BUSY|PG_WANTED);
                UVM_PAGE_OWN(uobjpage, NULL);
 
-uvm_fault_lower_promote_done:
                mutex_exit(&uobj->vmobjlock);
                uobj = NULL;
 
@@ -2162,10 +2158,9 @@
         */
        KASSERT(amap == NULL || mutex_owned(&amap->am_l));
        KASSERT(uobj == NULL || mutex_owned(&uobj->vmobjlock));
-       KASSERT(uobj == NULL || uvm_pageisdirect_p(uobjpage) ||
-           (uobjpage->flags & PG_BUSY) != 0);
+       KASSERT(uobj == NULL || (uobjpage->flags & PG_BUSY) != 0);
        KASSERT(anon == NULL || mutex_owned(&anon->an_lock));
-       KASSERT(uvm_pageisdirect_p(pg) || (pg->flags & PG_BUSY) != 0);
+       KASSERT((pg->flags & PG_BUSY) != 0);
 
        /*
         * all resources are present.   we can now map it in and free our
@@ -2203,10 +2198,9 @@
                 */
                KASSERT((pg->flags & PG_RELEASED) == 0);
 
+uvm_fault_lower_enter_error_done:
                pg->flags &= ~(PG_BUSY|PG_FAKE|PG_WANTED);
                UVM_PAGE_OWN(pg, NULL);
-
-uvm_fault_lower_enter_error_done:
                uvmfault_unlockall(ufi, amap, uobj, anon);
                if (!uvm_reclaimable()) {
                        UVMHIST_LOG(maphist,
@@ -2223,6 +2217,9 @@
        if (!uvm_pageisdirect_p(pg))
                uvm_fault_lower_done(ufi, flt, uobj, anon, pg);
 
+       pg->flags &= ~(PG_BUSY|PG_FAKE|PG_WANTED);
+       UVM_PAGE_OWN(pg, NULL);
+
        uvmfault_unlockall(ufi, amap, uobj, anon);
        pmap_update(ufi->orig_map->pmap);
        UVMHIST_LOG(maphist, "<- done (SUCCESS!)",0,0,0,0);
@@ -2269,9 +2266,6 @@
         * lock since the last time we checked.
         */
        KASSERT((pg->flags & PG_RELEASED) == 0);
-
-       pg->flags &= ~(PG_BUSY|PG_FAKE|PG_WANTED);
-       UVM_PAGE_OWN(pg, NULL);
 }
 
 
diff -r 7fb09ab246c4 -r d25de79b9642 sys/uvm/uvm_page.c
--- a/sys/uvm/uvm_page.c        Thu Jul 08 07:47:37 2010 +0000
+++ b/sys/uvm/uvm_page.c        Fri Jul 09 12:49:21 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uvm_page.c,v 1.153.2.42 2010/07/08 06:55:13 uebayasi Exp $     */
+/*     $NetBSD: uvm_page.c,v 1.153.2.43 2010/07/09 12:49:21 uebayasi Exp $     */
 
 /*
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -97,7 +97,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uvm_page.c,v 1.153.2.42 2010/07/08 06:55:13 uebayasi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_page.c,v 1.153.2.43 2010/07/09 12:49:21 uebayasi Exp $");
 
 #include "opt_ddb.h"
 #include "opt_uvmhist.h"
@@ -870,7 +870,7 @@
                paddr_t paddr = (start + i) << PAGE_SHIFT;
 
                pg->phys_addr = paddr;
-               pg->flags |= PG_RDONLY | PG_DIRECT;
+               pg->flags |= PG_RDONLY | PG_DIRECT | PG_CLEAN;
 #ifdef __HAVE_VM_PAGE_MD
                VM_MDPAGE_INIT(&pg->mdpage, paddr);



Home | Main Index | Thread Index | Old Index