Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Turn PA_INITIALIZED to a reference count for the pool al...
details: https://anonhg.NetBSD.org/src/rev/506eaab374dd
branches: trunk
changeset: 750411:506eaab374dd
user: elad <elad%NetBSD.org@localhost>
date: Wed Dec 30 18:57:16 2009 +0000
description:
Turn PA_INITIALIZED to a reference count for the pool allocator, and once
it drops to zero destroy the mutex we initialize. This fixes the problem
mentioned in
http://mail-index.netbsd.org/tech-kern/2009/12/28/msg006727.html
Also remove pa_flags now that it's no longer needed.
Idea from matt@, okay matt@.
diffstat:
sys/kern/subr_pool.c | 19 +++++++++++++++----
sys/sys/pool.h | 5 ++---
2 files changed, 17 insertions(+), 7 deletions(-)
diffs (88 lines):
diff -r 718f277f4887 -r 506eaab374dd sys/kern/subr_pool.c
--- a/sys/kern/subr_pool.c Wed Dec 30 18:39:03 2009 +0000
+++ b/sys/kern/subr_pool.c Wed Dec 30 18:57:16 2009 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_pool.c,v 1.177 2009/10/20 17:24:22 jym Exp $ */
+/* $NetBSD: subr_pool.c,v 1.178 2009/12/30 18:57:17 elad Exp $ */
/*-
* Copyright (c) 1997, 1999, 2000, 2002, 2007, 2008 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_pool.c,v 1.177 2009/10/20 17:24:22 jym Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_pool.c,v 1.178 2009/12/30 18:57:17 elad Exp $");
#include "opt_ddb.h"
#include "opt_pool.h"
@@ -104,6 +104,9 @@
static kmutex_t pool_head_lock;
static kcondvar_t pool_busy;
+/* This lock protects initialization of a potentially shared pool allocator */
+static kmutex_t pool_allocator_lock;
+
typedef uint32_t pool_item_bitmap_t;
#define BITMAP_SIZE (CHAR_BIT * sizeof(pool_item_bitmap_t))
#define BITMAP_MASK (BITMAP_SIZE - 1)
@@ -604,6 +607,8 @@
pool_init(&cache_cpu_pool, sizeof(pool_cache_cpu_t), coherency_unit,
0, 0, "pcachecpu", &pool_allocator_nointr, IPL_NONE);
+
+ mutex_init(&pool_allocator_lock, MUTEX_DEFAULT, IPL_NONE);
}
/*
@@ -650,7 +655,8 @@
palloc = &pool_allocator_nointr_fullpage;
}
#endif /* POOL_SUBPAGE */
- if ((palloc->pa_flags & PA_INITIALIZED) == 0) {
+ mutex_enter(&pool_allocator_lock);
+ if (palloc->pa_refcnt++ == 0) {
if (palloc->pa_pagesz == 0)
palloc->pa_pagesz = PAGE_SIZE;
@@ -663,8 +669,8 @@
if (palloc->pa_backingmapptr != NULL) {
pa_reclaim_register(palloc);
}
- palloc->pa_flags |= PA_INITIALIZED;
}
+ mutex_exit(&pool_allocator_lock);
if (align == 0)
align = ALIGN(1);
@@ -892,6 +898,11 @@
TAILQ_REMOVE(&pp->pr_alloc->pa_list, pp, pr_alloc_list);
mutex_exit(&pp->pr_alloc->pa_lock);
+ mutex_enter(&pool_allocator_lock);
+ if (--pp->pr_alloc->pa_refcnt == 0)
+ mutex_destroy(&pp->pr_alloc->pa_lock);
+ mutex_exit(&pool_allocator_lock);
+
mutex_enter(&pp->pr_lock);
KASSERT(pp->pr_cache == NULL);
diff -r 718f277f4887 -r 506eaab374dd sys/sys/pool.h
--- a/sys/sys/pool.h Wed Dec 30 18:39:03 2009 +0000
+++ b/sys/sys/pool.h Wed Dec 30 18:57:16 2009 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pool.h,v 1.67 2009/10/15 20:50:12 thorpej Exp $ */
+/* $NetBSD: pool.h,v 1.68 2009/12/30 18:57:16 elad Exp $ */
/*-
* Copyright (c) 1997, 1998, 1999, 2000, 2007 The NetBSD Foundation, Inc.
@@ -63,8 +63,7 @@
/* The following fields are for internal use only. */
kmutex_t pa_lock;
TAILQ_HEAD(, pool) pa_list; /* list of pools using this allocator */
- int pa_flags;
-#define PA_INITIALIZED 0x01
+ uint32_t pa_refcnt; /* number of pools using this allocator */
int pa_pagemask;
int pa_pageshift;
struct vm_map *pa_backingmap;
Home |
Main Index |
Thread Index |
Old Index