Source-Changes-HG archive

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

[src/trunk]: src/sys/uvm lots of cleanup:



details:   https://anonhg.NetBSD.org/src/rev/bb6dbac65d62
branches:  trunk
changeset: 499636:bb6dbac65d62
user:      chs <chs%NetBSD.org@localhost>
date:      Sat Nov 25 06:27:59 2000 +0000

description:
lots of cleanup:
use queue.h macros and KASSERT().
address amap offsets in pages instead of bytes.
make amap_ref() and amap_unref() take an amap, offset and length
  instead of a vm_map_entry_t.
improve whitespace and comments.

diffstat:

 sys/uvm/uvm_amap.c    |   32 ++--
 sys/uvm/uvm_amap.h    |    8 +-
 sys/uvm/uvm_amap_i.h  |   43 ++---
 sys/uvm/uvm_anon.c    |   26 +--
 sys/uvm/uvm_aobj.c    |   44 ++---
 sys/uvm/uvm_ddb.h     |    5 +-
 sys/uvm/uvm_device.c  |   67 +++-----
 sys/uvm/uvm_glue.c    |   49 +++---
 sys/uvm/uvm_map.c     |  354 +++++++++++++++++++------------------------------
 sys/uvm/uvm_pager_i.h |   12 +-
 sys/uvm/uvm_pglist.c  |   41 ++---
 11 files changed, 286 insertions(+), 395 deletions(-)

diffs (truncated from 2058 to 300 lines):

diff -r 72c1e58a28bb -r bb6dbac65d62 sys/uvm/uvm_amap.c
--- a/sys/uvm/uvm_amap.c        Sat Nov 25 05:27:19 2000 +0000
+++ b/sys/uvm/uvm_amap.c        Sat Nov 25 06:27:59 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uvm_amap.c,v 1.26 2000/08/03 00:47:02 thorpej Exp $    */
+/*     $NetBSD: uvm_amap.c,v 1.27 2000/11/25 06:27:59 chs Exp $        */
 
 /*
  *
@@ -49,6 +49,7 @@
 #include <sys/systm.h>
 #include <sys/proc.h>
 #include <sys/malloc.h>
+#include <sys/kernel.h>
 #include <sys/pool.h>
 
 #define UVM_AMAP_C             /* ensure disabled inlines are in */
@@ -322,7 +323,7 @@
        if (amap->am_nslot >= slotneed) {
 #ifdef UVM_AMAP_PPREF
                if (amap->am_ppref && amap->am_ppref != PPREF_NONE) {
-                       amap_pp_adjref(amap, slotoff + slotmapped, addsize, 1);
+                       amap_pp_adjref(amap, slotoff + slotmapped, slotadd, 1);
                }
 #endif
                amap_unlock(amap);
@@ -340,8 +341,8 @@
                if (amap->am_ppref && amap->am_ppref != PPREF_NONE) {
                        if ((slotoff + slotmapped) < amap->am_nslot)
                                amap_pp_adjref(amap, slotoff + slotmapped, 
-                                   (amap->am_nslot - (slotoff + slotmapped)) <<
-                                   PAGE_SHIFT, 1);
+                                   (amap->am_nslot - (slotoff + slotmapped)),
+                                   1);
                        pp_setreflen(amap->am_ppref, amap->am_nslot, 1, 
                           slotneed - amap->am_nslot);
                }
@@ -419,8 +420,7 @@
                amap->am_ppref = newppref;
                if ((slotoff + slotmapped) < amap->am_nslot)
                        amap_pp_adjref(amap, slotoff + slotmapped, 
-                           (amap->am_nslot - (slotoff + slotmapped)) <<
-                           PAGE_SHIFT, 1);
+                           (amap->am_nslot - (slotoff + slotmapped)), 1);
                pp_setreflen(newppref, amap->am_nslot, 1, slotadded);
        }
 #endif
@@ -568,7 +568,8 @@
        int slots, lcv;
        vaddr_t chunksize;
        UVMHIST_FUNC("amap_copy"); UVMHIST_CALLED(maphist);
-       UVMHIST_LOG(maphist, "  (map=%p, entry=%p, waitf=%d)", map, entry, waitf, 0);
+       UVMHIST_LOG(maphist, "  (map=%p, entry=%p, waitf=%d)",
+                   map, entry, waitf, 0);
 
        /*
         * is there a map to copy?   if not, create one from scratch.
@@ -686,7 +687,7 @@
 #ifdef UVM_AMAP_PPREF
        if (srcamap->am_ppref && srcamap->am_ppref != PPREF_NONE) {
                amap_pp_adjref(srcamap, entry->aref.ar_pageoff, 
-                   entry->end - entry->start, -1);
+                   (entry->end - entry->start) >> PAGE_SHIFT, -1);
        }
 #endif
 
@@ -804,8 +805,10 @@
                                 * XXXCDC: we should cause fork to fail, but
                                 * we can't ...
                                 */
-                               if (nanon)
+                               if (nanon) {
+                                       simple_lock(&nanon->an_lock);
                                        uvm_anfree(nanon);
+                               }
                                simple_unlock(&anon->an_lock);
                                amap_unlock(amap);
                                uvm_wait("cownowpage");
@@ -855,7 +858,6 @@
        vaddr_t offset;
 {
        int leftslots;
-       UVMHIST_FUNC("amap_splitref"); UVMHIST_CALLED(maphist);
 
        AMAP_B2SLOT(leftslots, offset);
        if (leftslots == 0)
@@ -927,21 +929,20 @@
  * => caller must check that ppref != PPREF_NONE before calling
  */
 void
-amap_pp_adjref(amap, curslot, bytelen, adjval)
+amap_pp_adjref(amap, curslot, slotlen, adjval)
        struct vm_amap *amap;
        int curslot;
-       vsize_t bytelen;
+       vsize_t slotlen;
        int adjval;
 {
-       int slots, stopslot, *ppref, lcv;
+       int stopslot, *ppref, lcv;
        int ref, len;
 
        /*
         * get init values
         */
 
-       AMAP_B2SLOT(slots, bytelen);
-       stopslot = curslot + slots;
+       stopslot = curslot + slotlen;
        ppref = amap->am_ppref;
 
        /*
@@ -996,7 +997,6 @@
 {
        int byanon, lcv, stop, curslot, ptr;
        struct vm_anon *anon;
-       UVMHIST_FUNC("amap_wiperange"); UVMHIST_CALLED(maphist);
 
        /*
         * we can either traverse the amap by am_anon or by am_slots depending
diff -r 72c1e58a28bb -r bb6dbac65d62 sys/uvm/uvm_amap.h
--- a/sys/uvm/uvm_amap.h        Sat Nov 25 05:27:19 2000 +0000
+++ b/sys/uvm/uvm_amap.h        Sat Nov 25 06:27:59 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uvm_amap.h,v 1.12 1999/07/07 05:31:40 thorpej Exp $    */
+/*     $NetBSD: uvm_amap.h,v 1.13 2000/11/25 06:27:59 chs Exp $        */
 
 /*
  *
@@ -83,7 +83,7 @@
 AMAP_INLINE
 void           amap_add        /* add an anon to an amap */
                        __P((struct vm_aref *, vaddr_t,
-                            struct vm_anon *, int));
+                            struct vm_anon *, boolean_t));
 struct vm_amap *amap_alloc     /* allocate a new amap */
                        __P((vaddr_t, vaddr_t, int));
 void           amap_copy       /* clear amap needs-copy flag */
@@ -110,7 +110,7 @@
                             struct vm_anon **, int));
 AMAP_INLINE
 void           amap_ref        /* add a reference to an amap */
-                       __P((vm_map_entry_t, int));
+                       __P((struct vm_amap *, vaddr_t, vsize_t, int));
 int            amap_refs       /* get number of references of amap */
                        __P((struct vm_amap *));
 void           amap_share_protect /* protect pages in a shared amap */
@@ -125,7 +125,7 @@
                        __P((struct vm_amap *));
 AMAP_INLINE
 void           amap_unref      /* drop reference to an amap */
-                        __P((vm_map_entry_t, int));
+                        __P((struct vm_amap *, vaddr_t, vsize_t, int));
 void           amap_wipeout    /* remove all anons from amap */
                        __P((struct vm_amap *));
 
diff -r 72c1e58a28bb -r bb6dbac65d62 sys/uvm/uvm_amap_i.h
--- a/sys/uvm/uvm_amap_i.h      Sat Nov 25 05:27:19 2000 +0000
+++ b/sys/uvm/uvm_amap_i.h      Sat Nov 25 06:27:59 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uvm_amap_i.h,v 1.14 1999/09/12 01:17:34 chs Exp $      */
+/*     $NetBSD: uvm_amap_i.h,v 1.15 2000/11/25 06:27:59 chs Exp $      */
 
 /*
  *
@@ -37,8 +37,6 @@
 #ifndef _UVM_UVM_AMAP_I_H_
 #define _UVM_UVM_AMAP_I_H_
 
-#include "opt_uvmhist.h"
-
 /*
  * uvm_amap_i.h
  */
@@ -120,7 +118,7 @@
        struct vm_aref *aref;
        vaddr_t offset;
        struct vm_anon *anon;
-       int replace;
+       boolean_t replace;
 {
        int slot;
        struct vm_amap *amap = aref->ar_amap;
@@ -196,14 +194,16 @@
  * amap_ref: gain a reference to an amap
  *
  * => amap must not be locked (we will lock)
+ * => "offset" and "len" are in units of pages
  * => called at fork time to gain the child's reference
  */
 AMAP_INLINE void
-amap_ref(entry, flags)
-       vm_map_entry_t entry;
+amap_ref(amap, offset, len, flags)
+       struct vm_amap *amap;
+       vaddr_t offset;
+       vsize_t len;
        int flags;
 {
-       struct vm_amap *amap = entry->aref.ar_amap;
        UVMHIST_FUNC("amap_ref"); UVMHIST_CALLED(maphist);
 
        amap_lock(amap);
@@ -212,14 +212,13 @@
                amap->am_flags |= AMAP_SHARED;
 #ifdef UVM_AMAP_PPREF
        if (amap->am_ppref == NULL && (flags & AMAP_REFALL) == 0 &&
-           (entry->start - entry->end) >> PAGE_SHIFT != amap->am_nslot)
+           len != amap->am_nslot)
                amap_pp_establish(amap);
        if (amap->am_ppref && amap->am_ppref != PPREF_NONE) {
                if (flags & AMAP_REFALL)
-                       amap_pp_adjref(amap, 0, amap->am_nslot << PAGE_SHIFT, 1);
+                       amap_pp_adjref(amap, 0, amap->am_nslot, 1);
                else
-                       amap_pp_adjref(amap, entry->aref.ar_pageoff, 
-                               entry->end - entry->start, 1);
+                       amap_pp_adjref(amap, offset, len, 1);
        }
 #endif
        amap_unlock(amap);
@@ -236,20 +235,20 @@
  * => amap must be unlocked (we will lock it).
  */
 AMAP_INLINE void
-amap_unref(entry, all)
-       vm_map_entry_t entry;
-       int all;
+amap_unref(amap, offset, len, all)
+       struct vm_amap *amap;
+       vaddr_t offset;
+       vsize_t len;
+       boolean_t all;
 {
-       struct vm_amap *amap = entry->aref.ar_amap;
        UVMHIST_FUNC("amap_unref"); UVMHIST_CALLED(maphist);
 
        /*
         * lock it
         */
        amap_lock(amap);
-
-       UVMHIST_LOG(maphist,"(entry=0x%x)  amap=0x%x  refs=%d, nused=%d",
-           entry, amap, amap->am_ref, amap->am_nused);
+       UVMHIST_LOG(maphist,"  amap=0x%x  refs=%d, nused=%d",
+           amap, amap->am_ref, amap->am_nused, 0);
 
        /*
         * if we are the last reference, free the amap and return.
@@ -269,15 +268,13 @@
        if (amap->am_ref == 1 && (amap->am_flags & AMAP_SHARED) != 0)
                amap->am_flags &= ~AMAP_SHARED; /* clear shared flag */
 #ifdef UVM_AMAP_PPREF
-       if (amap->am_ppref == NULL && all == 0 &&
-           (entry->start - entry->end) >> PAGE_SHIFT != amap->am_nslot)
+       if (amap->am_ppref == NULL && all == 0 && len != amap->am_nslot)
                amap_pp_establish(amap);
        if (amap->am_ppref && amap->am_ppref != PPREF_NONE) {
                if (all)
-                       amap_pp_adjref(amap, 0, amap->am_nslot << PAGE_SHIFT, -1);
+                       amap_pp_adjref(amap, 0, amap->am_nslot, -1);
                else
-                       amap_pp_adjref(amap, entry->aref.ar_pageoff, 
-                           entry->end - entry->start, -1);
+                       amap_pp_adjref(amap, offset, len, -1);
        }
 #endif
        amap_unlock(amap);
diff -r 72c1e58a28bb -r bb6dbac65d62 sys/uvm/uvm_anon.c
--- a/sys/uvm/uvm_anon.c        Sat Nov 25 05:27:19 2000 +0000
+++ b/sys/uvm/uvm_anon.c        Sat Nov 25 06:27:59 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uvm_anon.c,v 1.9 2000/08/06 00:21:57 thorpej Exp $     */
+/*     $NetBSD: uvm_anon.c,v 1.10 2000/11/25 06:27:59 chs Exp $        */
 
 /*
  *
@@ -213,19 +213,12 @@
                 */
 
                if (pg->uobject) {
-
-                       /* kill loan */
                        uvm_lock_pageq();
-#ifdef DIAGNOSTIC
-                       if (pg->loan_count < 1)
-                               panic("uvm_anfree: obj owned page "
-                                     "with no loan count");
-#endif
+                       KASSERT(pg->loan_count > 0);
                        pg->loan_count--;
                        pg->uanon = NULL;
                        uvm_unlock_pageq();
                        simple_unlock(&pg->uobject->vmobjlock);
-
                } else {
 
                        /*
@@ -245,13 +238,11 @@
                                    anon, pg, 0, 0);



Home | Main Index | Thread Index | Old Index