Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/kern replacing malloc(9) with kmem(9)
details: https://anonhg.NetBSD.org/src/rev/cfc9bcac4cde
branches: trunk
changeset: 773142:cfc9bcac4cde
user: para <para%NetBSD.org@localhost>
date: Sat Jan 28 18:02:56 2012 +0000
description:
replacing malloc(9) with kmem(9)
wapbl_entries get there own pool, they are freed from softint context
ok: rmind@
diffstat:
sys/kern/vfs_wapbl.c | 61 ++++++++++++++++++++++++++-------------------------
1 files changed, 31 insertions(+), 30 deletions(-)
diffs (211 lines):
diff -r d14e9a3928f4 -r cfc9bcac4cde sys/kern/vfs_wapbl.c
--- a/sys/kern/vfs_wapbl.c Sat Jan 28 16:30:23 2012 +0000
+++ b/sys/kern/vfs_wapbl.c Sat Jan 28 18:02:56 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vfs_wapbl.c,v 1.50 2012/01/27 19:48:40 para Exp $ */
+/* $NetBSD: vfs_wapbl.c,v 1.51 2012/01/28 18:02:56 para Exp $ */
/*-
* Copyright (c) 2003, 2008, 2009 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
#define WAPBL_INTERNAL
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_wapbl.c,v 1.50 2012/01/27 19:48:40 para Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_wapbl.c,v 1.51 2012/01/28 18:02:56 para Exp $");
#include <sys/param.h>
#include <sys/bitops.h>
@@ -49,7 +49,6 @@
#include <sys/uio.h>
#include <sys/vnode.h>
#include <sys/file.h>
-#include <sys/malloc.h>
#include <sys/module.h>
#include <sys/resourcevar.h>
#include <sys/conf.h>
@@ -63,16 +62,9 @@
#include <miscfs/specfs/specdev.h>
-#if 0 /* notyet */
-#define wapbl_malloc(s) kmem_intr_alloc((s), KM_SLEEP)
-#define wapbl_free(a, s) kmem_intr_free((a), (s))
-#define wapbl_calloc(n, s) kmem_intr_zalloc((n)*(s), KM_SLEEP)
-#else
-MALLOC_JUSTDEFINE(M_WAPBL, "wapbl", "write-ahead physical block logging");
-#define wapbl_malloc(s) malloc((s), M_WAPBL, M_WAITOK)
-#define wapbl_free(a, s) free((a), M_WAPBL)
-#define wapbl_calloc(n, s) malloc((n)*(s), M_WAPBL, M_WAITOK | M_ZERO)
-#endif
+#define wapbl_alloc(s) kmem_alloc((s), KM_SLEEP)
+#define wapbl_free(a, s) kmem_free((a), (s))
+#define wapbl_calloc(n, s) kmem_zalloc((n)*(s), KM_SLEEP)
static struct sysctllog *wapbl_sysctl;
static int wapbl_flush_disk_cache = 1;
@@ -92,7 +84,7 @@
#define KDASSERT(x) assert(x)
#define KASSERT(x) assert(x)
-#define wapbl_malloc(s) malloc(s)
+#define wapbl_alloc(s) malloc(s)
#define wapbl_free(a, s) free(a)
#define wapbl_calloc(n, s) calloc((n), (s))
@@ -220,6 +212,8 @@
#ifdef _KERNEL
+static struct pool wapbl_entry_pool;
+
#define WAPBL_INODETRK_SIZE 83
static int wapbl_ino_pool_refcount;
static struct pool wapbl_ino_pool;
@@ -310,7 +304,10 @@
static void
wapbl_init(void)
{
- //malloc_type_attach(M_WAPBL);
+
+ pool_init(&wapbl_entry_pool, sizeof(struct wapbl_entry), 0, 0, 0,
+ "wapblentrypl", &pool_allocator_kmem, IPL_VM);
+
wapbl_sysctl_init();
}
@@ -318,8 +315,12 @@
static int
wapbl_fini(bool interface)
{
+
if (aio_sysctl != NULL)
sysctl_teardown(&aio_sysctl);
+
+ pool_destroy(&wapbl_entry_pool);
+
return 0;
}
#endif
@@ -483,9 +484,9 @@
/* XXX tie this into resource estimation */
wl->wl_dealloclim = wl->wl_bufbytes_max / mp->mnt_stat.f_bsize / 2;
- wl->wl_deallocblks = wapbl_malloc(sizeof(*wl->wl_deallocblks) *
+ wl->wl_deallocblks = wapbl_alloc(sizeof(*wl->wl_deallocblks) *
wl->wl_dealloclim);
- wl->wl_dealloclens = wapbl_malloc(sizeof(*wl->wl_dealloclens) *
+ wl->wl_dealloclens = wapbl_alloc(sizeof(*wl->wl_dealloclens) *
wl->wl_dealloclim);
wapbl_inodetrk_init(wl, WAPBL_INODETRK_SIZE);
@@ -503,7 +504,7 @@
wc->wc_log_dev_bshift = wl->wl_log_dev_bshift;
wc->wc_fs_dev_bshift = wl->wl_fs_dev_bshift;
wl->wl_wc_header = wc;
- wl->wl_wc_scratch = wapbl_malloc(len);
+ wl->wl_wc_scratch = wapbl_alloc(len);
}
/*
@@ -657,7 +658,7 @@
#ifdef WAPBL_DEBUG_BUFBYTES
KASSERT(we->we_unsynced_bufbytes == 0);
#endif
- wapbl_free(we, sizeof(*we));
+ pool_put(&wapbl_entry_pool, we);
}
}
@@ -1239,7 +1240,7 @@
#ifdef WAPBL_DEBUG_BUFBYTES
KASSERT(we->we_unsynced_bufbytes == 0);
#endif
- wapbl_free(we, sizeof(*we));
+ pool_put(&wapbl_entry_pool, we);
}
brelse(bp, 0);
@@ -1331,7 +1332,7 @@
if (we->we_error)
errcnt++;
SIMPLEQ_REMOVE_HEAD(&wl->wl_entries, we_entries);
- wapbl_free(we, sizeof(*we));
+ pool_put(&wapbl_entry_pool, we);
}
if (delta) {
@@ -1472,7 +1473,7 @@
if (error)
goto out2;
- we = wapbl_calloc(1, sizeof(*we));
+ we = pool_get(&wapbl_entry_pool, PR_WAITOK);
#ifdef WAPBL_DEBUG_BUFBYTES
WAPBL_PRINTF(WAPBL_PRINT_FLUSH,
@@ -2093,7 +2094,7 @@
if (padding) {
void *zero;
- zero = wapbl_malloc(padding);
+ zero = wapbl_alloc(padding);
memset(zero, 0, padding);
error = wapbl_circ_write(wl, zero, padding, &off);
wapbl_free(zero, padding);
@@ -2220,7 +2221,7 @@
unsigned long i, hashsize;
for (hashsize = 1; hashsize < size; hashsize <<= 1)
continue;
- wr->wr_blkhash = wapbl_malloc(hashsize * sizeof(*wr->wr_blkhash));
+ wr->wr_blkhash = wapbl_alloc(hashsize * sizeof(*wr->wr_blkhash));
for (i = 0; i < hashsize; i++)
LIST_INIT(&wr->wr_blkhash[i]);
wr->wr_blkhashmask = hashsize - 1;
@@ -2263,7 +2264,7 @@
KASSERT(wb->wb_blk == blk);
wb->wb_off = off;
} else {
- wb = wapbl_malloc(sizeof(*wb));
+ wb = wapbl_alloc(sizeof(*wb));
wb->wb_blk = blk;
wb->wb_off = off;
wbh = &wr->wr_blkhash[blk & wr->wr_blkhashmask];
@@ -2411,7 +2412,7 @@
logpbn = off;
#endif /* ! _KERNEL */
- scratch = wapbl_malloc(MAXBSIZE);
+ scratch = wapbl_alloc(MAXBSIZE);
pbn = logpbn;
#ifdef _KERNEL
@@ -2577,7 +2578,7 @@
if (wc->wc_inocnt == 0)
return;
- new_inodes = wapbl_malloc((wr->wr_inodescnt + wc->wc_inocnt) *
+ new_inodes = wapbl_alloc((wr->wr_inodescnt + wc->wc_inocnt) *
sizeof(wr->wr_inodes[0]));
if (wr->wr_inodes != NULL) {
memcpy(new_inodes, wr->wr_inodes, oldsize);
@@ -2648,8 +2649,8 @@
int mismatchcnt = 0;
int logblklen = 1 << wr->wr_log_dev_bshift;
int fsblklen = 1 << wr->wr_fs_dev_bshift;
- void *scratch1 = wapbl_malloc(MAXBSIZE);
- void *scratch2 = wapbl_malloc(MAXBSIZE);
+ void *scratch1 = wapbl_alloc(MAXBSIZE);
+ void *scratch2 = wapbl_alloc(MAXBSIZE);
int error = 0;
KDASSERT(wapbl_replay_isopen(wr));
@@ -2772,7 +2773,7 @@
KDASSERT(wapbl_replay_isopen(wr));
- scratch = wapbl_malloc(MAXBSIZE);
+ scratch = wapbl_alloc(MAXBSIZE);
for (i = 0; i <= wr->wr_blkhashmask; ++i) {
LIST_FOREACH(wb, &wr->wr_blkhash[i], wb_hash) {
Home |
Main Index |
Thread Index |
Old Index