Source-Changes-HG archive

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

[src/trunk]: src/sys/kern More locking protocol fixes. Protect pool_head wit...



details:   https://anonhg.NetBSD.org/src/rev/fe193607b256
branches:  trunk
changeset: 471655:fe193607b256
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Tue Apr 06 23:32:44 1999 +0000

description:
More locking protocol fixes.  Protect pool_head with a spin lock (statically
initialized).  This lock also protects the "next drain candidate" pointer.

XXX There is still one locking protocol problem, which should not be
a problem in practice, but is still marked as an issue in the code anyhow.

diffstat:

 sys/kern/subr_pool.c |  33 ++++++++++++++++++++++-----------
 1 files changed, 22 insertions(+), 11 deletions(-)

diffs (89 lines):

diff -r ccf896667514 -r fe193607b256 sys/kern/subr_pool.c
--- a/sys/kern/subr_pool.c      Tue Apr 06 23:08:48 1999 +0000
+++ b/sys/kern/subr_pool.c      Tue Apr 06 23:32:44 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: subr_pool.c,v 1.22 1999/04/04 17:17:31 chs Exp $       */
+/*     $NetBSD: subr_pool.c,v 1.23 1999/04/06 23:32:44 thorpej Exp $   */
 
 /*-
  * Copyright (c) 1997, 1999 The NetBSD Foundation, Inc.
@@ -73,7 +73,10 @@
 int pool_inactive_time = 10;
 
 /* Next candidate for drainage (see pool_drain()) */
-static struct pool     *drainpp = NULL;
+static struct pool     *drainpp;
+
+/* This spin lock protects both pool_head and drainpp. */
+struct simplelock pool_head_slock = SIMPLELOCK_INITIALIZER;
 
 struct pool_item_header {
        /* Page headers */
@@ -363,7 +366,6 @@
        /*
         * Initialize the pool structure.
         */
-       TAILQ_INSERT_TAIL(&pool_head, pp, pr_poollist);
        TAILQ_INIT(&pp->pr_pagelist);
        pp->pr_curpage = NULL;
        pp->pr_npages = 0;
@@ -451,13 +453,17 @@
 
        /*
         * Initialize private page header pool if we haven't done so yet.
+        * XXX LOCKING.
         */
        if (phpool.pr_size == 0) {
                pool_init(&phpool, sizeof(struct pool_item_header), 0, 0,
                          0, "phpool", 0, 0, 0, 0);
        }
 
-       return;
+       /* Insert into the list of all pools. */
+       simple_lock(&pool_head_slock);
+       TAILQ_INSERT_TAIL(&pool_head, pp, pr_poollist);
+       simple_unlock(&pool_head_slock);
 }
 
 /*
@@ -483,8 +489,11 @@
                        pr_rmpage(pp, ph);
 
        /* Remove from global pool list */
+       simple_lock(&pool_head_slock);
        TAILQ_REMOVE(&pool_head, pp, pr_poollist);
+       /* XXX Only clear this if we were drainpp? */
        drainpp = NULL;
+       simple_unlock(&pool_head_slock);
 
 #ifdef POOL_DIAGNOSTIC
        if ((pp->pr_roflags & PR_LOGGING) != 0)
@@ -1215,19 +1224,21 @@
        void *arg;
 {
        struct pool *pp;
-       int s = splimp();
+       int s;
 
-       /* XXX:lock pool head */
-       if (drainpp == NULL && (drainpp = TAILQ_FIRST(&pool_head)) == NULL) {
-               splx(s);
-               return;
-       }
+       s = splimp();
+       simple_lock(&pool_head_slock);
+
+       if (drainpp == NULL && (drainpp = TAILQ_FIRST(&pool_head)) == NULL)
+               goto out;
 
        pp = drainpp;
        drainpp = TAILQ_NEXT(pp, pr_poollist);
-       /* XXX:unlock pool head */
 
        pool_reclaim(pp);
+
+ out:
+       simple_unlock(&pool_head_slock);
        splx(s);
 }
 



Home | Main Index | Thread Index | Old Index