Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys - Replace few malloc(9) uses with kmem(9).
details: https://anonhg.NetBSD.org/src/rev/cb1a690a54b7
branches: trunk
changeset: 764458:cb1a690a54b7
user: rmind <rmind%NetBSD.org@localhost>
date: Sun Apr 24 18:46:22 2011 +0000
description:
- Replace few malloc(9) uses with kmem(9).
- Rename buf_malloc() to buf_alloc(), fix comments.
- Remove some unnecessary inclusions.
diffstat:
sys/kern/exec_aout.c | 5 ++---
sys/kern/exec_ecoff.c | 5 ++---
sys/kern/kern_ksyms.c | 6 +++---
sys/kern/kern_pax.c | 25 +++++++++++--------------
sys/kern/kern_softint.c | 5 ++---
sys/kern/subr_autoconf.c | 5 ++---
sys/kern/subr_blist.c | 25 ++++++++++++-------------
sys/kern/subr_prf.c | 5 ++---
sys/kern/subr_userconf.c | 5 ++---
sys/kern/uipc_mbuf.c | 5 ++---
sys/kern/uipc_socket2.c | 5 ++---
sys/kern/uipc_syscalls.c | 5 ++---
sys/kern/vfs_bio.c | 12 ++++++------
sys/sys/device.h | 4 ++--
sys/sys/event.h | 5 +----
sys/sys/file.h | 3 +--
sys/sys/namei.h | 5 ++---
sys/sys/namei.src | 5 ++---
18 files changed, 58 insertions(+), 77 deletions(-)
diffs (truncated from 582 to 300 lines):
diff -r 1b5d274e2b3f -r cb1a690a54b7 sys/kern/exec_aout.c
--- a/sys/kern/exec_aout.c Sun Apr 24 16:26:51 2011 +0000
+++ b/sys/kern/exec_aout.c Sun Apr 24 18:46:22 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: exec_aout.c,v 1.34 2008/11/19 18:36:06 ad Exp $ */
+/* $NetBSD: exec_aout.c,v 1.35 2011/04/24 18:46:22 rmind Exp $ */
/*
* Copyright (c) 1993, 1994 Christopher G. Demetriou
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: exec_aout.c,v 1.34 2008/11/19 18:36:06 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: exec_aout.c,v 1.35 2011/04/24 18:46:22 rmind Exp $");
#ifdef _KERNEL_OPT
#include "opt_coredump.h"
@@ -40,7 +40,6 @@
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/proc.h>
-#include <sys/malloc.h>
#include <sys/vnode.h>
#include <sys/exec.h>
#include <sys/exec_aout.h>
diff -r 1b5d274e2b3f -r cb1a690a54b7 sys/kern/exec_ecoff.c
--- a/sys/kern/exec_ecoff.c Sun Apr 24 16:26:51 2011 +0000
+++ b/sys/kern/exec_ecoff.c Sun Apr 24 18:46:22 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: exec_ecoff.c,v 1.28 2008/11/19 21:29:32 cegger Exp $ */
+/* $NetBSD: exec_ecoff.c,v 1.29 2011/04/24 18:46:22 rmind Exp $ */
/*
* Copyright (c) 1994 Adam Glass
@@ -33,7 +33,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: exec_ecoff.c,v 1.28 2008/11/19 21:29:32 cegger Exp $");
+__KERNEL_RCSID(0, "$NetBSD: exec_ecoff.c,v 1.29 2011/04/24 18:46:22 rmind Exp $");
#ifdef _KERNEL_OPT
#include "opt_coredump.h"
@@ -42,7 +42,6 @@
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/proc.h>
-#include <sys/malloc.h>
#include <sys/vnode.h>
#include <sys/exec.h>
#include <sys/resourcevar.h>
diff -r 1b5d274e2b3f -r cb1a690a54b7 sys/kern/kern_ksyms.c
--- a/sys/kern/kern_ksyms.c Sun Apr 24 16:26:51 2011 +0000
+++ b/sys/kern/kern_ksyms.c Sun Apr 24 18:46:22 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_ksyms.c,v 1.62 2011/01/04 01:40:19 matt Exp $ */
+/* $NetBSD: kern_ksyms.c,v 1.63 2011/04/24 18:46:22 rmind Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -71,7 +71,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_ksyms.c,v 1.62 2011/01/04 01:40:19 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_ksyms.c,v 1.63 2011/04/24 18:46:22 rmind Exp $");
#if defined(_KERNEL) && defined(_KERNEL_OPT)
#include "opt_ddb.h"
@@ -280,7 +280,7 @@
char *str;
int nsyms = symsize / sizeof(Elf_Sym);
- /* sanity check for pre-malloc map table used during startup */
+ /* Sanity check for pre-allocated map table used during startup. */
if ((nmap == ksyms_nmap) && (nsyms >= KSYMS_MAX_ID)) {
printf("kern_ksyms: ERROR %d > %d, increase KSYMS_MAX_ID\n",
nsyms, KSYMS_MAX_ID);
diff -r 1b5d274e2b3f -r cb1a690a54b7 sys/kern/kern_pax.c
--- a/sys/kern/kern_pax.c Sun Apr 24 16:26:51 2011 +0000
+++ b/sys/kern/kern_pax.c Sun Apr 24 18:46:22 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_pax.c,v 1.24 2010/08/23 20:53:08 christos Exp $ */
+/* $NetBSD: kern_pax.c,v 1.25 2011/04/24 18:46:22 rmind Exp $ */
/*-
* Copyright (c) 2006 Elad Efrat <elad%NetBSD.org@localhost>
@@ -28,7 +28,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_pax.c,v 1.24 2010/08/23 20:53:08 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_pax.c,v 1.25 2011/04/24 18:46:22 rmind Exp $");
#include "opt_pax.h"
@@ -37,7 +37,7 @@
#include <sys/exec_elf.h>
#include <sys/pax.h>
#include <sys/sysctl.h>
-#include <sys/malloc.h>
+#include <sys/kmem.h>
#include <sys/fileassoc.h>
#include <sys/syslog.h>
#include <sys/vnode.h>
@@ -363,19 +363,17 @@
static void
pax_segvguard_cb(void *v)
{
- struct pax_segvguard_entry *p;
+ struct pax_segvguard_entry *p = v;
struct pax_segvguard_uid_entry *up;
- if (v == NULL)
+ if (p == NULL) {
return;
-
- p = v;
+ }
while ((up = LIST_FIRST(&p->segv_uids)) != NULL) {
LIST_REMOVE(up, sue_list);
- free(up, M_TEMP);
+ kmem_free(up, sizeof(*up));
}
-
- free(v, M_TEMP);
+ kmem_free(p, sizeof(*p));
}
/*
@@ -417,7 +415,7 @@
* for it.
*/
if (p == NULL) {
- p = malloc(sizeof(*p), M_TEMP, M_WAITOK);
+ p = kmem_alloc(sizeof(*p), KM_SLEEP);
fileassoc_add(vp, segvguard_id, p);
LIST_INIT(&p->segv_uids);
@@ -426,7 +424,7 @@
* The expiry time is when we purge the entry if it didn't
* reach the limit.
*/
- up = malloc(sizeof(*up), M_TEMP, M_WAITOK);
+ up = kmem_alloc(sizeof(*up), KM_SLEEP);
up->sue_uid = kauth_cred_getuid(l->l_cred);
up->sue_ncrashes = 1;
up->sue_expiry = tv.tv_sec + pax_segvguard_expiry;
@@ -455,7 +453,7 @@
*/
if (!have_uid) {
if (crashed) {
- up = malloc(sizeof(*up), M_TEMP, M_WAITOK);
+ up = kmem_alloc(sizeof(*up), KM_SLEEP);
up->sue_uid = uid;
up->sue_ncrashes = 1;
up->sue_expiry = tv.tv_sec + pax_segvguard_expiry;
@@ -463,7 +461,6 @@
LIST_INSERT_HEAD(&p->segv_uids, up, sue_list);
}
-
return (0);
}
diff -r 1b5d274e2b3f -r cb1a690a54b7 sys/kern/kern_softint.c
--- a/sys/kern/kern_softint.c Sun Apr 24 16:26:51 2011 +0000
+++ b/sys/kern/kern_softint.c Sun Apr 24 18:46:22 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_softint.c,v 1.34 2011/04/11 19:13:54 rmind Exp $ */
+/* $NetBSD: kern_softint.c,v 1.35 2011/04/24 18:46:22 rmind Exp $ */
/*-
* Copyright (c) 2007, 2008 The NetBSD Foundation, Inc.
@@ -176,10 +176,9 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_softint.c,v 1.34 2011/04/11 19:13:54 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_softint.c,v 1.35 2011/04/24 18:46:22 rmind Exp $");
#include <sys/param.h>
-#include <sys/malloc.h>
#include <sys/proc.h>
#include <sys/intr.h>
#include <sys/mutex.h>
diff -r 1b5d274e2b3f -r cb1a690a54b7 sys/kern/subr_autoconf.c
--- a/sys/kern/subr_autoconf.c Sun Apr 24 16:26:51 2011 +0000
+++ b/sys/kern/subr_autoconf.c Sun Apr 24 18:46:22 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_autoconf.c,v 1.214 2011/04/02 08:11:31 mbalmer Exp $ */
+/* $NetBSD: subr_autoconf.c,v 1.215 2011/04/24 18:46:22 rmind Exp $ */
/*
* Copyright (c) 1996, 2000 Christopher G. Demetriou
@@ -77,7 +77,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.214 2011/04/02 08:11:31 mbalmer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.215 2011/04/24 18:46:22 rmind Exp $");
#ifdef _KERNEL_OPT
#include "opt_ddb.h"
@@ -88,7 +88,6 @@
#include <sys/disklabel.h>
#include <sys/conf.h>
#include <sys/kauth.h>
-#include <sys/malloc.h>
#include <sys/kmem.h>
#include <sys/systm.h>
#include <sys/kernel.h>
diff -r 1b5d274e2b3f -r cb1a690a54b7 sys/kern/subr_blist.c
--- a/sys/kern/subr_blist.c Sun Apr 24 16:26:51 2011 +0000
+++ b/sys/kern/subr_blist.c Sun Apr 24 18:46:22 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_blist.c,v 1.9 2006/01/20 14:19:40 yamt Exp $ */
+/* $NetBSD: subr_blist.c,v 1.10 2011/04/24 18:46:22 rmind Exp $ */
/*-
* Copyright (c) 1998 Matthew Dillon. All Rights Reserved.
@@ -86,7 +86,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_blist.c,v 1.9 2006/01/20 14:19:40 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_blist.c,v 1.10 2011/04/24 18:46:22 rmind Exp $");
#if 0
__FBSDID("$FreeBSD: src/sys/kern/subr_blist.c,v 1.17 2004/06/04 04:03:25 alc Exp $");
#endif
@@ -96,7 +96,7 @@
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/blist.h>
-#include <sys/malloc.h>
+#include <sys/kmem.h>
#else
@@ -111,8 +111,10 @@
#include <stdarg.h>
#include <inttypes.h>
-#define malloc(a,b,c) calloc(a, 1)
-#define free(a,b) free(a)
+#define KM_SLEEP 1
+#define kmem_zalloc(a,b,c) calloc(1, (a))
+#define kmem_alloc(a,b,c) malloc(a)
+#define kmem_free(a,b) free(a)
#include "../sys/blist.h"
@@ -168,10 +170,6 @@
blist_blkno_t radix, blist_blkno_t skip, int tab);
#endif
-#ifdef _KERNEL
-static MALLOC_DEFINE(M_BLIST, "blist", "Bitmap allocator");
-#endif
-
/*
* blist_create() - create a blist capable of handling up to the specified
* number of blocks
@@ -201,14 +199,14 @@
skip = (skip + 1) * BLIST_META_RADIX;
}
- bl = malloc(sizeof(struct blist), M_BLIST, M_WAITOK | M_ZERO);
+ bl = kmem_zalloc(sizeof(struct blist), KM_SLEEP);
bl->bl_blocks = blocks;
bl->bl_radix = radix;
bl->bl_skip = skip;
bl->bl_rootblks = 1 +
blst_radix_init(NULL, bl->bl_radix, bl->bl_skip, blocks);
- bl->bl_root = malloc(sizeof(blmeta_t) * bl->bl_rootblks, M_BLIST, M_WAITOK);
+ bl->bl_root = kmem_alloc(sizeof(blmeta_t) * bl->bl_rootblks, KM_SLEEP);
#if defined(BLIST_DEBUG)
printf(
@@ -229,8 +227,9 @@
void
blist_destroy(blist_t bl)
{
- free(bl->bl_root, M_BLIST);
- free(bl, M_BLIST);
+
+ kmem_free(bl->bl_root, sizeof(blmeta_t) * bl->bl_rootblks);
+ kmem_free(bl, sizeof(struct blist));
}
/*
diff -r 1b5d274e2b3f -r cb1a690a54b7 sys/kern/subr_prf.c
--- a/sys/kern/subr_prf.c Sun Apr 24 16:26:51 2011 +0000
+++ b/sys/kern/subr_prf.c Sun Apr 24 18:46:22 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_prf.c,v 1.139 2011/01/21 17:46:19 dyoung Exp $ */
+/* $NetBSD: subr_prf.c,v 1.140 2011/04/24 18:46:22 rmind Exp $ */
Home |
Main Index |
Thread Index |
Old Index