Source-Changes-HG archive

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

[src/trunk]: src/sys - Replace some malloc(9) uses with kmem(9).



details:   https://anonhg.NetBSD.org/src/rev/e617f11e4e60
branches:  trunk
changeset: 779085:e617f11e4e60
user:      rmind <rmind%NetBSD.org@localhost>
date:      Mon Apr 30 22:51:27 2012 +0000

description:
- Replace some malloc(9) uses with kmem(9).
- G/C M_IPMOPTS, M_IPMADDR and M_BWMETER.

diffstat:

 sys/fs/union/union_vfsops.c         |  13 +++++------
 sys/kern/kern_malloc.c              |   7 +----
 sys/miscfs/nullfs/null_vfsops.c     |  10 ++++----
 sys/miscfs/overlay/overlay_vfsops.c |  14 +++++-------
 sys/miscfs/procfs/procfs_vfsops.c   |  11 ++++-----
 sys/miscfs/umapfs/umap_vfsops.c     |  17 ++++++---------
 sys/netinet/ip_mroute.c             |  12 +++++-----
 sys/netinet/ip_output.c             |  21 +++++++++----------
 sys/sys/malloc.h                    |   5 +---
 sys/ufs/chfs/chfs_vfsops.c          |  40 ++++++++++++------------------------
 sys/ufs/ext2fs/ext2fs_vfsops.c      |  26 +++++++++++------------
 sys/ufs/lfs/lfs_vfsops.c            |  19 +++++++++--------
 12 files changed, 84 insertions(+), 111 deletions(-)

diffs (truncated from 663 to 300 lines):

diff -r 3ac633ac8008 -r e617f11e4e60 sys/fs/union/union_vfsops.c
--- a/sys/fs/union/union_vfsops.c       Mon Apr 30 21:19:58 2012 +0000
+++ b/sys/fs/union/union_vfsops.c       Mon Apr 30 22:51:27 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: union_vfsops.c,v 1.67 2011/12/05 11:12:10 hannken Exp $        */
+/*     $NetBSD: union_vfsops.c,v 1.68 2012/04/30 22:51:27 rmind Exp $  */
 
 /*
  * Copyright (c) 1994 The Regents of the University of California.
@@ -77,7 +77,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: union_vfsops.c,v 1.67 2011/12/05 11:12:10 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: union_vfsops.c,v 1.68 2012/04/30 22:51:27 rmind Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -164,8 +164,7 @@
                goto bad;
        }
 
-       um = (struct union_mount *) malloc(sizeof(struct union_mount),
-                               M_UFSMNT, M_WAITOK);    /* XXX */
+       um = kmem_zalloc(sizeof(struct union_mount), KM_SLEEP);
 
        /*
         * Keep a held reference to the target vnodes.
@@ -291,7 +290,7 @@
 
 bad:
        if (um)
-               free(um, M_UFSMNT);
+               kmem_free(um, sizeof(struct union_mount));
        if (upperrootvp)
                vrele(upperrootvp);
        if (lowerrootvp)
@@ -372,9 +371,9 @@
        /*
         * Finally, throw away the union_mount structure
         */
-       free(mp->mnt_data, M_UFSMNT);   /* XXX */
+       kmem_free(um, sizeof(struct union_mount));
        mp->mnt_data = NULL;
-       return (0);
+       return 0;
 }
 
 int
diff -r 3ac633ac8008 -r e617f11e4e60 sys/kern/kern_malloc.c
--- a/sys/kern/kern_malloc.c    Mon Apr 30 21:19:58 2012 +0000
+++ b/sys/kern/kern_malloc.c    Mon Apr 30 22:51:27 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_malloc.c,v 1.141 2012/04/29 20:27:31 dsl Exp $    */
+/*     $NetBSD: kern_malloc.c,v 1.142 2012/04/30 22:51:27 rmind Exp $  */
 
 /*
  * Copyright (c) 1987, 1991, 1993
@@ -70,7 +70,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_malloc.c,v 1.141 2012/04/29 20:27:31 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_malloc.c,v 1.142 2012/04/30 22:51:27 rmind Exp $");
 
 #include <sys/param.h>
 #include <sys/malloc.h>
@@ -90,10 +90,7 @@
 MALLOC_DEFINE(M_FTABLE, "fragtbl", "fragment reassembly header");
 MALLOC_DEFINE(M_UFSMNT, "UFS mount", "UFS mount structure");
 MALLOC_DEFINE(M_NETADDR, "Export Host", "Export host address structure");
-MALLOC_DEFINE(M_IPMOPTS, "ip_moptions", "internet multicast options");
-MALLOC_DEFINE(M_IPMADDR, "in_multi", "internet multicast address");
 MALLOC_DEFINE(M_MRTABLE, "mrt", "multicast routing tables");
-MALLOC_DEFINE(M_BWMETER, "bwmeter", "multicast upcall bw meters");
 
 /*
  * Header contains total size, including the header itself.
diff -r 3ac633ac8008 -r e617f11e4e60 sys/miscfs/nullfs/null_vfsops.c
--- a/sys/miscfs/nullfs/null_vfsops.c   Mon Apr 30 21:19:58 2012 +0000
+++ b/sys/miscfs/nullfs/null_vfsops.c   Mon Apr 30 22:51:27 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: null_vfsops.c,v 1.83 2010/11/19 06:44:46 dholland Exp $        */
+/*     $NetBSD: null_vfsops.c,v 1.84 2012/04/30 22:51:27 rmind Exp $   */
 
 /*
  * Copyright (c) 1999 National Aeronautics & Space Administration
@@ -76,7 +76,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: null_vfsops.c,v 1.83 2010/11/19 06:44:46 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: null_vfsops.c,v 1.84 2012/04/30 22:51:27 rmind Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -137,7 +137,7 @@
        pathbuf_destroy(pb);
 
        /* Create the mount point. */
-       nmp = malloc(sizeof(struct null_mount), M_UFSMNT, M_WAITOK | M_ZERO);
+       nmp = kmem_zalloc(sizeof(struct null_mount), KM_SLEEP);
        mp->mnt_data = nmp;
        nmp->nullm_vfs = lowerrootvp->v_mount;
        if (nmp->nullm_vfs->mnt_flag & MNT_LOCAL)
@@ -164,7 +164,7 @@
                vput(lowerrootvp);
                hashdone(nmp->nullm_node_hashtbl, HASH_LIST,
                    nmp->nullm_node_hash);
-               free(nmp, M_UFSMNT);
+               kmem_free(nmp, sizeof(struct null_mount));
                return error;
        }
        /*
@@ -203,7 +203,7 @@
        /* Finally, destroy the mount point structures. */
        hashdone(nmp->nullm_node_hashtbl, HASH_LIST, nmp->nullm_node_hash);
        mutex_destroy(&nmp->nullm_hashlock);
-       free(mp->mnt_data, M_UFSMNT);
+       kmem_free(mp->mnt_data, sizeof(struct null_mount));
        mp->mnt_data = NULL;
        return 0;
 }
diff -r 3ac633ac8008 -r e617f11e4e60 sys/miscfs/overlay/overlay_vfsops.c
--- a/sys/miscfs/overlay/overlay_vfsops.c       Mon Apr 30 21:19:58 2012 +0000
+++ b/sys/miscfs/overlay/overlay_vfsops.c       Mon Apr 30 22:51:27 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: overlay_vfsops.c,v 1.56 2010/07/09 08:14:26 hannken Exp $      */
+/*     $NetBSD: overlay_vfsops.c,v 1.57 2012/04/30 22:51:27 rmind Exp $        */
 
 /*
  * Copyright (c) 1999, 2000 National Aeronautics & Space Administration
@@ -74,7 +74,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: overlay_vfsops.c,v 1.56 2010/07/09 08:14:26 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: overlay_vfsops.c,v 1.57 2012/04/30 22:51:27 rmind Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -145,9 +145,7 @@
        /*
         * First cut at fixing up upper mount point
         */
-       nmp = (struct overlay_mount *) malloc(sizeof(struct overlay_mount),
-                               M_UFSMNT, M_WAITOK);    /* XXX */
-       memset(nmp, 0, sizeof(struct overlay_mount));
+       nmp = kmem_zalloc(sizeof(struct overlay_mount), KM_SLEEP);
 
        mp->mnt_data = nmp;
        nmp->ovm_vfs = lowerrootvp->v_mount;
@@ -179,8 +177,8 @@
        if (error) {
                vput(lowerrootvp);
                hashdone(nmp->ovm_node_hashtbl, HASH_LIST, nmp->ovm_node_hash);
-               free(nmp, M_UFSMNT);    /* XXX */
-               return (error);
+               kmem_free(nmp, sizeof(struct overlay_mount));
+               return error;
        }
        /*
         * Unlock the node
@@ -239,7 +237,7 @@
        omp = mp->mnt_data;
        mutex_destroy(&omp->ovm_hashlock);
        hashdone(omp->ovm_node_hashtbl, HASH_LIST, omp->ovm_node_hash);
-       free(omp, M_UFSMNT);    /* XXX */
+       kmem_free(omp, sizeof(struct overlay_mount));
        mp->mnt_data = NULL;
        return 0;
 }
diff -r 3ac633ac8008 -r e617f11e4e60 sys/miscfs/procfs/procfs_vfsops.c
--- a/sys/miscfs/procfs/procfs_vfsops.c Mon Apr 30 21:19:58 2012 +0000
+++ b/sys/miscfs/procfs/procfs_vfsops.c Mon Apr 30 22:51:27 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: procfs_vfsops.c,v 1.86 2011/09/27 01:23:59 christos Exp $      */
+/*     $NetBSD: procfs_vfsops.c,v 1.87 2012/04/30 22:51:28 rmind Exp $ */
 
 /*
  * Copyright (c) 1993
@@ -76,7 +76,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: procfs_vfsops.c,v 1.86 2011/09/27 01:23:59 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: procfs_vfsops.c,v 1.87 2012/04/30 22:51:28 rmind Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_compat_netbsd.h"
@@ -154,8 +154,7 @@
        if (*data_len >= sizeof *args && args->version != PROCFS_ARGSVERSION)
                return EINVAL;
 
-       pmnt = (struct procfsmount *) malloc(sizeof(struct procfsmount),
-           M_UFSMNT, M_WAITOK);   /* XXX need new malloc type */
+       pmnt = kmem_zalloc(sizeof(struct procfsmount), KM_SLEEP);
 
        mp->mnt_stat.f_namemax = PROCFS_MAXNAMLEN;
        mp->mnt_flag |= MNT_LOCAL;
@@ -191,10 +190,10 @@
 
        exechook_disestablish(VFSTOPROC(mp)->pmnt_exechook);
 
-       free(mp->mnt_data, M_UFSMNT);
+       kmem_free(mp->mnt_data, sizeof(struct procfsmount));
        mp->mnt_data = NULL;
 
-       return (0);
+       return 0;
 }
 
 int
diff -r 3ac633ac8008 -r e617f11e4e60 sys/miscfs/umapfs/umap_vfsops.c
--- a/sys/miscfs/umapfs/umap_vfsops.c   Mon Apr 30 21:19:58 2012 +0000
+++ b/sys/miscfs/umapfs/umap_vfsops.c   Mon Apr 30 22:51:27 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: umap_vfsops.c,v 1.87 2012/03/13 18:40:58 elad Exp $    */
+/*     $NetBSD: umap_vfsops.c,v 1.88 2012/04/30 22:51:28 rmind Exp $   */
 
 /*
  * Copyright (c) 1992, 1993
@@ -41,7 +41,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: umap_vfsops.c,v 1.87 2012/03/13 18:40:58 elad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: umap_vfsops.c,v 1.88 2012/04/30 22:51:28 rmind Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -142,10 +142,7 @@
        printf("mp = %p\n", mp);
 #endif
 
-       amp = (struct umap_mount *) malloc(sizeof(struct umap_mount),
-                               M_UFSMNT, M_WAITOK);    /* XXX */
-       memset(amp, 0, sizeof(struct umap_mount));
-
+       amp = kmem_zalloc(sizeof(struct umap_mount), KM_SLEEP);
        mp->mnt_data = amp;
        amp->umapm_vfs = lowerrootvp->v_mount;
        if (amp->umapm_vfs->mnt_flag & MNT_LOCAL)
@@ -216,8 +213,8 @@
                vput(lowerrootvp);
                hashdone(amp->umapm_node_hashtbl, HASH_LIST,
                    amp->umapm_node_hash);
-               free(amp, M_UFSMNT);    /* XXX */
-               return (error);
+               kmem_free(amp, sizeof(struct umap_mount));
+               return error;
        }
        /*
         * Unlock the node (either the lower or the alias)
@@ -275,9 +272,9 @@
         */
        mutex_destroy(&amp->umapm_hashlock);
        hashdone(amp->umapm_node_hashtbl, HASH_LIST, amp->umapm_node_hash);
-       free(amp, M_UFSMNT);    /* XXX */
+       kmem_free(amp, sizeof(struct umap_mount));
        mp->mnt_data = NULL;
-       return (0);
+       return 0;
 }
 
 extern const struct vnodeopv_desc umapfs_vnodeop_opv_desc;
diff -r 3ac633ac8008 -r e617f11e4e60 sys/netinet/ip_mroute.c
--- a/sys/netinet/ip_mroute.c   Mon Apr 30 21:19:58 2012 +0000
+++ b/sys/netinet/ip_mroute.c   Mon Apr 30 22:51:27 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ip_mroute.c,v 1.123 2012/03/22 20:34:39 drochner Exp $ */
+/*     $NetBSD: ip_mroute.c,v 1.124 2012/04/30 22:51:28 rmind Exp $    */
 
 /*
  * Copyright (c) 1992, 1993
@@ -93,7 +93,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_mroute.c,v 1.123 2012/03/22 20:34:39 drochner Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_mroute.c,v 1.124 2012/04/30 22:51:28 rmind Exp $");
 
 #include "opt_inet.h"
 #include "opt_ipsec.h"
@@ -1571,7 +1571,7 @@
                                struct bw_meter *x = rt->mfc_bw_meter;
 
                                rt->mfc_bw_meter = x->bm_mfc_next;
-                               free(x, M_BWMETER);
+                               kmem_free(x, sizeof(*x));
                        }
 
                        ++mrtstat.mrts_cache_cleanups;
@@ -2511,7 +2511,7 @@
     }
 
     /* Allocate the new bw_meter entry */
-    x = (struct bw_meter *)malloc(sizeof(*x), M_BWMETER, M_NOWAIT);
+    x = kmem_intr_alloc(sizeof(*x), KM_NOSLEEP);
     if (x == NULL) {



Home | Main Index | Thread Index | Old Index