Source-Changes-HG archive

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

[src/trunk]: src/sys/kern Don't release the lock in the PR_NOWAIT allocation....



details:   https://anonhg.NetBSD.org/src/rev/93592ca2e07c
branches:  trunk
changeset: 828746:93592ca2e07c
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Dec 29 16:13:26 2017 +0000

description:
Don't release the lock in the PR_NOWAIT allocation. Move flags setting
after the acquiring the mutex. (from Tobias Nygren)

diffstat:

 sys/kern/subr_pool.c |  15 +++++++++------
 1 files changed, 9 insertions(+), 6 deletions(-)

diffs (54 lines):

diff -r e01e8e904e2f -r 93592ca2e07c sys/kern/subr_pool.c
--- a/sys/kern/subr_pool.c      Fri Dec 29 14:47:09 2017 +0000
+++ b/sys/kern/subr_pool.c      Fri Dec 29 16:13:26 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: subr_pool.c,v 1.219 2017/12/16 03:13:29 mrg Exp $      */
+/*     $NetBSD: subr_pool.c,v 1.220 2017/12/29 16:13:26 christos Exp $ */
 
 /*-
  * Copyright (c) 1997, 1999, 2000, 2002, 2007, 2008, 2010, 2014, 2015
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_pool.c,v 1.219 2017/12/16 03:13:29 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_pool.c,v 1.220 2017/12/29 16:13:26 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -1088,10 +1088,11 @@
                }
        }
        pp->pr_flags |= PR_GROWING;
-       if ((flags & PR_WAITOK) == 0)
+       if (flags & PR_WAITOK)
+               mutex_exit(&pp->pr_lock);
+       else
                pp->pr_flags |= PR_GROWINGNOWAIT;
 
-       mutex_exit(&pp->pr_lock);
        char *cp = pool_allocator_alloc(pp, flags);
        if (__predict_false(cp == NULL))
                goto out;
@@ -1102,7 +1103,8 @@
                goto out;
        }
 
-       mutex_enter(&pp->pr_lock);
+       if (flags & PR_WAITOK)
+               mutex_enter(&pp->pr_lock);
        pool_prime_page(pp, cp, ph);
        pp->pr_npagealloc++;
        KASSERT(pp->pr_flags & PR_GROWING);
@@ -1114,9 +1116,10 @@
        cv_broadcast(&pp->pr_cv);
        return 0;
 out:
+       if (flags & PR_WAITOK)
+               mutex_enter(&pp->pr_lock);
        KASSERT(pp->pr_flags & PR_GROWING);
        pp->pr_flags &= ~(PR_GROWING|PR_GROWINGNOWAIT);
-       mutex_enter(&pp->pr_lock);
        return ENOMEM;
 }
 



Home | Main Index | Thread Index | Old Index