Source-Changes-HG archive

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

[src/trunk]: src/sys/uvm don't for memory in uao_set_swlot() since we're hold...



details:   https://anonhg.NetBSD.org/src/rev/2b0e9375165d
branches:  trunk
changeset: 511648:2b0e9375165d
user:      chs <chs%NetBSD.org@localhost>
date:      Sat Jun 23 20:52:03 2001 +0000

description:
don't for memory in uao_set_swlot() since we're holding spinlocks,
instead return -1.  adjust callers to handle this new error return.
fixes PR 13194.

diffstat:

 sys/uvm/uvm_aobj.c    |  44 +++++++++++++++++++++++++-------------------
 sys/uvm/uvm_pdaemon.c |  17 ++++++++++++-----
 2 files changed, 37 insertions(+), 24 deletions(-)

diffs (143 lines):

diff -r cb0c954c75ad -r 2b0e9375165d sys/uvm/uvm_aobj.c
--- a/sys/uvm/uvm_aobj.c        Sat Jun 23 20:47:44 2001 +0000
+++ b/sys/uvm/uvm_aobj.c        Sat Jun 23 20:52:03 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uvm_aobj.c,v 1.44 2001/06/22 06:20:24 chs Exp $        */
+/*     $NetBSD: uvm_aobj.c,v 1.45 2001/06/23 20:52:03 chs Exp $        */
 
 /*
  * Copyright (c) 1998 Chuck Silvers, Charles D. Cranor and
@@ -236,32 +236,35 @@
        struct uao_swhash_elt *elt;
        voff_t page_tag;
 
-       swhash = UAO_SWHASH_HASH(aobj, pageidx); /* first hash to get bucket */
-       page_tag = UAO_SWHASH_ELT_TAG(pageidx); /* tag to search for */
+       swhash = UAO_SWHASH_HASH(aobj, pageidx);
+       page_tag = UAO_SWHASH_ELT_TAG(pageidx);
 
        /*
         * now search the bucket for the requested tag
         */
+
        LIST_FOREACH(elt, swhash, list) {
-               if (elt->tag == page_tag)
-                       return(elt);
+               if (elt->tag == page_tag) {
+                       return elt;
+               }
        }
-
-       /* fail now if we are not allowed to create a new entry in the bucket */
-       if (!create)
+       if (!create) {
                return NULL;
-
+       }
 
        /*
         * allocate a new entry for the bucket and init/insert it in
         */
-       elt = pool_get(&uao_swhash_elt_pool, PR_WAITOK);
+
+       elt = pool_get(&uao_swhash_elt_pool, PR_NOWAIT);
+       if (elt == NULL) {
+               return NULL;
+       }
        LIST_INSERT_HEAD(swhash, elt, list);
        elt->tag = page_tag;
        elt->count = 0;
        memset(elt->slots, 0, sizeof(elt->slots));
-
-       return(elt);
+       return elt;
 }
 
 /*
@@ -307,6 +310,8 @@
  *
  * => setting a slot to zero frees the slot
  * => object must be locked by caller
+ * => we return the old slot number, or -1 if we failed to allocate
+ *    memory to record the new slot number
  */
 int
 uao_set_swslot(uobj, pageidx, slot)
@@ -314,6 +319,7 @@
        int pageidx, slot;
 {
        struct uvm_aobj *aobj = (struct uvm_aobj *)uobj;
+       struct uao_swhash_elt *elt;
        int oldslot;
        UVMHIST_FUNC("uao_set_swslot"); UVMHIST_CALLED(pdhist);
        UVMHIST_LOG(pdhist, "aobj %p pageidx %d slot %d",
@@ -345,11 +351,9 @@
                 * we are freeing.
                 */
 
-               struct uao_swhash_elt *elt =
-                   uao_find_swhash_elt(aobj, pageidx, slot ? TRUE : FALSE);
+               elt = uao_find_swhash_elt(aobj, pageidx, slot ? TRUE : FALSE);
                if (elt == NULL) {
-                       KASSERT(slot == 0);
-                       return (0);
+                       return slot ? -1 : 0;
                }
 
                oldslot = UAO_SWHASH_ELT_PAGESLOT(elt, pageidx);
@@ -364,8 +368,8 @@
                if (slot) {
                        if (oldslot == 0)
                                elt->count++;
-               } else {                /* freeing slot ... */
-                       if (oldslot)    /* to be safe */
+               } else {
+                       if (oldslot)
                                elt->count--;
 
                        if (elt->count == 0) {
@@ -1194,7 +1198,9 @@
                                 */
                                swslot = uao_set_swslot(&aobj->u_obj, pageidx,
                                                        SWSLOT_BAD);
-                               uvm_swap_markbad(swslot, 1);
+                               if (swslot != -1) {
+                                       uvm_swap_markbad(swslot, 1);
+                               }
 
                                ptmp->flags &= ~(PG_WANTED|PG_BUSY);
                                UVM_PAGE_OWN(ptmp, NULL);
diff -r cb0c954c75ad -r 2b0e9375165d sys/uvm/uvm_pdaemon.c
--- a/sys/uvm/uvm_pdaemon.c     Sat Jun 23 20:47:44 2001 +0000
+++ b/sys/uvm/uvm_pdaemon.c     Sat Jun 23 20:52:03 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uvm_pdaemon.c,v 1.34 2001/05/25 04:06:16 chs Exp $     */
+/*     $NetBSD: uvm_pdaemon.c,v 1.35 2001/06/23 20:52:03 chs Exp $     */
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -696,13 +696,20 @@
                                 * add block to cluster
                                 */
 
-                               swpps[swcpages] = p;
-                               if (anon)
+                               if (anon) {
                                        anon->an_swslot = swslot + swcpages;
-                               else
-                                       uao_set_swslot(uobj,
+                               } else {
+                                       result = uao_set_swslot(uobj,
                                            p->offset >> PAGE_SHIFT,
                                            swslot + swcpages);
+                                       if (result == -1) {
+                                               p->flags &= ~PG_BUSY;
+                                               UVM_PAGE_OWN(p, NULL);
+                                               simple_unlock(&uobj->vmobjlock);
+                                               continue;
+                                       }
+                               }
+                               swpps[swcpages] = p;
                                swcpages++;
                        }
                } else {



Home | Main Index | Thread Index | Old Index