tech-kern archive

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

Re: kernel memory allocators



sorry, patch was broken (had one MALLOC_JUSTDEFINE those macros were removed)
fixed version attached....


On Fri, Feb 4, 2011 at 4:18 PM, Lars Heidieker
<lars.heidieker%googlemail.com@localhost> wrote:
> Here is an updated version of my kmem-pool patch....
> In the meantime I have compile tested this for:
>
> amd64
> i386
> sparc64
> sparc
> evbarm (BEAGLBOARD)
> dreamcast
> prep
> sgimips
> amiga
> atari
> hp700
>
> and some more where I had compile problems somewhere unrelated:
> alpha
> ia64
> sgimips64
>
> I succesfully use this patch on i386, amd64 and have successfully
> booted a sparc64 kernel on a dual processor Ultra60...
>
> Investigation of how malloc(9) is used it is pretty big piece of work
> to replace it with kmem(9) as sizes are unknown in a lot of places
> when free is called.
> uvm is now malloc(9) free as well as extent(9).
>
> As mentioned earlier in this thread having a variable sized memory
> allocator, that can be called from interrupt context shouldn't
> necessary.
> For me the next steps would be to identify, malloc(9) calls that
> require interrupt safety and remove either this requirement or make
> fixed sized pools for them.
> This will result in a situation where kmem(9) (patched version) can be
> made non-interrupt-safe again, leaving us with two interfaces to a
> generic memory allocator, a situation I don't like.
> I found a few places where external libs where involved that require a
> malloc/free styled interface as they get such functions hooked in
> therefor a small malloc wrapper around kmem(9) is required.
> This wrapper can either made very thin (my preferences) removing all
> the malloc_types or it can be made more elaborate to gather statistics
> in which case it doesn't make sense to "bypass" it with a second
> interface (kmem).
>
> Lars
>



-- 
Mystische Erklärungen:
Die mystischen Erklärungen gelten für tief;
die Wahrheit ist, dass sie noch nicht einmal oberflächlich sind.
   -- Friedrich Nietzsche
   [ Die Fröhliche Wissenschaft Buch 3, 126 ]
? external/mit/xorg/lib/xkeyboard-config/xkeyboard-config.pc
? sys/arch/i386/compile/BOX
? sys/arch/i386/conf/BOX
Index: share/man/man9/extent.9
===================================================================
RCS file: /cvsroot/src/share/man/man9/extent.9,v
retrieving revision 1.29
diff -u -r1.29 extent.9
--- share/man/man9/extent.9     2 Dec 2010 12:54:13 -0000       1.29
+++ share/man/man9/extent.9     4 Feb 2011 15:35:45 -0000
@@ -44,7 +44,7 @@
 .In sys/malloc.h
 .In sys/extent.h
 .Ft struct extent *
-.Fn extent_create "char *name" "u_long start" "u_long end" "int mtype" "void 
*storage" "size_t storagesize" "int flags"
+.Fn extent_create "char *name" "u_long start" "u_long end" "void *storage" 
"size_t storagesize" "int flags"
 .Ft void
 .Fn extent_destroy "struct extent *ex"
 .Ft int
@@ -87,12 +87,6 @@
 to
 .Fa end
 inclusive.
-All memory allocation will use the memory type
-.Fa mtype
-.Po
-see
-.Xr malloc 9
-.Pc .
 The extent map will have the name
 .Fa name ,
 used for identification in case of an error.
Index: sys/arch/algor/dev/mainbus.c
===================================================================
RCS file: /cvsroot/src/sys/arch/algor/dev/mainbus.c,v
retrieving revision 1.20
diff -u -r1.20 mainbus.c
--- sys/arch/algor/dev/mainbus.c        28 Apr 2008 20:23:10 -0000      1.20
+++ sys/arch/algor/dev/mainbus.c        4 Feb 2011 15:35:47 -0000
@@ -159,9 +159,9 @@
         * Reserve the bottom 64K of the I/O space for ISA devices.
         */
        ioext  = extent_create("pciio",  0x00010000, 0x000effff,
-           M_DEVBUF, NULL, 0, EX_NOWAIT);
+           NULL, 0, EX_NOWAIT);
        memext = extent_create("pcimem", 0x01000000, 0x07ffffff,
-           M_DEVBUF, NULL, 0, EX_NOWAIT);
+           NULL, 0, EX_NOWAIT);
 
        pc = &p4032_configuration.ac_pc;
 #elif defined(ALGOR_P5064)
@@ -171,9 +171,9 @@
         * a bug in the ISA bridge.
         */
        ioext  = extent_create("pciio",  0x00080000, 0x00ffffff,
-           M_DEVBUF, NULL, 0, EX_NOWAIT);
+           NULL, 0, EX_NOWAIT);
        memext = extent_create("pcimem", 0x01000000, 0x07ffffff,
-           M_DEVBUF, NULL, 0, EX_NOWAIT);
+           NULL, 0, EX_NOWAIT);
 
        pc = &p5064_configuration.ac_pc;
 #if defined(PCI_NETBSD_ENABLE_IDE)
@@ -184,9 +184,9 @@
         * Reserve the bottom 64K of the I/O space for ISA devices.
         */
        ioext  = extent_create("pciio",  0x00010000, 0x000effff,
-           M_DEVBUF, NULL, 0, EX_NOWAIT);
+           NULL, 0, EX_NOWAIT);
        memext = extent_create("pcimem", 0x01000000, 0x0affffff,
-           M_DEVBUF, NULL, 0, EX_NOWAIT);
+           NULL, 0, EX_NOWAIT);
 
        pc = &p6032_configuration.ac_pc;
 #if defined(PCI_NETBSD_ENABLE_IDE)
Index: sys/arch/algor/pci/pci_alignstride_bus_io_chipdep.c
===================================================================
RCS file: /cvsroot/src/sys/arch/algor/pci/pci_alignstride_bus_io_chipdep.c,v
retrieving revision 1.9
diff -u -r1.9 pci_alignstride_bus_io_chipdep.c
--- sys/arch/algor/pci/pci_alignstride_bus_io_chipdep.c 14 Mar 2009 14:45:52 
-0000      1.9
+++ sys/arch/algor/pci/pci_alignstride_bus_io_chipdep.c 4 Feb 2011 15:35:48 
-0000
@@ -310,7 +310,7 @@
 #ifdef CHIP_IO_EXTENT
        /* XXX WE WANT EXTENT_NOCOALESCE, BUT WE CAN'T USE IT. XXX */
        ex = extent_create(__S(__C(CHIP,_bus_io)), 0x0UL, 0xffffffffUL,
-           M_DEVBUF, (void *)CHIP_IO_EX_STORE(v), CHIP_IO_EX_STORE_SIZE(v),
+           (void *)CHIP_IO_EX_STORE(v), CHIP_IO_EX_STORE_SIZE(v),
            EX_NOWAIT);
        extent_alloc_region(ex, 0, 0xffffffffUL, EX_NOWAIT);
 
Index: sys/arch/algor/pci/pci_alignstride_bus_mem_chipdep.c
===================================================================
RCS file: /cvsroot/src/sys/arch/algor/pci/pci_alignstride_bus_mem_chipdep.c,v
retrieving revision 1.8
diff -u -r1.8 pci_alignstride_bus_mem_chipdep.c
--- sys/arch/algor/pci/pci_alignstride_bus_mem_chipdep.c        14 Mar 2009 
14:45:52 -0000      1.8
+++ sys/arch/algor/pci/pci_alignstride_bus_mem_chipdep.c        4 Feb 2011 
15:35:49 -0000
@@ -304,7 +304,7 @@
 
        /* XXX WE WANT EXTENT_NOCOALESCE, BUT WE CAN'T USE IT. XXX */
        ex = extent_create(__S(__C(CHIP,_bus_mem)), 0x0UL, 0xffffffffUL,
-           M_DEVBUF, (void *)CHIP_MEM_EX_STORE(v), CHIP_MEM_EX_STORE_SIZE(v),
+           (void *)CHIP_MEM_EX_STORE(v), CHIP_MEM_EX_STORE_SIZE(v),
            EX_NOWAIT);
        extent_alloc_region(ex, 0, 0xffffffffUL, EX_NOWAIT);
 
Index: sys/arch/alpha/alpha/pmap.c
===================================================================
RCS file: /cvsroot/src/sys/arch/alpha/alpha/pmap.c,v
retrieving revision 1.255
diff -u -r1.255 pmap.c
--- sys/arch/alpha/alpha/pmap.c 12 Nov 2010 07:59:25 -0000      1.255
+++ sys/arch/alpha/alpha/pmap.c 4 Feb 2011 15:35:51 -0000
@@ -759,7 +759,7 @@
        /*
         * Compute the number of pages kmem_map will have.
         */
-       kmeminit_nkmempages();
+       uvm_km_setupkmemsize();
 
        /*
         * Figure out how many initial PTE's are necessary to map the
@@ -882,20 +882,6 @@
        /* Nothing to do; it's already zero'd */
 
        /*
-        * Initialize the pmap pools and list.
-        */
-       pmap_ncpuids = ncpuids;
-       pool_cache_bootstrap(&pmap_pmap_cache, PMAP_SIZEOF(pmap_ncpuids), 0,
-           0, 0, "pmap", NULL, IPL_NONE, NULL, NULL, NULL);
-       pool_cache_bootstrap(&pmap_l1pt_cache, PAGE_SIZE, 0, 0, 0, "pmapl1pt",
-           &pmap_l1pt_allocator, IPL_NONE, pmap_l1pt_ctor, NULL, NULL);
-       pool_cache_bootstrap(&pmap_pv_cache, sizeof(struct pv_entry), 0, 0,
-           PR_LARGECACHE, "pmappv", &pmap_pv_page_allocator, IPL_NONE, NULL,
-           NULL, NULL);
-
-       TAILQ_INIT(&pmap_all_pmaps);
-
-       /*
         * Initialize the ASN logic.
         */
        pmap_max_asn = maxasn;
@@ -903,10 +889,14 @@
                pmap_asn_info[i].pma_asn = 1;
                pmap_asn_info[i].pma_asngen = 0;
        }
+       pmap_ncpuids = ncpuids;
 
        /*
         * Initialize the locks.
         */
+
+       TAILQ_INIT(&pmap_all_pmaps);
+
        rw_init(&pmap_main_lock);
        mutex_init(&pmap_all_pmaps_lock, MUTEX_DEFAULT, IPL_NONE);
        for (i = 0; i < __arraycount(pmap_pvh_locks); i++) {
@@ -931,19 +921,6 @@
        mutex_init(&pmap_kernel()->pm_lock, MUTEX_DEFAULT, IPL_NONE);
        TAILQ_INSERT_TAIL(&pmap_all_pmaps, pmap_kernel(), pm_list);
 
-#if defined(MULTIPROCESSOR)
-       /*
-        * Initialize the TLB shootdown queues.
-        */
-       pool_cache_bootstrap(&pmap_tlb_shootdown_job_cache,
-           sizeof(struct pmap_tlb_shootdown_job), CACHE_LINE_SIZE,
-            0, PR_LARGECACHE, "pmaptlb", NULL, IPL_VM, NULL, NULL, NULL);
-       for (i = 0; i < ALPHA_MAXPROCS; i++) {
-               TAILQ_INIT(&pmap_tlb_shootdown_q[i].pq_head);
-               mutex_init(&pmap_tlb_shootdown_q[i].pq_lock, MUTEX_DEFAULT,
-                   IPL_SCHED);
-       }
-#endif
 
        /*
         * Set up lwp0's PCB such that the ptbr points to the right place
@@ -1086,14 +1063,43 @@
  *     Note: no locking is necessary in this function.
  */
 void
-pmap_init(void)
+pmap_init()
 {
+#if defined(MULTIPROCESSOR)
+       int i;
+#endif
 
 #ifdef DEBUG
         if (pmapdebug & PDB_FOLLOW)
                 printf("pmap_init()\n");
 #endif
 
+       /*
+        * Initialize the pmap pools and list.
+        */
+       pool_cache_bootstrap(&pmap_pmap_cache, PMAP_SIZEOF(pmap_ncpuids), 0,
+               0, 0, "pmap", NULL, IPL_NONE, NULL, NULL, NULL);
+       pool_cache_bootstrap(&pmap_l1pt_cache, PAGE_SIZE, 0, 0, 0, "pmapl1pt",
+               &pmap_l1pt_allocator, IPL_NONE, pmap_l1pt_ctor, NULL, NULL);
+       pool_cache_bootstrap(&pmap_pv_cache, sizeof(struct pv_entry), 0, 0,
+               PR_LARGECACHE, "pmappv", &pmap_pv_page_allocator, IPL_NONE, 
NULL,
+               NULL, NULL);
+
+
+#if defined(MULTIPROCESSOR)
+       /*
+        * Initialize the TLB shootdown queues.
+        */
+       pool_cache_bootstrap(&pmap_tlb_shootdown_job_cache,
+               sizeof(struct pmap_tlb_shootdown_job), CACHE_LINE_SIZE,
+               0, PR_LARGECACHE, "pmaptlb", NULL, IPL_VM, NULL, NULL, NULL);
+       for (i = 0; i < ALPHA_MAXPROCS; i++) {
+               TAILQ_INIT(&pmap_tlb_shootdown_q[i].pq_head);
+               mutex_init(&pmap_tlb_shootdown_q[i].pq_lock, MUTEX_DEFAULT,
+                       IPL_SCHED);
+       }
+#endif
+
        /* initialize protection array */
        alpha_protection_init();
 
Index: sys/arch/alpha/common/sgmap_common.c
===================================================================
RCS file: /cvsroot/src/sys/arch/alpha/common/sgmap_common.c,v
retrieving revision 1.24
diff -u -r1.24 sgmap_common.c
--- sys/arch/alpha/common/sgmap_common.c        28 Apr 2008 20:23:11 -0000      
1.24
+++ sys/arch/alpha/common/sgmap_common.c        4 Feb 2011 15:35:51 -0000
@@ -107,7 +107,7 @@
         * space.
         */
        sgmap->aps_ex = extent_create(name, sgvabase, sgvasize - 1,
-           M_DMAMAP, NULL, 0, EX_NOWAIT|EX_NOCOALESCE);
+           NULL, 0, EX_NOWAIT|EX_NOCOALESCE);
        if (sgmap->aps_ex == NULL) {
                printf("unable to create extent map for sgmap `%s'\n",
                    name);
Index: sys/arch/alpha/pci/pci_bwx_bus_io_chipdep.c
===================================================================
RCS file: /cvsroot/src/sys/arch/alpha/pci/pci_bwx_bus_io_chipdep.c,v
retrieving revision 1.18
diff -u -r1.18 pci_bwx_bus_io_chipdep.c
--- sys/arch/alpha/pci/pci_bwx_bus_io_chipdep.c 14 Mar 2009 14:45:53 -0000      
1.18
+++ sys/arch/alpha/pci/pci_bwx_bus_io_chipdep.c 4 Feb 2011 15:35:52 -0000
@@ -302,7 +302,7 @@
        t->abs_c_8 =            __C(CHIP,_io_copy_region_8);
 
        ex = extent_create(__S(__C(CHIP,_bus_io)), 0x0UL, 0xffffffffUL,
-           M_DEVBUF, (void *)CHIP_IO_EX_STORE(v), CHIP_IO_EX_STORE_SIZE(v),
+           (void *)CHIP_IO_EX_STORE(v), CHIP_IO_EX_STORE_SIZE(v),
            EX_NOWAIT|EX_NOCOALESCE);
 
        CHIP_IO_EXTENT(v) = ex;
Index: sys/arch/alpha/pci/pci_bwx_bus_mem_chipdep.c
===================================================================
RCS file: /cvsroot/src/sys/arch/alpha/pci/pci_bwx_bus_mem_chipdep.c,v
retrieving revision 1.22
diff -u -r1.22 pci_bwx_bus_mem_chipdep.c
--- sys/arch/alpha/pci/pci_bwx_bus_mem_chipdep.c        14 Mar 2009 14:45:53 
-0000      1.22
+++ sys/arch/alpha/pci/pci_bwx_bus_mem_chipdep.c        4 Feb 2011 15:35:52 
-0000
@@ -302,7 +302,7 @@
        t->abs_c_8 =            __C(CHIP,_mem_copy_region_8);
 
        ex = extent_create(__S(__C(CHIP,_bus_mem)), 0x0UL, 0xffffffffUL,
-           M_DEVBUF, (void *)CHIP_MEM_EX_STORE(v), CHIP_MEM_EX_STORE_SIZE(v),
+           (void *)CHIP_MEM_EX_STORE(v), CHIP_MEM_EX_STORE_SIZE(v),
            EX_NOWAIT|EX_NOCOALESCE);
 
         CHIP_MEM_EXTENT(v) = ex;
Index: sys/arch/alpha/pci/pci_swiz_bus_io_chipdep.c
===================================================================
RCS file: /cvsroot/src/sys/arch/alpha/pci/pci_swiz_bus_io_chipdep.c,v
retrieving revision 1.38
diff -u -r1.38 pci_swiz_bus_io_chipdep.c
--- sys/arch/alpha/pci/pci_swiz_bus_io_chipdep.c        18 Mar 2009 07:41:54 
-0000      1.38
+++ sys/arch/alpha/pci/pci_swiz_bus_io_chipdep.c        4 Feb 2011 15:35:53 
-0000
@@ -307,7 +307,7 @@
 
        /* XXX WE WANT EXTENT_NOCOALESCE, BUT WE CAN'T USE IT. XXX */
        ex = extent_create(__S(__C(CHIP,_bus_io)), 0x0UL, 0xffffffffUL,
-           M_DEVBUF, (void *)CHIP_IO_EX_STORE(v), CHIP_IO_EX_STORE_SIZE(v),
+           (void *)CHIP_IO_EX_STORE(v), CHIP_IO_EX_STORE_SIZE(v),
            EX_NOWAIT);
        extent_alloc_region(ex, 0, 0xffffffffUL, EX_NOWAIT);
 
Index: sys/arch/alpha/pci/pci_swiz_bus_mem_chipdep.c
===================================================================
RCS file: /cvsroot/src/sys/arch/alpha/pci/pci_swiz_bus_mem_chipdep.c,v
retrieving revision 1.43
diff -u -r1.43 pci_swiz_bus_mem_chipdep.c
--- sys/arch/alpha/pci/pci_swiz_bus_mem_chipdep.c       18 Mar 2009 07:41:54 
-0000      1.43
+++ sys/arch/alpha/pci/pci_swiz_bus_mem_chipdep.c       4 Feb 2011 15:35:54 
-0000
@@ -329,7 +329,7 @@
 #ifdef CHIP_D_MEM_W1_SYS_START
        /* XXX WE WANT EXTENT_NOCOALESCE, BUT WE CAN'T USE IT. XXX */
        dex = extent_create(__S(__C(CHIP,_bus_dmem)), 0x0UL,
-           0xffffffffffffffffUL, M_DEVBUF,
+           0xffffffffffffffffUL,
            (void *)CHIP_D_MEM_EX_STORE(v), CHIP_D_MEM_EX_STORE_SIZE(v),
            EX_NOWAIT);
        extent_alloc_region(dex, 0, 0xffffffffffffffffUL, EX_NOWAIT);
@@ -352,7 +352,7 @@
 
        /* XXX WE WANT EXTENT_NOCOALESCE, BUT WE CAN'T USE IT. XXX */
        sex = extent_create(__S(__C(CHIP,_bus_smem)), 0x0UL,
-           0xffffffffffffffffUL, M_DEVBUF,
+           0xffffffffffffffffUL,
            (void *)CHIP_S_MEM_EX_STORE(v), CHIP_S_MEM_EX_STORE_SIZE(v),
            EX_NOWAIT);
        extent_alloc_region(sex, 0, 0xffffffffffffffffUL, EX_NOWAIT);
Index: sys/arch/arc/arc/bus_space.c
===================================================================
RCS file: /cvsroot/src/sys/arch/arc/arc/bus_space.c,v
retrieving revision 1.10
diff -u -r1.10 bus_space.c
--- sys/arch/arc/arc/bus_space.c        28 Apr 2008 20:23:13 -0000      1.10
+++ sys/arch/arc/arc/bus_space.c        4 Feb 2011 15:35:55 -0000
@@ -76,7 +76,7 @@
 {
 
        bst->bs_extent = extent_create(bst->bs_name,
-           bst->bs_start, bst->bs_start + bst->bs_size, M_DEVBUF,
+           bst->bs_start, bst->bs_start + bst->bs_size,
            storage, storagesize, EX_NOWAIT);
        if (bst->bs_extent == NULL)
                panic("arc_bus_space_init_extent: cannot create extent map %s",
Index: sys/arch/arc/arc/wired_map_machdep.c
===================================================================
RCS file: /cvsroot/src/sys/arch/arc/arc/wired_map_machdep.c,v
retrieving revision 1.6
diff -u -r1.6 wired_map_machdep.c
--- sys/arch/arc/arc/wired_map_machdep.c        16 Dec 2009 23:19:06 -0000      
1.6
+++ sys/arch/arc/arc/wired_map_machdep.c        4 Feb 2011 15:35:55 -0000
@@ -55,7 +55,7 @@
 
        mips3_nwired_page = 0;
        arc_wired_map_ex = extent_create("wired_map",
-           VM_MIN_WIRED_MAP_ADDRESS, VM_MAX_WIRED_MAP_ADDRESS, M_DEVBUF,
+           VM_MIN_WIRED_MAP_ADDRESS, VM_MAX_WIRED_MAP_ADDRESS,
            (void *)wired_map_ex_storage, sizeof(wired_map_ex_storage),
            EX_NOWAIT);
        if (arc_wired_map_ex == NULL)
Index: sys/arch/arc/jazz/jazzdmatlb.c
===================================================================
RCS file: /cvsroot/src/sys/arch/arc/jazz/jazzdmatlb.c,v
retrieving revision 1.14
diff -u -r1.14 jazzdmatlb.c
--- sys/arch/arc/jazz/jazzdmatlb.c      1 Mar 2006 12:38:10 -0000       1.14
+++ sys/arch/arc/jazz/jazzdmatlb.c      4 Feb 2011 15:35:55 -0000
@@ -85,8 +85,7 @@
        mips_dcache_wbinv_all();/* Make sure no map entries are cached */
        memset((char *)dma_tlb, 0, JAZZ_DMATLB_SIZE);
 
-       dmatlbmap = extent_create("dmatlb", 0, NDMATLB, M_DEVBUF, NULL, 0,
-           EX_NOWAIT);
+       dmatlbmap = extent_create("dmatlb", 0, NDMATLB, NULL, 0, EX_NOWAIT);
        if (dmatlbmap == NULL)
                panic("jazz_dmatlb_init: cannot create extent map");
 
Index: sys/arch/arc/pci/necpb.c
===================================================================
RCS file: /cvsroot/src/sys/arch/arc/pci/necpb.c,v
retrieving revision 1.33
diff -u -r1.33 necpb.c
--- sys/arch/arc/pci/necpb.c    2 Nov 2010 16:03:47 -0000       1.33
+++ sys/arch/arc/pci/necpb.c    4 Feb 2011 15:35:55 -0000
@@ -242,9 +242,9 @@
        pc = &sc->sc_ncp->nc_pc;
 #ifdef PCI_NETBSD_CONFIGURE
        pc->pc_ioext = extent_create("necpbio", 0x00100000, 0x01ffffff,
-           M_DEVBUF, NULL, 0, EX_NOWAIT);
+           NULL, 0, EX_NOWAIT);
        pc->pc_memext = extent_create("necpbmem", 0x08000000, 0x3fffffff,
-           M_DEVBUF, NULL, 0, EX_NOWAIT);
+           NULL, 0, EX_NOWAIT);
        pci_configure_bus(pc, pc->pc_ioext, pc->pc_memext, NULL, 0,
            mips_dcache_align);
 #endif
Index: sys/arch/arm/arm32/pmap.c
===================================================================
RCS file: /cvsroot/src/sys/arch/arm/arm32/pmap.c,v
retrieving revision 1.219
diff -u -r1.219 pmap.c
--- sys/arch/arm/arm32/pmap.c   12 Nov 2010 07:59:25 -0000      1.219
+++ sys/arch/arm/arm32/pmap.c   4 Feb 2011 15:35:58 -0000
@@ -197,7 +197,7 @@
 #include <sys/kernel.h>
 #include <sys/systm.h>
 #include <sys/proc.h>
-#include <sys/malloc.h>
+#include <sys/kmem.h>
 #include <sys/pool.h>
 #include <sys/cdefs.h>
 #include <sys/cpu.h>
@@ -281,11 +281,6 @@
  * Pool of PV structures
  */
 static struct pool pmap_pv_pool;
-static void *pmap_bootstrap_pv_page_alloc(struct pool *, int);
-static void pmap_bootstrap_pv_page_free(struct pool *, void *);
-static struct pool_allocator pmap_bootstrap_pv_allocator = {
-       pmap_bootstrap_pv_page_alloc, pmap_bootstrap_pv_page_free
-};
 
 /*
  * Pool and cache of l2_dtable structures.
@@ -5285,32 +5280,11 @@
                pm->pm_pl1vec = NULL;
 
        /*
-        * Initialize the pmap cache
+        * Initialize the pmap list
         */
-       pool_cache_bootstrap(&pmap_cache, sizeof(struct pmap), 0, 0, 0,
-           "pmappl", NULL, IPL_NONE, pmap_pmap_ctor, NULL, NULL);
        LIST_INIT(&pmap_pmaps);
        LIST_INSERT_HEAD(&pmap_pmaps, pm, pm_list);
 
-       /*
-        * Initialize the pv pool.
-        */
-       pool_init(&pmap_pv_pool, sizeof(struct pv_entry), 0, 0, 0, "pvepl",
-           &pmap_bootstrap_pv_allocator, IPL_NONE);
-
-       /*
-        * Initialize the L2 dtable pool and cache.
-        */
-       pool_cache_bootstrap(&pmap_l2dtable_cache, sizeof(struct l2_dtable), 0,
-           0, 0, "l2dtblpl", NULL, IPL_NONE, pmap_l2dtable_ctor, NULL, NULL);
-
-       /*
-        * Initialise the L2 descriptor table pool and cache
-        */
-       pool_cache_bootstrap(&pmap_l2ptp_cache, L2_TABLE_SIZE_REAL, 0,
-           L2_TABLE_SIZE_REAL, 0, "l2ptppl", NULL, IPL_NONE,
-           pmap_l2ptp_ctor, NULL, NULL);
-
        cpu_dcache_wbinv_all();
 }
 
@@ -5378,6 +5352,30 @@
 void
 pmap_init(void)
 {
+       /*
+        * Initialize the pmap cache
+        */
+       pool_cache_bootstrap(&pmap_cache, sizeof(struct pmap), 0, 0, 0,
+               "pmappl", NULL, IPL_NONE, pmap_pmap_ctor, NULL, NULL);
+       
+       /*
+        * Initialize the pv pool.
+        */
+       pool_init(&pmap_pv_pool, sizeof(struct pv_entry), 0, 0, 0, "pvepl",
+               &pool_allocator_kmem, IPL_NONE);
+
+       /*
+        * Initialize the L2 dtable pool and cache.
+        */
+       pool_cache_bootstrap(&pmap_l2dtable_cache, sizeof(struct l2_dtable), 0,
+               0, 0, "l2dtblpl", NULL, IPL_NONE, pmap_l2dtable_ctor, NULL, 
NULL);
+
+       /*
+        * Initialise the L2 descriptor table pool and cache
+        */
+       pool_cache_bootstrap(&pmap_l2ptp_cache, L2_TABLE_SIZE_REAL, 0,
+               L2_TABLE_SIZE_REAL, 0, "l2ptppl", NULL, IPL_NONE,
+               pmap_l2ptp_ctor, NULL, NULL);
 
        /*
         * Set the available memory vars - These do not map to real memory
@@ -5406,50 +5404,6 @@
        pmap_initialized = true;
 }
 
-static vaddr_t last_bootstrap_page = 0;
-static void *free_bootstrap_pages = NULL;
-
-static void *
-pmap_bootstrap_pv_page_alloc(struct pool *pp, int flags)
-{
-       extern void *pool_page_alloc(struct pool *, int);
-       vaddr_t new_page;
-       void *rv;
-
-       if (pmap_initialized)
-               return (pool_page_alloc(pp, flags));
-
-       if (free_bootstrap_pages) {
-               rv = free_bootstrap_pages;
-               free_bootstrap_pages = *((void **)rv);
-               return (rv);
-       }
-
-       new_page = uvm_km_alloc(kernel_map, PAGE_SIZE, 0,
-           UVM_KMF_WIRED | ((flags & PR_WAITOK) ? 0 : UVM_KMF_NOWAIT));
-
-       KASSERT(new_page > last_bootstrap_page);
-       last_bootstrap_page = new_page;
-       return ((void *)new_page);
-}
-
-static void
-pmap_bootstrap_pv_page_free(struct pool *pp, void *v)
-{
-       extern void pool_page_free(struct pool *, void *);
-
-       if ((vaddr_t)v <= last_bootstrap_page) {
-               *((void **)v) = free_bootstrap_pages;
-               free_bootstrap_pages = v;
-               return;
-       }
-
-       if (pmap_initialized) {
-               pool_page_free(pp, v);
-               return;
-       }
-}
-
 /*
  * pmap_postinit()
  *
@@ -5479,7 +5433,7 @@
        needed = (maxproc / PMAP_DOMAINS) + ((maxproc % PMAP_DOMAINS) ? 1 : 0);
        needed -= 1;
 
-       l1 = malloc(sizeof(*l1) * needed, M_VMPMAP, M_WAITOK);
+       l1 = kmem_alloc(sizeof(*l1) * needed, KM_SLEEP);
 
        for (loop = 0; loop < needed; loop++, l1++) {
                /* Allocate a L1 page table */
@@ -5488,7 +5442,7 @@
                        panic("Cannot allocate L1 KVM");
 
                error = uvm_pglistalloc(L1_TABLE_SIZE, physical_start,
-                   physical_end, L1_TABLE_SIZE, 0, &plist, 1, M_WAITOK);
+                   physical_end, L1_TABLE_SIZE, 0, &plist, 1, 0);
                if (error)
                        panic("Cannot allocate L1 physical pages");
 
Index: sys/arch/arm/gemini/gemini_pci.c
===================================================================
RCS file: /cvsroot/src/sys/arch/arm/gemini/gemini_pci.c,v
retrieving revision 1.8
diff -u -r1.8 gemini_pci.c
--- sys/arch/arm/gemini/gemini_pci.c    5 Jan 2010 13:14:56 -0000       1.8
+++ sys/arch/arm/gemini/gemini_pci.c    4 Feb 2011 15:35:58 -0000
@@ -211,7 +211,7 @@
        ioext  = extent_create("pciio",
                GEMINI_PCIIO_BASE,
                GEMINI_PCIIO_BASE + GEMINI_PCIIO_SIZE - 1,
-               M_DEVBUF, NULL, 0, EX_NOWAIT);
+               NULL, 0, EX_NOWAIT);
 
        /*
         * XXX PCI mem addr should be inherited ?
@@ -219,7 +219,7 @@
        memext = extent_create("pcimem",
                GEMINI_PCIMEM_BASE,
                GEMINI_PCIMEM_BASE + GEMINI_PCIMEM_SIZE - 1,
-               M_DEVBUF, NULL, 0, EX_NOWAIT);
+               NULL, 0, EX_NOWAIT);
 
        pci_configure_bus(pc, ioext, memext, NULL, 0, arm_dcache_align);
 
Index: sys/arch/arm/ixp12x0/ixp12x0_pci.c
===================================================================
RCS file: /cvsroot/src/sys/arch/arm/ixp12x0/ixp12x0_pci.c,v
retrieving revision 1.10
diff -u -r1.10 ixp12x0_pci.c
--- sys/arch/arm/ixp12x0/ixp12x0_pci.c  14 Mar 2009 21:04:05 -0000      1.10
+++ sys/arch/arm/ixp12x0/ixp12x0_pci.c  4 Feb 2011 15:35:58 -0000
@@ -95,12 +95,12 @@
 
 #if NPCI > 0 && defined(PCI_NETBSD_CONFIGURE)
        ioext  = extent_create("pciio", 0, IXP12X0_PCI_IO_SIZE - 1,
-                               M_DEVBUF, NULL, 0, EX_NOWAIT);
+                               NULL, 0, EX_NOWAIT);
        /* PCI MEM space is mapped same address as real memory */
        memext = extent_create("pcimem", IXP12X0_PCI_MEM_HWBASE,
                                IXP12X0_PCI_MEM_HWBASE +
                                IXP12X0_PCI_MEM_SIZE - 1,
-                               M_DEVBUF, NULL, 0, EX_NOWAIT);
+                               NULL, 0, EX_NOWAIT);
        printf("%s: configuring PCI bus\n", sc->sc_dev.dv_xname);
        pci_configure_bus(pc, ioext, memext, NULL, 0 /* XXX bus = 0 */,
                          arm_dcache_align);
Index: sys/arch/arm/s3c2xx0/s3c2800_pci.c
===================================================================
RCS file: /cvsroot/src/sys/arch/arm/s3c2xx0/s3c2800_pci.c,v
retrieving revision 1.13
diff -u -r1.13 s3c2800_pci.c
--- sys/arch/arm/s3c2xx0/s3c2800_pci.c  6 Jan 2008 01:37:56 -0000       1.13
+++ sys/arch/arm/s3c2xx0/s3c2800_pci.c  4 Feb 2011 15:35:58 -0000
@@ -292,10 +292,10 @@
 
 #if defined(PCI_NETBSD_CONFIGURE)
        ioext = extent_create("pciio", 0x100, S3C2800_PCI_IOSPACE_SIZE - 0x100,
-           M_DEVBUF, NULL, 0, EX_NOWAIT);
+           NULL, 0, EX_NOWAIT);
 
        memext = extent_create("pcimem", 0, S3C2800_PCI_MEMSPACE_SIZE,
-           M_DEVBUF, NULL, 0, EX_NOWAIT);
+           NULL, 0, EX_NOWAIT);
 
        sspci_chipset.pc_conf_v = (void *) sc;
        sspci_chipset.pc_intr_v = (void *) sc;
Index: sys/arch/arm/xscale/becc_pci.c
===================================================================
RCS file: /cvsroot/src/sys/arch/arm/xscale/becc_pci.c,v
retrieving revision 1.8
diff -u -r1.8 becc_pci.c
--- sys/arch/arm/xscale/becc_pci.c      24 Dec 2005 20:06:52 -0000      1.8
+++ sys/arch/arm/xscale/becc_pci.c      4 Feb 2011 15:35:58 -0000
@@ -125,10 +125,10 @@
        /* Reserve the bottom 32K of the PCI address space. */
        ioext  = extent_create("pciio", sc->sc_ioout_xlate + (32 * 1024),
            sc->sc_ioout_xlate + (64 * 1024) - 1,
-           M_DEVBUF, NULL, 0, EX_NOWAIT);
+           NULL, 0, EX_NOWAIT);
        memext = extent_create("pcimem", sc->sc_owin_xlate[0],
            sc->sc_owin_xlate[0] + BECC_PCI_MEM1_SIZE - 1,
-           M_DEVBUF, NULL, 0, EX_NOWAIT);
+           NULL, 0, EX_NOWAIT);
 
        aprint_normal("%s: configuring PCI bus\n", sc->sc_dev.dv_xname);
        pci_configure_bus(pc, ioext, memext, NULL, 0, arm_dcache_align);
Index: sys/arch/arm/xscale/i80312_pci.c
===================================================================
RCS file: /cvsroot/src/sys/arch/arm/xscale/i80312_pci.c,v
retrieving revision 1.9
diff -u -r1.9 i80312_pci.c
--- sys/arch/arm/xscale/i80312_pci.c    11 Dec 2005 12:16:51 -0000      1.9
+++ sys/arch/arm/xscale/i80312_pci.c    4 Feb 2011 15:35:59 -0000
@@ -108,10 +108,10 @@
 
        ioext  = extent_create("pciio", sc->sc_sioout_base,
            sc->sc_sioout_base + sc->sc_sioout_size - 1,
-           M_DEVBUF, NULL, 0, EX_NOWAIT);
+           NULL, 0, EX_NOWAIT);
        memext = extent_create("pcimem", sc->sc_smemout_base,
            sc->sc_smemout_base + sc->sc_smemout_size - 1,
-           M_DEVBUF, NULL, 0, EX_NOWAIT);
+           NULL, 0, EX_NOWAIT);
 
        aprint_normal("%s: configuring Secondary PCI bus\n", 
sc->sc_dev.dv_xname);
        pci_configure_bus(pc, ioext, memext, NULL, sbus, arm_dcache_align);
Index: sys/arch/arm/xscale/i80321_pci.c
===================================================================
RCS file: /cvsroot/src/sys/arch/arm/xscale/i80321_pci.c,v
retrieving revision 1.9
diff -u -r1.9 i80321_pci.c
--- sys/arch/arm/xscale/i80321_pci.c    17 Oct 2007 19:53:43 -0000      1.9
+++ sys/arch/arm/xscale/i80321_pci.c    4 Feb 2011 15:35:59 -0000
@@ -110,16 +110,16 @@
        ioext  = extent_create("pciio",
            sc->sc_ioout_xlate + sc->sc_ioout_xlate_offset,
            sc->sc_ioout_xlate + VERDE_OUT_XLATE_IO_WIN_SIZE - 1,
-           M_DEVBUF, NULL, 0, EX_NOWAIT);
+           NULL, 0, EX_NOWAIT);
 
 #ifdef I80321_USE_DIRECT_WIN
        memext = extent_create("pcimem", VERDE_OUT_DIRECT_WIN_BASE + 
VERDE_OUT_DIRECT_WIN_SKIP,
            VERDE_OUT_DIRECT_WIN_BASE + VERDE_OUT_DIRECT_WIN_SIZE- 1,
-           M_DEVBUF, NULL, 0, EX_NOWAIT);
+           NULL, 0, EX_NOWAIT);
 #else
        memext = extent_create("pcimem", sc->sc_owin[0].owin_xlate_lo,
            sc->sc_owin[0].owin_xlate_lo + VERDE_OUT_XLATE_MEM_WIN_SIZE - 1,
-           M_DEVBUF, NULL, 0, EX_NOWAIT);
+           NULL, 0, EX_NOWAIT);
 #endif
 
        aprint_normal("%s: configuring PCI bus\n", sc->sc_dev.dv_xname);
Index: sys/arch/arm/xscale/ixp425_pci.c
===================================================================
RCS file: /cvsroot/src/sys/arch/arm/xscale/ixp425_pci.c,v
retrieving revision 1.6
diff -u -r1.6 ixp425_pci.c
--- sys/arch/arm/xscale/ixp425_pci.c    21 Oct 2009 14:15:50 -0000      1.6
+++ sys/arch/arm/xscale/ixp425_pci.c    4 Feb 2011 15:35:59 -0000
@@ -89,12 +89,12 @@
 
 #if NPCI > 0 && defined(PCI_NETBSD_CONFIGURE)
        ioext  = extent_create("pciio", 0, IXP425_PCI_IO_SIZE - 1,
-                               M_DEVBUF, NULL, 0, EX_NOWAIT);
+                               NULL, 0, EX_NOWAIT);
        /* PCI MEM space is mapped same address as real memory */
        memext = extent_create("pcimem", IXP425_PCI_MEM_HWBASE,
                                IXP425_PCI_MEM_HWBASE +
                                IXP425_PCI_MEM_SIZE - 1,
-                               M_DEVBUF, NULL, 0, EX_NOWAIT);
+                               NULL, 0, EX_NOWAIT);
        printf("%s: configuring PCI bus\n", sc->sc_dev.dv_xname);
        pci_configure_bus(pc, ioext, memext, NULL, 0 /* XXX bus = 0 */,
                          arm_dcache_align);
Index: sys/arch/atari/atari/atari_init.c
===================================================================
RCS file: /cvsroot/src/sys/arch/atari/atari/atari_init.c,v
retrieving revision 1.95
diff -u -r1.95 atari_init.c
--- sys/arch/atari/atari/atari_init.c   2 Jan 2011 18:48:05 -0000       1.95
+++ sys/arch/atari/atari/atari_init.c   4 Feb 2011 15:36:00 -0000
@@ -587,7 +587,7 @@
         * on the machine.  When the amount of RAM is found, all
         * extents of RAM are allocated from the map.
         */
-       iomem_ex = extent_create("iomem", 0x0, 0xffffffff, M_DEVBUF,
+       iomem_ex = extent_create("iomem", 0x0, 0xffffffff,
            (void *)iomem_ex_storage, sizeof(iomem_ex_storage),
            EX_NOCOALESCE|EX_NOWAIT);
 
Index: sys/arch/atari/atari/bus.c
===================================================================
RCS file: /cvsroot/src/sys/arch/atari/atari/bus.c,v
retrieving revision 1.55
diff -u -r1.55 bus.c
--- sys/arch/atari/atari/bus.c  6 Nov 2010 11:46:00 -0000       1.55
+++ sys/arch/atari/atari/bus.c  4 Feb 2011 15:36:00 -0000
@@ -86,7 +86,7 @@
 void
 bootm_init(vaddr_t va, pt_entry_t *ptep, u_long size)
 {
-       bootm_ex = extent_create("bootmem", va, va + size, M_DEVBUF,
+       bootm_ex = extent_create("bootmem", va, va + size,
            (void *)bootm_ex_storage, sizeof(bootm_ex_storage),
            EX_NOCOALESCE|EX_NOWAIT);
        bootm_ptep = ptep;
Index: sys/arch/bebox/bebox/mainbus.c
===================================================================
RCS file: /cvsroot/src/sys/arch/bebox/bebox/mainbus.c,v
retrieving revision 1.24
diff -u -r1.24 mainbus.c
--- sys/arch/bebox/bebox/mainbus.c      18 Mar 2009 16:00:10 -0000      1.24
+++ sys/arch/bebox/bebox/mainbus.c      4 Feb 2011 15:36:00 -0000
@@ -132,9 +132,9 @@
        SIMPLEQ_INSERT_TAIL(&genppc_pct->pc_pbi, pbi, next);
 
 #ifdef PCI_NETBSD_CONFIGURE
-       ioext  = extent_create("pciio",  0x00008000, 0x0000ffff, M_DEVBUF,
+       ioext  = extent_create("pciio",  0x00008000, 0x0000ffff,
            NULL, 0, EX_NOWAIT);
-       memext = extent_create("pcimem", 0x00000000, 0x0fffffff, M_DEVBUF,
+       memext = extent_create("pcimem", 0x00000000, 0x0fffffff,
            NULL, 0, EX_NOWAIT);
 
        pci_configure_bus(genppc_pct, ioext, memext, NULL, 0, CACHELINESIZE);
Index: sys/arch/cobalt/dev/gt.c
===================================================================
RCS file: /cvsroot/src/sys/arch/cobalt/dev/gt.c,v
retrieving revision 1.22
diff -u -r1.22 gt.c
--- sys/arch/cobalt/dev/gt.c    27 Nov 2009 03:23:05 -0000      1.22
+++ sys/arch/cobalt/dev/gt.c    4 Feb 2011 15:36:00 -0000
@@ -127,9 +127,9 @@
 
 #ifdef PCI_NETBSD_CONFIGURE
        pc->pc_ioext = extent_create("pciio", 0x10001000, 0x11ffffff,
-           M_DEVBUF, NULL, 0, EX_NOWAIT);
+           NULL, 0, EX_NOWAIT);
        pc->pc_memext = extent_create("pcimem", 0x12000000, 0x13ffffff,
-           M_DEVBUF, NULL, 0, EX_NOWAIT);
+           NULL, 0, EX_NOWAIT);
        pci_configure_bus(pc, pc->pc_ioext, pc->pc_memext, NULL, 0,
            mips_dcache_align);
 #endif
Index: sys/arch/dreamcast/dev/g2/gapspci_dma.c
===================================================================
RCS file: /cvsroot/src/sys/arch/dreamcast/dev/g2/gapspci_dma.c,v
retrieving revision 1.18
diff -u -r1.18 gapspci_dma.c
--- sys/arch/dreamcast/dev/g2/gapspci_dma.c     12 Nov 2010 13:18:56 -0000      
1.18
+++ sys/arch/dreamcast/dev/g2/gapspci_dma.c     4 Feb 2011 15:36:01 -0000
@@ -109,7 +109,7 @@
         */
        sc->sc_dma_ex = extent_create("gaps dma",
            sc->sc_dmabase, sc->sc_dmabase + (sc->sc_dmasize - 1),
-           M_DEVBUF, NULL, 0, EX_WAITOK | EXF_NOCOALESCE);
+           NULL, 0, EX_WAITOK | EXF_NOCOALESCE);
 
        if (bus_space_map(sc->sc_memt, sc->sc_dmabase, sc->sc_dmasize,
            0, &sc->sc_dma_memh) != 0)
Index: sys/arch/emips/emips/machdep.c
===================================================================
RCS file: /cvsroot/src/sys/arch/emips/emips/machdep.c,v
retrieving revision 1.1
diff -u -r1.1 machdep.c
--- sys/arch/emips/emips/machdep.c      26 Jan 2011 01:18:50 -0000      1.1
+++ sys/arch/emips/emips/machdep.c      4 Feb 2011 15:36:02 -0000
@@ -395,7 +395,7 @@
         */
        KASSERT(iospace != 0);
        iomap_ex = extent_create("iomap", iospace,
-           iospace + iospace_size - 1, M_DEVBUF,
+           iospace + iospace_size - 1,
            (void *) iomap_ex_storage, sizeof(iomap_ex_storage),
            EX_NOCOALESCE|EX_NOWAIT);
 
Index: sys/arch/evbarm/ifpga/ifpga.c
===================================================================
RCS file: /cvsroot/src/sys/arch/evbarm/ifpga/ifpga.c,v
retrieving revision 1.23
diff -u -r1.23 ifpga.c
--- sys/arch/evbarm/ifpga/ifpga.c       21 Jul 2009 16:04:16 -0000      1.23
+++ sys/arch/evbarm/ifpga/ifpga.c       4 Feb 2011 15:36:02 -0000
@@ -296,13 +296,13 @@
 
 #if defined(PCI_NETBSD_CONFIGURE)
        ioext = extent_create("pciio", 0x00000000,
-           0x00000000 + IFPGA_PCI_IO_VSIZE, M_DEVBUF, NULL, 0, EX_NOWAIT);
+           0x00000000 + IFPGA_PCI_IO_VSIZE, NULL, 0, EX_NOWAIT);
        memext = extent_create("pcimem", IFPGA_PCI_APP0_BASE,
            IFPGA_PCI_APP0_BASE + IFPGA_PCI_APP0_SIZE,
-           M_DEVBUF, NULL, 0, EX_NOWAIT);
+           NULL, 0, EX_NOWAIT);
        pmemext = extent_create("pcipmem", IFPGA_PCI_APP1_BASE,
            IFPGA_PCI_APP1_BASE + IFPGA_PCI_APP1_SIZE,
-           M_DEVBUF, NULL, 0, EX_NOWAIT);
+           NULL, 0, EX_NOWAIT);
        ifpga_pci_chipset.pc_conf_v = (void *)pci_sc;
        pci_configure_bus(&ifpga_pci_chipset, ioext, memext, pmemext, 0,
            arm_dcache_align);
Index: sys/arch/evbmips/gdium/mainbus.c
===================================================================
RCS file: /cvsroot/src/sys/arch/evbmips/gdium/mainbus.c,v
retrieving revision 1.3
diff -u -r1.3 mainbus.c
--- sys/arch/evbmips/gdium/mainbus.c    11 Aug 2009 02:32:38 -0000      1.3
+++ sys/arch/evbmips/gdium/mainbus.c    4 Feb 2011 15:36:03 -0000
@@ -103,9 +103,9 @@
                struct extent *ioext, *memext;
 
                ioext = extent_create("pciio",  0x00001000, 0x00003fff,
-                   M_DEVBUF, NULL, 0, EX_NOWAIT);
+                   NULL, 0, EX_NOWAIT);
                memext = extent_create("pcimem", 0, BONITO_PCILO_SIZE,
-                   M_DEVBUF, NULL, 0, EX_NOWAIT);
+                   NULL, 0, EX_NOWAIT);
 
                pci_configure_bus(&gdium_configuration.gc_pc, ioext, memext,
                    NULL, 0, mips_dcache_align);
Index: sys/arch/evbmips/rmixl/machdep.c
===================================================================
RCS file: /cvsroot/src/sys/arch/evbmips/rmixl/machdep.c,v
retrieving revision 1.5
diff -u -r1.5 machdep.c
--- sys/arch/evbmips/rmixl/machdep.c    14 Jan 2011 02:06:25 -0000      1.5
+++ sys/arch/evbmips/rmixl/machdep.c    4 Feb 2011 15:36:04 -0000
@@ -496,7 +496,7 @@
        u_long size;
        uint32_t r;
 
-       ext = extent_create("physaddr", start, end, M_DEVBUF,
+       ext = extent_create("physaddr", start, end,
                (void *)rmixl_physaddr_storage, sizeof(rmixl_physaddr_storage),
                EX_NOWAIT | EX_NOCOALESCE);
 
Index: sys/arch/evbppc/mpc85xx/machdep.c
===================================================================
RCS file: /cvsroot/src/sys/arch/evbppc/mpc85xx/machdep.c,v
retrieving revision 1.2
diff -u -r1.2 machdep.c
--- sys/arch/evbppc/mpc85xx/machdep.c   18 Jan 2011 01:10:25 -0000      1.2
+++ sys/arch/evbppc/mpc85xx/machdep.c   4 Feb 2011 15:36:05 -0000
@@ -896,12 +896,12 @@
 #if NPCI > 0 && defined(PCI_MEMBASE)
        pcimem_ex = extent_create("pcimem",
            PCI_MEMBASE, PCI_MEMBASE + 4*PCI_MEMSIZE,
-           M_DEVBUF, NULL, 0, EX_WAITOK);
+           NULL, 0, EX_WAITOK);
 #endif
 #if NPCI > 0 && defined(PCI_IOBASE)
        pciio_ex = extent_create("pciio",
            PCI_IOBASE, PCI_IOBASE + 4*PCI_IOSIZE,
-           M_DEVBUF, NULL, 0, EX_WAITOK);
+           NULL, 0, EX_WAITOK);
 #endif
        mpc85xx_extirq_setup();
        /*
Index: sys/arch/ews4800mips/ews4800mips/bus_space.c
===================================================================
RCS file: /cvsroot/src/sys/arch/ews4800mips/ews4800mips/bus_space.c,v
retrieving revision 1.4
diff -u -r1.4 bus_space.c
--- sys/arch/ews4800mips/ews4800mips/bus_space.c        28 Apr 2008 20:23:18 
-0000      1.4
+++ sys/arch/ews4800mips/ews4800mips/bus_space.c        4 Feb 2011 15:36:05 
-0000
@@ -166,7 +166,7 @@
                ebs->ebs_size = size;
        } else {
                ebs->ebs_extent = extent_create(name, addr, addr + size - 1,
-                   M_DEVBUF, 0, 0, EX_NOWAIT);
+                   0, 0, EX_NOWAIT);
                if (ebs->ebs_extent == NULL) {
                        panic("%s:: unable to create bus_space for "
                            "0x%08lx-%#lx", __func__, addr, size);
Index: sys/arch/hp300/hp300/autoconf.c
===================================================================
RCS file: /cvsroot/src/sys/arch/hp300/hp300/autoconf.c,v
retrieving revision 1.92
diff -u -r1.92 autoconf.c
--- sys/arch/hp300/hp300/autoconf.c     19 Dec 2008 17:11:57 -0000      1.92
+++ sys/arch/hp300/hp300/autoconf.c     4 Feb 2011 15:36:06 -0000
@@ -937,7 +937,7 @@
 
        /* extiobase is initialized by pmap_bootstrap(). */
        extio_ex = extent_create("extio", (u_long) extiobase,
-           (u_long) extiobase + (ptoa(EIOMAPSIZE) - 1), M_DEVBUF,
+           (u_long) extiobase + (ptoa(EIOMAPSIZE) - 1),
            (void *) extio_ex_storage, sizeof(extio_ex_storage),
            EX_NOCOALESCE|EX_NOWAIT);
 }
Index: sys/arch/hp700/dev/astro.c
===================================================================
RCS file: /cvsroot/src/sys/arch/hp700/dev/astro.c,v
retrieving revision 1.13
diff -u -r1.13 astro.c
--- sys/arch/hp700/dev/astro.c  13 Jan 2011 21:15:13 -0000      1.13
+++ sys/arch/hp700/dev/astro.c  4 Feb 2011 15:36:06 -0000
@@ -328,7 +328,7 @@
        snprintf(sc->sc_dvmamapname, sizeof(sc->sc_dvmamapname),
            "%s_dvma", device_xname(sc->sc_dv));
        sc->sc_dvmamap = extent_create(sc->sc_dvmamapname, 0, (1 << iova_bits),
-           M_DEVBUF, 0, 0, EX_NOWAIT);
+           0, 0, EX_NOWAIT);
 
        sc->sc_dmatag = astro_dmat;
        sc->sc_dmatag._cookie = sc;
Index: sys/arch/hp700/dev/dino.c
===================================================================
RCS file: /cvsroot/src/sys/arch/hp700/dev/dino.c,v
retrieving revision 1.29
diff -u -r1.29 dino.c
--- sys/arch/hp700/dev/dino.c   1 Feb 2011 18:33:24 -0000       1.29
+++ sys/arch/hp700/dev/dino.c   4 Feb 2011 15:36:07 -0000
@@ -1643,7 +1643,7 @@
        snprintf(sc->sc_ioexname, sizeof(sc->sc_ioexname),
            "%s_io", device_xname(self));
        if ((sc->sc_ioex = extent_create(sc->sc_ioexname, 0, 0xffff,
-           M_DEVBUF, NULL, 0, EX_NOWAIT | EX_MALLOCOK)) == NULL) {
+           NULL, 0, EX_NOWAIT | EX_MALLOCOK)) == NULL) {
                aprint_error(": can't allocate I/O extent map\n");
                bus_space_unmap(sc->sc_bt, sc->sc_bh, PAGE_SIZE);
                return;
Index: sys/arch/hp700/dev/elroy.c
===================================================================
RCS file: /cvsroot/src/sys/arch/hp700/dev/elroy.c,v
retrieving revision 1.10
diff -u -r1.10 elroy.c
--- sys/arch/hp700/dev/elroy.c  8 Nov 2010 23:10:24 -0000       1.10
+++ sys/arch/hp700/dev/elroy.c  4 Feb 2011 15:36:07 -0000
@@ -454,7 +454,7 @@
                        snprintf(sc->sc_memexname, sizeof(sc->sc_memexname),
                            "%s_mem", sc->sc_dv.dv_xname);
                        if ((sc->sc_memex = extent_create(sc->sc_memexname,
-                           mem_start, mem_start + ELROY_MEM_WINDOW, M_DEVBUF,
+                           mem_start, mem_start + ELROY_MEM_WINDOW,
                            NULL, 0, EX_NOWAIT | EX_MALLOCOK)) == NULL) {
                                extent_destroy(sc->sc_ioex);
                                bus_space_free(sc->sc_bt, memh,
Index: sys/arch/hp700/hp700/machdep.c
===================================================================
RCS file: /cvsroot/src/sys/arch/hp700/hp700/machdep.c,v
retrieving revision 1.98
diff -u -r1.98 machdep.c
--- sys/arch/hp700/hp700/machdep.c      23 Jan 2011 21:53:40 -0000      1.98
+++ sys/arch/hp700/hp700/machdep.c      4 Feb 2011 15:36:09 -0000
@@ -517,7 +517,7 @@
 
        /* we hope this won't fail */
        hp700_io_extent = extent_create("io",
-           HPPA_IOSPACE, 0xffffffff, M_DEVBUF,
+           HPPA_IOSPACE, 0xffffffff,
            (void *)hp700_io_extent_store, sizeof(hp700_io_extent_store),
            EX_NOCOALESCE|EX_NOWAIT);
 
Index: sys/arch/hpcmips/hpcmips/bus_space.c
===================================================================
RCS file: /cvsroot/src/sys/arch/hpcmips/hpcmips/bus_space.c,v
retrieving revision 1.28
diff -u -r1.28 bus_space.c
--- sys/arch/hpcmips/hpcmips/bus_space.c        7 Nov 2009 07:27:43 -0000       
1.28
+++ sys/arch/hpcmips/hpcmips/bus_space.c        4 Feb 2011 15:36:09 -0000
@@ -215,7 +215,7 @@
        }
 
        t->extent = (void*)extent_create(t->name, t->base, 
-           t->base + t->size, M_DEVBUF,
+           t->base + t->size,
            0, 0, EX_NOWAIT);
        if (!t->extent) {
                panic("hpcmips_init_bus_space_extent:"
Index: sys/arch/hpcmips/tx/tx3912video.c
===================================================================
RCS file: /cvsroot/src/sys/arch/hpcmips/tx/tx3912video.c,v
retrieving revision 1.40
diff -u -r1.40 tx3912video.c
--- sys/arch/hpcmips/tx/tx3912video.c   14 Mar 2009 15:36:07 -0000      1.40
+++ sys/arch/hpcmips/tx/tx3912video.c   4 Feb 2011 15:36:10 -0000
@@ -366,7 +366,7 @@
 
        /* extent V-RAM region */
        ex = extent_create("Frame buffer address", fb_start, *fb_end,
-           0, (void *)ex_fixed, sizeof ex_fixed,
+           (void *)ex_fixed, sizeof ex_fixed,
            EX_NOWAIT);
        if (ex == 0)
                return (1);
Index: sys/arch/hpcsh/hpcsh/bus_space.c
===================================================================
RCS file: /cvsroot/src/sys/arch/hpcsh/hpcsh/bus_space.c,v
retrieving revision 1.16
diff -u -r1.16 bus_space.c
--- sys/arch/hpcsh/hpcsh/bus_space.c    28 Jun 2010 11:18:44 -0000      1.16
+++ sys/arch/hpcsh/hpcsh/bus_space.c    4 Feb 2011 15:36:10 -0000
@@ -155,7 +155,7 @@
                hbs->hbs_base_addr = addr; /* no extent */
        } else {
                hbs->hbs_extent = extent_create(name, addr, addr + size - 1,
-                                               M_DEVBUF, 0, 0, EX_NOWAIT);
+                                               0, 0, EX_NOWAIT);
                if (hbs->hbs_extent == NULL) {
                        panic("%s:: unable to create bus_space for "
                              "0x%08lx-%#lx", __func__, addr, size);
Index: sys/arch/ia64/ia64/pmap.c
===================================================================
RCS file: /cvsroot/src/sys/arch/ia64/ia64/pmap.c,v
retrieving revision 1.27
diff -u -r1.27 pmap.c
--- sys/arch/ia64/ia64/pmap.c   12 Nov 2010 07:59:26 -0000      1.27
+++ sys/arch/ia64/ia64/pmap.c   4 Feb 2011 15:36:12 -0000
@@ -638,24 +638,9 @@
                VM_GATEWAY_SIZE;
        
        /*
-        * Initialize the pmap pools and list.
+        * Initialize the pmap rids and list.
         */
        pmap_ncpuids = pmap_ridmax;
-       pool_init(&pmap_pmap_pool, sizeof(struct pmap), 0, 0, 0, "pmappl",
-           &pool_allocator_nointr, IPL_NONE); /* This may block. */
-
-       /* XXX: Need to convert ia64_kptdir[][] to a pool. ????*/
-
-       /* The default pool allocator uses uvm_km_alloc & friends. 
-        * XXX: We should be using regular vm_alloced mem for regular, 
non-kernel ptesl
-        */
-
-       pool_init(&pmap_ia64_lpte_pool, sizeof (struct ia64_lpte),
-           sizeof(void *), 0, 0, "ptpl", NULL, IPL_NONE); 
-
-       pool_init(&pmap_pv_pool, sizeof (struct pv_entry), sizeof(void *),
-           0, 0, "pvpl", &pmap_pv_page_allocator, IPL_NONE);
-
        TAILQ_INIT(&pmap_all_pmaps);
 
 
@@ -794,7 +779,23 @@
 void
 pmap_init(void)
 {
+       /*
+        * Initialize the pmap pools and list.
+        */
+       pool_init(&pmap_pmap_pool, sizeof(struct pmap), 0, 0, 0, "pmappl",
+               &pool_allocator_nointr, IPL_NONE); /* This may block. */
+       
+       /* XXX: Need to convert ia64_kptdir[][] to a pool. ????*/
 
+       /* The default pool allocator uses uvm_km_alloc & friends. 
+        * XXX: We should be using regular vm_alloced mem for regular, 
non-kernel ptesl
+        */
+       
+       pool_init(&pmap_ia64_lpte_pool, sizeof (struct ia64_lpte),
+               sizeof(void *), 0, 0, "ptpl", NULL, IPL_NONE); 
+
+       pool_init(&pmap_pv_pool, sizeof (struct pv_entry), sizeof(void *),
+               0, 0, "pvpl", &pmap_pv_page_allocator, IPL_NONE);
 
        /*
         * Set a low water mark on the pv_entry pool, so that we are
Index: sys/arch/ibmnws/ibmnws/mainbus.c
===================================================================
RCS file: /cvsroot/src/sys/arch/ibmnws/ibmnws/mainbus.c,v
retrieving revision 1.8
diff -u -r1.8 mainbus.c
--- sys/arch/ibmnws/ibmnws/mainbus.c    18 Mar 2009 16:00:13 -0000      1.8
+++ sys/arch/ibmnws/ibmnws/mainbus.c    4 Feb 2011 15:36:13 -0000
@@ -124,9 +124,9 @@
        ibmnws_pci_get_chipset_tag_indirect (genppc_pct);
 
 #ifdef PCI_NETBSD_CONFIGURE
-       ioext  = extent_create("pciio",  0x00008000, 0x0000ffff, M_DEVBUF,
+       ioext  = extent_create("pciio",  0x00008000, 0x0000ffff,
            NULL, 0, EX_NOWAIT);
-       memext = extent_create("pcimem", 0x00000000, 0x0fffffff, M_DEVBUF,
+       memext = extent_create("pcimem", 0x00000000, 0x0fffffff,
            NULL, 0, EX_NOWAIT);
 
        pci_configure_bus(genppc_pct, ioext, memext, NULL, 0, CACHELINESIZE);
Index: sys/arch/mac68k/mac68k/machdep.c
===================================================================
RCS file: /cvsroot/src/sys/arch/mac68k/mac68k/machdep.c,v
retrieving revision 1.337
diff -u -r1.337 machdep.c
--- sys/arch/mac68k/mac68k/machdep.c    17 Jan 2011 14:53:43 -0000      1.337
+++ sys/arch/mac68k/mac68k/machdep.c    4 Feb 2011 15:36:19 -0000
@@ -310,7 +310,7 @@
         * on the machine.  When the amount of RAM is found, all
         * extents of RAM are allocated from the map.
         */
-       iomem_ex = extent_create("iomem", 0x0, 0xffffffff, M_DEVBUF,
+       iomem_ex = extent_create("iomem", 0x0, 0xffffffff,
            (void *)iomem_ex_storage, sizeof(iomem_ex_storage),
            EX_NOCOALESCE|EX_NOWAIT);
 
Index: sys/arch/mips/alchemy/au_himem_space.c
===================================================================
RCS file: /cvsroot/src/sys/arch/mips/alchemy/au_himem_space.c,v
retrieving revision 1.11
diff -u -r1.11 au_himem_space.c
--- sys/arch/mips/alchemy/au_himem_space.c      7 Jun 2010 13:33:33 -0000       
1.11
+++ sys/arch/mips/alchemy/au_himem_space.c      4 Feb 2011 15:36:20 -0000
@@ -701,7 +701,7 @@
        c->c_physoff = physoff;
 
        /* allocate extent manager */
-       c->c_extent = extent_create(name, start, end, M_DEVBUF,
+       c->c_extent = extent_create(name, start, end,
            NULL, 0, EX_NOWAIT);
        if (c->c_extent == NULL)
                panic("au_himem_space_init: %s: cannot create extent", name);
Index: sys/arch/mips/alchemy/au_wired_space.c
===================================================================
RCS file: /cvsroot/src/sys/arch/mips/alchemy/au_wired_space.c,v
retrieving revision 1.6
diff -u -r1.6 au_wired_space.c
--- sys/arch/mips/alchemy/au_wired_space.c      28 Apr 2008 20:23:27 -0000      
1.6
+++ sys/arch/mips/alchemy/au_wired_space.c      4 Feb 2011 15:36:21 -0000
@@ -641,7 +641,7 @@
        c->c_size = size;
 
        /* allocate extent manager */
-       c->c_extent = extent_create(name, start, start + size, M_DEVBUF,
+       c->c_extent = extent_create(name, start, start + size, 
            (void *)c->c_exstore, sizeof (c->c_exstore), EX_NOWAIT);
        if (c->c_extent == NULL)
                panic("au_wired_space_init: %s: cannot create extent", name);
Index: sys/arch/mips/mips/bus_space_alignstride_chipdep.c
===================================================================
RCS file: /cvsroot/src/sys/arch/mips/mips/bus_space_alignstride_chipdep.c,v
retrieving revision 1.12
diff -u -r1.12 bus_space_alignstride_chipdep.c
--- sys/arch/mips/mips/bus_space_alignstride_chipdep.c  15 Dec 2009 06:07:14 
-0000      1.12
+++ sys/arch/mips/mips/bus_space_alignstride_chipdep.c  4 Feb 2011 15:36:23 
-0000
@@ -552,7 +552,7 @@
 
 #ifdef CHIP_EXTENT
        /* XXX WE WANT EXTENT_NOCOALESCE, BUT WE CAN'T USE IT. XXX */
-       ex = extent_create(__S(__BS(bus)), 0x0UL, ~0UL, M_DEVBUF,
+       ex = extent_create(__S(__BS(bus)), 0x0UL, ~0UL, 
            (void *)CHIP_EX_STORE(v), CHIP_EX_STORE_SIZE(v), EX_NOWAIT);
        extent_alloc_region(ex, 0, ~0UL, EX_NOWAIT);
 
Index: sys/arch/mips/mips/pmap.c
===================================================================
RCS file: /cvsroot/src/sys/arch/mips/mips/pmap.c,v
retrieving revision 1.193
diff -u -r1.193 pmap.c
--- sys/arch/mips/mips/pmap.c   26 Jan 2011 01:18:54 -0000      1.193
+++ sys/arch/mips/mips/pmap.c   4 Feb 2011 15:36:24 -0000
@@ -312,7 +312,7 @@
        /*
         * Compute the number of pages kmem_map will have.
         */
-       kmeminit_nkmempages();
+       uvm_km_setupkmemsize();
 
        /*
         * Figure out how many PTE's are necessary to map the kernel.
@@ -378,14 +378,6 @@
            uvm_pageboot_alloc(sizeof(struct pv_entry) * pv_table_npages);
 
        /*
-        * Initialize the pools.
-        */
-       pool_init(&pmap_pmap_pool, sizeof(struct pmap), 0, 0, 0, "pmappl",
-           &pool_allocator_nointr, IPL_NONE);
-       pool_init(&pmap_pv_pool, sizeof(struct pv_entry), 0, 0, 0, "pvpl",
-           &pmap_pv_page_allocator, IPL_NONE);
-
-       /*
         * Initialize the kernel pmap.
         */
        pmap_kernel()->pm_count = 1;
@@ -529,6 +521,14 @@
 #endif
 
        /*
+        * Initialize the pools.
+        */
+       pool_init(&pmap_pmap_pool, sizeof(struct pmap), 0, 0, 0, "pmappl",
+               &pool_allocator_nointr, IPL_NONE);
+       pool_init(&pmap_pv_pool, sizeof(struct pv_entry), 0, 0, 0, "pvpl",
+               &pmap_pv_page_allocator, IPL_NONE);
+
+       /*
         * Memory for the pv entry heads has
         * already been allocated.  Initialize the physical memory
         * segments.
Index: sys/arch/mips/rmi/rmixl_pcie.c
===================================================================
RCS file: /cvsroot/src/sys/arch/mips/rmi/rmixl_pcie.c,v
retrieving revision 1.2
diff -u -r1.2 rmixl_pcie.c
--- sys/arch/mips/rmi/rmixl_pcie.c      14 Dec 2009 00:46:07 -0000      1.2
+++ sys/arch/mips/rmi/rmixl_pcie.c      4 Feb 2011 15:36:25 -0000
@@ -653,12 +653,12 @@
        ioext  = extent_create("pciio",
                rcp->rc_pci_io_pbase,
                rcp->rc_pci_io_pbase + rcp->rc_pci_io_size - 1,
-               M_DEVBUF, NULL, 0, EX_NOWAIT);
+               NULL, 0, EX_NOWAIT);
 
        memext = extent_create("pcimem",
                rcp->rc_pci_mem_pbase,
                rcp->rc_pci_mem_pbase + rcp->rc_pci_mem_size - 1,
-               M_DEVBUF, NULL, 0, EX_NOWAIT);
+               NULL, 0, EX_NOWAIT);
 
        pci_configure_bus(pc, ioext, memext, NULL, 0, mips_dcache_align);
 
Index: sys/arch/mipsco/mipsco/bus_space.c
===================================================================
RCS file: /cvsroot/src/sys/arch/mipsco/mipsco/bus_space.c,v
retrieving revision 1.11
diff -u -r1.11 bus_space.c
--- sys/arch/mipsco/mipsco/bus_space.c  18 Mar 2009 10:22:32 -0000      1.11
+++ sys/arch/mipsco/mipsco/bus_space.c  4 Feb 2011 15:36:25 -0000
@@ -69,7 +69,7 @@
 mipsco_bus_space_init_extent(bus_space_tag_t bst, void *storage, size_t 
storagesize)
 {
        bst->bs_extent = extent_create(bst->bs_name,
-           bst->bs_start, bst->bs_start + bst->bs_size, M_DEVBUF,
+           bst->bs_start, bst->bs_start + bst->bs_size,
            storage, storagesize, EX_NOWAIT);
        if (bst->bs_extent == NULL)
            panic("mipsco_bus_space_init_extent: cannot create extent map %s",
Index: sys/arch/mvmeppc/mvmeppc/mainbus.c
===================================================================
RCS file: /cvsroot/src/sys/arch/mvmeppc/mvmeppc/mainbus.c,v
retrieving revision 1.11
diff -u -r1.11 mainbus.c
--- sys/arch/mvmeppc/mvmeppc/mainbus.c  14 Mar 2009 15:36:11 -0000      1.11
+++ sys/arch/mvmeppc/mvmeppc/mainbus.c  4 Feb 2011 15:36:26 -0000
@@ -118,9 +118,9 @@
        SIMPLEQ_INSERT_TAIL(&genppc_pct->pc_pbi, pbi, next);
 
 #ifdef PCI_NETBSD_CONFIGURE
-       ioext  = extent_create("pciio",  0x00008000, 0x0000ffff, M_DEVBUF,
+       ioext  = extent_create("pciio",  0x00008000, 0x0000ffff,
            NULL, 0, EX_NOWAIT);
-       memext = extent_create("pcimem", 0x00000000, 0x0fffffff, M_DEVBUF,
+       memext = extent_create("pcimem", 0x00000000, 0x0fffffff,
            NULL, 0, EX_NOWAIT);
 
        pci_configure_bus(0, ioext, memext, NULL, 0, 32);
Index: sys/arch/ofppc/pci/ofwpci.c
===================================================================
RCS file: /cvsroot/src/sys/arch/ofppc/pci/ofwpci.c,v
retrieving revision 1.8
diff -u -r1.8 ofwpci.c
--- sys/arch/ofppc/pci/ofwpci.c 28 Apr 2008 20:23:31 -0000      1.8
+++ sys/arch/ofppc/pci/ofwpci.c 4 Feb 2011 15:36:27 -0000
@@ -200,9 +200,9 @@
        ioext  = extent_create("pciio",
            modeldata.pciiodata[device_unit(self)].start,
            modeldata.pciiodata[device_unit(self)].limit,
-           M_DEVBUF, NULL, 0, EX_NOWAIT);
+           NULL, 0, EX_NOWAIT);
        memext = extent_create("pcimem", sc->sc_memt.pbs_base,
-           sc->sc_memt.pbs_limit-1, M_DEVBUF, NULL, 0, EX_NOWAIT);
+           sc->sc_memt.pbs_limit-1, NULL, 0, EX_NOWAIT);
 
        if (pci_configure_bus(pc, ioext, memext, NULL, 0, CACHELINESIZE))
                aprint_error("pci_configure_bus() failed\n");
Index: sys/arch/powerpc/powerpc/bus_space.c
===================================================================
RCS file: /cvsroot/src/sys/arch/powerpc/powerpc/bus_space.c,v
retrieving revision 1.24
diff -u -r1.24 bus_space.c
--- sys/arch/powerpc/powerpc/bus_space.c        18 Jan 2011 01:02:55 -0000      
1.24
+++ sys/arch/powerpc/powerpc/bus_space.c        4 Feb 2011 15:36:28 -0000
@@ -403,7 +403,7 @@
 {
        if (t->pbs_extent == NULL && extent_name != NULL) {
                t->pbs_extent = extent_create(extent_name, t->pbs_base,
-                   t->pbs_limit-1, M_DEVBUF, storage, storage_size,
+                   t->pbs_limit-1, storage, storage_size,
                    EX_NOCOALESCE|EX_NOWAIT);
                if (t->pbs_extent == NULL)
                        return ENOMEM;
Index: sys/arch/prep/prep/mainbus.c
===================================================================
RCS file: /cvsroot/src/sys/arch/prep/prep/mainbus.c,v
retrieving revision 1.29
diff -u -r1.29 mainbus.c
--- sys/arch/prep/prep/mainbus.c        18 Mar 2009 16:00:14 -0000      1.29
+++ sys/arch/prep/prep/mainbus.c        4 Feb 2011 15:36:28 -0000
@@ -144,9 +144,9 @@
        setup_pciintr_map(pbi, 0, 0, 0);
 
 #ifdef PCI_NETBSD_CONFIGURE
-       ioext  = extent_create("pciio",  0x00008000, 0x0000ffff, M_DEVBUF,
+       ioext  = extent_create("pciio",  0x00008000, 0x0000ffff,
            NULL, 0, EX_NOWAIT);
-       memext = extent_create("pcimem", 0x00000000, 0x0fffffff, M_DEVBUF,
+       memext = extent_create("pcimem", 0x00000000, 0x0fffffff,
            NULL, 0, EX_NOWAIT);
 
        pci_configure_bus(genppc_pct, ioext, memext, NULL, 0, CACHELINESIZE);
Index: sys/arch/sandpoint/sandpoint/mainbus.c
===================================================================
RCS file: /cvsroot/src/sys/arch/sandpoint/sandpoint/mainbus.c,v
retrieving revision 1.21
diff -u -r1.21 mainbus.c
--- sys/arch/sandpoint/sandpoint/mainbus.c      14 Mar 2009 21:04:15 -0000      
1.21
+++ sys/arch/sandpoint/sandpoint/mainbus.c      4 Feb 2011 15:36:29 -0000
@@ -98,9 +98,9 @@
         */
 #if NPCI > 0
 #if defined(PCI_NETBSD_CONFIGURE)
-       ioext  = extent_create("pciio",  0x00001000, 0x0000ffff, M_DEVBUF,
+       ioext  = extent_create("pciio",  0x00001000, 0x0000ffff,
            NULL, 0, EX_NOWAIT);
-       memext = extent_create("pcimem", 0x80000000, 0x8fffffff, M_DEVBUF,
+       memext = extent_create("pcimem", 0x80000000, 0x8fffffff,
            NULL, 0, EX_NOWAIT);
 
        pci_configure_bus(0, ioext, memext, NULL, 0, 32);
Index: sys/arch/sgimips/gio/pci_gio.c
===================================================================
RCS file: /cvsroot/src/sys/arch/sgimips/gio/pci_gio.c,v
retrieving revision 1.5
diff -u -r1.5 pci_gio.c
--- sys/arch/sgimips/gio/pci_gio.c      19 Feb 2007 04:48:37 -0000      1.5
+++ sys/arch/sgimips/gio/pci_gio.c      4 Feb 2011 15:36:29 -0000
@@ -213,7 +213,7 @@
 
 #ifdef PCI_NETBSD_CONFIGURE
        pc->pc_memext = extent_create("giopcimem", m_start, m_end,
-           M_DEVBUF, NULL, 0, EX_NOWAIT);
+           NULL, 0, EX_NOWAIT);
        pci_configure_bus(pc, NULL, pc->pc_memext, NULL, 0, mips_dcache_align);
 #endif
 
Index: sys/arch/sgimips/mace/pci_mace.c
===================================================================
RCS file: /cvsroot/src/sys/arch/sgimips/mace/pci_mace.c,v
retrieving revision 1.9
diff -u -r1.9 pci_mace.c
--- sys/arch/sgimips/mace/pci_mace.c    17 Apr 2007 12:41:57 -0000      1.9
+++ sys/arch/sgimips/mace/pci_mace.c    4 Feb 2011 15:36:29 -0000
@@ -145,9 +145,9 @@
 
 #if NPCI > 0
        pc->pc_ioext = extent_create("macepciio", 0x00001000, 0x01ffffff,
-           M_DEVBUF, NULL, 0, EX_NOWAIT);
+           NULL, 0, EX_NOWAIT);
        pc->pc_memext = extent_create("macepcimem", 0x80100000, 0x81ffffff,
-           M_DEVBUF, NULL, 0, EX_NOWAIT);
+           NULL, 0, EX_NOWAIT);
        pci_configure_bus(pc, pc->pc_ioext, pc->pc_memext, NULL, 0,
            mips_dcache_align);
        memset(&pba, 0, sizeof pba);
Index: sys/arch/sh3/dev/shpcic.c
===================================================================
RCS file: /cvsroot/src/sys/arch/sh3/dev/shpcic.c,v
retrieving revision 1.13
diff -u -r1.13 shpcic.c
--- sys/arch/sh3/dev/shpcic.c   2 Aug 2009 00:06:44 -0000       1.13
+++ sys/arch/sh3/dev/shpcic.c   4 Feb 2011 15:36:30 -0000
@@ -228,10 +228,10 @@
 #ifdef PCI_NETBSD_CONFIGURE
        ioext  = extent_create("pciio",
            SH4_PCIC_IO, SH4_PCIC_IO + SH4_PCIC_IO_SIZE - 1,
-           M_DEVBUF, NULL, 0, EX_NOWAIT);
+           NULL, 0, EX_NOWAIT);
        memext = extent_create("pcimem",
            SH4_PCIC_MEM, SH4_PCIC_MEM + SH4_PCIC_MEM_SIZE - 1,
-           M_DEVBUF, NULL, 0, EX_NOWAIT);
+           NULL, 0, EX_NOWAIT);
 
        pci_configure_bus(NULL, ioext, memext, NULL, 0, sh_cache_line_size);
 
Index: sys/arch/sparc/dev/vme_machdep.c
===================================================================
RCS file: /cvsroot/src/sys/arch/sparc/dev/vme_machdep.c,v
retrieving revision 1.63
diff -u -r1.63 vme_machdep.c
--- sys/arch/sparc/dev/vme_machdep.c    14 Jan 2011 02:06:31 -0000      1.63
+++ sys/arch/sparc/dev/vme_machdep.c    4 Feb 2011 15:36:30 -0000
@@ -316,7 +316,7 @@
                sizeof(vmebus_translations)/sizeof(vmebus_translations[0]);
 
        vme_dvmamap = extent_create("vmedvma", VME4_DVMA_BASE, VME4_DVMA_END,
-                                   M_DEVBUF, 0, 0, EX_NOWAIT);
+                                   0, 0, EX_NOWAIT);
        if (vme_dvmamap == NULL)
                panic("vme: unable to allocate DVMA map");
 
Index: sys/arch/sparc/sparc/iommu.c
===================================================================
RCS file: /cvsroot/src/sys/arch/sparc/sparc/iommu.c,v
retrieving revision 1.92
diff -u -r1.92 iommu.c
--- sys/arch/sparc/sparc/iommu.c        7 Nov 2009 07:27:46 -0000       1.92
+++ sys/arch/sparc/sparc/iommu.c        4 Feb 2011 15:36:31 -0000
@@ -277,7 +277,7 @@
 
        sc->sc_dvmamap = extent_create("iommudvma",
                                        IOMMU_DVMA_BASE, IOMMU_DVMA_END,
-                                       M_DEVBUF, 0, 0, EX_NOWAIT);
+                                       0, 0, EX_NOWAIT);
        if (sc->sc_dvmamap == NULL)
                panic("iommu: unable to allocate DVMA map");
 
Index: sys/arch/sparc/sparc/machdep.c
===================================================================
RCS file: /cvsroot/src/sys/arch/sparc/sparc/machdep.c,v
retrieving revision 1.305
diff -u -r1.305 machdep.c
--- sys/arch/sparc/sparc/machdep.c      14 Jan 2011 02:06:31 -0000      1.305
+++ sys/arch/sparc/sparc/machdep.c      4 Feb 2011 15:36:32 -0000
@@ -320,7 +320,7 @@
                 */
                dvmamap24 = extent_create("dvmamap24",
                                          D24_DVMA_BASE, D24_DVMA_END,
-                                         M_DEVBUF, 0, 0, EX_NOWAIT);
+                                         0, 0, EX_NOWAIT);
                if (dvmamap24 == NULL)
                        panic("unable to allocate DVMA map");
        }
Index: sys/arch/sparc64/dev/iommu.c
===================================================================
RCS file: /cvsroot/src/sys/arch/sparc64/dev/iommu.c,v
retrieving revision 1.100
diff -u -r1.100 iommu.c
--- sys/arch/sparc64/dev/iommu.c        6 Nov 2010 11:46:02 -0000       1.100
+++ sys/arch/sparc64/dev/iommu.c        4 Feb 2011 15:36:32 -0000
@@ -212,7 +212,7 @@
                (unsigned long long)(is->is_ptsb + size - 1));
        is->is_dvmamap = extent_create(name,
            is->is_dvmabase, is->is_dvmaend,
-           M_DEVBUF, 0, 0, EX_NOWAIT);
+           0, 0, EX_NOWAIT);
        /* XXXMRG Check is_dvmamap is valid. */
 }
 
Index: sys/arch/sparc64/dev/psycho.c
===================================================================
RCS file: /cvsroot/src/sys/arch/sparc64/dev/psycho.c,v
retrieving revision 1.101
diff -u -r1.101 psycho.c
--- sys/arch/sparc64/dev/psycho.c       10 Jul 2010 10:07:40 -0000      1.101
+++ sys/arch/sparc64/dev/psycho.c       4 Feb 2011 15:36:33 -0000
@@ -788,8 +788,7 @@
        }
 
        /* create extent */
-       ex = extent_create(name, baddr, bsize - baddr - 1, M_DEVBUF, 0, 0,
-                          EX_NOWAIT);
+       ex = extent_create(name, baddr, bsize - baddr - 1, 0, 0, EX_NOWAIT);
        if (ex == NULL) {
                printf("psycho_alloc_extent: extent_create failed\n");
                goto ret;
Index: sys/arch/sparc64/sparc64/machdep.c
===================================================================
RCS file: /cvsroot/src/sys/arch/sparc64/sparc64/machdep.c,v
retrieving revision 1.255
diff -u -r1.255 machdep.c
--- sys/arch/sparc64/sparc64/machdep.c  14 Jan 2011 02:06:32 -0000      1.255
+++ sys/arch/sparc64/sparc64/machdep.c  4 Feb 2011 15:36:34 -0000
@@ -1643,7 +1643,7 @@
                 */
                io_space = extent_create("IOSPACE",
                                         (u_long)IODEV_BASE, (u_long)IODEV_END,
-                                        M_DEVBUF, 0, 0, EX_NOWAIT);
+                                        0, 0, EX_NOWAIT);
 
 
        size = round_page(size);
Index: sys/arch/sun2/sun2/machdep.c
===================================================================
RCS file: /cvsroot/src/sys/arch/sun2/sun2/machdep.c,v
retrieving revision 1.66
diff -u -r1.66 machdep.c
--- sys/arch/sun2/sun2/machdep.c        17 Jan 2011 14:36:33 -0000      1.66
+++ sys/arch/sun2/sun2/machdep.c        4 Feb 2011 15:36:35 -0000
@@ -361,7 +361,7 @@
         */
        dvmamap = extent_create("dvmamap",
            DVMA_MAP_BASE, DVMA_MAP_BASE + DVMA_MAP_AVAIL,
-           M_DEVBUF, 0, 0, EX_NOWAIT);
+           0, 0, EX_NOWAIT);
        if (dvmamap == NULL)
                panic("unable to allocate DVMA map");
 
Index: sys/arch/sun3/sun3/dvma.c
===================================================================
RCS file: /cvsroot/src/sys/arch/sun3/sun3/dvma.c,v
retrieving revision 1.36
diff -u -r1.36 dvma.c
--- sys/arch/sun3/sun3/dvma.c   11 Dec 2009 13:52:57 -0000      1.36
+++ sys/arch/sun3/sun3/dvma.c   4 Feb 2011 15:36:35 -0000
@@ -43,7 +43,7 @@
 #include <sys/core.h>
 #include <sys/exec.h>
 
-#include <uvm/uvm.h> /* XXX: not _extern ... need uvm_map_create */
+#include <uvm/uvm.h> /* XXX: not _extern ... need uvm_map_setup */
 
 #define _SUN68K_BUS_DMA_PRIVATE
 #include <machine/autoconf.h>
@@ -82,11 +82,13 @@
         * dvma_extent manages things handled in interrupt
         * context.
         */
-       phys_map = uvm_map_create(pmap_kernel(),
-           DVMA_MAP_BASE, DVMA_MAP_END, 0);
+       phys_map = kmem_alloc(sizeof(struct vm_map), KM_SLEEP);
        if (phys_map == NULL)
                panic("unable to create DVMA map");
 
+       uvm_map_setup(phys_map, DVMA_MAP_BASE, DVMA_MAP_END, 0);
+       phys_map->pmap = pmap_kernel();
+
        /*
         * Reserve the DVMA space used for segment remapping.
         * The remainder of phys_map is used for DVMA scratch
@@ -102,7 +104,7 @@
         * into DVMA space for the purpose of data transfer.
         */
        dvma_extent = extent_create("dvma", segmap_addr,
-           segmap_addr + (dvma_segmap_size - 1), M_DEVBUF,
+           segmap_addr + (dvma_segmap_size - 1), 
            NULL, 0, EX_NOCOALESCE|EX_NOWAIT);
 }
 
Index: sys/arch/sun3/sun3/pmap.c
===================================================================
RCS file: /cvsroot/src/sys/arch/sun3/sun3/pmap.c,v
retrieving revision 1.165
diff -u -r1.165 pmap.c
--- sys/arch/sun3/sun3/pmap.c   15 Oct 2010 15:55:53 -0000      1.165
+++ sys/arch/sun3/sun3/pmap.c   4 Feb 2011 15:36:36 -0000
@@ -88,7 +88,7 @@
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/proc.h>
-#include <sys/malloc.h>
+#include <sys/kmem.h>
 #include <sys/pool.h>
 #include <sys/queue.h>
 #include <sys/kcore.h>
@@ -1855,7 +1855,7 @@
 pmap_user_init(pmap_t pmap)
 {
        int i;
-       pmap->pm_segmap = malloc(sizeof(char)*NUSEG, M_VMPMAP, M_WAITOK);
+       pmap->pm_segmap = kmem_alloc(sizeof(char)*NUSEG, KM_SLEEP);
        for (i = 0; i < NUSEG; i++) {
                pmap->pm_segmap[i] = SEGINV;
        }
@@ -1906,7 +1906,7 @@
 #endif
                context_free(pmap);
        }
-       free(pmap->pm_segmap, M_VMPMAP);
+       kmem_free(pmap->pm_segmap, sizeof(char)*NUSEG);
        pmap->pm_segmap = NULL;
 
        splx(s);
Index: sys/arch/sun3/sun3x/dvma.c
===================================================================
RCS file: /cvsroot/src/sys/arch/sun3/sun3x/dvma.c,v
retrieving revision 1.40
diff -u -r1.40 dvma.c
--- sys/arch/sun3/sun3x/dvma.c  21 Nov 2009 04:16:53 -0000      1.40
+++ sys/arch/sun3/sun3x/dvma.c  4 Feb 2011 15:36:37 -0000
@@ -114,7 +114,7 @@
         * Create the extent map for DVMA pages.
         */
        dvma_extent = extent_create("dvma", DVMA_MAP_BASE,
-           DVMA_MAP_BASE + (DVMA_MAP_AVAIL - 1), M_DEVBUF,
+           DVMA_MAP_BASE + (DVMA_MAP_AVAIL - 1),
            NULL, 0, EX_NOCOALESCE|EX_NOWAIT);
 
        /*
Index: sys/arch/vax/vax/machdep.c
===================================================================
RCS file: /cvsroot/src/sys/arch/vax/vax/machdep.c,v
retrieving revision 1.180
diff -u -r1.180 machdep.c
--- sys/arch/vax/vax/machdep.c  14 Dec 2010 23:44:49 -0000      1.180
+++ sys/arch/vax/vax/machdep.c  4 Feb 2011 15:36:37 -0000
@@ -308,7 +308,7 @@
         */
        KASSERT(iospace != 0);
        iomap_ex = extent_create("iomap", iospace + VAX_NBPG,
-           iospace + ((IOSPSZ * VAX_NBPG) - 1), M_DEVBUF,
+           iospace + ((IOSPSZ * VAX_NBPG) - 1),
            (void *) iomap_ex_storage, sizeof(iomap_ex_storage),
            EX_NOCOALESCE|EX_NOWAIT);
 #ifdef DEBUG
Index: sys/arch/vax/vax/pmap.c
===================================================================
RCS file: /cvsroot/src/sys/arch/vax/vax/pmap.c,v
retrieving revision 1.179
diff -u -r1.179 pmap.c
--- sys/arch/vax/vax/pmap.c     14 Dec 2010 23:44:49 -0000      1.179
+++ sys/arch/vax/vax/pmap.c     4 Feb 2011 15:36:38 -0000
@@ -479,7 +479,7 @@
         * Create the extent map used to manage the page table space.
         */
        ptemap = extent_create("ptemap", ptemapstart, ptemapend,
-           M_VMPMAP, ptmapstorage, PTMAPSZ, EX_NOCOALESCE);
+           ptmapstorage, PTMAPSZ, EX_NOCOALESCE);
        if (ptemap == NULL)
                panic("pmap_init");
 }
Index: sys/arch/vax/vax/sgmap.c
===================================================================
RCS file: /cvsroot/src/sys/arch/vax/vax/sgmap.c,v
retrieving revision 1.16
diff -u -r1.16 sgmap.c
--- sys/arch/vax/vax/sgmap.c    14 Dec 2010 23:44:50 -0000      1.16
+++ sys/arch/vax/vax/sgmap.c    4 Feb 2011 15:36:38 -0000
@@ -93,7 +93,7 @@
         * space.
         */
        sgmap->aps_ex = extent_create(name, sgvabase, sgvasize - 1,
-           M_DMAMAP, NULL, 0, EX_NOWAIT|EX_NOCOALESCE);
+           NULL, 0, EX_NOWAIT|EX_NOCOALESCE);
        if (sgmap->aps_ex == NULL) {
                printf("unable to create extent map for sgmap `%s'\n", name);
                goto die;
Index: sys/arch/x68k/dev/intio.c
===================================================================
RCS file: /cvsroot/src/sys/arch/x68k/dev/intio.c,v
retrieving revision 1.42
diff -u -r1.42 intio.c
--- sys/arch/x68k/dev/intio.c   18 Jan 2009 05:00:39 -0000      1.42
+++ sys/arch/x68k/dev/intio.c   4 Feb 2011 15:36:39 -0000
@@ -162,7 +162,7 @@
        sc->sc_map = extent_create("intiomap",
                                  INTIOBASE,
                                  INTIOBASE + 0x400000,
-                                 M_DEVBUF, NULL, 0, EX_NOWAIT);
+                                 NULL, 0, EX_NOWAIT);
        intio_alloc_system_ports(sc);
 
        sc->sc_bst = &intio_bus;
Index: sys/arch/x86/pci/pci_addr_fixup.c
===================================================================
RCS file: /cvsroot/src/sys/arch/x86/pci/pci_addr_fixup.c,v
retrieving revision 1.5
diff -u -r1.5 pci_addr_fixup.c
--- sys/arch/x86/pci/pci_addr_fixup.c   26 Jul 2010 22:33:23 -0000      1.5
+++ sys/arch/x86/pci/pci_addr_fixup.c   4 Feb 2011 15:36:39 -0000
@@ -94,12 +94,12 @@
        pciaddr.extent_mem = extent_create("PCI I/O memory space",
                                           PCIADDR_MEM_START, 
                                           PCIADDR_MEM_END,
-                                          M_DEVBUF, 0, 0, EX_NOWAIT);
+                                          0, 0, EX_NOWAIT);
        KASSERT(pciaddr.extent_mem);
        pciaddr.extent_port = extent_create("PCI I/O port space",
                                            PCIADDR_PORT_START,
                                            PCIADDR_PORT_END,
-                                           M_DEVBUF, 0, 0, EX_NOWAIT);
+                                           0, 0, EX_NOWAIT);
        KASSERT(pciaddr.extent_port);
 
        /* 
Index: sys/arch/x86/x86/bus_space.c
===================================================================
RCS file: /cvsroot/src/sys/arch/x86/x86/bus_space.c,v
retrieving revision 1.32
diff -u -r1.32 bus_space.c
--- sys/arch/x86/x86/bus_space.c        10 Jan 2011 16:59:09 -0000      1.32
+++ sys/arch/x86/x86/bus_space.c        4 Feb 2011 15:36:40 -0000
@@ -125,10 +125,10 @@
         * extents of RAM are allocated from the map (0 -> ISA hole
         * and end of ISA hole -> end of RAM).
         */
-       ioport_ex = extent_create("ioport", 0x0, 0xffff, M_DEVBUF,
+       ioport_ex = extent_create("ioport", 0x0, 0xffff, 
            (void *)ioport_ex_storage, sizeof(ioport_ex_storage),
            EX_NOCOALESCE|EX_NOWAIT);
-       iomem_ex = extent_create("iomem", 0x0, 0xffffffff, M_DEVBUF,
+       iomem_ex = extent_create("iomem", 0x0, 0xffffffff,
            (void *)iomem_ex_storage, sizeof(iomem_ex_storage),
            EX_NOCOALESCE|EX_NOWAIT);
 
Index: sys/arch/x86/x86/intr.c
===================================================================
RCS file: /cvsroot/src/sys/arch/x86/x86/intr.c,v
retrieving revision 1.70
diff -u -r1.70 intr.c
--- sys/arch/x86/x86/intr.c     22 Jan 2011 14:01:27 -0000      1.70
+++ sys/arch/x86/x86/intr.c     4 Feb 2011 15:36:41 -0000
@@ -988,7 +988,6 @@
        struct intrsource *isp;
 #if NLAPIC > 0 && defined(MULTIPROCESSOR)
        int i;
-       static int first = 1;
 #endif
 #ifdef INTRSTACKSIZE
        vaddr_t istack;
@@ -1003,10 +1002,8 @@
        isp->is_handlers = &fake_timer_intrhand;
        isp->is_pic = &local_pic;
        ci->ci_isources[LIR_TIMER] = isp;
-       evcnt_attach_dynamic(&isp->is_evcnt,
-           first ? EVCNT_TYPE_INTR : EVCNT_TYPE_MISC, NULL,
+       evcnt_attach_dynamic(&isp->is_evcnt, EVCNT_TYPE_INTR, NULL,
            device_xname(ci->ci_dev), "timer");
-       first = 0;
 
 #ifdef MULTIPROCESSOR
        isp = kmem_zalloc(sizeof(*isp), KM_SLEEP);
Index: sys/arch/x86/x86/pmap.c
===================================================================
RCS file: /cvsroot/src/sys/arch/x86/x86/pmap.c,v
retrieving revision 1.115
diff -u -r1.115 pmap.c
--- sys/arch/x86/x86/pmap.c     1 Feb 2011 20:20:19 -0000       1.115
+++ sys/arch/x86/x86/pmap.c     4 Feb 2011 15:36:44 -0000
@@ -1552,24 +1552,6 @@
        pmap_cpu_init_early(curcpu());
 
        /*
-        * initialize caches.
-        */
-
-       pool_cache_bootstrap(&pmap_cache, sizeof(struct pmap), 0, 0, 0,
-           "pmappl", NULL, IPL_NONE, NULL, NULL, NULL);
-#ifdef PAE
-       pool_cache_bootstrap(&pmap_pdp_cache, PAGE_SIZE * PDP_SIZE, 0, 0, 0,
-           "pdppl", &pmap_pdp_allocator, IPL_NONE,
-           pmap_pdp_ctor, pmap_pdp_dtor, NULL);
-#else /* PAE */
-       pool_cache_bootstrap(&pmap_pdp_cache, PAGE_SIZE, 0, 0, 0,
-           "pdppl", NULL, IPL_NONE, pmap_pdp_ctor, pmap_pdp_dtor, NULL);
-#endif /* PAE */
-       pool_cache_bootstrap(&pmap_pv_cache, sizeof(struct pv_entry), 0, 0,
-           PR_LARGECACHE, "pvpl", &pool_allocator_meta, IPL_NONE, NULL,
-           NULL, NULL);
-
-       /*
         * ensure the TLB is sync'd with reality by flushing it...
         */
 
@@ -1655,6 +1637,24 @@
 {
        int i;
 
+       /*
+        * initialize caches.
+        */
+
+       pool_cache_bootstrap(&pmap_cache, sizeof(struct pmap), 0, 0, 0,
+               "pmappl", NULL, IPL_NONE, NULL, NULL, NULL);
+#ifdef PAE
+       pool_cache_bootstrap(&pmap_pdp_cache, PAGE_SIZE * PDP_SIZE, 0, 0, 0,
+               "pdppl", &pmap_pdp_allocator, IPL_NONE,
+               pmap_pdp_ctor, pmap_pdp_dtor, NULL);
+#else /* PAE */
+       pool_cache_bootstrap(&pmap_pdp_cache, PAGE_SIZE, 0, 0, 0,
+               "pdppl", NULL, IPL_NONE, pmap_pdp_ctor, pmap_pdp_dtor, NULL);
+#endif /* PAE */
+       pool_cache_bootstrap(&pmap_pv_cache, sizeof(struct pv_entry), 0, 0,
+               PR_LARGECACHE, "pvpl", &pool_allocator_meta, IPL_NONE, NULL,
+               NULL, NULL);
+
        for (i = 0; i < PV_HASH_SIZE; i++) {
                SLIST_INIT(&pv_hash_heads[i].hh_list);
        }
@@ -1700,7 +1700,7 @@
                    NULL, "x86", "ldt sync");
        }
 
-       evcnt_attach_dynamic(&ci->ci_tlb_evcnt, EVCNT_TYPE_MISC,
+       evcnt_attach_dynamic(&ci->ci_tlb_evcnt, EVCNT_TYPE_INTR,
            NULL, device_xname(ci->ci_dev), "TLB IPI");
 
 #ifdef PAE
Index: sys/dev/cardbus/rbus.c
===================================================================
RCS file: /cvsroot/src/sys/dev/cardbus/rbus.c,v
retrieving revision 1.28
diff -u -r1.28 rbus.c
--- sys/dev/cardbus/rbus.c      15 Dec 2009 22:17:12 -0000      1.28
+++ sys/dev/cardbus/rbus.c      4 Feb 2011 15:36:46 -0000
@@ -258,7 +258,7 @@
        if (flags == RBUS_SPACE_SHARE) {
                ex = parent->rb_ext;
        } else if (flags == RBUS_SPACE_DEDICATE) {
-               if (NULL == (ex = extent_create("rbus", start, end, M_DEVBUF,
+               if (NULL == (ex = extent_create("rbus", start, end,
                    NULL, 0, EX_NOCOALESCE|EX_NOWAIT))) {
                        return NULL;
                }
@@ -295,7 +295,7 @@
        struct extent *ex;
 
        if (NULL == (ex = extent_create("rbus root", start, start + size,
-           M_DEVBUF, NULL, 0, EX_NOCOALESCE|EX_NOWAIT))) {
+           NULL, 0, EX_NOCOALESCE|EX_NOWAIT))) {
                return NULL;
        }
 
Index: sys/dev/ic/cpc700.c
===================================================================
RCS file: /cvsroot/src/sys/dev/ic/cpc700.c,v
retrieving revision 1.17
diff -u -r1.17 cpc700.c
--- sys/dev/ic/cpc700.c 10 Dec 2010 00:38:49 -0000      1.17
+++ sys/dev/ic/cpc700.c 4 Feb 2011 15:36:47 -0000
@@ -191,9 +191,9 @@
 
 #if NPCI > 0 && defined(PCI_NETBSD_CONFIGURE)
        ioext  = extent_create("pciio",  CPC_PCI_IO_START, CPC_PCI_IO_END,
-           M_DEVBUF, NULL, 0, EX_NOWAIT);
+           NULL, 0, EX_NOWAIT);
        memext = extent_create("pcimem", CPC_PCI_MEM_BASE, CPC_PCI_MEM_END,
-           M_DEVBUF, NULL, 0, EX_NOWAIT);
+           NULL, 0, EX_NOWAIT);
 
        pci_configure_bus(0, ioext, memext, NULL, 0, 32);
 
Index: sys/dev/marvell/gtpci.c
===================================================================
RCS file: /cvsroot/src/sys/dev/marvell/gtpci.c,v
retrieving revision 1.27
diff -u -r1.27 gtpci.c
--- sys/dev/marvell/gtpci.c     1 Aug 2010 06:57:06 -0000       1.27
+++ sys/dev/marvell/gtpci.c     4 Feb 2011 15:36:48 -0000
@@ -454,10 +454,8 @@
        p2pc = GTPCI_READ(sc, GTPCI_P2PC);
 
 #ifdef PCI_NETBSD_CONFIGURE
-       ioext = extent_create("pciio", iostart, ioend, M_DEVBUF, NULL, 0,
-           EX_NOWAIT);
-       memext = extent_create("pcimem", memstart, memend, M_DEVBUF, NULL, 0,
-           EX_NOWAIT);
+       ioext = extent_create("pciio", iostart, ioend, NULL, 0, EX_NOWAIT);
+       memext = extent_create("pcimem", memstart, memend, NULL, 0, EX_NOWAIT);
        if (ioext != NULL && memext != NULL)
                pci_configure_bus(pc, ioext, memext, NULL,
                    GTPCI_P2PC_BUSNUMBER(p2pc), cacheline_size);
Index: sys/dev/marvell/mvpex.c
===================================================================
RCS file: /cvsroot/src/sys/dev/marvell/mvpex.c,v
retrieving revision 1.3
diff -u -r1.3 mvpex.c
--- sys/dev/marvell/mvpex.c     23 Jan 2011 18:13:42 -0000      1.3
+++ sys/dev/marvell/mvpex.c     4 Feb 2011 15:36:48 -0000
@@ -417,10 +417,8 @@
        stat = bus_space_read_4(sc->sc_iot, sc->sc_ioh, MVPEX_STAT);
 
 #ifdef PCI_NETBSD_CONFIGURE
-       ioext = extent_create("pexio", iostart, ioend, M_DEVBUF, NULL, 0,
-           EX_NOWAIT);
-       memext = extent_create("pexmem", memstart, memend, M_DEVBUF, NULL, 0,
-           EX_NOWAIT);
+       ioext = extent_create("pexio", iostart, ioend, NULL, 0, EX_NOWAIT);
+       memext = extent_create("pexmem", memstart, memend, NULL, 0, EX_NOWAIT);
        if (ioext != NULL && memext != NULL)
                pci_configure_bus(pc, ioext, memext, NULL,
                    MVPEX_STAT_PEXBUSNUM(stat), cacheline_size);
Index: sys/dev/pci/btvmei.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/btvmei.c,v
retrieving revision 1.26
diff -u -r1.26 btvmei.c
--- sys/dev/pci/btvmei.c        26 Nov 2009 15:17:08 -0000      1.26
+++ sys/dev/pci/btvmei.c        4 Feb 2011 15:36:49 -0000
@@ -303,16 +303,16 @@
         * set up scatter page allocation control
         */
        sc->vmeext = extent_create("pcivme", MR_PCI_VME,
-                                  MR_PCI_VME + MR_PCI_VME_SIZE - 1, M_DEVBUF,
+                                  MR_PCI_VME + MR_PCI_VME_SIZE - 1,
                                   sc->vmemap, sizeof(sc->vmemap),
                                   EX_NOCOALESCE);
 #if 0
        sc->pciext = extent_create("vmepci", MR_VME_PCI,
-                                  MR_VME_PCI + MR_VME_PCI_SIZE - 1, M_DEVBUF,
+                                  MR_VME_PCI + MR_VME_PCI_SIZE - 1,
                                   sc->pcimap, sizeof(sc->pcimap),
                                   EX_NOCOALESCE);
        sc->dmaext = extent_create("dmapci", MR_DMA_PCI,
-                                  MR_DMA_PCI + MR_DMA_PCI_SIZE - 1, M_DEVBUF,
+                                  MR_DMA_PCI + MR_DMA_PCI_SIZE - 1,
                                   sc->dmamap, sizeof(sc->dmamap),
                                   EX_NOCOALESCE);
 #endif
Index: sys/dev/pci/pciconf.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/pciconf.c,v
retrieving revision 1.32
diff -u -r1.32 pciconf.c
--- sys/dev/pci/pciconf.c       11 Dec 2010 18:21:14 -0000      1.32
+++ sys/dev/pci/pciconf.c       4 Feb 2011 15:36:49 -0000
@@ -713,8 +713,7 @@
                }
                if (pd->ppb && pi->reg == 0) {
                        pd->ppb->ioext = extent_create("pciconf", pi->address,
-                           pi->address + pi->size, M_DEVBUF, NULL, 0,
-                           EX_NOWAIT);
+                           pi->address + pi->size, NULL, 0, EX_NOWAIT);
                        if (pd->ppb->ioext == NULL) {
                                print_tag(pd->pc, pd->tag);
                                printf("Failed to alloc I/O ext. for bus %d\n",
@@ -764,8 +763,7 @@
                }
                if (pd->ppb && pm->reg == 0) {
                        ex = extent_create("pciconf", pm->address,
-                           pm->address + pm->size, M_DEVBUF, NULL, 0,
-                           EX_NOWAIT);
+                           pm->address + pm->size, NULL, 0, EX_NOWAIT);
                        if (ex == NULL) {
                                print_tag(pd->pc, pd->tag);
                                printf("Failed to alloc MEM ext. for bus %d\n",
Index: sys/dev/pci/tga.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/tga.c,v
retrieving revision 1.82
diff -u -r1.82 tga.c
--- sys/dev/pci/tga.c   25 Jan 2011 07:17:07 -0000      1.82
+++ sys/dev/pci/tga.c   4 Feb 2011 15:36:50 -0000
@@ -598,7 +598,11 @@
                    cmd, data, flag, l);
 
        case WSDISPLAYIO_GET_BUSID:
+<<<<<<< tga.c
+               return wsdisplayio_busid_pci(sc->softc->sc_dev, dc->dc_pc,
+=======
                return wsdisplayio_busid_pci(sc->sc_dev, dc->dc_pc,
+>>>>>>> 1.82
                    dc->dc_pcitag, data);
        }
        return EPASSTHROUGH;
Index: sys/dev/usb/usb_mem.c
===================================================================
RCS file: /cvsroot/src/sys/dev/usb/usb_mem.c,v
retrieving revision 1.45
diff -u -r1.45 usb_mem.c
--- sys/dev/usb/usb_mem.c       4 Jan 2011 01:37:55 -0000       1.45
+++ sys/dev/usb/usb_mem.c       4 Feb 2011 15:36:51 -0000
@@ -400,7 +400,7 @@
        rs->paddr = rs->map->dm_segs[0].ds_addr;
        rs->extent = extent_create(device_xname(dv), (u_long)rs->paddr,
            (u_long)(rs->paddr + USB_MEM_RESERVE - 1),
-           M_USB, 0, 0, 0);
+           0, 0, 0);
        if (rs->extent == NULL) {
                rs->vaddr = 0;
                return ENOMEM;
Index: sys/dev/vme/vme.c
===================================================================
RCS file: /cvsroot/src/sys/dev/vme/vme.c,v
retrieving revision 1.24
diff -u -r1.24 vme.c
--- sys/dev/vme/vme.c   11 Dec 2010 18:12:45 -0000      1.24
+++ sys/dev/vme/vme.c   4 Feb 2011 15:36:51 -0000
@@ -188,21 +188,21 @@
         * set up address space accounting - assume incomplete decoding
         */
        sc->vme32ext = extent_create("vme32", 0, 0xffffffff,
-                                    M_DEVBUF, 0, 0, 0);
+                                    0, 0, 0);
        if (!sc->vme32ext) {
                printf("error creating A32 map\n");
                return;
        }
 
        sc->vme24ext = extent_create("vme24", 0, 0x00ffffff,
-                                    M_DEVBUF, 0, 0, 0);
+                                    0, 0, 0);
        if (!sc->vme24ext) {
                printf("error creating A24 map\n");
                return;
        }
 
        sc->vme16ext = extent_create("vme16", 0, 0x0000ffff,
-                                    M_DEVBUF, 0, 0, 0);
+                                    0, 0, 0);
        if (!sc->vme16ext) {
                printf("error creating A16 map\n");
                return;
Index: sys/fs/adosfs/advfsops.c
===================================================================
RCS file: /cvsroot/src/sys/fs/adosfs/advfsops.c,v
retrieving revision 1.60
diff -u -r1.60 advfsops.c
--- sys/fs/adosfs/advfsops.c    24 Jun 2010 13:03:08 -0000      1.60
+++ sys/fs/adosfs/advfsops.c    4 Feb 2011 15:36:53 -0000
@@ -74,9 +74,9 @@
 
 struct pool adosfs_node_pool;
 
-MALLOC_JUSTDEFINE(M_ADOSFSMNT, "adosfs mount", "adosfs mount structures");
-MALLOC_JUSTDEFINE(M_ANODE, "adosfs anode","adosfs anode structures and 
tables");
-MALLOC_JUSTDEFINE(M_ADOSFSBITMAP, "adosfs bitmap", "adosfs bitmap");
+MALLOC_DEFINE(M_ADOSFSMNT, "adosfs mount", "adosfs mount structures");
+MALLOC_DEFINE(M_ANODE, "adosfs anode","adosfs anode structures and tables");
+MALLOC_DEFINE(M_ADOSFSBITMAP, "adosfs bitmap", "adosfs bitmap");
 
 static const struct genfs_ops adosfs_genfsops = {
        .gop_size = genfs_size,
Index: sys/fs/cd9660/cd9660_vfsops.c
===================================================================
RCS file: /cvsroot/src/sys/fs/cd9660/cd9660_vfsops.c,v
retrieving revision 1.71
diff -u -r1.71 cd9660_vfsops.c
--- sys/fs/cd9660/cd9660_vfsops.c       24 Jun 2010 13:03:09 -0000      1.71
+++ sys/fs/cd9660/cd9660_vfsops.c       4 Feb 2011 15:36:53 -0000
@@ -76,7 +76,7 @@
 
 MODULE(MODULE_CLASS_VFS, cd9660, NULL);
 
-MALLOC_JUSTDEFINE(M_ISOFSMNT, "ISOFS mount", "ISOFS mount structure");
+MALLOC_DEFINE(M_ISOFSMNT, "ISOFS mount", "ISOFS mount structure");
 
 static struct sysctllog *cd9660_sysctl_log;
 
Index: sys/fs/efs/efs_vfsops.c
===================================================================
RCS file: /cvsroot/src/sys/fs/efs/efs_vfsops.c,v
retrieving revision 1.21
diff -u -r1.21 efs_vfsops.c
--- sys/fs/efs/efs_vfsops.c     19 Nov 2010 06:44:41 -0000      1.21
+++ sys/fs/efs/efs_vfsops.c     4 Feb 2011 15:36:53 -0000
@@ -51,9 +51,9 @@
 
 MODULE(MODULE_CLASS_VFS, efs, NULL);
 
-MALLOC_JUSTDEFINE(M_EFSMNT, "efsmnt", "efs mount structure");
-MALLOC_JUSTDEFINE(M_EFSINO, "efsino", "efs in-core inode structure");
-MALLOC_JUSTDEFINE(M_EFSTMP, "efstmp", "efs temporary allocations");
+MALLOC_DEFINE(M_EFSMNT, "efsmnt", "efs mount structure");
+MALLOC_DEFINE(M_EFSINO, "efsino", "efs in-core inode structure");
+MALLOC_DEFINE(M_EFSTMP, "efstmp", "efs temporary allocations");
 
 extern int (**efs_vnodeop_p)(void *);  /* for getnewvnode() */
 extern int (**efs_specop_p)(void *);   /* for getnewvnode() */
Index: sys/fs/filecorefs/filecore_vfsops.c
===================================================================
RCS file: /cvsroot/src/sys/fs/filecorefs/filecore_vfsops.c,v
retrieving revision 1.64
diff -u -r1.64 filecore_vfsops.c
--- sys/fs/filecorefs/filecore_vfsops.c 24 Jun 2010 13:03:09 -0000      1.64
+++ sys/fs/filecorefs/filecore_vfsops.c 4 Feb 2011 15:36:53 -0000
@@ -98,9 +98,9 @@
 
 MODULE(MODULE_CLASS_VFS, filecore, NULL);
 
-MALLOC_JUSTDEFINE(M_FILECOREMNT,
+MALLOC_DEFINE(M_FILECOREMNT,
     "filecore mount", "Filecore FS mount structures");
-MALLOC_JUSTDEFINE(M_FILECORETMP,
+MALLOC_DEFINE(M_FILECORETMP,
     "filecore temp", "Filecore FS temporary structures");
 
 static struct sysctllog *filecore_sysctl_log;
Index: sys/fs/hfs/hfs_vfsops.c
===================================================================
RCS file: /cvsroot/src/sys/fs/hfs/hfs_vfsops.c,v
retrieving revision 1.26
diff -u -r1.26 hfs_vfsops.c
--- sys/fs/hfs/hfs_vfsops.c     24 Jun 2010 13:03:09 -0000      1.26
+++ sys/fs/hfs/hfs_vfsops.c     4 Feb 2011 15:36:53 -0000
@@ -137,7 +137,7 @@
 
 MODULE(MODULE_CLASS_VFS, hfs, NULL);
 
-MALLOC_JUSTDEFINE(M_HFSMNT, "hfs mount", "hfs mount structures");
+MALLOC_DEFINE(M_HFSMNT, "hfs mount", "hfs mount structures");
 
 extern kmutex_t hfs_hashlock;
 
Index: sys/fs/msdosfs/msdosfs_vfsops.c
===================================================================
RCS file: /cvsroot/src/sys/fs/msdosfs/msdosfs_vfsops.c,v
retrieving revision 1.89
diff -u -r1.89 msdosfs_vfsops.c
--- sys/fs/msdosfs/msdosfs_vfsops.c     27 Dec 2010 18:49:42 -0000      1.89
+++ sys/fs/msdosfs/msdosfs_vfsops.c     4 Feb 2011 15:36:54 -0000
@@ -103,9 +103,9 @@
 
 static int update_mp(struct mount *, struct msdosfs_args *);
 
-MALLOC_JUSTDEFINE(M_MSDOSFSMNT, "MSDOSFS mount", "MSDOS FS mount structure");
-MALLOC_JUSTDEFINE(M_MSDOSFSFAT, "MSDOSFS fat", "MSDOS FS fat table");
-MALLOC_JUSTDEFINE(M_MSDOSFSTMP, "MSDOSFS temp", "MSDOS FS temp. structures");
+MALLOC_DEFINE(M_MSDOSFSMNT, "MSDOSFS mount", "MSDOS FS mount structure");
+MALLOC_DEFINE(M_MSDOSFSFAT, "MSDOSFS fat", "MSDOS FS fat table");
+MALLOC_DEFINE(M_MSDOSFSTMP, "MSDOSFS temp", "MSDOS FS temp. structures");
 
 #define ROOTNAME "root_device"
 
Index: sys/fs/nilfs/nilfs_vfsops.c
===================================================================
RCS file: /cvsroot/src/sys/fs/nilfs/nilfs_vfsops.c,v
retrieving revision 1.5
diff -u -r1.5 nilfs_vfsops.c
--- sys/fs/nilfs/nilfs_vfsops.c 11 Aug 2010 13:26:25 -0000      1.5
+++ sys/fs/nilfs/nilfs_vfsops.c 4 Feb 2011 15:36:54 -0000
@@ -86,8 +86,8 @@
 int nilfs_verbose = NILFS_DEBUGGING;
 
 /* malloc regions */
-MALLOC_JUSTDEFINE(M_NILFSMNT,   "NILFS mount", "NILFS mount structures");
-MALLOC_JUSTDEFINE(M_NILFSTEMP,  "NILFS temp",  "NILFS scrap space");
+MALLOC_DEFINE(M_NILFSMNT,   "NILFS mount",     "NILFS mount structures");
+MALLOC_DEFINE(M_NILFSTEMP,  "NILFS temp",      "NILFS scrap space");
 struct pool nilfs_node_pool;
 
 /* globals */
Index: sys/fs/ntfs/ntfs_subr.c
===================================================================
RCS file: /cvsroot/src/sys/fs/ntfs/ntfs_subr.c,v
retrieving revision 1.44
diff -u -r1.44 ntfs_subr.c
--- sys/fs/ntfs/ntfs_subr.c     8 Jan 2010 11:35:08 -0000       1.44
+++ sys/fs/ntfs/ntfs_subr.c     4 Feb 2011 15:36:54 -0000
@@ -58,11 +58,11 @@
 int ntfs_debug = NTFS_DEBUG;
 #endif
 
-MALLOC_JUSTDEFINE(M_NTFSNTVATTR, "NTFS vattr",
+MALLOC_DEFINE(M_NTFSNTVATTR, "NTFS vattr",
     "NTFS file attribute information");
-MALLOC_JUSTDEFINE(M_NTFSRDATA, "NTFS res data", "NTFS resident data");
-MALLOC_JUSTDEFINE(M_NTFSRUN, "NTFS vrun", "NTFS vrun storage");
-MALLOC_JUSTDEFINE(M_NTFSDECOMP, "NTFS decomp", "NTFS decompression temporary");
+MALLOC_DEFINE(M_NTFSRDATA, "NTFS res data", "NTFS resident data");
+MALLOC_DEFINE(M_NTFSRUN, "NTFS vrun", "NTFS vrun storage");
+MALLOC_DEFINE(M_NTFSDECOMP, "NTFS decomp", "NTFS decompression temporary");
 
 /* Local struct used in ntfs_ntlookupfile() */
 struct ntfs_lookup_ctx {
Index: sys/fs/ntfs/ntfs_vfsops.c
===================================================================
RCS file: /cvsroot/src/sys/fs/ntfs/ntfs_vfsops.c,v
retrieving revision 1.85
diff -u -r1.85 ntfs_vfsops.c
--- sys/fs/ntfs/ntfs_vfsops.c   25 Jul 2010 09:54:37 -0000      1.85
+++ sys/fs/ntfs/ntfs_vfsops.c   4 Feb 2011 15:36:55 -0000
@@ -61,10 +61,10 @@
 
 MODULE(MODULE_CLASS_VFS, ntfs, NULL);
 
-MALLOC_JUSTDEFINE(M_NTFSMNT, "NTFS mount", "NTFS mount structure");
-MALLOC_JUSTDEFINE(M_NTFSNTNODE,"NTFS ntnode",  "NTFS ntnode information");
-MALLOC_JUSTDEFINE(M_NTFSFNODE,"NTFS fnode",  "NTFS fnode information");
-MALLOC_JUSTDEFINE(M_NTFSDIR,"NTFS dir",  "NTFS dir buffer");
+MALLOC_DEFINE(M_NTFSMNT, "NTFS mount", "NTFS mount structure");
+MALLOC_DEFINE(M_NTFSNTNODE,"NTFS ntnode",  "NTFS ntnode information");
+MALLOC_DEFINE(M_NTFSFNODE,"NTFS fnode",  "NTFS fnode information");
+MALLOC_DEFINE(M_NTFSDIR,"NTFS dir",  "NTFS dir buffer");
 
 static int     ntfs_mount(struct mount *, const char *, void *, size_t *);
 static int     ntfs_root(struct mount *, struct vnode **);
Index: sys/fs/ptyfs/ptyfs_vfsops.c
===================================================================
RCS file: /cvsroot/src/sys/fs/ptyfs/ptyfs_vfsops.c,v
retrieving revision 1.42
diff -u -r1.42 ptyfs_vfsops.c
--- sys/fs/ptyfs/ptyfs_vfsops.c 8 Jan 2010 11:35:09 -0000       1.42
+++ sys/fs/ptyfs/ptyfs_vfsops.c 4 Feb 2011 15:36:55 -0000
@@ -65,8 +65,8 @@
 
 MODULE(MODULE_CLASS_VFS, ptyfs, NULL);
 
-MALLOC_JUSTDEFINE(M_PTYFSMNT, "ptyfs mount", "ptyfs mount structures");
-MALLOC_JUSTDEFINE(M_PTYFSTMP, "ptyfs temp", "ptyfs temporary structures");
+MALLOC_DEFINE(M_PTYFSMNT, "ptyfs mount", "ptyfs mount structures");
+MALLOC_DEFINE(M_PTYFSTMP, "ptyfs temp", "ptyfs temporary structures");
 
 VFS_PROTOS(ptyfs);
 
Index: sys/fs/smbfs/smbfs_node.c
===================================================================
RCS file: /cvsroot/src/sys/fs/smbfs/smbfs_node.c,v
retrieving revision 1.45
diff -u -r1.45 smbfs_node.c
--- sys/fs/smbfs/smbfs_node.c   21 Jul 2010 17:52:11 -0000      1.45
+++ sys/fs/smbfs/smbfs_node.c   4 Feb 2011 15:36:55 -0000
@@ -64,7 +64,7 @@
 
 #define        SMBFS_NOHASH(smp, hval) (&(smp)->sm_hash[(hval) & 
(smp)->sm_hashlen])
 
-MALLOC_JUSTDEFINE(M_SMBNODENAME, "SMBFS nname", "SMBFS node name");
+MALLOC_DEFINE(M_SMBNODENAME, "SMBFS nname", "SMBFS node name");
 
 extern int (**smbfs_vnodeop_p)(void *);
 extern int prtactive;
Index: sys/fs/smbfs/smbfs_subr.c
===================================================================
RCS file: /cvsroot/src/sys/fs/smbfs/smbfs_subr.c,v
retrieving revision 1.14
diff -u -r1.14 smbfs_subr.c
--- sys/fs/smbfs/smbfs_subr.c   30 Jun 2007 09:37:57 -0000      1.14
+++ sys/fs/smbfs/smbfs_subr.c   4 Feb 2011 15:36:55 -0000
@@ -57,7 +57,7 @@
 #include <fs/smbfs/smbfs_node.h>
 #include <fs/smbfs/smbfs_subr.h>
 
-MALLOC_JUSTDEFINE(M_SMBFSDATA, "SMBFS data", "SMBFS private data");
+MALLOC_DEFINE(M_SMBFSDATA, "SMBFS data", "SMBFS private data");
 
 /*
  * Time & date conversion routines taken from msdosfs. Although leap
Index: sys/fs/sysvbfs/bfs.c
===================================================================
RCS file: /cvsroot/src/sys/fs/sysvbfs/bfs.c,v
retrieving revision 1.13
diff -u -r1.13 bfs.c
--- sys/fs/sysvbfs/bfs.c        26 Jul 2010 13:43:26 -0000      1.13
+++ sys/fs/sysvbfs/bfs.c        4 Feb 2011 15:36:55 -0000
@@ -43,7 +43,7 @@
 #include <sys/time.h>
 
 #ifdef _KERNEL
-MALLOC_JUSTDEFINE(M_BFS, "sysvbfs core", "sysvbfs internal structures");
+MALLOC_DEFINE(M_BFS, "sysvbfs core", "sysvbfs internal structures");
 #define        __MALLOC(s, t, f)       malloc(s, t, f)
 #define        __FREE(a, s, t)         free(a, t)
 #elif defined _STANDALONE
Index: sys/fs/sysvbfs/sysvbfs_vfsops.c
===================================================================
RCS file: /cvsroot/src/sys/fs/sysvbfs/sysvbfs_vfsops.c,v
retrieving revision 1.35
diff -u -r1.35 sysvbfs_vfsops.c
--- sys/fs/sysvbfs/sysvbfs_vfsops.c     25 Jul 2010 10:00:48 -0000      1.35
+++ sys/fs/sysvbfs/sysvbfs_vfsops.c     4 Feb 2011 15:36:55 -0000
@@ -60,7 +60,7 @@
 #define        DPRINTF(arg...)         ((void)0)
 #endif
 
-MALLOC_JUSTDEFINE(M_SYSVBFS_VFS, "sysvbfs vfs", "sysvbfs vfs structures");
+MALLOC_DEFINE(M_SYSVBFS_VFS, "sysvbfs vfs", "sysvbfs vfs structures");
 
 struct pool sysvbfs_node_pool;
 
Index: sys/fs/sysvbfs/sysvbfs_vnops.c
===================================================================
RCS file: /cvsroot/src/sys/fs/sysvbfs/sysvbfs_vnops.c,v
retrieving revision 1.36
diff -u -r1.36 sysvbfs_vnops.c
--- sys/fs/sysvbfs/sysvbfs_vnops.c      31 Jan 2011 18:48:50 -0000      1.36
+++ sys/fs/sysvbfs/sysvbfs_vnops.c      4 Feb 2011 15:36:55 -0000
@@ -57,7 +57,7 @@
 #endif
 #define        ROUND_SECTOR(x)         (((x) + 511) & ~511)
 
-MALLOC_JUSTDEFINE(M_SYSVBFS_VNODE, "sysvbfs vnode", "sysvbfs vnode 
structures");
+MALLOC_DEFINE(M_SYSVBFS_VNODE, "sysvbfs vnode", "sysvbfs vnode structures");
 MALLOC_DECLARE(M_BFS);
 
 int
Index: sys/fs/udf/udf_vfsops.c
===================================================================
RCS file: /cvsroot/src/sys/fs/udf/udf_vfsops.c,v
retrieving revision 1.60
diff -u -r1.60 udf_vfsops.c
--- sys/fs/udf/udf_vfsops.c     24 Jun 2010 13:03:11 -0000      1.60
+++ sys/fs/udf/udf_vfsops.c     4 Feb 2011 15:36:56 -0000
@@ -74,9 +74,9 @@
 int udf_verbose = UDF_DEBUGGING;
 
 /* malloc regions */
-MALLOC_JUSTDEFINE(M_UDFMNT,   "UDF mount",     "UDF mount structures");
-MALLOC_JUSTDEFINE(M_UDFVOLD,  "UDF volspace",  "UDF volume space descriptors");
-MALLOC_JUSTDEFINE(M_UDFTEMP,  "UDF temp",      "UDF scrap space");
+MALLOC_DEFINE(M_UDFMNT,   "UDF mount", "UDF mount structures");
+MALLOC_DEFINE(M_UDFVOLD,  "UDF volspace",      "UDF volume space descriptors");
+MALLOC_DEFINE(M_UDFTEMP,  "UDF temp",  "UDF scrap space");
 struct pool udf_node_pool;
 
 /* supported functions predefined */
Index: sys/kern/core_elf32.c
===================================================================
RCS file: /cvsroot/src/sys/kern/core_elf32.c,v
retrieving revision 1.35
diff -u -r1.35 core_elf32.c
--- sys/kern/core_elf32.c       14 Dec 2009 00:48:35 -0000      1.35
+++ sys/kern/core_elf32.c       4 Feb 2011 15:36:56 -0000
@@ -57,7 +57,7 @@
 #include <sys/exec.h>
 #include <sys/exec_elf.h>
 #include <sys/ptrace.h>
-#include <sys/malloc.h>
+#include <sys/kmem.h>
 #include <sys/kauth.h>
 
 #include <machine/reg.h>
@@ -104,6 +104,7 @@
        struct proc *p;
        Elf_Ehdr ehdr;
        Elf_Phdr phdr, *psections;
+       size_t psectionssize;
        struct countsegs_state cs;
        struct writesegs_state ws;
        off_t notestart, secstart, offset;
@@ -180,8 +181,8 @@
        notestart = offset + sizeof(phdr) * cs.npsections;
        secstart = notestart + notesize;
 
-       psections = malloc(cs.npsections * sizeof(Elf_Phdr),
-           M_TEMP, M_WAITOK|M_ZERO);
+       psectionssize = cs.npsections * sizeof(Elf_Phdr);
+       psections = kmem_zalloc(psectionssize, KM_SLEEP);
 
        /* Pass 2: now write the P-section headers. */
        ws.secoff = secstart;
@@ -250,7 +251,7 @@
 
   out:
        if (psections)
-               free(psections, M_TEMP);
+               kmem_free(psections, psectionssize);
        return (error);
 }
 
Index: sys/kern/exec_aout.c
===================================================================
RCS file: /cvsroot/src/sys/kern/exec_aout.c,v
retrieving revision 1.34
diff -u -r1.34 exec_aout.c
--- sys/kern/exec_aout.c        19 Nov 2008 18:36:06 -0000      1.34
+++ sys/kern/exec_aout.c        4 Feb 2011 15:36:56 -0000
@@ -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>
Index: sys/kern/exec_ecoff.c
===================================================================
RCS file: /cvsroot/src/sys/kern/exec_ecoff.c,v
retrieving revision 1.28
diff -u -r1.28 exec_ecoff.c
--- sys/kern/exec_ecoff.c       19 Nov 2008 21:29:32 -0000      1.28
+++ sys/kern/exec_ecoff.c       4 Feb 2011 15:36:56 -0000
@@ -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>
Index: sys/kern/exec_elf.c
===================================================================
RCS file: /cvsroot/src/sys/kern/exec_elf.c,v
retrieving revision 1.27
diff -u -r1.27 exec_elf.c
--- sys/kern/exec_elf.c 7 Oct 2010 02:14:02 -0000       1.27
+++ sys/kern/exec_elf.c 4 Feb 2011 15:36:56 -0000
@@ -65,7 +65,6 @@
 
 #include <sys/param.h>
 #include <sys/proc.h>
-#include <sys/malloc.h>
 #include <sys/kmem.h>
 #include <sys/namei.h>
 #include <sys/vnode.h>
@@ -239,7 +238,7 @@
                        a++;
                }
 
-               free(ap, M_TEMP);
+               kmem_free(ap, sizeof(struct elf_args));
                pack->ep_emul_arg = NULL;
        }
 
@@ -776,7 +775,7 @@
                }
        }
        if (interp || (epp->ep_flags & EXEC_FORCEAUX) != 0) {
-               ap = malloc(sizeof(struct elf_args), M_TEMP, M_WAITOK);
+               ap = kmem_alloc(sizeof(struct elf_args), KM_SLEEP);
                ap->arg_interp = (vaddr_t)NULL;
        }
 
@@ -809,6 +808,7 @@
                ap->arg_phnum = eh->e_phnum;
                ap->arg_entry = eh->e_entry;
                epp->ep_emul_arg = ap;
+               epp->ep_emul_arg_size = sizeof(*ap);
        }
 
 #ifdef ELF_MAP_PAGE_ZERO
@@ -823,7 +823,7 @@
        if (interp)
                PNBUF_PUT(interp);
        if (ap)
-               free(ap, M_TEMP);
+               kmem_free(ap, sizeof(struct elf_args));
        kmem_free(ph, phsize);
        kill_vmcmds(&epp->ep_vmcmds);
        return error;
Index: sys/kern/exec_macho.c
===================================================================
RCS file: /cvsroot/src/sys/kern/exec_macho.c,v
retrieving revision 1.45
diff -u -r1.45 exec_macho.c
--- sys/kern/exec_macho.c       17 Jan 2011 07:13:31 -0000      1.45
+++ sys/kern/exec_macho.c       4 Feb 2011 15:36:56 -0000
@@ -34,7 +34,6 @@
 
 #include <sys/param.h>
 #include <sys/proc.h>
-#include <sys/malloc.h>
 #include <sys/namei.h>
 #include <sys/vnode.h>
 #include <sys/exec.h>
@@ -465,8 +464,8 @@
                                goto bad;
                        }
                        if (bf != &lc)
-                               free(bf, M_TEMP);
-                       bf = malloc(size = lc.cmdsize, M_TEMP, M_WAITOK);
+                               kmem_free(bf, size);
+                       bf = kmem_alloc(size = lc.cmdsize, KM_SLEEP);
                }
 
                if ((error = exec_read_from(l, vp, offs, bf, lc.cmdsize)) != 0)
@@ -542,7 +541,7 @@
        error = 0;
 bad:
        if (bf != &lc)
-               free(bf, M_TEMP);
+               kmem_free(bf, size);
        return error;
 }
 
@@ -580,8 +579,9 @@
        if (error)
                return (error);
 
-       emea = malloc(sizeof(struct exec_macho_emul_arg), M_TEMP, M_WAITOK);
+       emea = kmem_alloc(sizeof(struct exec_macho_emul_arg), KM_SLEEP);
        epp->ep_emul_arg = (void *)emea;
+       epp->ep_emul_arg_size = sizeof(*emea);
        emea->dynamic = 0;
 
        if (!epp->ep_esch->u.mach_probe_func)
@@ -616,6 +616,6 @@
 bad:
        kill_vmcmds(&epp->ep_vmcmds);
 bad2:
-       free(emea, M_TEMP);
+       kmem_free(emea, sizeof(struct exec_macho_emul_arg));
        return error;
 }
Index: sys/kern/kern_exec.c
===================================================================
RCS file: /cvsroot/src/sys/kern/kern_exec.c,v
retrieving revision 1.305
diff -u -r1.305 kern_exec.c
--- sys/kern/kern_exec.c        18 Jan 2011 08:21:03 -0000      1.305
+++ sys/kern/kern_exec.c        4 Feb 2011 15:36:57 -0000
@@ -74,7 +74,6 @@
 #include <sys/kernel.h>
 #include <sys/proc.h>
 #include <sys/mount.h>
-#include <sys/malloc.h>
 #include <sys/kmem.h>
 #include <sys/namei.h>
 #include <sys/vnode.h>
@@ -1240,7 +1239,7 @@
        uvm_deallocate(&vm->vm_map, VM_MIN_ADDRESS,
                VM_MAXUSER_ADDRESS - VM_MIN_ADDRESS);
        if (pack.ep_emul_arg)
-               free(pack.ep_emul_arg, M_TEMP);
+               kmem_free(pack.ep_emul_arg, pack.ep_emul_arg_size);
        pool_put(&exec_pool, argp);
        kmem_free(pack.ep_hdr, pack.ep_hdrlen);
        if (pack.ep_emul_root != NULL)
Index: sys/kern/kern_hook.c
===================================================================
RCS file: /cvsroot/src/sys/kern/kern_hook.c,v
retrieving revision 1.4
diff -u -r1.4 kern_hook.c
--- sys/kern/kern_hook.c        11 Dec 2010 22:27:53 -0000      1.4
+++ sys/kern/kern_hook.c        4 Feb 2011 15:36:57 -0000
@@ -34,7 +34,7 @@
 __KERNEL_RCSID(0, "$NetBSD: kern_hook.c,v 1.4 2010/12/11 22:27:53 matt Exp $");
 
 #include <sys/param.h>
-#include <sys/malloc.h>
+#include <sys/kmem.h>
 #include <sys/rwlock.h>
 #include <sys/systm.h>
 #include <sys/device.h>
@@ -56,7 +56,7 @@
 {
        struct hook_desc *hd;
 
-       hd = malloc(sizeof(*hd), M_DEVBUF, M_NOWAIT);
+       hd = kmem_alloc(sizeof(struct hook_desc), KM_NOSLEEP);
        if (hd == NULL)
                return (NULL);
 
@@ -82,7 +82,7 @@
                panic("hook_disestablish: hook %p not established", vhook);
 #endif
        LIST_REMOVE((struct hook_desc *)vhook, hk_list);
-       free(vhook, M_DEVBUF);
+       kmem_free(vhook, sizeof(struct hook_desc));
 }
 
 static void
@@ -92,7 +92,7 @@
 
        while ((hd = LIST_FIRST(list)) != NULL) {
                LIST_REMOVE(hd, hk_list);
-               free(hd, M_DEVBUF);
+               kmem_free(hd, sizeof(*hd));
        }
 }
 
@@ -329,7 +329,7 @@
        struct powerhook_desc *ndp;
 
        ndp = (struct powerhook_desc *)
-           malloc(sizeof(*ndp), M_DEVBUF, M_NOWAIT);
+           kmem_alloc(sizeof(*ndp), KM_NOSLEEP);
        if (ndp == NULL)
                return (NULL);
 
@@ -357,7 +357,7 @@
 
        CIRCLEQ_REMOVE(&powerhook_list, (struct powerhook_desc *)vhook,
            sfd_list);
-       free(vhook, M_DEVBUF);
+       kmem_free(vhook, sizeof(struct powerhook_desc));
 }
 
 /*
Index: sys/kern/kern_malloc.c
===================================================================
RCS file: /cvsroot/src/sys/kern/kern_malloc.c,v
retrieving revision 1.131
diff -u -r1.131 kern_malloc.c
--- sys/kern/kern_malloc.c      5 May 2010 02:20:42 -0000       1.131
+++ sys/kern/kern_malloc.c      4 Feb 2011 15:36:57 -0000
@@ -72,6 +72,7 @@
 #include <sys/proc.h>
 #include <sys/kernel.h>
 #include <sys/malloc.h>
+#include <sys/kmem.h>
 #include <sys/systm.h>
 #include <sys/debug.h>
 #include <sys/mutex.h>
@@ -79,249 +80,25 @@
 
 #include <uvm/uvm_extern.h>
 
-static struct vm_map_kernel kmem_map_store;
-struct vm_map *kmem_map = NULL;
-
 #include "opt_kmempages.h"
 
-#ifdef NKMEMCLUSTERS
-#error NKMEMCLUSTERS is obsolete; remove it from your kernel config file and 
use NKMEMPAGES instead or let the kernel auto-size
-#endif
-
-/*
- * Default number of pages in kmem_map.  We attempt to calculate this
- * at run-time, but allow it to be either patched or set in the kernel
- * config file.
- */
-#ifndef NKMEMPAGES
-#define        NKMEMPAGES      0
-#endif
-int    nkmempages = NKMEMPAGES;
-
-/*
- * Defaults for lower- and upper-bounds for the kmem_map page count.
- * Can be overridden by kernel config options.
- */
-#ifndef        NKMEMPAGES_MIN
-#define        NKMEMPAGES_MIN  NKMEMPAGES_MIN_DEFAULT
-#endif
-
-#ifndef NKMEMPAGES_MAX
-#define        NKMEMPAGES_MAX  NKMEMPAGES_MAX_DEFAULT
-#endif
-
 #include "opt_kmemstats.h"
 #include "opt_malloclog.h"
 #include "opt_malloc_debug.h"
 
-#define        MINALLOCSIZE    (1 << MINBUCKET)
-#define        BUCKETINDX(size) \
-       ((size) <= (MINALLOCSIZE * 128) \
-               ? (size) <= (MINALLOCSIZE * 8) \
-                       ? (size) <= (MINALLOCSIZE * 2) \
-                               ? (size) <= (MINALLOCSIZE * 1) \
-                                       ? (MINBUCKET + 0) \
-                                       : (MINBUCKET + 1) \
-                               : (size) <= (MINALLOCSIZE * 4) \
-                                       ? (MINBUCKET + 2) \
-                                       : (MINBUCKET + 3) \
-                       : (size) <= (MINALLOCSIZE* 32) \
-                               ? (size) <= (MINALLOCSIZE * 16) \
-                                       ? (MINBUCKET + 4) \
-                                       : (MINBUCKET + 5) \
-                               : (size) <= (MINALLOCSIZE * 64) \
-                                       ? (MINBUCKET + 6) \
-                                       : (MINBUCKET + 7) \
-               : (size) <= (MINALLOCSIZE * 2048) \
-                       ? (size) <= (MINALLOCSIZE * 512) \
-                               ? (size) <= (MINALLOCSIZE * 256) \
-                                       ? (MINBUCKET + 8) \
-                                       : (MINBUCKET + 9) \
-                               : (size) <= (MINALLOCSIZE * 1024) \
-                                       ? (MINBUCKET + 10) \
-                                       : (MINBUCKET + 11) \
-                       : (size) <= (MINALLOCSIZE * 8192) \
-                               ? (size) <= (MINALLOCSIZE * 4096) \
-                                       ? (MINBUCKET + 12) \
-                                       : (MINBUCKET + 13) \
-                               : (size) <= (MINALLOCSIZE * 16384) \
-                                       ? (MINBUCKET + 14) \
-                                       : (MINBUCKET + 15))
-
-/*
- * Array of descriptors that describe the contents of each page
- */
-struct kmemusage {
-       short ku_indx;          /* bucket index */
-       union {
-               u_short freecnt;/* for small allocations, free pieces in page */
-               u_short pagecnt;/* for large allocations, pages alloced */
-       } ku_un;
-};
-#define        ku_freecnt ku_un.freecnt
-#define        ku_pagecnt ku_un.pagecnt
-
-struct kmembuckets kmembuckets[MINBUCKET + 16];
-struct kmemusage *kmemusage;
-char *kmembase, *kmemlimit;
-
-#ifdef DEBUG
-static void *malloc_freecheck;
-#endif
-
-/*
- * Turn virtual addresses into kmem map indicies
- */
-#define        btokup(addr)    (&kmemusage[((char *)(addr) - kmembase) >> 
PGSHIFT])
-
 struct malloc_type *kmemstatistics;
 
-#ifdef MALLOCLOG
-#ifndef MALLOCLOGSIZE
-#define        MALLOCLOGSIZE   100000
-#endif
-
-struct malloclog {
-       void *addr;
-       long size;
-       struct malloc_type *type;
-       int action;
-       const char *file;
-       long line;
-} malloclog[MALLOCLOGSIZE];
-
-long   malloclogptr;
-
 /*
  * Fuzz factor for neighbour address match this must be a mask of the lower
  * bits we wish to ignore when comparing addresses
  */
 __uintptr_t malloclog_fuzz = 0x7FL;
 
-
-static void
-domlog(void *a, long size, struct malloc_type *type, int action,
-    const char *file, long line)
-{
-
-       malloclog[malloclogptr].addr = a;
-       malloclog[malloclogptr].size = size;
-       malloclog[malloclogptr].type = type;
-       malloclog[malloclogptr].action = action;
-       malloclog[malloclogptr].file = file;
-       malloclog[malloclogptr].line = line;
-       malloclogptr++;
-       if (malloclogptr >= MALLOCLOGSIZE)
-               malloclogptr = 0;
-}
-
-#ifdef DIAGNOSTIC
-static void
-hitmlog(void *a)
-{
-       struct malloclog *lp;
-       long l;
-
-#define        PRT do { \
-       lp = &malloclog[l]; \
-       if (lp->addr == a && lp->action) { \
-               printf("malloc log entry %ld:\n", l); \
-               printf("\taddr = %p\n", lp->addr); \
-               printf("\tsize = %ld\n", lp->size); \
-               printf("\ttype = %s\n", lp->type->ks_shortdesc); \
-               printf("\taction = %s\n", lp->action == 1 ? "alloc" : "free"); \
-               printf("\tfile = %s\n", lp->file); \
-               printf("\tline = %ld\n", lp->line); \
-       } \
-} while (/* CONSTCOND */0)
-
-/*
- * Print fuzzy matched "neighbour" - look for the memory block that has
- * been allocated below the address we are interested in.  We look for a
- * base address + size that is within malloclog_fuzz of our target
- * address. If the base address and target address are the same then it is
- * likely we have found a free (size is 0 in this case) so we won't report
- * those, they will get reported by PRT anyway.
- */
-#define        NPRT do { \
-       __uintptr_t fuzz_mask = ~(malloclog_fuzz); \
-       lp = &malloclog[l]; \
-       if ((__uintptr_t)lp->addr != (__uintptr_t)a && \
-           (((__uintptr_t)lp->addr + lp->size + malloclog_fuzz) & fuzz_mask) \
-           == ((__uintptr_t)a & fuzz_mask) && lp->action) {            \
-               printf("neighbour malloc log entry %ld:\n", l); \
-               printf("\taddr = %p\n", lp->addr); \
-               printf("\tsize = %ld\n", lp->size); \
-               printf("\ttype = %s\n", lp->type->ks_shortdesc); \
-               printf("\taction = %s\n", lp->action == 1 ? "alloc" : "free"); \
-               printf("\tfile = %s\n", lp->file); \
-               printf("\tline = %ld\n", lp->line); \
-       } \
-} while (/* CONSTCOND */0)
-
-       for (l = malloclogptr; l < MALLOCLOGSIZE; l++) {
-               PRT;
-               NPRT;
-       }
-
-
-       for (l = 0; l < malloclogptr; l++) {
-               PRT;
-               NPRT;
-       }
-
-#undef PRT
-}
-#endif /* DIAGNOSTIC */
-#endif /* MALLOCLOG */
-
-#ifdef DIAGNOSTIC
-/*
- * This structure provides a set of masks to catch unaligned frees.
- */
-const long addrmask[] = { 0,
-       0x00000001, 0x00000003, 0x00000007, 0x0000000f,
-       0x0000001f, 0x0000003f, 0x0000007f, 0x000000ff,
-       0x000001ff, 0x000003ff, 0x000007ff, 0x00000fff,
-       0x00001fff, 0x00003fff, 0x00007fff, 0x0000ffff,
+struct malloc_header {
+       size_t mh_size;
 };
 
 /*
- * The WEIRD_ADDR is used as known text to copy into free objects so
- * that modifications after frees can be detected.
- */
-#define        WEIRD_ADDR      ((uint32_t) 0xdeadbeef)
-#ifdef DEBUG
-#define        MAX_COPY        PAGE_SIZE
-#else
-#define        MAX_COPY        32
-#endif
-
-/*
- * Normally the freelist structure is used only to hold the list pointer
- * for free objects.  However, when running with diagnostics, the first
- * 8/16 bytes of the structure is unused except for diagnostic information,
- * and the free list pointer is at offset 8/16 in the structure.  Since the
- * first 8 bytes is the portion of the structure most often modified, this
- * helps to detect memory reuse problems and avoid free list corruption.
- */
-struct freelist {
-       uint32_t spare0;
-#ifdef _LP64
-       uint32_t spare1;                /* explicit padding */
-#endif
-       struct malloc_type *type;
-       void *  next;
-};
-#else /* !DIAGNOSTIC */
-struct freelist {
-       void *  next;
-};
-#endif /* DIAGNOSTIC */
-
-kmutex_t malloc_lock;
-
-/*
  * Allocate a block of memory
  */
 #ifdef MALLOCLOG
@@ -333,212 +110,23 @@
 kern_malloc(unsigned long size, struct malloc_type *ksp, int flags)
 #endif /* MALLOCLOG */
 {
-       struct kmembuckets *kbp;
-       struct kmemusage *kup;
-       struct freelist *freep;
-       long indx, npg, allocsize;
-       char *va, *cp, *savedlist;
-#ifdef DIAGNOSTIC
-       uint32_t *end, *lp;
-       int copysize;
-#endif
-
-#ifdef LOCKDEBUG
-       if ((flags & M_NOWAIT) == 0) {
-               ASSERT_SLEEPABLE();
-       }
-#endif
-#ifdef MALLOC_DEBUG
-       if (debug_malloc(size, ksp, flags, (void *) &va)) {
-               if (va != 0) {
-                       FREECHECK_OUT(&malloc_freecheck, (void *)va);
-               }
-               return ((void *) va);
+       struct malloc_header *mh;
+       int kmflags = ((flags & M_NOWAIT) != 0) ? KM_NOSLEEP : KM_SLEEP;
+       size_t allocsize = sizeof(struct malloc_header) + size;
+       void *p;
+
+       if ((flags & M_ZERO) != 0) {
+               p = kmem_zalloc(allocsize, kmflags);
+       } else {
+               p = kmem_alloc(allocsize, kmflags);
        }
-#endif
-       indx = BUCKETINDX(size);
-       kbp = &kmembuckets[indx];
-       mutex_spin_enter(&malloc_lock);
-#ifdef KMEMSTATS
-       while (ksp->ks_memuse >= ksp->ks_limit) {
-               if (flags & M_NOWAIT) {
-                       mutex_spin_exit(&malloc_lock);
-                       return ((void *) NULL);
-               }
-               if (ksp->ks_limblocks < 65535)
-                       ksp->ks_limblocks++;
-               mtsleep((void *)ksp, PSWP+2, ksp->ks_shortdesc, 0,
-                       &malloc_lock);
-       }
-       ksp->ks_size |= 1 << indx;
-#ifdef DIAGNOSTIC
-       if (ksp->ks_active[indx - MINBUCKET] == USHRT_MAX)
-               panic("too many allocations in bucket");
-#endif
-       ksp->ks_active[indx - MINBUCKET]++;
-#endif
-#ifdef DIAGNOSTIC
-       copysize = 1 << indx < MAX_COPY ? 1 << indx : MAX_COPY;
-#endif
-       if (kbp->kb_next == NULL) {
-               int s;
-               kbp->kb_last = NULL;
-               if (size > MAXALLOCSAVE)
-                       allocsize = round_page(size);
-               else
-                       allocsize = 1 << indx;
-               npg = btoc(allocsize);
-               mutex_spin_exit(&malloc_lock);
-               s = splvm();
-               va = (void *) uvm_km_alloc(kmem_map,
-                   (vsize_t)ctob(npg), 0,
-                   ((flags & M_NOWAIT) ? UVM_KMF_NOWAIT : 0) |
-                   ((flags & M_CANFAIL) ? UVM_KMF_CANFAIL : 0) |
-                   UVM_KMF_WIRED);
-               splx(s);
-               if (__predict_false(va == NULL)) {
-                       /*
-                        * Kmem_malloc() can return NULL, even if it can
-                        * wait, if there is no map space available, because
-                        * it can't fix that problem.  Neither can we,
-                        * right now.  (We should release pages which
-                        * are completely free and which are in kmembuckets
-                        * with too many free elements.)
-                        */
-                       if ((flags & (M_NOWAIT|M_CANFAIL)) == 0)
-                               panic("malloc: out of space in kmem_map");
-                       return (NULL);
-               }
-               mutex_spin_enter(&malloc_lock);
-#ifdef KMEMSTATS
-               kbp->kb_total += kbp->kb_elmpercl;
-#endif
-               kup = btokup(va);
-               kup->ku_indx = indx;
-               if (allocsize > MAXALLOCSAVE) {
-                       if (npg > 65535)
-                               panic("malloc: allocation too large");
-                       kup->ku_pagecnt = npg;
-#ifdef KMEMSTATS
-                       ksp->ks_memuse += allocsize;
-#endif
-                       goto out;
-               }
-#ifdef KMEMSTATS
-               kup->ku_freecnt = kbp->kb_elmpercl;
-               kbp->kb_totalfree += kbp->kb_elmpercl;
-#endif
-               /*
-                * Just in case we blocked while allocating memory,
-                * and someone else also allocated memory for this
-                * kmembucket, don't assume the list is still empty.
-                */
-               savedlist = kbp->kb_next;
-               kbp->kb_next = cp = va + (npg << PAGE_SHIFT) - allocsize;
-               for (;;) {
-                       freep = (struct freelist *)cp;
-#ifdef DIAGNOSTIC
-                       /*
-                        * Copy in known text to detect modification
-                        * after freeing.
-                        */
-                       end = (uint32_t *)&cp[copysize];
-                       for (lp = (uint32_t *)cp; lp < end; lp++)
-                               *lp = WEIRD_ADDR;
-                       freep->type = M_FREE;
-#endif /* DIAGNOSTIC */
-                       if (cp <= va)
-                               break;
-                       cp -= allocsize;
-                       freep->next = cp;
-               }
-               freep->next = savedlist;
-               if (savedlist == NULL)
-                       kbp->kb_last = (void *)freep;
-       }
-       va = kbp->kb_next;
-       kbp->kb_next = ((struct freelist *)va)->next;
-#ifdef DIAGNOSTIC
-       freep = (struct freelist *)va;
-       /* XXX potential to get garbage pointer here. */
-       if (kbp->kb_next) {
-               int rv;
-               vaddr_t addr = (vaddr_t)kbp->kb_next;
-
-               vm_map_lock(kmem_map);
-               rv = uvm_map_checkprot(kmem_map, addr,
-                   addr + sizeof(struct freelist), VM_PROT_WRITE);
-               vm_map_unlock(kmem_map);
-
-               if (__predict_false(rv == 0)) {
-                       printf("Data modified on freelist: "
-                           "word %ld of object %p size %ld previous type %s "
-                           "(invalid addr %p)\n",
-                           (long)((int32_t *)&kbp->kb_next - (int32_t *)kbp),
-                           va, size, "foo", kbp->kb_next);
-#ifdef MALLOCLOG
-                       hitmlog(va);
-#endif
-                       kbp->kb_next = NULL;
-               }
-       }
-
-       /* Fill the fields that we've used with WEIRD_ADDR */
-#ifdef _LP64
-       freep->type = (struct malloc_type *)
-           (WEIRD_ADDR | (((u_long) WEIRD_ADDR) << 32));
-#else
-       freep->type = (struct malloc_type *) WEIRD_ADDR;
-#endif
-       end = (uint32_t *)&freep->next +
-           (sizeof(freep->next) / sizeof(int32_t));
-       for (lp = (uint32_t *)&freep->next; lp < end; lp++)
-               *lp = WEIRD_ADDR;
-
-       /* and check that the data hasn't been modified. */
-       end = (uint32_t *)&va[copysize];
-       for (lp = (uint32_t *)va; lp < end; lp++) {
-               if (__predict_true(*lp == WEIRD_ADDR))
-                       continue;
-               printf("Data modified on freelist: "
-                   "word %ld of object %p size %ld previous type %s "
-                   "(0x%x != 0x%x)\n",
-                   (long)(lp - (uint32_t *)va), va, size,
-                   "bar", *lp, WEIRD_ADDR);
-#ifdef MALLOCLOG
-               hitmlog(va);
-#endif
-               break;
+       if (p == NULL) {
+               return NULL;
        }
+       mh = (void *)p;
+       mh->mh_size = allocsize;
 
-       freep->spare0 = 0;
-#endif /* DIAGNOSTIC */
-#ifdef KMEMSTATS
-       kup = btokup(va);
-       if (kup->ku_indx != indx)
-               panic("malloc: wrong bucket");
-       if (kup->ku_freecnt == 0)
-               panic("malloc: lost data");
-       kup->ku_freecnt--;
-       kbp->kb_totalfree--;
-       ksp->ks_memuse += 1 << indx;
-out:
-       kbp->kb_calls++;
-       ksp->ks_inuse++;
-       ksp->ks_calls++;
-       if (ksp->ks_memuse > ksp->ks_maxused)
-               ksp->ks_maxused = ksp->ks_memuse;
-#else
-out:
-#endif
-#ifdef MALLOCLOG
-       domlog(va, size, ksp, 1, file, line);
-#endif
-       mutex_spin_exit(&malloc_lock);
-       if ((flags & M_ZERO) != 0)
-               memset(va, 0, size);
-       FREECHECK_OUT(&malloc_freecheck, (void *)va);
-       return ((void *) va);
+       return mh + 1;
 }
 
 /*
@@ -552,145 +140,11 @@
 kern_free(void *addr, struct malloc_type *ksp)
 #endif /* MALLOCLOG */
 {
-       struct kmembuckets *kbp;
-       struct kmemusage *kup;
-       struct freelist *freep;
-       long size;
-#ifdef DIAGNOSTIC
-       void *cp;
-       int32_t *end, *lp;
-       long alloc, copysize;
-#endif
-
-       FREECHECK_IN(&malloc_freecheck, addr);
-#ifdef MALLOC_DEBUG
-       if (debug_free(addr, ksp))
-               return;
-#endif
-
-#ifdef DIAGNOSTIC
-       /*
-        * Ensure that we're free'ing something that we could
-        * have allocated in the first place.  That is, check
-        * to see that the address is within kmem_map.
-        */
-       if (__predict_false((vaddr_t)addr < vm_map_min(kmem_map) ||
-           (vaddr_t)addr >= vm_map_max(kmem_map)))
-               panic("free: addr %p not within kmem_map", addr);
-#endif
-
-       kup = btokup(addr);
-       size = 1 << kup->ku_indx;
-       kbp = &kmembuckets[kup->ku_indx];
-
-       LOCKDEBUG_MEM_CHECK(addr,
-           size <= MAXALLOCSAVE ? size : ctob(kup->ku_pagecnt));
-
-       mutex_spin_enter(&malloc_lock);
-#ifdef MALLOCLOG
-       domlog(addr, 0, ksp, 2, file, line);
-#endif
-#ifdef DIAGNOSTIC
-       /*
-        * Check for returns of data that do not point to the
-        * beginning of the allocation.
-        */
-       if (size > PAGE_SIZE)
-               alloc = addrmask[BUCKETINDX(PAGE_SIZE)];
-       else
-               alloc = addrmask[kup->ku_indx];
-       if (((u_long)addr & alloc) != 0)
-               panic("free: unaligned addr %p, size %ld, type %s, mask %ld",
-                   addr, size, ksp->ks_shortdesc, alloc);
-#endif /* DIAGNOSTIC */
-       if (size > MAXALLOCSAVE) {
-               uvm_km_free(kmem_map, (vaddr_t)addr, ctob(kup->ku_pagecnt),
-                   UVM_KMF_WIRED);
-#ifdef KMEMSTATS
-               size = kup->ku_pagecnt << PGSHIFT;
-               ksp->ks_memuse -= size;
-#ifdef DIAGNOSTIC
-               if (ksp->ks_active[kup->ku_indx - MINBUCKET] == 0)
-                       panic("no active allocation(1), probably double free");
-#endif
-               ksp->ks_active[kup->ku_indx - MINBUCKET]--;
-               kup->ku_indx = 0;
-               kup->ku_pagecnt = 0;
-               if (ksp->ks_memuse + size >= ksp->ks_limit &&
-                   ksp->ks_memuse < ksp->ks_limit)
-                       wakeup((void *)ksp);
-#ifdef DIAGNOSTIC
-               if (ksp->ks_inuse == 0)
-                       panic("free 1: inuse 0, probable double free");
-#endif
-               ksp->ks_inuse--;
-               kbp->kb_total -= 1;
-#endif
-               mutex_spin_exit(&malloc_lock);
-               return;
-       }
-       freep = (struct freelist *)addr;
-#ifdef DIAGNOSTIC
-       /*
-        * Check for multiple frees. Use a quick check to see if
-        * it looks free before laboriously searching the freelist.
-        */
-       if (__predict_false(freep->spare0 == WEIRD_ADDR)) {
-               for (cp = kbp->kb_next; cp;
-                   cp = ((struct freelist *)cp)->next) {
-                       if (addr != cp)
-                               continue;
-                       printf("multiply freed item %p\n", addr);
-#ifdef MALLOCLOG
-                       hitmlog(addr);
-#endif
-                       panic("free: duplicated free");
-               }
-       }
+       struct malloc_header *mh;
 
-       /*
-        * Copy in known text to detect modification after freeing
-        * and to make it look free. Also, save the type being freed
-        * so we can list likely culprit if modification is detected
-        * when the object is reallocated.
-        */
-       copysize = size < MAX_COPY ? size : MAX_COPY;
-       end = (int32_t *)&((char *)addr)[copysize];
-       for (lp = (int32_t *)addr; lp < end; lp++)
-               *lp = WEIRD_ADDR;
-       freep->type = ksp;
-#endif /* DIAGNOSTIC */
-#ifdef KMEMSTATS
-       kup->ku_freecnt++;
-       if (kup->ku_freecnt >= kbp->kb_elmpercl) {
-               if (kup->ku_freecnt > kbp->kb_elmpercl)
-                       panic("free: multiple frees");
-               else if (kbp->kb_totalfree > kbp->kb_highwat)
-                       kbp->kb_couldfree++;
-       }
-       kbp->kb_totalfree++;
-       ksp->ks_memuse -= size;
-#ifdef DIAGNOSTIC
-       if (ksp->ks_active[kup->ku_indx - MINBUCKET] == 0)
-               panic("no active allocation(2), probably double free");
-#endif
-       ksp->ks_active[kup->ku_indx - MINBUCKET]--;
-       if (ksp->ks_memuse + size >= ksp->ks_limit &&
-           ksp->ks_memuse < ksp->ks_limit)
-               wakeup((void *)ksp);
-#ifdef DIAGNOSTIC
-       if (ksp->ks_inuse == 0)
-               panic("free 2: inuse 0, probable double free");
-#endif
-       ksp->ks_inuse--;
-#endif
-       if (kbp->kb_next == NULL)
-               kbp->kb_next = addr;
-       else
-               ((struct freelist *)kbp->kb_last)->next = addr;
-       freep->next = NULL;
-       kbp->kb_last = addr;
-       mutex_spin_exit(&malloc_lock);
+       mh = addr;
+       mh--;
+       kmem_free(mh, mh->mh_size);
 }
 
 /*
@@ -700,12 +154,13 @@
 kern_realloc(void *curaddr, unsigned long newsize, struct malloc_type *ksp,
     int flags)
 {
-       struct kmemusage *kup;
        unsigned long cursize;
        void *newaddr;
-#ifdef DIAGNOSTIC
-       long alloc;
-#endif
+       
+       struct malloc_header *mh;
+       mh = curaddr;
+       mh--;
+       cursize = mh->mh_size;
 
        /*
         * realloc() with a NULL pointer is the same as malloc().
@@ -721,37 +176,6 @@
                return (NULL);
        }
 
-#ifdef LOCKDEBUG
-       if ((flags & M_NOWAIT) == 0) {
-               ASSERT_SLEEPABLE();
-       }
-#endif
-
-       /*
-        * Find out how large the old allocation was (and do some
-        * sanity checking).
-        */
-       kup = btokup(curaddr);
-       cursize = 1 << kup->ku_indx;
-
-#ifdef DIAGNOSTIC
-       /*
-        * Check for returns of data that do not point to the
-        * beginning of the allocation.
-        */
-       if (cursize > PAGE_SIZE)
-               alloc = addrmask[BUCKETINDX(PAGE_SIZE)];
-       else
-               alloc = addrmask[kup->ku_indx];
-       if (((u_long)curaddr & alloc) != 0)
-               panic("realloc: "
-                   "unaligned addr %p, size %ld, type %s, mask %ld\n",
-                   curaddr, cursize, ksp->ks_shortdesc, alloc);
-#endif /* DIAGNOSTIC */
-
-       if (cursize > MAXALLOCSAVE)
-               cursize = ctob(kup->ku_pagecnt);
-
        /*
         * If we already actually have as much as they want, we're done.
         */
@@ -782,51 +206,11 @@
 }
 
 /*
- * Roundup size to the actual allocation size.
- */
-unsigned long
-malloc_roundup(unsigned long size)
-{
-
-       if (size > MAXALLOCSAVE)
-               return (roundup(size, PAGE_SIZE));
-       else
-               return (1 << BUCKETINDX(size));
-}
-
-/*
  * Add a malloc type to the system.
  */
 void
 malloc_type_attach(struct malloc_type *type)
 {
-
-       if (nkmempages == 0)
-               panic("malloc_type_attach: nkmempages == 0");
-
-       if (type->ks_magic != M_MAGIC)
-               panic("malloc_type_attach: bad magic");
-
-#ifdef DIAGNOSTIC
-       {
-               struct malloc_type *ksp;
-               for (ksp = kmemstatistics; ksp != NULL; ksp = ksp->ks_next) {
-                       if (ksp == type)
-                               panic("%s: `%s' already on list", __func__,
-                                   type->ks_shortdesc);
-               }
-       }
-#endif
-
-#ifdef KMEMSTATS
-       if (type->ks_limit == 0)
-               type->ks_limit = ((u_long)nkmempages << PAGE_SHIFT) * 6U / 10U;
-#else
-       type->ks_limit = 0;
-#endif
-
-       type->ks_next = kmemstatistics;
-       kmemstatistics = type;
 }
 
 /*
@@ -835,70 +219,6 @@
 void
 malloc_type_detach(struct malloc_type *type)
 {
-       struct malloc_type *ksp;
-
-#ifdef DIAGNOSTIC
-       if (type->ks_magic != M_MAGIC)
-               panic("malloc_type_detach: bad magic");
-#endif
-
-       if (type == kmemstatistics)
-               kmemstatistics = type->ks_next;
-       else {
-               for (ksp = kmemstatistics; ksp->ks_next != NULL;
-                    ksp = ksp->ks_next) {
-                       if (ksp->ks_next == type) {
-                               ksp->ks_next = type->ks_next;
-                               break;
-                       }
-               }
-#ifdef DIAGNOSTIC
-               if (ksp->ks_next == NULL)
-                       panic("malloc_type_detach: not on list");
-#endif
-       }
-       type->ks_next = NULL;
-}
-
-/*
- * Set the limit on a malloc type.
- */
-void
-malloc_type_setlimit(struct malloc_type *type, u_long limit)
-{
-#ifdef KMEMSTATS
-       mutex_spin_enter(&malloc_lock);
-       type->ks_limit = limit;
-       mutex_spin_exit(&malloc_lock);
-#endif
-}
-
-/*
- * Compute the number of pages that kmem_map will map, that is,
- * the size of the kernel malloc arena.
- */
-void
-kmeminit_nkmempages(void)
-{
-       int npages;
-
-       if (nkmempages != 0) {
-               /*
-                * It's already been set (by us being here before, or
-                * by patching or kernel config options), bail out now.
-                */
-               return;
-       }
-
-       npages = physmem;
-
-       if (npages > NKMEMPAGES_MAX)
-               npages = NKMEMPAGES_MAX;
-
-       if (npages < NKMEMPAGES_MIN)
-               npages = NKMEMPAGES_MIN;
-
-       nkmempages = npages;
 }
 
 /*
@@ -909,130 +229,9 @@
 {
        __link_set_decl(malloc_types, struct malloc_type);
        struct malloc_type * const *ksp;
-       vaddr_t kmb, kml;
-#ifdef KMEMSTATS
-       long indx;
-#endif
-
-#if    ((MAXALLOCSAVE & (MAXALLOCSAVE - 1)) != 0)
-               ERROR!_kmeminit:_MAXALLOCSAVE_not_power_of_2
-#endif
-#if    (MAXALLOCSAVE > MINALLOCSIZE * 32768)
-               ERROR!_kmeminit:_MAXALLOCSAVE_too_big
-#endif
-#if    (MAXALLOCSAVE < NBPG)
-               ERROR!_kmeminit:_MAXALLOCSAVE_too_small
-#endif
-
-       if (sizeof(struct freelist) > (1 << MINBUCKET))
-               panic("minbucket too small/struct freelist too big");
-
-       mutex_init(&malloc_lock, MUTEX_DEFAULT, IPL_VM);
-
-       /*
-        * Compute the number of kmem_map pages, if we have not
-        * done so already.
-        */
-       kmeminit_nkmempages();
-
-       kmemusage = (struct kmemusage *) uvm_km_alloc(kernel_map,
-           (vsize_t)(nkmempages * sizeof(struct kmemusage)), 0,
-           UVM_KMF_WIRED|UVM_KMF_ZERO);
-       kmb = 0;
-       kmem_map = uvm_km_suballoc(kernel_map, &kmb,
-           &kml, ((vsize_t)nkmempages << PAGE_SHIFT),
-           VM_MAP_INTRSAFE, false, &kmem_map_store);
-       uvm_km_vacache_init(kmem_map, "kvakmem", 0);
-       kmembase = (char *)kmb;
-       kmemlimit = (char *)kml;
-#ifdef KMEMSTATS
-       for (indx = 0; indx < MINBUCKET + 16; indx++) {
-               if (1 << indx >= PAGE_SIZE)
-                       kmembuckets[indx].kb_elmpercl = 1;
-               else
-                       kmembuckets[indx].kb_elmpercl = PAGE_SIZE / (1 << indx);
-               kmembuckets[indx].kb_highwat =
-                       5 * kmembuckets[indx].kb_elmpercl;
-       }
-#endif
 
        /* Attach all of the statically-linked malloc types. */
        __link_set_foreach(ksp, malloc_types)
                malloc_type_attach(*ksp);
-
-#ifdef MALLOC_DEBUG
-       debug_malloc_init();
-#endif
-}
-
-#ifdef DDB
-#include <ddb/db_output.h>
-
-/*
- * Dump kmem statistics from ddb.
- *
- * usage: call dump_kmemstats
- */
-void   dump_kmemstats(void);
-
-void
-dump_kmemstats(void)
-{
-#ifdef KMEMSTATS
-       struct malloc_type *ksp;
-
-       for (ksp = kmemstatistics; ksp != NULL; ksp = ksp->ks_next) {
-               if (ksp->ks_memuse == 0)
-                       continue;
-               db_printf("%s%.*s %ld\n", ksp->ks_shortdesc,
-                   (int)(20 - strlen(ksp->ks_shortdesc)),
-                   "                    ",
-                   ksp->ks_memuse);
-       }
-#else
-       db_printf("Kmem stats are not being collected.\n");
-#endif /* KMEMSTATS */
 }
-#endif /* DDB */
 
-
-#if 0
-/*
- * Diagnostic messages about "Data modified on
- * freelist" indicate a memory corruption, but
- * they do not help tracking it down.
- * This function can be called at various places
- * to sanity check malloc's freelist and discover
- * where does the corruption take place.
- */
-int
-freelist_sanitycheck(void) {
-       int i,j;
-       struct kmembuckets *kbp;
-       struct freelist *freep;
-       int rv = 0;
-
-       for (i = MINBUCKET; i <= MINBUCKET + 15; i++) {
-               kbp = &kmembuckets[i];
-               freep = (struct freelist *)kbp->kb_next;
-               j = 0;
-               while(freep) {
-                       vm_map_lock(kmem_map);
-                       rv = uvm_map_checkprot(kmem_map, (vaddr_t)freep,
-                           (vaddr_t)freep + sizeof(struct freelist),
-                           VM_PROT_WRITE);
-                       vm_map_unlock(kmem_map);
-
-                       if ((rv == 0) || (*(int *)freep != WEIRD_ADDR)) {
-                               printf("bucket %i, chunck %d at %p modified\n",
-                                   i, j, freep);
-                               return 1;
-                       }
-                       freep = (struct freelist *)freep->next;
-                       j++;
-               }
-       }
-
-       return 0;
-}
-#endif
Index: sys/kern/kern_pax.c
===================================================================
RCS file: /cvsroot/src/sys/kern/kern_pax.c,v
retrieving revision 1.24
diff -u -r1.24 kern_pax.c
--- sys/kern/kern_pax.c 23 Aug 2010 20:53:08 -0000      1.24
+++ sys/kern/kern_pax.c 4 Feb 2011 15:36:57 -0000
@@ -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>
@@ -372,10 +372,10 @@
        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 +417,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 +426,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 +455,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;
Index: sys/kern/kern_resource.c
===================================================================
RCS file: /cvsroot/src/sys/kern/kern_resource.c,v
retrieving revision 1.157
diff -u -r1.157 kern_resource.c
--- sys/kern/kern_resource.c    1 Jul 2010 02:38:30 -0000       1.157
+++ sys/kern/kern_resource.c    4 Feb 2011 15:36:57 -0000
@@ -44,7 +44,6 @@
 #include <sys/kernel.h>
 #include <sys/file.h>
 #include <sys/resourcevar.h>
-#include <sys/malloc.h>
 #include <sys/kmem.h>
 #include <sys/namei.h>
 #include <sys/pool.h>
@@ -638,14 +637,14 @@
                }
                mutex_exit(&lim->pl_lock);
                if (corename != NULL)
-                       free(corename, M_TEMP);
+                       kmem_free(corename, strlen(corename) + 1);
                alen = len;
-               corename = malloc(alen, M_TEMP, M_WAITOK);
+               corename = kmem_alloc(alen, KM_SLEEP);
                mutex_enter(&lim->pl_lock);
        }
        mutex_exit(&lim->pl_lock);
        if (corename != NULL)
-               free(corename, M_TEMP);
+               kmem_free(corename, strlen(corename) + 1);
        return newlim;
 }
 
@@ -706,8 +705,10 @@
        do {
                if (atomic_dec_uint_nv(&lim->pl_refcnt) > 0)
                        return;
-               if (lim->pl_corename != defcorename)
-                       free(lim->pl_corename, M_TEMP);
+               if (lim->pl_corename != defcorename) {
+                       kmem_free(lim->pl_corename, 
+                               strlen(lim->pl_corename) + 1);
+               }
                sv_lim = lim->pl_sv_limit;
                mutex_destroy(&lim->pl_lock);
                pool_cache_put(plimit_cache, lim);
@@ -871,7 +872,7 @@
        /*
         * hmm...looks good.  now...where do we put it?
         */
-       tmp = malloc(len + 1, M_TEMP, M_WAITOK|M_CANFAIL);
+       tmp = kmem_alloc(len + 1, KM_SLEEP);
        if (tmp == NULL) {
                error = ENOMEM;
                goto done;
@@ -885,7 +886,7 @@
        lim->pl_corename = tmp;
        mutex_exit(&lim->pl_lock);
        if (ocore != defcorename)
-               free(ocore, M_TEMP);
+               kmem_free(ocore, strlen(ocore) + 1);
 
 done:
        rw_exit(&ptmp->p_reflock);
Index: sys/kern/kern_softint.c
===================================================================
RCS file: /cvsroot/src/sys/kern/kern_softint.c,v
retrieving revision 1.33
diff -u -r1.33 kern_softint.c
--- sys/kern/kern_softint.c     20 Dec 2010 00:25:46 -0000      1.33
+++ sys/kern/kern_softint.c     4 Feb 2011 15:36:57 -0000
@@ -179,7 +179,6 @@
 __KERNEL_RCSID(0, "$NetBSD: kern_softint.c,v 1.33 2010/12/20 00:25:46 matt Exp 
$");
 
 #include <sys/param.h>
-#include <sys/malloc.h>
 #include <sys/proc.h>
 #include <sys/intr.h>
 #include <sys/mutex.h>
Index: sys/kern/subr_autoconf.c
===================================================================
RCS file: /cvsroot/src/sys/kern/subr_autoconf.c,v
retrieving revision 1.212
diff -u -r1.212 subr_autoconf.c
--- sys/kern/subr_autoconf.c    31 Jan 2011 23:07:16 -0000      1.212
+++ sys/kern/subr_autoconf.c    4 Feb 2011 15:37:01 -0000
@@ -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>
Index: sys/kern/subr_blist.c
===================================================================
RCS file: /cvsroot/src/sys/kern/subr_blist.c,v
retrieving revision 1.9
diff -u -r1.9 subr_blist.c
--- sys/kern/subr_blist.c       20 Jan 2006 14:19:40 -0000      1.9
+++ sys/kern/subr_blist.c       4 Feb 2011 15:37:01 -0000
@@ -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,9 +111,6 @@
 #include <stdarg.h>
 #include <inttypes.h>
 
-#define malloc(a,b,c)  calloc(a, 1)
-#define free(a,b)      free(a)
-
 #include "../sys/blist.h"
 
 void panic(const char *ctl, ...);
@@ -168,10 +165,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 +194,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 +222,8 @@
 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));
 }
 
 /*
Index: sys/kern/subr_extent.c
===================================================================
RCS file: /cvsroot/src/sys/kern/subr_extent.c,v
retrieving revision 1.72
diff -u -r1.72 subr_extent.c
--- sys/kern/subr_extent.c      28 Apr 2008 20:24:04 -0000      1.72
+++ sys/kern/subr_extent.c      4 Feb 2011 15:37:02 -0000
@@ -41,7 +41,7 @@
 
 #include <sys/param.h>
 #include <sys/extent.h>
-#include <sys/malloc.h>
+#include <sys/kmem.h>
 #include <sys/pool.h>
 #include <sys/time.h>
 #include <sys/systm.h>
@@ -69,15 +69,15 @@
  * in subr_extent.c rather than subr_prf.c.
  */
 #define        \
-malloc(s, t, flags)            malloc(s)
+kmem_alloc(s, flags)           malloc(s)
 #define        \
-free(p, t)                     free(p)
+kmem_free(p, s)                        free(p)
 #define        \
 cv_wait_sig(cv, lock)          (EWOULDBLOCK)
 #define        \
-pool_get(pool, flags)          malloc((pool)->pr_size,0,0)
+pool_get(pool, flags)          kmem_alloc((pool)->pr_size,0)
 #define        \
-pool_put(pool, rp)             free(rp,0)
+pool_put(pool, rp)             kmem_free(rp,0)
 #define        \
 panic(a)                       printf(a)
 #define        mutex_init(a, b, c)
@@ -235,7 +235,7 @@
  */
 struct extent *
 extent_create(const char *name, u_long start, u_long end,
-    struct malloc_type *mtype, void *storage, size_t storagesize, int flags)
+    void *storage, size_t storagesize, int flags)
 {
        struct extent *ex;
        char *cp = storage;
@@ -291,8 +291,8 @@
                        LIST_INSERT_HEAD(&fex->fex_freelist, rp, er_link);
                }
        } else {
-               ex = (struct extent *)malloc(sizeof(struct extent),
-                   mtype, (flags & EX_WAITOK) ? M_WAITOK : M_NOWAIT);
+               ex = (struct extent *)kmem_alloc(sizeof(struct extent),
+                   (flags & EX_WAITOK) ? KM_SLEEP : KM_NOSLEEP);
                if (ex == NULL)
                        return (NULL);
        }
@@ -304,7 +304,6 @@
        ex->ex_name = name;
        ex->ex_start = start;
        ex->ex_end = end;
-       ex->ex_mtype = mtype;
        ex->ex_flags = 0;
        if (fixed_extent)
                ex->ex_flags |= EXF_FIXED;
@@ -342,7 +341,7 @@
 
        /* If we're not a fixed extent, free the extent descriptor itself. */
        if ((ex->ex_flags & EXF_FIXED) == 0)
-               free(ex, ex->ex_mtype);
+               kmem_free(ex, sizeof(*ex));
 }
 
 /*
Index: sys/kern/subr_kmem.c
===================================================================
RCS file: /cvsroot/src/sys/kern/subr_kmem.c,v
retrieving revision 1.33
diff -u -r1.33 subr_kmem.c
--- sys/kern/subr_kmem.c        11 Feb 2010 23:13:46 -0000      1.33
+++ sys/kern/subr_kmem.c        4 Feb 2011 15:37:02 -0000
@@ -58,8 +58,6 @@
 /*
  * allocator of kernel wired memory.
  *
- * TODO:
- * -   worth to have "intrsafe" version?  maybe..
  */
 
 #include <sys/cdefs.h>
@@ -68,57 +66,75 @@
 #include <sys/param.h>
 #include <sys/callback.h>
 #include <sys/kmem.h>
-#include <sys/vmem.h>
+#include <sys/pool.h>
 #include <sys/debug.h>
 #include <sys/lockdebug.h>
 #include <sys/cpu.h>
 
 #include <uvm/uvm_extern.h>
 #include <uvm/uvm_map.h>
-#include <uvm/uvm_kmguard.h>
 
 #include <lib/libkern/libkern.h>
 
 #include <machine/stdarg.h>
 
-#define        KMEM_QUANTUM_SIZE       (ALIGNBYTES + 1)
-#define        KMEM_QCACHE_MAX         (KMEM_QUANTUM_SIZE * 32)
-#define        KMEM_CACHE_COUNT        16
-
-typedef struct kmem_cache {
-       pool_cache_t            kc_cache;
-       struct pool_allocator   kc_pa;
-       char                    kc_name[12];
-} kmem_cache_t;
-
-static vmem_t *kmem_arena;
-static struct callback_entry kmem_kva_reclaim_entry;
-
-static kmem_cache_t kmem_cache[KMEM_CACHE_COUNT + 1];
-static size_t kmem_cache_max;
-static size_t kmem_cache_min;
-static size_t kmem_cache_mask;
-static int kmem_cache_shift;
+
+struct kmem_cache_info {
+       int kc_size;
+       const char *kc_name;
+       struct pool_allocator *kc_allocator;
+};
+
+static const struct kmem_cache_info kmem_cache_tiny_sizes[] = {
+       { 16, "kmem-16", NULL },
+       { 32, "kmem-32", NULL },  
+       { 48, "kmem-48", NULL },  
+        { 64, "kmem-64", NULL }, 
+       { 96, "kmem-96", NULL }, 
+        { 128, "kmem-128", NULL }, 
+       { 192, "kmem-192", NULL }, 
+       { 256, "kmem-256", NULL }, 
+        { 384, "kmem-384", NULL }, 
+       { 512, "kmem-512", NULL }, 
+       { 768, "kmem-768", NULL },
+       { 1024, "kmem-1024", NULL },
+       /* { 1536, "kmem-1536", NULL }, */
+       { 2048, "kmem-2048", NULL },
+       /* { 3072, "kmem-3072", NULL }, */
+       { 4096, "kmem-4096", NULL },
+       { 0, NULL, NULL }
+};
+
+static struct pool_allocator kmem_big_8k_pa;
+static struct pool_allocator kmem_big_12k_pa;
+static struct pool_allocator kmem_big_16k_pa;
+
+static const struct kmem_cache_info kmem_cache_big_sizes[] = {
+       { 8192, "kmem-8192", &kmem_big_8k_pa },
+       { 12288, "kmem-12288", &kmem_big_12k_pa },
+       { 16384, "kmem-16384", &kmem_big_16k_pa },
+       { 0, NULL, NULL }
+};
+
+#define KMEM_TINY_MAXSIZE      4096
+#define KMEM_TINY_ALIGN        16
+#define KMEM_TINY_ALIGN_2      64
+#define KMEM_TINY_SHIFT        4
+
+#define KMEM_BIG_MAXSIZE       (4*4096)
+#define KMEM_BIG_SHIFT         12
+
+static pool_cache_t kmem_cache_tiny[KMEM_TINY_MAXSIZE >> KMEM_TINY_SHIFT];
+static pool_cache_t kmem_cache_big[KMEM_BIG_MAXSIZE >> KMEM_BIG_SHIFT];
+
+#define DBUG 
 
 #if defined(DEBUG)
-int kmem_guard_depth;
-size_t kmem_guard_size;
-static struct uvm_kmguard kmem_guard;
 static void *kmem_freecheck;
-#define        KMEM_POISON
 #define        KMEM_REDZONE
 #define        KMEM_SIZE
-#define        KMEM_GUARD
 #endif /* defined(DEBUG) */
 
-#if defined(KMEM_POISON)
-static void kmem_poison_fill(void *, size_t);
-static void kmem_poison_check(void *, size_t);
-#else /* defined(KMEM_POISON) */
-#define        kmem_poison_fill(p, sz)         /* nothing */
-#define        kmem_poison_check(p, sz)        /* nothing */
-#endif /* defined(KMEM_POISON) */
-
 #if defined(KMEM_REDZONE)
 #define        REDZONE_SIZE    1
 #else /* defined(KMEM_REDZONE) */
@@ -126,7 +142,7 @@
 #endif /* defined(KMEM_REDZONE) */
 
 #if defined(KMEM_SIZE)
-#define        SIZE_SIZE       (max(KMEM_QUANTUM_SIZE, sizeof(size_t)))
+#define        SIZE_SIZE       (max(KMEM_TINY_ALIGN, sizeof(size_t)))
 static void kmem_size_set(void *, size_t);
 static void kmem_size_check(const void *, size_t);
 #else
@@ -135,47 +151,24 @@
 #define        kmem_size_check(p, sz)  /* nothing */
 #endif
 
-static vmem_addr_t kmem_backend_alloc(vmem_t *, vmem_size_t, vmem_size_t *,
-    vm_flag_t);
-static void kmem_backend_free(vmem_t *, vmem_addr_t, vmem_size_t);
-static int kmem_kva_reclaim_callback(struct callback_entry *, void *, void *);
 
 CTASSERT(KM_SLEEP == PR_WAITOK);
 CTASSERT(KM_NOSLEEP == PR_NOWAIT);
 
-static inline vm_flag_t
-kmf_to_vmf(km_flag_t kmflags)
-{
-       vm_flag_t vmflags;
-
-       KASSERT((kmflags & (KM_SLEEP|KM_NOSLEEP)) != 0);
-       KASSERT((~kmflags & (KM_SLEEP|KM_NOSLEEP)) != 0);
-
-       vmflags = 0;
-       if ((kmflags & KM_SLEEP) != 0) {
-               vmflags |= VM_SLEEP;
-       }
-       if ((kmflags & KM_NOSLEEP) != 0) {
-               vmflags |= VM_NOSLEEP;
-       }
-
-       return vmflags;
-}
-
 static void *
-kmem_poolpage_alloc(struct pool *pool, int prflags)
+kmem_bigpoolpage_alloc(struct pool *pool, int prflags)
 {
+        bool waitok = (prflags & PR_WAITOK) ? true : false;
 
-       return (void *)vmem_alloc(kmem_arena, pool->pr_alloc->pa_pagesz,
-           kmf_to_vmf(prflags) | VM_INSTANTFIT);
-
+       return ((void *) uvm_km_alloc_poolpage_cache(kmem_map, 
+               pool->pr_alloc->pa_pagesz, waitok));
 }
 
 static void
-kmem_poolpage_free(struct pool *pool, void *addr)
+kmem_bigpoolpage_free(struct pool *pool, void *addr)
 {
-
-       vmem_free(kmem_arena, (vmem_addr_t)addr, pool->pr_alloc->pa_pagesz);
+       uvm_km_free_poolpage_cache(kmem_map, (vaddr_t) addr, 
+               pool->pr_alloc->pa_pagesz);
 }
 
 /* ---- kmem API */
@@ -189,32 +182,27 @@
 void *
 kmem_alloc(size_t size, km_flag_t kmflags)
 {
-       kmem_cache_t *kc;
+       pool_cache_t pc;
+       size_t index;
        uint8_t *p;
 
-       KASSERT(!cpu_intr_p());
-       KASSERT(!cpu_softintr_p());
        KASSERT(size > 0);
 
-#ifdef KMEM_GUARD
-       if (size <= kmem_guard_size) {
-               return uvm_kmguard_alloc(&kmem_guard, size,
-                   (kmflags & KM_SLEEP) != 0);
-       }
-#endif
-
        size += REDZONE_SIZE + SIZE_SIZE;
-       if (size >= kmem_cache_min && size <= kmem_cache_max) {
-               kc = &kmem_cache[(size + kmem_cache_mask) >> kmem_cache_shift];
-               KASSERT(size <= kc->kc_pa.pa_pagesz);
-               kmflags &= (KM_SLEEP | KM_NOSLEEP);
-               p = pool_cache_get(kc->kc_cache, kmflags);
+
+       if ((index = ((size - 1) >> KMEM_TINY_SHIFT)) < (KMEM_TINY_MAXSIZE >> 
KMEM_TINY_SHIFT)) {
+               pc = kmem_cache_tiny[index];
+       } else if ((index = ((size - 1) >> KMEM_BIG_SHIFT)) < (KMEM_BIG_MAXSIZE 
>> KMEM_BIG_SHIFT)) {
+               pc = kmem_cache_big[index];
        } else {
-               p = (void *)vmem_alloc(kmem_arena, size,
-                   kmf_to_vmf(kmflags) | VM_INSTANTFIT);
+               return (void *) uvm_km_alloc(kmem_map,
+                   (vsize_t)round_page(size), 0, 
+                   ((kmflags & KM_SLEEP) ? 0 : UVM_KMF_NOWAIT | 
UVM_KMF_TRYLOCK) | UVM_KMF_WIRED);
        }
+
+       p = pool_cache_get(pc, kmflags);
+
        if (__predict_true(p != NULL)) {
-               kmem_poison_check(p, kmem_roundup_size(size));
                FREECHECK_OUT(&kmem_freecheck, p);
                kmem_size_set(p, size);
                p = (uint8_t *)p + SIZE_SIZE;
@@ -249,195 +237,102 @@
 void
 kmem_free(void *p, size_t size)
 {
-       kmem_cache_t *kc;
+       pool_cache_t pc;
+       size_t index;
 
-       KASSERT(!cpu_intr_p());
-       KASSERT(!cpu_softintr_p());
        KASSERT(p != NULL);
        KASSERT(size > 0);
 
-#ifdef KMEM_GUARD
-       if (size <= kmem_guard_size) {
-               uvm_kmguard_free(&kmem_guard, size, p);
+       size += REDZONE_SIZE + SIZE_SIZE;
+
+        if ((index = ((size - 1) >> KMEM_TINY_SHIFT)) < (KMEM_TINY_MAXSIZE >> 
KMEM_TINY_SHIFT)) {
+                pc = kmem_cache_tiny[index];
+        } else if ((index = ((size - 1) >> KMEM_BIG_SHIFT)) < 
(KMEM_BIG_MAXSIZE >> KMEM_BIG_SHIFT)) {
+                pc = kmem_cache_big[index];
+        } else {
+                uvm_km_free(kmem_map, (vaddr_t)p, round_page(size), 
UVM_KMF_WIRED);
                return;
-       }
-#endif
-       size += SIZE_SIZE;
+        }
+
        p = (uint8_t *)p - SIZE_SIZE;
-       kmem_size_check(p, size + REDZONE_SIZE);
+       kmem_size_check(p, size);
        FREECHECK_IN(&kmem_freecheck, p);
-       LOCKDEBUG_MEM_CHECK(p, size);
-       kmem_poison_check((char *)p + size,
-           kmem_roundup_size(size + REDZONE_SIZE) - size);
-       kmem_poison_fill(p, size);
-       size += REDZONE_SIZE;
-       if (size >= kmem_cache_min && size <= kmem_cache_max) {
-               kc = &kmem_cache[(size + kmem_cache_mask) >> kmem_cache_shift];
-               KASSERT(size <= kc->kc_pa.pa_pagesz);
-               pool_cache_put(kc->kc_cache, p);
-       } else {
-               vmem_free(kmem_arena, (vmem_addr_t)p, size);
-       }
-}
+       LOCKDEBUG_MEM_CHECK(p, size - REDZONE_SIZE);
 
+        pool_cache_put(pc, p);
+}
 
-void
-kmem_init(void)
+static void
+kmem_create_caches(const struct kmem_cache_info *array, pool_cache_t 
alloc_table[],
+       size_t maxbuf, int shift)
 {
-       kmem_cache_t *kc;
-       size_t sz;
+       size_t table_unit = (1 << shift);
+       size_t size = table_unit;
        int i;
 
-#ifdef KMEM_GUARD
-       uvm_kmguard_init(&kmem_guard, &kmem_guard_depth, &kmem_guard_size,
-           kernel_map);
-#endif
-
-       kmem_arena = vmem_create("kmem", 0, 0, KMEM_QUANTUM_SIZE,
-           kmem_backend_alloc, kmem_backend_free, NULL, KMEM_QCACHE_MAX,
-           VM_SLEEP, IPL_NONE);
-       callback_register(&vm_map_to_kernel(kernel_map)->vmk_reclaim_callback,
-           &kmem_kva_reclaim_entry, kmem_arena, kmem_kva_reclaim_callback);
+       for (i = 0; array[i].kc_size != 0 ; i++) {
+               size_t cache_size = array[i].kc_size;
+               size_t align = (cache_size < PAGE_SIZE) ?
+                                 (cache_size < KMEM_TINY_ALIGN_2 ?
+                                    KMEM_TINY_ALIGN : KMEM_TINY_ALIGN_2)
+                                : PAGE_SIZE;
+               const char *name = array[i].kc_name;
+               pool_cache_t pc;
 
-       /*
-        * kmem caches start at twice the size of the largest vmem qcache
-        * and end at PAGE_SIZE or earlier.  assert that KMEM_QCACHE_MAX
-        * is a power of two.
-        */
-       KASSERT(ffs(KMEM_QCACHE_MAX) != 0);
-       KASSERT(KMEM_QCACHE_MAX - (1 << (ffs(KMEM_QCACHE_MAX) - 1)) == 0);
-       kmem_cache_shift = ffs(KMEM_QCACHE_MAX);
-       kmem_cache_min = 1 << kmem_cache_shift;
-       kmem_cache_mask = kmem_cache_min - 1;
-       for (i = 1; i <= KMEM_CACHE_COUNT; i++) {
-               sz = i << kmem_cache_shift;
-               if (sz > PAGE_SIZE) {
+               /* check if we reached the requested size */
+               if (size > maxbuf)
                        break;
+
+               pc = pool_cache_init(cache_size,
+                               align, 0, PR_NOALIGN,
+                               name, array[i].kc_allocator, IPL_VM,
+                               NULL, NULL, NULL);
+
+               while (size <= cache_size) {
+                       alloc_table[(size - 1) >> shift] = pc;
+                       size += table_unit;
                }
-               kmem_cache_max = sz;
-               kc = &kmem_cache[i];
-               kc->kc_pa.pa_pagesz = sz;
-               kc->kc_pa.pa_alloc = kmem_poolpage_alloc;
-               kc->kc_pa.pa_free = kmem_poolpage_free;
-               sprintf(kc->kc_name, "kmem-%zu", sz);
-               kc->kc_cache = pool_cache_init(sz,
-                   KMEM_QUANTUM_SIZE, 0, PR_NOALIGN | PR_NOTOUCH,
-                   kc->kc_name, &kc->kc_pa, IPL_NONE,
-                   NULL, NULL, NULL);
-               KASSERT(kc->kc_cache != NULL);
        }
 }
 
-size_t
-kmem_roundup_size(size_t size)
+void
+kmem_init(void)
 {
+       /*
+        * Make allocation size the same size as the va cache size in uvm_km to 
lower fragmentation.
+        */
+       kmem_big_8k_pa.pa_pagesz = 2*4096;
+       kmem_big_8k_pa.pa_alloc = kmem_bigpoolpage_alloc;
+       kmem_big_8k_pa.pa_free = kmem_bigpoolpage_free;
+       kmem_big_8k_pa.pa_backingmap = kmem_map;
+
+       kmem_big_12k_pa.pa_pagesz = 3*4096;
+       kmem_big_12k_pa.pa_alloc = kmem_bigpoolpage_alloc;
+       kmem_big_12k_pa.pa_free = kmem_bigpoolpage_free;
+       kmem_big_12k_pa.pa_backingmap = kmem_map;
+
+       kmem_big_16k_pa.pa_pagesz = 4*4096;
+       kmem_big_16k_pa.pa_alloc = kmem_bigpoolpage_alloc;
+       kmem_big_16k_pa.pa_free = kmem_bigpoolpage_free;
+       kmem_big_16k_pa.pa_backingmap = kmem_map;
 
-       return vmem_roundup_size(kmem_arena, size);
-}
-
-/* ---- uvm glue */
-
-static vmem_addr_t
-kmem_backend_alloc(vmem_t *dummy, vmem_size_t size, vmem_size_t *resultsize,
-    vm_flag_t vmflags)
-{
-       uvm_flag_t uflags;
-       vaddr_t va;
+       kmem_create_caches(kmem_cache_tiny_sizes, kmem_cache_tiny,
+                       KMEM_TINY_MAXSIZE, KMEM_TINY_SHIFT);
 
-       KASSERT(dummy == NULL);
-       KASSERT(size != 0);
-       KASSERT((vmflags & (VM_SLEEP|VM_NOSLEEP)) != 0);
-       KASSERT((~vmflags & (VM_SLEEP|VM_NOSLEEP)) != 0);
+       kmem_create_caches(kmem_cache_big_sizes, kmem_cache_big,
+                       KMEM_BIG_MAXSIZE, KMEM_BIG_SHIFT); 
 
-       if ((vmflags & VM_NOSLEEP) != 0) {
-               uflags = UVM_KMF_TRYLOCK | UVM_KMF_NOWAIT;
-       } else {
-               uflags = UVM_KMF_WAITVA;
-       }
-       *resultsize = size = round_page(size);
-       va = uvm_km_alloc(kernel_map, size, 0,
-           uflags | UVM_KMF_WIRED | UVM_KMF_CANFAIL);
-       if (va != 0) {
-               kmem_poison_fill((void *)va, size);
-       }
-       return (vmem_addr_t)va;
 }
 
-static void
-kmem_backend_free(vmem_t *dummy, vmem_addr_t addr, vmem_size_t size)
-{
-
-       KASSERT(dummy == NULL);
-       KASSERT(addr != 0);
-       KASSERT(size != 0);
-       KASSERT(size == round_page(size));
-
-       kmem_poison_check((void *)addr, size);
-       uvm_km_free(kernel_map, (vaddr_t)addr, size, UVM_KMF_WIRED);
-}
 
-static int
-kmem_kva_reclaim_callback(struct callback_entry *ce, void *obj, void *arg)
+size_t
+kmem_roundup_size(size_t size)
 {
-       vmem_t *vm = obj;
-
-       vmem_reap(vm);
-       return CALLBACK_CHAIN_CONTINUE;
+       return (size + (KMEM_TINY_ALIGN - 1)) & ~(KMEM_TINY_ALIGN - 1);
 }
 
 /* ---- debug */
 
-#if defined(KMEM_POISON)
-
-#if defined(_LP64)
-#define        PRIME   0x9e37fffffffc0001UL
-#else /* defined(_LP64) */
-#define        PRIME   0x9e3779b1
-#endif /* defined(_LP64) */
-
-static inline uint8_t
-kmem_poison_pattern(const void *p)
-{
-
-       return (uint8_t)((((uintptr_t)p) * PRIME)
-           >> ((sizeof(uintptr_t) - sizeof(uint8_t))) * CHAR_BIT);
-}
-
-static void
-kmem_poison_fill(void *p, size_t sz)
-{
-       uint8_t *cp;
-       const uint8_t *ep;
-
-       cp = p;
-       ep = cp + sz;
-       while (cp < ep) {
-               *cp = kmem_poison_pattern(cp);
-               cp++;
-       }
-}
-
-static void
-kmem_poison_check(void *p, size_t sz)
-{
-       uint8_t *cp;
-       const uint8_t *ep;
-
-       cp = p;
-       ep = cp + sz;
-       while (cp < ep) {
-               const uint8_t expected = kmem_poison_pattern(cp);
-
-               if (*cp != expected) {
-                       panic("%s: %p: 0x%02x != 0x%02x\n",
-                           __func__, cp, *cp, expected);
-               }
-               cp++;
-       }
-}
-
-#endif /* defined(KMEM_POISON) */
-
 #if defined(KMEM_SIZE)
 static void
 kmem_size_set(void *p, size_t sz)
Index: sys/kern/subr_pool.c
===================================================================
RCS file: /cvsroot/src/sys/kern/subr_pool.c,v
retrieving revision 1.188
diff -u -r1.188 subr_pool.c
--- sys/kern/subr_pool.c        17 Jan 2011 07:36:58 -0000      1.188
+++ sys/kern/subr_pool.c        4 Feb 2011 15:37:03 -0000
@@ -72,6 +72,12 @@
  * an internal pool of page headers (`phpool').
  */
 
+/* Flag for beeing bootstrapped */
+static int bootstrapped = 0;
+
+/* Flag for beeing initialized */
+static int initialized = 0;
+
 /* List of all pools */
 static TAILQ_HEAD(, pool) pool_head = TAILQ_HEAD_INITIALIZER(pool_head);
 
@@ -86,16 +92,13 @@
 static struct pool psppool;
 #endif
 
-static SLIST_HEAD(, pool_allocator) pa_deferinitq =
-    SLIST_HEAD_INITIALIZER(pa_deferinitq);
-
 static void *pool_page_alloc_meta(struct pool *, int);
 static void pool_page_free_meta(struct pool *, void *);
 
 /* allocator for pool metadata */
 struct pool_allocator pool_allocator_meta = {
-       pool_page_alloc_meta, pool_page_free_meta,
-       .pa_backingmapptr = &kmem_map,
+       .pa_alloc = pool_page_alloc_meta, 
+       .pa_free = pool_page_free_meta 
 };
 
 /* # of seconds to retain page after last use */
@@ -588,41 +591,70 @@
        splx(s);
 }
 
-static void
-pa_reclaim_register(struct pool_allocator *pa)
-{
-       struct vm_map *map = *pa->pa_backingmapptr;
-       struct pool *pp;
-
-       KASSERT(pa->pa_backingmap == NULL);
-       if (map == NULL) {
-               SLIST_INSERT_HEAD(&pa_deferinitq, pa, pa_q);
-               return;
-       }
-       pa->pa_backingmap = map;
-       TAILQ_FOREACH(pp, &pa->pa_list, pr_alloc_list) {
-               pool_reclaim_register(pp);
-       }
-}
-
 /*
- * Initialize all the pools listed in the "pools" link set.
+ * Initialize all the internal pools.
  */
 void
-pool_subsystem_init(void)
+pool_subsystem_bootstrap(void)
 {
-       struct pool_allocator *pa;
+       int idx;
+       size_t size;
 
        mutex_init(&pool_head_lock, MUTEX_DEFAULT, IPL_NONE);
        mutex_init(&pool_allocator_lock, MUTEX_DEFAULT, IPL_NONE);
        cv_init(&pool_busy, "poolbusy");
 
-       while ((pa = SLIST_FIRST(&pa_deferinitq)) != NULL) {
-               KASSERT(pa->pa_backingmapptr != NULL);
-               KASSERT(*pa->pa_backingmapptr != NULL);
-               SLIST_REMOVE_HEAD(&pa_deferinitq, pa_q);
-               pa_reclaim_register(pa);
+       pool_allocator_meta.pa_backingmap = kmem_map;
+       pool_allocator_meta.pa_pagesz = PAGE_SIZE;
+       pool_allocator_kmem.pa_backingmap = kmem_map;
+       pool_allocator_kmem.pa_pagesz = PAGE_SIZE;
+       pool_allocator_nointr.pa_backingmap = kernel_map;
+       pool_allocator_nointr.pa_pagesz = PAGE_SIZE;
+#ifdef POOL_SUBPAGE
+       pool_allocator_kmem.pa_pagesz = POOL_SUBPAGE;
+       pool_allocator_nointr.pa_pagesz = POOL_SUBPAGE;
+       pool_allocator_kmem_fullpage.pa_backingmap = kmem_map;
+       pool_allocator_kmem_fullpage.pa_pagesz = PAGE_SIZE;
+       pool_allocator_nointr_fullpage.pa_backingmap = kernel_map;
+       pool_allocator_nointr_fullpage.pa_pagesz = PAGE_SIZE;
+#endif
+
+       /* 
+         * setup flag to stop pool_init from panicing, 
+         * when initializing our private pools 
+        */
+       bootstrapped = 1;
+
+       for (idx = 0; idx < PHPOOL_MAX; idx++) {
+               static char phpool_names[PHPOOL_MAX][6+1+6+1];
+               int nelem;
+               size_t sz;
+
+               nelem = PHPOOL_FREELIST_NELEM(idx);
+               snprintf(phpool_names[idx], sizeof(phpool_names[idx]),
+                       "phpool-%d", nelem);
+               sz = sizeof(struct pool_item_header);
+               if (nelem) {
+                       sz = offsetof(struct pool_item_header,
+                               ph_bitmap[howmany(nelem, BITMAP_SIZE)]);
+               }
+               pool_init(&phpool[idx], sz, 0, 0, 0,
+                       phpool_names[idx], &pool_allocator_meta, IPL_VM);
        }
+#ifdef POOL_SUBPAGE
+       pool_init(&psppool, POOL_SUBPAGE, POOL_SUBPAGE, 0,
+               PR_RECURSIVE, "psppool", &pool_allocator_meta, IPL_VM);
+#endif
+
+       size = sizeof(pcg_t) +
+               (PCG_NOBJECTS_NORMAL - 1) * sizeof(pcgpair_t);
+       pool_init(&pcg_normal_pool, size, coherency_unit, 0, 0,
+               "pcgnormal", &pool_allocator_meta, IPL_VM);
+
+       size = sizeof(pcg_t) +
+               (PCG_NOBJECTS_LARGE - 1) * sizeof(pcgpair_t);
+       pool_init(&pcg_large_pool, size, coherency_unit, 0, 0,
+               "pcglarge", &pool_allocator_meta, IPL_VM);
 
        pool_init(&cache_pool, sizeof(struct pool_cache), coherency_unit,
            0, 0, "pcache", &pool_allocator_nointr, IPL_NONE);
@@ -631,6 +663,12 @@
            0, 0, "pcachecpu", &pool_allocator_nointr, IPL_NONE);
 }
 
+void
+pool_subsystem_init(void)
+{
+       initialized = 1;
+}
+
 /*
  * Initialize the given pool resource structure.
  *
@@ -645,6 +683,9 @@
        size_t trysize, phsize;
        int off, slack;
 
+       if (!bootstrapped)
+               panic("pool_init: pool-subsystem not bootstrapped");
+
 #ifdef DEBUG
        /*
         * Check that the pool hasn't already been initialised and
@@ -675,24 +716,19 @@
                        palloc = &pool_allocator_nointr_fullpage;
        }               
 #endif /* POOL_SUBPAGE */
-       if (!cold)
-               mutex_enter(&pool_allocator_lock);
+       mutex_enter(&pool_allocator_lock);
        if (palloc->pa_refcnt++ == 0) {
-               if (palloc->pa_pagesz == 0)
-                       palloc->pa_pagesz = PAGE_SIZE;
+               KASSERT(palloc->pa_alloc);
+               KASSERT(palloc->pa_free);
+               KASSERT(palloc->pa_pagesz > 0);
 
                TAILQ_INIT(&palloc->pa_list);
 
                mutex_init(&palloc->pa_lock, MUTEX_DEFAULT, IPL_VM);
                palloc->pa_pagemask = ~(palloc->pa_pagesz - 1);
                palloc->pa_pageshift = ffs(palloc->pa_pagesz) - 1;
-
-               if (palloc->pa_backingmapptr != NULL) {
-                       pa_reclaim_register(palloc);
-               }
        }
-       if (!cold)
-               mutex_exit(&pool_allocator_lock);
+       mutex_exit(&pool_allocator_lock);
 
        if (align == 0)
                align = ALIGN(1);
@@ -824,48 +860,8 @@
        cv_init(&pp->pr_cv, wchan);
        pp->pr_ipl = ipl;
 
-       /*
-        * Initialize private page header pool and cache magazine pool if we
-        * haven't done so yet.
-        * XXX LOCKING.
-        */
-       if (phpool[0].pr_size == 0) {
-               int idx;
-               for (idx = 0; idx < PHPOOL_MAX; idx++) {
-                       static char phpool_names[PHPOOL_MAX][6+1+6+1];
-                       int nelem;
-                       size_t sz;
-
-                       nelem = PHPOOL_FREELIST_NELEM(idx);
-                       snprintf(phpool_names[idx], sizeof(phpool_names[idx]),
-                           "phpool-%d", nelem);
-                       sz = sizeof(struct pool_item_header);
-                       if (nelem) {
-                               sz = offsetof(struct pool_item_header,
-                                   ph_bitmap[howmany(nelem, BITMAP_SIZE)]);
-                       }
-                       pool_init(&phpool[idx], sz, 0, 0, 0,
-                           phpool_names[idx], &pool_allocator_meta, IPL_VM);
-               }
-#ifdef POOL_SUBPAGE
-               pool_init(&psppool, POOL_SUBPAGE, POOL_SUBPAGE, 0,
-                   PR_RECURSIVE, "psppool", &pool_allocator_meta, IPL_VM);
-#endif
-
-               size = sizeof(pcg_t) +
-                   (PCG_NOBJECTS_NORMAL - 1) * sizeof(pcgpair_t);
-               pool_init(&pcg_normal_pool, size, coherency_unit, 0, 0,
-                   "pcgnormal", &pool_allocator_meta, IPL_VM);
-
-               size = sizeof(pcg_t) +
-                   (PCG_NOBJECTS_LARGE - 1) * sizeof(pcgpair_t);
-               pool_init(&pcg_large_pool, size, coherency_unit, 0, 0,
-                   "pcglarge", &pool_allocator_meta, IPL_VM);
-       }
-
        /* Insert into the list of all pools. */
-       if (!cold)
-               mutex_enter(&pool_head_lock);
+       mutex_enter(&pool_head_lock);
        TAILQ_FOREACH(pp1, &pool_head, pr_poollist) {
                if (strcmp(pp1->pr_wchan, pp->pr_wchan) > 0)
                        break;
@@ -874,15 +870,12 @@
                TAILQ_INSERT_TAIL(&pool_head, pp, pr_poollist);
        else
                TAILQ_INSERT_BEFORE(pp1, pp, pr_poollist);
-       if (!cold)
-               mutex_exit(&pool_head_lock);
+       mutex_exit(&pool_head_lock);
 
        /* Insert this into the list of pools using this allocator. */
-       if (!cold)
-               mutex_enter(&palloc->pa_lock);
+       mutex_enter(&palloc->pa_lock);
        TAILQ_INSERT_TAIL(&palloc->pa_list, pp, pr_alloc_list);
-       if (!cold)
-               mutex_exit(&palloc->pa_lock);
+       mutex_exit(&palloc->pa_lock);
 
        pool_reclaim_register(pp);
 }
@@ -991,6 +984,9 @@
        struct pool_item_header *ph;
        void *v;
 
+       if (__predict_false(!initialized))
+               panic("pool_get: called prior to pool_subsystem 
initialization");
+
 #ifdef DIAGNOSTIC
        if (pp->pr_itemsperpage == 0)
                panic("pool_get: pool '%s': pr_itemsperpage is zero, "
@@ -2130,8 +2126,7 @@
        }
 
        /* Add to list of all pools. */
-       if (__predict_true(!cold))
-               mutex_enter(&pool_head_lock);
+       mutex_enter(&pool_head_lock);
        TAILQ_FOREACH(pc1, &pool_cache_head, pc_cachelist) {
                if (strcmp(pc1->pc_pool.pr_wchan, pc->pc_pool.pr_wchan) > 0)
                        break;
@@ -2140,8 +2135,7 @@
                TAILQ_INSERT_TAIL(&pool_cache_head, pc, pc_cachelist);
        else
                TAILQ_INSERT_BEFORE(pc1, pc, pc_cachelist);
-       if (__predict_true(!cold))
-               mutex_exit(&pool_head_lock);
+       mutex_exit(&pool_head_lock);
 
        membar_sync();
        pp->pr_cache = pc;
@@ -2804,13 +2798,13 @@
 
 #ifdef POOL_SUBPAGE
 struct pool_allocator pool_allocator_kmem_fullpage = {
-       pool_page_alloc, pool_page_free, 0,
-       .pa_backingmapptr = &kmem_map,
+       .pa_alloc = pool_page_alloc, 
+       .pa_free = pool_page_free, 
 };
 #else
 struct pool_allocator pool_allocator_kmem = {
-       pool_page_alloc, pool_page_free, 0,
-       .pa_backingmapptr = &kmem_map,
+       .pa_alloc = pool_page_alloc, 
+       .pa_free = pool_page_free, 
 };
 #endif
 
@@ -2819,13 +2813,13 @@
 
 #ifdef POOL_SUBPAGE
 struct pool_allocator pool_allocator_nointr_fullpage = {
-       pool_page_alloc_nointr, pool_page_free_nointr, 0,
-       .pa_backingmapptr = &kernel_map,
+       .pa_alloc = pool_page_alloc_nointr, 
+       .pa_free = pool_page_free_nointr, 
 };
 #else
 struct pool_allocator pool_allocator_nointr = {
-       pool_page_alloc_nointr, pool_page_free_nointr, 0,
-       .pa_backingmapptr = &kernel_map,
+       .pa_alloc = pool_page_alloc_nointr, 
+       .pa_free = pool_page_free_nointr, 
 };
 #endif
 
@@ -2834,16 +2828,15 @@
 void   pool_subpage_free(struct pool *, void *);
 
 struct pool_allocator pool_allocator_kmem = {
-       pool_subpage_alloc, pool_subpage_free, POOL_SUBPAGE,
-       .pa_backingmapptr = &kmem_map,
+       .pa_alloc = pool_subpage_alloc, 
+       .pa_free = pool_subpage_free, 
 };
 
 void   *pool_subpage_alloc_nointr(struct pool *, int);
 void   pool_subpage_free_nointr(struct pool *, void *);
 
 struct pool_allocator pool_allocator_nointr = {
-       pool_subpage_alloc, pool_subpage_free, POOL_SUBPAGE,
-       .pa_backingmapptr = &kmem_map,
+       pool_subpage_alloc, pool_subpage_free, 
 };
 #endif /* POOL_SUBPAGE */
 
@@ -2881,14 +2874,14 @@
 {
        bool waitok = (flags & PR_WAITOK) ? true : false;
 
-       return ((void *) uvm_km_alloc_poolpage_cache(kmem_map, waitok));
+       return ((void *) uvm_km_alloc_poolpage_cache(kmem_map, PAGE_SIZE, 
waitok));
 }
 
 void
 pool_page_free(struct pool *pp, void *v)
 {
 
-       uvm_km_free_poolpage_cache(kmem_map, (vaddr_t) v);
+       uvm_km_free_poolpage_cache(kmem_map, (vaddr_t) v, PAGE_SIZE);
 }
 
 static void *
@@ -2896,14 +2889,14 @@
 {
        bool waitok = (flags & PR_WAITOK) ? true : false;
 
-       return ((void *) uvm_km_alloc_poolpage(kmem_map, waitok));
+       return ((void *) uvm_km_alloc_poolpage(kmem_map, PAGE_SIZE, waitok));
 }
 
 static void
 pool_page_free_meta(struct pool *pp, void *v)
 {
 
-       uvm_km_free_poolpage(kmem_map, (vaddr_t) v);
+       uvm_km_free_poolpage(kmem_map, (vaddr_t) v, PAGE_SIZE);
 }
 
 #ifdef POOL_SUBPAGE
@@ -2940,14 +2933,14 @@
 {
        bool waitok = (flags & PR_WAITOK) ? true : false;
 
-       return ((void *) uvm_km_alloc_poolpage_cache(kernel_map, waitok));
+       return ((void *) uvm_km_alloc_poolpage_cache(kernel_map, PAGE_SIZE, 
waitok));
 }
 
 void
 pool_page_free_nointr(struct pool *pp, void *v)
 {
 
-       uvm_km_free_poolpage_cache(kernel_map, (vaddr_t) v);
+       uvm_km_free_poolpage_cache(kernel_map, (vaddr_t) v, PAGE_SIZE);
 }
 
 #if defined(DDB)
Index: sys/kern/subr_userconf.c
===================================================================
RCS file: /cvsroot/src/sys/kern/subr_userconf.c,v
retrieving revision 1.20
diff -u -r1.20 subr_userconf.c
--- sys/kern/subr_userconf.c    12 Sep 2010 16:06:08 -0000      1.20
+++ sys/kern/subr_userconf.c    4 Feb 2011 15:37:03 -0000
@@ -36,7 +36,6 @@
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/device.h>
-#include <sys/malloc.h>
 #include <sys/time.h>
 
 #include <dev/cons.h>
Index: sys/kern/subr_vmem.c
===================================================================
RCS file: /cvsroot/src/sys/kern/subr_vmem.c,v
retrieving revision 1.58
diff -u -r1.58 subr_vmem.c
--- sys/kern/subr_vmem.c        17 Dec 2010 22:24:11 -0000      1.58
+++ sys/kern/subr_vmem.c        4 Feb 2011 15:37:04 -0000
@@ -53,7 +53,7 @@
 #include <sys/systm.h>
 #include <sys/kernel.h>        /* hz */
 #include <sys/callout.h>
-#include <sys/malloc.h>
+#include <sys/kmem.h>
 #include <sys/once.h>
 #include <sys/pool.h>
 #include <sys/vmem.h>
@@ -204,28 +204,23 @@
        return i;
 }
 
-#if defined(_KERNEL)
-static MALLOC_DEFINE(M_VMEM, "vmem", "vmem");
-#endif /* defined(_KERNEL) */
-
 static void *
 xmalloc(size_t sz, vm_flag_t flags)
 {
 
 #if defined(_KERNEL)
-       return malloc(sz, M_VMEM,
-           M_CANFAIL | ((flags & VM_SLEEP) ? M_WAITOK : M_NOWAIT));
+       return kmem_alloc(sz, ((flags & VM_SLEEP) ? KM_SLEEP : KM_NOSLEEP));
 #else /* defined(_KERNEL) */
        return malloc(sz);
 #endif /* defined(_KERNEL) */
 }
 
 static void
-xfree(void *p)
+xfree(void *p, size_t sz)
 {
 
 #if defined(_KERNEL)
-       return free(p, M_VMEM);
+       return kmem_free(p, sz);
 #else /* defined(_KERNEL) */
        return free(p);
 #endif /* defined(_KERNEL) */
@@ -627,10 +622,11 @@
                                bt_free(vm, bt);
                        }
                }
-               xfree(vm->vm_hashlist);
+               xfree(vm->vm_hashlist, 
+                       sizeof(struct vmem_hashlist *) * vm->vm_hashsize);
        }
        VMEM_LOCK_DESTROY(vm);
-       xfree(vm);
+       xfree(vm, sizeof(*vm));
 }
 
 static int
@@ -676,7 +672,8 @@
        }
 
        if (!VMEM_TRYLOCK(vm)) {
-               xfree(newhashlist);
+               xfree(newhashlist, 
+                       sizeof(struct vmem_hashlist *) * newhashsize);
                return EBUSY;
        }
        oldhashlist = vm->vm_hashlist;
@@ -695,7 +692,7 @@
        }
        VMEM_UNLOCK(vm);
 
-       xfree(oldhashlist);
+       xfree(oldhashlist, sizeof(struct vmem_hashlist *) * oldhashsize);
 
        return 0;
 }
Index: sys/kern/uipc_mbuf.c
===================================================================
RCS file: /cvsroot/src/sys/kern/uipc_mbuf.c,v
retrieving revision 1.139
diff -u -r1.139 uipc_mbuf.c
--- sys/kern/uipc_mbuf.c        17 Jan 2011 07:13:32 -0000      1.139
+++ sys/kern/uipc_mbuf.c        4 Feb 2011 15:37:05 -0000
@@ -73,7 +73,6 @@
 #include <sys/atomic.h>
 #include <sys/cpu.h>
 #include <sys/proc.h>
-#include <sys/malloc.h>
 #define MBTYPES
 #include <sys/mbuf.h>
 #include <sys/kernel.h>
Index: sys/kern/uipc_mbuf2.c
===================================================================
RCS file: /cvsroot/src/sys/kern/uipc_mbuf2.c,v
retrieving revision 1.28
diff -u -r1.28 uipc_mbuf2.c
--- sys/kern/uipc_mbuf2.c       18 Apr 2009 14:58:04 -0000      1.28
+++ sys/kern/uipc_mbuf2.c       4 Feb 2011 15:37:05 -0000
@@ -67,7 +67,7 @@
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/proc.h>
-#include <sys/malloc.h>
+#include <sys/kmem.h>
 #include <sys/mbuf.h>
 
 MALLOC_DEFINE(M_PACKET_TAGS, "packet tags", "Packet-attached information");
@@ -260,7 +260,8 @@
 
        if (len < 0)
                return (NULL);
-       t = malloc(len + sizeof(struct m_tag), M_PACKET_TAGS, wait);
+       t = kmem_alloc(len + sizeof(struct m_tag), 
+               wait ? KM_SLEEP : KM_NOSLEEP);
        if (t == NULL)
                return (NULL);
        t->m_tag_id = type;
@@ -273,7 +274,7 @@
 m_tag_free(struct m_tag *t)
 {
 
-       free(t, M_PACKET_TAGS);
+       kmem_free(t, sizeof(struct m_tag) + t->m_tag_len);
 }
 
 /* Prepend a packet tag. */
Index: sys/kern/uipc_socket2.c
===================================================================
RCS file: /cvsroot/src/sys/kern/uipc_socket2.c,v
retrieving revision 1.106
diff -u -r1.106 uipc_socket2.c
--- sys/kern/uipc_socket2.c     30 Dec 2009 22:12:12 -0000      1.106
+++ sys/kern/uipc_socket2.c     4 Feb 2011 15:37:06 -0000
@@ -68,7 +68,6 @@
 #include <sys/proc.h>
 #include <sys/file.h>
 #include <sys/buf.h>
-#include <sys/malloc.h>
 #include <sys/mbuf.h>
 #include <sys/protosw.h>
 #include <sys/domain.h>
Index: sys/kern/uipc_syscalls.c
===================================================================
RCS file: /cvsroot/src/sys/kern/uipc_syscalls.c,v
retrieving revision 1.141
diff -u -r1.141 uipc_syscalls.c
--- sys/kern/uipc_syscalls.c    23 Apr 2010 15:19:19 -0000      1.141
+++ sys/kern/uipc_syscalls.c    4 Feb 2011 15:37:07 -0000
@@ -71,7 +71,6 @@
 #include <sys/proc.h>
 #include <sys/file.h>
 #include <sys/buf.h>
-#include <sys/malloc.h>
 #include <sys/mbuf.h>
 #include <sys/protosw.h>
 #include <sys/socket.h>
Index: sys/kern/vfs_wapbl.c
===================================================================
RCS file: /cvsroot/src/sys/kern/vfs_wapbl.c,v
retrieving revision 1.39
diff -u -r1.39 vfs_wapbl.c
--- sys/kern/vfs_wapbl.c        8 Jan 2011 20:37:05 -0000       1.39
+++ sys/kern/vfs_wapbl.c        4 Feb 2011 15:37:08 -0000
@@ -49,7 +49,7 @@
 #include <sys/uio.h>
 #include <sys/vnode.h>
 #include <sys/file.h>
-#include <sys/malloc.h>
+#include <sys/kmem.h>
 #include <sys/module.h>
 #include <sys/resourcevar.h>
 #include <sys/conf.h>
@@ -63,16 +63,9 @@
 
 #include <miscfs/specfs/specdev.h>
 
-#if 0 /* notyet */
 #define        wapbl_malloc(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)
-#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
 
 static struct sysctllog *wapbl_sysctl;
 static int wapbl_flush_disk_cache = 1;
@@ -310,7 +303,6 @@
 static void
 wapbl_init(void)
 {
-       malloc_type_attach(M_WAPBL);
        wapbl_sysctl_init();
 }
 
Index: sys/miscfs/kernfs/kernfs_vfsops.c
===================================================================
RCS file: /cvsroot/src/sys/miscfs/kernfs/kernfs_vfsops.c,v
retrieving revision 1.90
diff -u -r1.90 kernfs_vfsops.c
--- sys/miscfs/kernfs/kernfs_vfsops.c   30 Nov 2009 10:59:20 -0000      1.90
+++ sys/miscfs/kernfs/kernfs_vfsops.c   4 Feb 2011 15:37:09 -0000
@@ -65,7 +65,7 @@
 
 MODULE(MODULE_CLASS_VFS, kernfs, NULL);
 
-MALLOC_JUSTDEFINE(M_KERNFSMNT, "kernfs mount", "kernfs mount structures");
+MALLOC_DEFINE(M_KERNFSMNT, "kernfs mount", "kernfs mount structures");
 
 dev_t rrootdev = NODEV;
 
Index: sys/rump/librump/rumpkern/vm.c
===================================================================
RCS file: /cvsroot/src/sys/rump/librump/rumpkern/vm.c,v
retrieving revision 1.108
diff -u -r1.108 vm.c
--- sys/rump/librump/rumpkern/vm.c      22 Jan 2011 13:13:46 -0000      1.108
+++ sys/rump/librump/rumpkern/vm.c      4 Feb 2011 15:37:10 -0000
@@ -714,32 +714,32 @@
 }
 
 vaddr_t
-uvm_km_alloc_poolpage(struct vm_map *map, bool waitok)
+uvm_km_alloc_poolpage(struct vm_map *map, size_t size, bool waitok)
 {
 
-       return (vaddr_t)rump_hypermalloc(PAGE_SIZE, PAGE_SIZE,
+       return (vaddr_t)rump_hypermalloc(size, PAGE_SIZE,
            waitok, "kmalloc");
 }
 
 void
-uvm_km_free_poolpage(struct vm_map *map, vaddr_t addr)
+uvm_km_free_poolpage(struct vm_map *map, vaddr_t addr, size_t size)
 {
 
-       rump_hyperfree((void *)addr, PAGE_SIZE);
+       rump_hyperfree((void *)addr, size);
 }
 
 vaddr_t
-uvm_km_alloc_poolpage_cache(struct vm_map *map, bool waitok)
+uvm_km_alloc_poolpage_cache(struct vm_map *map, size_t size, bool waitok)
 {
 
-       return uvm_km_alloc_poolpage(map, waitok);
+       return uvm_km_alloc_poolpage(map, size, waitok);
 }
 
 void
-uvm_km_free_poolpage_cache(struct vm_map *map, vaddr_t vaddr)
+uvm_km_free_poolpage_cache(struct vm_map *map, vaddr_t vaddr, size_t size)
 {
 
-       uvm_km_free_poolpage(map, vaddr);
+       uvm_km_free_poolpage(map, vaddr, size);
 }
 
 void
Index: sys/sys/exec.h
===================================================================
RCS file: /cvsroot/src/sys/sys/exec.h,v
retrieving revision 1.132
diff -u -r1.132 exec.h
--- sys/sys/exec.h      19 Nov 2010 06:44:34 -0000      1.132
+++ sys/sys/exec.h      4 Feb 2011 15:37:11 -0000
@@ -200,6 +200,7 @@
        } *ep_fa;                       /* a fake args vector for scripts */
        int     ep_fd;                  /* a file descriptor we're holding */
        void    *ep_emul_arg;           /* emulation argument */
+       size_t  ep_emul_arg_size;
        const struct    execsw *ep_esch;/* execsw entry */
        struct vnode *ep_emul_root;     /* base of emulation filesystem */
        struct vnode *ep_interp;        /* vnode of (elf) interpeter */
Index: sys/sys/extent.h
===================================================================
RCS file: /cvsroot/src/sys/sys/extent.h,v
retrieving revision 1.18
diff -u -r1.18 extent.h
--- sys/sys/extent.h    28 Apr 2008 20:24:10 -0000      1.18
+++ sys/sys/extent.h    4 Feb 2011 15:37:11 -0000
@@ -54,7 +54,6 @@
        LIST_HEAD(, extent_region) ex_regions;
        u_long  ex_start;               /* start of extent */
        u_long  ex_end;                 /* end of extent */
-       struct malloc_type *ex_mtype;   /* memory type */
        int     ex_flags;               /* misc. information */
 };
 
@@ -79,7 +78,7 @@
 #define EX_FAST                0x02            /* take first fit in 
extent_alloc() */
 #define EX_CATCH       0x04            /* catch signals while sleeping */
 #define EX_NOCOALESCE  0x08            /* create a non-coalescing extent */
-#define EX_MALLOCOK    0x10            /* safe to call malloc() */
+#define EX_MALLOCOK    0x10            /* safe to call kmem_alloc() */
 #define EX_WAITSPACE   0x20            /* wait for space to become free */
 #define EX_BOUNDZERO   0x40            /* boundary lines start at 0 */
 
@@ -96,10 +95,8 @@
        ((ALIGN(sizeof(struct extent_region))) *        \
         (_nregions)))
 
-struct malloc_type;
-
 struct extent *extent_create(const char *, u_long, u_long,
-           struct malloc_type *, void *, size_t, int);
+           void *, size_t, int);
 void   extent_destroy(struct extent *);
 int    extent_alloc_subregion1(struct extent *, u_long, u_long,
            u_long, u_long, u_long, u_long, int, u_long *);
Index: sys/sys/malloc.h
===================================================================
RCS file: /cvsroot/src/sys/sys/malloc.h,v
retrieving revision 1.107
diff -u -r1.107 malloc.h
--- sys/sys/malloc.h    23 Apr 2010 19:09:15 -0000      1.107
+++ sys/sys/malloc.h    4 Feb 2011 15:37:11 -0000
@@ -36,8 +36,6 @@
 
 #if defined(_KERNEL_OPT)
 #include "opt_kmemstats.h"
-#include "opt_malloclog.h"
-#include "opt_malloc_debug.h"
 #endif
 
 
@@ -73,48 +71,14 @@
 MALLOC_DECLARE(M_BWMETER);
 #endif /* _KERNEL */
 
-/*
- * Set of buckets for each size of memory block that is retained
- */
-struct kmembuckets {
-       void *kb_next;  /* list of free blocks */
-       void *kb_last;  /* last free block */
-       long    kb_calls;       /* total calls to allocate this size */
-       long    kb_total;       /* total number of blocks allocated */
-       long    kb_totalfree;   /* # of free elements in this bucket */
-       long    kb_elmpercl;    /* # of elements in this sized allocation */
-       long    kb_highwat;     /* high water mark */
-       long    kb_couldfree;   /* over high water mark and could free */
-};
-
 #ifdef _KERNEL
-#ifdef MALLOCLOG
-void   *_kern_malloc(unsigned long, struct malloc_type *, int, const char *, 
long);
-void   _kern_free(void *, struct malloc_type *, const char *, long);
-#define        malloc(size, type, flags) \
-           _kern_malloc((size), (type), (flags), __FILE__, __LINE__)
-#define        free(addr, type) \
-           _kern_free((addr), (type), __FILE__, __LINE__)
-#else
 void   *kern_malloc(unsigned long, struct malloc_type *, int);
 void   kern_free(void *, struct malloc_type *);
 #define malloc(size, type, flags) kern_malloc(size, type, flags)
 #define free(addr, type) kern_free(addr, type)
-#endif /* MALLOCLOG */
-
-#ifdef MALLOC_DEBUG
-void   debug_malloc_init(void);
-int    debug_malloc(unsigned long, struct malloc_type *, int, void **);
-int    debug_free(void *, struct malloc_type *);
-
-void   debug_malloc_print(void);
-void   debug_malloc_printit(void (*)(const char *, ...), vaddr_t);
-#endif /* MALLOC_DEBUG */
 
 void   *kern_realloc(void *, unsigned long, struct malloc_type *, int);
 #define realloc(ptr, size, type, flags) \
            kern_realloc(ptr, size, type, flags)
-unsigned long
-       malloc_roundup(unsigned long);
 #endif /* _KERNEL */
 #endif /* !_SYS_MALLOC_H_ */
Index: sys/sys/mallocvar.h
===================================================================
RCS file: /cvsroot/src/sys/sys/mallocvar.h,v
retrieving revision 1.9
diff -u -r1.9 mallocvar.h
--- sys/sys/mallocvar.h 5 Apr 2010 08:03:41 -0000       1.9
+++ sys/sys/mallocvar.h 4 Feb 2011 15:37:11 -0000
@@ -47,46 +47,23 @@
        struct malloc_type *ks_next;    /* next in list */
        u_long  ks_magic;        /* indicates valid structure */
        const char *ks_shortdesc;/* short description */
-
-       /* Statistics */
-       u_long  ks_inuse;       /* # of packets of this type currently in use */
-       u_long  ks_calls;       /* total packets of this type ever allocated */
-       u_long  ks_memuse;      /* total memory held in bytes */
-       u_short ks_limblocks;   /* number of times blocked for hitting limit */
-       u_short ks_mapblocks;   /* number of times blocked for kernel map */
-       u_long  ks_maxused;     /* maximum number ever used */
-       u_long  ks_limit;       /* most that are allowed to exist */
-       u_long  ks_size;        /* sizes of this thing that are allocated */
-       u_short ks_active[MAXBUCKET+1]; /* number of active allocations per 
size */
 };
 
 #ifdef _KERNEL
-#define        MALLOC_JUSTDEFINE_LIMIT(type, shortdesc, longdesc, limit)       
\
+#define        MALLOC_DEFINE(type, shortdesc, longdesc)        \
 struct malloc_type type[1] = {                                         \
        [0] = {                                                         \
                .ks_magic = M_MAGIC,                                    \
                .ks_shortdesc = shortdesc,                              \
-               .ks_limit = limit,                                      \
        },                                                              \
 };
 
-#define        MALLOC_JUSTDEFINE(type, shortdesc, longdesc)                    
\
-       MALLOC_JUSTDEFINE_LIMIT(type, shortdesc, longdesc, 0)
-
-#define        MALLOC_DEFINE_LIMIT(type, shortdesc, longdesc, limit)           
\
-       MALLOC_JUSTDEFINE_LIMIT(type, shortdesc, longdesc, limit)       \
-       __link_set_add_data(malloc_types, type)
-
-#define        MALLOC_DEFINE(type, shortdesc, longdesc)                        
\
-       MALLOC_DEFINE_LIMIT(type, shortdesc, longdesc, 0)
-
 #define        MALLOC_DECLARE(type)                                            
\
        extern struct malloc_type type[1]
 
 void   malloc_type_attach(struct malloc_type *);
 void   malloc_type_detach(struct malloc_type *);
 
-void   malloc_type_setlimit(struct malloc_type *, u_long);
 #endif /* _KERNEL */
 
 #endif /* _SYS_MALLOCVAR_H_ */
Index: sys/sys/pool.h
===================================================================
RCS file: /cvsroot/src/sys/sys/pool.h,v
retrieving revision 1.70
diff -u -r1.70 pool.h
--- sys/sys/pool.h      3 Jun 2010 10:40:17 -0000       1.70
+++ sys/sys/pool.h      4 Feb 2011 15:37:11 -0000
@@ -68,10 +68,6 @@
        int             pa_pagemask;
        int             pa_pageshift;
        struct vm_map *pa_backingmap;
-#if defined(_KERNEL)
-       struct vm_map **pa_backingmapptr;
-       SLIST_ENTRY(pool_allocator) pa_q;
-#endif /* defined(_KERNEL) */
 };
 
 LIST_HEAD(pool_pagelist,pool_item_header);
@@ -265,6 +261,7 @@
 extern struct pool_allocator pool_allocator_nointr_fullpage;
 #endif
 
+void           pool_subsystem_bootstrap(void);
 void           pool_subsystem_init(void);
 
 void           pool_init(struct pool *, size_t, u_int, u_int,
Index: sys/ufs/lfs/lfs_segment.c
===================================================================
RCS file: /cvsroot/src/sys/ufs/lfs/lfs_segment.c,v
retrieving revision 1.217
diff -u -r1.217 lfs_segment.c
--- sys/ufs/lfs/lfs_segment.c   21 Jul 2010 17:52:13 -0000      1.217
+++ sys/ufs/lfs/lfs_segment.c   4 Feb 2011 15:37:12 -0000
@@ -106,7 +106,7 @@
 #include <uvm/uvm.h>
 #include <uvm/uvm_extern.h>
 
-MALLOC_JUSTDEFINE(M_SEGMENT, "LFS segment", "Segment for LFS");
+MALLOC_DEFINE(M_SEGMENT, "LFS segment", "Segment for LFS");
 
 extern int count_lock_queue(void);
 extern kmutex_t vnode_free_list_lock;          /* XXX */
Index: sys/ufs/ufs/ufs_extattr.c
===================================================================
RCS file: /cvsroot/src/sys/ufs/ufs/ufs_extattr.c,v
retrieving revision 1.28
diff -u -r1.28 ufs_extattr.c
--- sys/ufs/ufs/ufs_extattr.c   30 Nov 2010 10:30:04 -0000      1.28
+++ sys/ufs/ufs/ufs_extattr.c   4 Feb 2011 15:37:13 -0000
@@ -77,7 +77,7 @@
 #include <ufs/ufs/ufs_bswap.h>
 #include <ufs/ufs/ufs_extern.h>
 
-static MALLOC_JUSTDEFINE(M_UFS_EXTATTR, "ufs_extattr","ufs extended 
attribute");
+static MALLOC_DEFINE(M_UFS_EXTATTR, "ufs_extattr","ufs extended attribute");
 
 int ufs_extattr_sync = 1;
 
Index: sys/uvm/uvm_amap.c
===================================================================
RCS file: /cvsroot/src/sys/uvm/uvm_amap.c,v
retrieving revision 1.89
diff -u -r1.89 uvm_amap.c
--- sys/uvm/uvm_amap.c  2 Feb 2011 15:13:33 -0000       1.89
+++ sys/uvm/uvm_amap.c  4 Feb 2011 15:37:14 -0000
@@ -98,7 +98,7 @@
  * when enabled, an array of ints is allocated for the pprefs.  this
  * array is allocated only when a partial reference is added to the
  * map (either by unmapping part of the amap, or gaining a reference
- * to only a part of an amap).  if the malloc of the array fails
+ * to only a part of an amap).  if the kmem of the array fails
  * (M_NOWAIT), then we set the array pointer to PPREF_NONE to indicate
  * that we tried to do ppref's but couldn't alloc the array so just
  * give up (after all, this is an optional feature!).
@@ -475,15 +475,11 @@
        }
 
        /*
-        * case 3: we need to malloc a new amap and copy all the amap
+        * case 3: we need to kmem_alloc a new amap and copy all the amap
         * data over from old amap to the new one.
-        *
-        * note that the use of a kernel realloc() probably would not
-        * help here, since we wish to abort cleanly if one of the
-        * three (or four) mallocs fails.
         */
 
-       amap_unlock(amap);      /* unlock in case we sleep in malloc */
+       amap_unlock(amap);      /* unlock in case we sleep in kmem_alloc */
 
        if (slotneed >= UVM_AMAP_LARGE) {
                return E2BIG;
@@ -519,7 +515,7 @@
        KASSERT(amap->am_maxslot < slotneed);
 
        /*
-        * now copy everything over to new malloc'd areas...
+        * now copy everything over to new kmem_alloc'd areas...
         */
 
        slotadded = slotalloc - amap->am_nslot;
@@ -829,7 +825,7 @@
        /*
         * need to double check reference count now that we've got the
         * src amap locked down.  the reference count could have
-        * changed while we were in malloc.  if the reference count
+        * changed while we were in kmem.  if the reference count
         * dropped down to one we take over the old map rather than
         * copying the amap.
         */
Index: sys/uvm/uvm_amap.h
===================================================================
RCS file: /cvsroot/src/sys/uvm/uvm_amap.h,v
retrieving revision 1.35
diff -u -r1.35 uvm_amap.h
--- sys/uvm/uvm_amap.h  2 Feb 2011 15:13:33 -0000       1.35
+++ sys/uvm/uvm_amap.h  4 Feb 2011 15:37:14 -0000
@@ -208,7 +208,7 @@
  * of this VM is actually used.  since the stack is anonymous memory
  * it makes sense for it to live in an amap, but if we allocated an
  * amap for the entire stack range we could end up wasting a large
- * amount of malloc'd KVM.
+ * amount of kmem_alloc'd KVM.
  *
  * for example, on the i386 at boot time we allocate two amaps for the stack
  * of /sbin/init:
Index: sys/uvm/uvm_anon.c
===================================================================
RCS file: /cvsroot/src/sys/uvm/uvm_anon.c,v
retrieving revision 1.52
diff -u -r1.52 uvm_anon.c
--- sys/uvm/uvm_anon.c  2 Feb 2011 15:13:34 -0000       1.52
+++ sys/uvm/uvm_anon.c  4 Feb 2011 15:37:14 -0000
@@ -37,7 +37,6 @@
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/proc.h>
-#include <sys/malloc.h>
 #include <sys/pool.h>
 #include <sys/kernel.h>
 
Index: sys/uvm/uvm_aobj.c
===================================================================
RCS file: /cvsroot/src/sys/uvm/uvm_aobj.c,v
retrieving revision 1.112
diff -u -r1.112 uvm_aobj.c
--- sys/uvm/uvm_aobj.c  2 Feb 2011 15:28:38 -0000       1.112
+++ sys/uvm/uvm_aobj.c  4 Feb 2011 15:37:16 -0000
@@ -443,7 +443,7 @@
        int refs;
 
        /*
-        * malloc a new aobj unless we are asked for the kernel object
+        * kmem_alloc a new aobj unless we are asked for the kernel object
         */
 
        if (flags & UAO_FLAG_KERNOBJ) {
@@ -487,7 +487,7 @@
                        aobj->u_swslots = kmem_zalloc(pages * sizeof(int),
                            kernswap ? KM_NOSLEEP : KM_SLEEP);
                        if (aobj->u_swslots == NULL)
-                               panic("uao_create: malloc swslots failed");
+                               panic("uao_create: kmem_alloc swslots failed");
                }
 #endif /* defined(VMSWAP) */
 
Index: sys/uvm/uvm_device.c
===================================================================
RCS file: /cvsroot/src/sys/uvm/uvm_device.c,v
retrieving revision 1.58
diff -u -r1.58 uvm_device.c
--- sys/uvm/uvm_device.c        2 Feb 2011 15:13:34 -0000       1.58
+++ sys/uvm/uvm_device.c        4 Feb 2011 15:37:16 -0000
@@ -40,7 +40,7 @@
 #include <sys/systm.h>
 #include <sys/conf.h>
 #include <sys/proc.h>
-#include <sys/malloc.h>
+#include <sys/kmem.h>
 
 #include <uvm/uvm.h>
 #include <uvm/uvm_device.h>
@@ -209,12 +209,12 @@
                }
 
                /*
-                * did not find it on main list.   need to malloc a new one.
+                * did not find it on main list.   need to kmem_alloc a new one.
                 */
 
                mutex_exit(&udv_lock);
-               /* NOTE: we could sleep in the following malloc() */
-               udv = malloc(sizeof(*udv), M_TEMP, M_WAITOK);
+               /* NOTE: we could sleep in the following kmem_alloc */
+               udv = kmem_alloc(sizeof(*udv), KM_SLEEP);
                mutex_enter(&udv_lock);
 
                /*
@@ -234,7 +234,7 @@
 
                if (lcv) {
                        mutex_exit(&udv_lock);
-                       free(udv, M_TEMP);
+                       kmem_free(udv, sizeof(*udv));
                        continue;
                }
 
@@ -324,7 +324,7 @@
        mutex_exit(&udv_lock);
        mutex_exit(&uobj->vmobjlock);
        UVM_OBJ_DESTROY(uobj);
-       free(udv, M_TEMP);
+       kmem_free(udv, sizeof(*udv));
        UVMHIST_LOG(maphist," <- done, freed uobj=0x%x", uobj,0,0,0);
 }
 
Index: sys/uvm/uvm_extern.h
===================================================================
RCS file: /cvsroot/src/sys/uvm/uvm_extern.h,v
retrieving revision 1.169
diff -u -r1.169 uvm_extern.h
--- sys/uvm/uvm_extern.h        2 Feb 2011 15:13:34 -0000       1.169
+++ sys/uvm/uvm_extern.h        4 Feb 2011 15:37:16 -0000
@@ -554,9 +554,6 @@
 
 #define vm_resident_count(vm) (pmap_resident_count((vm)->vm_map.pmap))
 
-#include <sys/mallocvar.h>
-MALLOC_DECLARE(M_VMMAP);
-MALLOC_DECLARE(M_VMPMAP);
 
 /* vm_machdep.c */
 void           vmapbuf(struct buf *, vsize_t);
@@ -645,12 +642,11 @@
 struct vm_map          *uvm_km_suballoc(struct vm_map *, vaddr_t *,
                            vaddr_t *, vsize_t, int, bool,
                            struct vm_map_kernel *);
-vaddr_t                        uvm_km_alloc_poolpage(struct vm_map *, bool);
-void                   uvm_km_free_poolpage(struct vm_map *, vaddr_t);
-vaddr_t                        uvm_km_alloc_poolpage_cache(struct vm_map *, 
bool);
-void                   uvm_km_free_poolpage_cache(struct vm_map *, vaddr_t);
-void                   uvm_km_vacache_init(struct vm_map *,
-                           const char *, size_t);
+vaddr_t                        uvm_km_alloc_poolpage(struct vm_map *, size_t, 
bool);
+void                   uvm_km_free_poolpage(struct vm_map *, vaddr_t, size_t);
+vaddr_t                        uvm_km_alloc_poolpage_cache(struct vm_map *, 
size_t, bool);
+void                   uvm_km_free_poolpage_cache(struct vm_map *, vaddr_t, 
size_t);
+void                   uvm_km_vacache_init(struct vm_map *, const char *);
 
 /* uvm_map.c */
 int                    uvm_map(struct vm_map *, vaddr_t *, vsize_t,
@@ -757,7 +753,6 @@
 bool                   uvn_needs_writefault_p(struct uvm_object *);
 
 /* kern_malloc.c */
-void                   kmeminit_nkmempages(void);
 void                   kmeminit(void);
 extern int             nkmempages;
 
Index: sys/uvm/uvm_fault.c
===================================================================
RCS file: /cvsroot/src/sys/uvm/uvm_fault.c,v
retrieving revision 1.181
diff -u -r1.181 uvm_fault.c
--- sys/uvm/uvm_fault.c 2 Feb 2011 15:13:34 -0000       1.181
+++ sys/uvm/uvm_fault.c 4 Feb 2011 15:37:17 -0000
@@ -40,7 +40,6 @@
 #include <sys/systm.h>
 #include <sys/kernel.h>
 #include <sys/proc.h>
-#include <sys/malloc.h>
 #include <sys/mman.h>
 
 #include <uvm/uvm.h>
Index: sys/uvm/uvm_init.c
===================================================================
RCS file: /cvsroot/src/sys/uvm/uvm_init.c,v
retrieving revision 1.39
diff -u -r1.39 uvm_init.c
--- sys/uvm/uvm_init.c  2 Feb 2011 15:13:34 -0000       1.39
+++ sys/uvm/uvm_init.c  4 Feb 2011 15:37:17 -0000
@@ -43,7 +43,6 @@
 #include <sys/kmem.h>
 #include <sys/mman.h>
 #include <sys/proc.h>
-#include <sys/malloc.h>
 #include <sys/vnode.h>
 
 #include <uvm/uvm.h>
@@ -93,7 +92,6 @@
 
        memset(&uvm, 0, sizeof(uvm));
        averunnable.fscale = FSCALE;
-       uvm_amap_init();
 
        /*
         * step 2: init the page sub-system.  this includes allocating the
@@ -106,9 +104,7 @@
        uvm_page_init(&kvm_start, &kvm_end);
 
        /*
-        * step 3: init the map sub-system.  allocates the static pool of
-        * vm_map_entry structures that are used for "special" kernel maps
-        * (e.g. kernel_map, kmem_map, etc...).
+        * step 3: init the map sub-system. 
         */
 
        uvm_map_init();
@@ -116,9 +112,18 @@
        /*
         * step 4: setup the kernel's virtual memory data structures.  this
         * includes setting up the kernel_map/kernel_object.
+        * Bootstrap all kernel memory allocators.
+        */
+
+       uvm_km_bootstrap(kvm_start, kvm_end);
+
+       /* 
+        * step 5: setup uvm_map pool_caches and init the amap.
         */
 
-       uvm_km_init(kvm_start, kvm_end);
+       uvm_map_init_caches();
+       uvm_amap_init();
+       uao_init();
 
        /*
         * step 5: init the pmap module.   the pmap module is free to allocate
@@ -126,45 +131,31 @@
         */
 
        pmap_init();
-
-       /*
-        * step 6: init the kernel memory allocator.   after this call the
-        * kernel memory allocator (malloc) can be used. this includes
-        * setting up the kmem_map.
+       
+       /* step 6: init the kernel maps virtual address caches.
+        * make kenrle memory allocator ready for use. 
+         * After this call the pool/kmem memory allocators can be used.
         */
 
-       kmeminit();
+       uvm_km_init();
 
 #ifdef DEBUG
        debug_init();
 #endif
 
        /*
-        * step 7: init all pagers and the pager_map.
+        * step 6: init all pagers and the pager_map.
         */
 
        uvm_pager_init();
 
        /*
-        * step 8: init the uvm_loan() facility.
+        * step 7: init the uvm_loan() facility.
         */
 
        uvm_loan_init();
 
        /*
-        * Initialize pools.  This must be done before anyone manipulates
-        * any vm_maps because we use a pool for some map entry structures.
-        */
-
-       pool_subsystem_init();
-
-       /*
-        * init slab memory allocator kmem(9).
-        */
-
-       kmem_init();
-
-       /*
         * init emap subsystem.
         */
 
Index: sys/uvm/uvm_io.c
===================================================================
RCS file: /cvsroot/src/sys/uvm/uvm_io.c,v
retrieving revision 1.25
diff -u -r1.25 uvm_io.c
--- sys/uvm/uvm_io.c    2 Feb 2011 15:13:34 -0000       1.25
+++ sys/uvm/uvm_io.c    4 Feb 2011 15:37:17 -0000
@@ -38,7 +38,6 @@
 #include <sys/systm.h>
 #include <sys/mman.h>
 #include <sys/proc.h>
-#include <sys/malloc.h>
 #include <sys/uio.h>
 
 #include <uvm/uvm.h>
Index: sys/uvm/uvm_km.c
===================================================================
RCS file: /cvsroot/src/sys/uvm/uvm_km.c,v
retrieving revision 1.108
diff -u -r1.108 uvm_km.c
--- sys/uvm/uvm_km.c    2 Feb 2011 15:25:27 -0000       1.108
+++ sys/uvm/uvm_km.c    4 Feb 2011 15:37:18 -0000
@@ -85,7 +85,6 @@
  *
  * the vm system has several standard kernel submaps, including:
  *   kmem_map => contains only wired kernel memory for the kernel
- *             malloc.
  *   pager_map => used to map "buf" structures into kernel space
  *   exec_map => used during exec to handle exec args
  *   etc...
@@ -127,10 +126,10 @@
 #include "opt_uvmhist.h"
 
 #include <sys/param.h>
-#include <sys/malloc.h>
 #include <sys/systm.h>
 #include <sys/proc.h>
 #include <sys/pool.h>
+#include <sys/kmem.h>
 
 #include <uvm/uvm.h>
 
@@ -139,6 +138,7 @@
  */
 
 struct vm_map *kernel_map = NULL;
+struct vm_map *kmem_map = NULL;
 
 /*
  * local data structues
@@ -147,35 +147,52 @@
 static struct vm_map_kernel    kernel_map_store;
 static struct vm_map_entry     kernel_first_mapent_store;
 
-#if !defined(PMAP_MAP_POOLPAGE)
+/*
+ * Default number of pages in kmem_map.  We attempt to calculate this
+ * at run-time, but allow it to be either patched or set in the kernel
+ * config file.
+ */
+#ifndef NKMEMPAGES
+#define NKMEMPAGES      0
+#endif
+int     nkmempages = NKMEMPAGES;
+
+/*
+ * Defaults for lower- and upper-bounds for the kmem_map page count.
+ * Can be overridden by kernel config options.
+ */
+#ifndef NKMEMPAGES_MIN
+#define NKMEMPAGES_MIN  NKMEMPAGES_MIN_DEFAULT
+#endif
+
+#ifndef NKMEMPAGES_MAX
+#define NKMEMPAGES_MAX  NKMEMPAGES_MAX_DEFAULT
+#endif
+
+static struct vm_map_kernel kmem_map_store;
+static char *kmembase, *kmemlimit;
 
 /*
  * kva cache
  *
- * XXX maybe it's better to do this at the uvm_map layer.
+ * caches are up to PAGE_SIZE * 4. 
+ * KM_VACACHE_SIZE should be multiply of largest cache.
+ * if PMAP_MAP_POOLPAGE is defined the PAGE_SIZE cache is skipped.
  */
-
-#define        KM_VACACHE_SIZE (32 * PAGE_SIZE) /* XXX tune */
+#define        KM_VACACHE_SIZE (32 * PAGE_SIZE) 
 
 static void *km_vacache_alloc(struct pool *, int);
 static void km_vacache_free(struct pool *, void *);
 static void km_vacache_init(struct vm_map *, const char *, size_t);
 
-/* XXX */
-#define        KM_VACACHE_POOL_TO_MAP(pp) \
-       ((struct vm_map *)((char *)(pp) - \
-           offsetof(struct vm_map_kernel, vmk_vacache)))
-
 static void *
 km_vacache_alloc(struct pool *pp, int flags)
 {
        vaddr_t va;
        size_t size;
-       struct vm_map *map;
+       struct vm_map *map = pp->pr_alloc->pa_backingmap;
        size = pp->pr_alloc->pa_pagesz;
 
-       map = KM_VACACHE_POOL_TO_MAP(pp);
-
        va = vm_map_min(map); /* hint */
        if (uvm_map(map, &va, size, NULL, UVM_UNKNOWN_OFFSET, size,
            UVM_MAPFLAG(UVM_PROT_ALL, UVM_PROT_ALL, UVM_INH_NONE,
@@ -192,9 +209,8 @@
 {
        vaddr_t va = (vaddr_t)v;
        size_t size = pp->pr_alloc->pa_pagesz;
-       struct vm_map *map;
+       struct vm_map *map = pp->pr_alloc->pa_backingmap;
 
-       map = KM_VACACHE_POOL_TO_MAP(pp);
        uvm_unmap1(map, va, va + size, UVM_FLAG_QUANTUM|UVM_FLAG_VAONLY);
 }
 
@@ -208,52 +224,51 @@
        struct vm_map_kernel *vmk;
        struct pool *pp;
        struct pool_allocator *pa;
+       char *cn;
        int ipl;
+       int i;
 
        KASSERT(VM_MAP_IS_KERNEL(map));
        KASSERT(size < (vm_map_max(map) - vm_map_min(map)) / 2); /* sanity */
 
 
        vmk = vm_map_to_kernel(map);
-       pp = &vmk->vmk_vacache;
-       pa = &vmk->vmk_vacache_allocator;
-       memset(pa, 0, sizeof(*pa));
-       pa->pa_alloc = km_vacache_alloc;
-       pa->pa_free = km_vacache_free;
-       pa->pa_pagesz = (unsigned int)size;
-       pa->pa_backingmap = map;
-       pa->pa_backingmapptr = NULL;
-
-       if ((map->flags & VM_MAP_INTRSAFE) != 0)
-               ipl = IPL_VM;
-       else
-               ipl = IPL_NONE;
 
-       pool_init(pp, PAGE_SIZE, 0, 0, PR_NOTOUCH | PR_RECURSIVE, name, pa,
-           ipl);
+#if defined(PMAP_MAP_POOLPAGE)
+       i = 1;
+#else
+       i = 0;
+#endif
+       for (; i < VMK_VACACHE_COUNT; i++) {
+               size_t cachesize = (i+1) * PAGE_SIZE;
+               pp = &vmk->vmk_vacache[i];
+               pa = &vmk->vmk_vacache_allocator[i];
+               cn = vmk->vmk_vacache_name[i];
+               memset(pa, 0, sizeof(*pa));
+               pa->pa_alloc = km_vacache_alloc;
+               pa->pa_free = km_vacache_free;
+               pa->pa_pagesz = (unsigned int)size;
+               pa->pa_backingmap = map;
+
+               if ((map->flags & VM_MAP_INTRSAFE) != 0)
+                       ipl = IPL_VM;
+               else
+                       ipl = IPL_NONE;
+
+               sprintf(cn, "%s-%i", name, i+1);
+               pool_init(pp, cachesize, 0, 0, PR_NOTOUCH | PR_RECURSIVE, cn, 
pa,
+                       ipl);
+       }
 }
 
 void
-uvm_km_vacache_init(struct vm_map *map, const char *name, size_t size)
+uvm_km_vacache_init(struct vm_map *map, const char *name)
 {
 
        map->flags |= VM_MAP_VACACHE;
-       if (size == 0)
-               size = KM_VACACHE_SIZE;
-       km_vacache_init(map, name, size);
+       km_vacache_init(map, name, KM_VACACHE_SIZE);
 }
 
-#else /* !defined(PMAP_MAP_POOLPAGE) */
-
-void
-uvm_km_vacache_init(struct vm_map *map, const char *name, size_t size)
-{
-
-       /* nothing */
-}
-
-#endif /* !defined(PMAP_MAP_POOLPAGE) */
-
 void
 uvm_km_va_drain(struct vm_map *map, uvm_flag_t flags)
 {
@@ -263,7 +278,7 @@
 }
 
 /*
- * uvm_km_init: init kernel maps and objects to reflect reality (i.e.
+ * uvm_km_bootstrap: init kernel maps and objects to reflect reality (i.e.
  * KVM already allocated for text, data, bss, and static data structures).
  *
  * => KVM is defined by VM_MIN_KERNEL_ADDRESS/VM_MAX_KERNEL_ADDRESS.
@@ -272,18 +287,20 @@
  */
 
 void
-uvm_km_init(vaddr_t start, vaddr_t end)
+uvm_km_bootstrap(vaddr_t start, vaddr_t end)
 {
        vaddr_t base = VM_MIN_KERNEL_ADDRESS;
+       vaddr_t kmb = 0;
+       vaddr_t kml;
 
        /*
         * next, init kernel memory objects.
         */
 
        /* kernel_object: for pageable anonymous kernel memory */
-       uao_init();
        uvm_kernel_object = uao_create(VM_MAX_KERNEL_ADDRESS -
-                                VM_MIN_KERNEL_ADDRESS, UAO_FLAG_KERNOBJ);
+                               VM_MIN_KERNEL_ADDRESS, UAO_FLAG_KERNOBJ);
+
 
        /*
         * init the map and reserve any space that might already
@@ -318,7 +335,50 @@
         */
 
        kernel_map = &kernel_map_store.vmk_map;
-       uvm_km_vacache_init(kernel_map, "kvakernel", 0);
+
+       /* 
+        * Boostrap kmem submap 
+        */
+       uvm_km_setupkmemsize();
+       
+        kmem_map = uvm_km_suballoc(kernel_map, &kmb,
+            &kml, ((vsize_t)nkmempages << PAGE_SHIFT),
+            VM_MAP_INTRSAFE, false, &kmem_map_store);
+        kmembase = (char *)kmb;
+        kmemlimit = (char *)kml;
+
+       pool_subsystem_bootstrap();
+}
+
+void
+uvm_km_setupkmemsize(void)
+{
+       /* if allready setup or KMEMSIZE defined in kernel config */
+       if (nkmempages > 0)
+               return;
+
+        nkmempages = physmem;
+
+        if (nkmempages > NKMEMPAGES_MAX)
+                nkmempages = NKMEMPAGES_MAX;
+
+        if (nkmempages < NKMEMPAGES_MIN)
+                nkmempages = NKMEMPAGES_MIN;
+}
+
+/*
+ * uvm_km_init: init the kernel maps virtual memory caches
+ * and start the pool/kmem allocator.
+ */
+void
+uvm_km_init(void)
+{
+       uvm_km_vacache_init(kernel_map, "kvakernel");
+        uvm_km_vacache_init(kmem_map, "kvakmem");
+
+       kmeminit(); // killme
+       pool_subsystem_init();  
+       kmem_init();
 }
 
 /*
@@ -366,7 +426,7 @@
 
        pmap_reference(vm_map_pmap(map));
        if (submap == NULL) {
-               submap = malloc(sizeof(*submap), M_VMMAP, M_WAITOK);
+               submap = kmem_alloc(sizeof(*submap), KM_SLEEP);
                if (submap == NULL)
                        panic("uvm_km_suballoc: unable to create submap");
        }
@@ -684,73 +744,89 @@
 
 /* ARGSUSED */
 vaddr_t
-uvm_km_alloc_poolpage_cache(struct vm_map *map, bool waitok)
+uvm_km_alloc_poolpage_cache(struct vm_map *map, size_t size, bool waitok)
 {
-#if defined(PMAP_MAP_POOLPAGE)
-       return uvm_km_alloc_poolpage(map, waitok);
-#else
        struct vm_page *pg;
-       struct pool *pp = &vm_map_to_kernel(map)->vmk_vacache;
+       int index;
+       struct pool *pp;
        vaddr_t va;
+       vaddr_t loopva;
+       vsize_t loopsize;
+
+
+#if defined(PMAP_MAP_POOLPAGE)
+       if (size == PAGE_SIZE) 
+               return uvm_km_alloc_poolpage(map, size, waitok);
+#endif /* PMAP_MAP_POOLPAGE */
 
        if ((map->flags & VM_MAP_VACACHE) == 0)
-               return uvm_km_alloc_poolpage(map, waitok);
+               return uvm_km_alloc_poolpage(map, size, waitok);
+       
+       index = (size >> PAGE_SHIFT) - 1;
+       pp = &vm_map_to_kernel(map)->vmk_vacache[index];
 
        va = (vaddr_t)pool_get(pp, waitok ? PR_WAITOK : PR_NOWAIT);
        if (va == 0)
                return 0;
-       KASSERT(!pmap_extract(pmap_kernel(), va, NULL));
-again:
-       pg = uvm_pagealloc(NULL, 0, NULL, waitok ? 0 : UVM_PGA_USERESERVE);
-       if (__predict_false(pg == NULL)) {
-               if (waitok) {
-                       uvm_wait("plpg");
-                       goto again;
-               } else {
-                       pool_put(pp, (void *)va);
-                       return 0;
+
+       loopva = va;
+       loopsize = size;
+
+       while (loopsize) {
+               KASSERT(!pmap_extract(pmap_kernel(), loopva, NULL));
+       
+               pg = uvm_pagealloc(NULL, 0, NULL, waitok ? 0 : 
UVM_PGA_USERESERVE);
+               if (__predict_false(pg == NULL)) {
+                       if (waitok) {
+                               uvm_wait("plpg");
+                               continue;
+                       } else {
+                               pool_put(pp, (void *)va);
+                               return 0;
+                       }
                }
+       
+               pmap_kenter_pa(loopva, VM_PAGE_TO_PHYS(pg),
+                       VM_PROT_READ|VM_PROT_WRITE, PMAP_KMPAGE);
+
+               loopva += PAGE_SIZE;
+               loopsize -= PAGE_SIZE;
        }
-       pmap_kenter_pa(va, VM_PAGE_TO_PHYS(pg),
-           VM_PROT_READ|VM_PROT_WRITE, PMAP_KMPAGE);
        pmap_update(pmap_kernel());
 
        return va;
-#endif /* PMAP_MAP_POOLPAGE */
 }
 
 vaddr_t
-uvm_km_alloc_poolpage(struct vm_map *map, bool waitok)
+uvm_km_alloc_poolpage(struct vm_map *map, size_t size, bool waitok)
 {
+       vaddr_t va;
 #if defined(PMAP_MAP_POOLPAGE)
        struct vm_page *pg;
-       vaddr_t va;
-
 
+       if (size == PAGE_SIZE) {
  again:
 #ifdef PMAP_ALLOC_POOLPAGE
-       pg = PMAP_ALLOC_POOLPAGE(waitok ? 0 : UVM_PGA_USERESERVE);
+               pg = PMAP_ALLOC_POOLPAGE(waitok ? 0 : UVM_PGA_USERESERVE);
 #else
-       pg = uvm_pagealloc(NULL, 0, NULL, waitok ? 0 : UVM_PGA_USERESERVE);
+               pg = uvm_pagealloc(NULL, 0, NULL, waitok ? 0 : 
UVM_PGA_USERESERVE);
 #endif
-       if (__predict_false(pg == NULL)) {
-               if (waitok) {
-                       uvm_wait("plpg");
-                       goto again;
-               } else
-                       return (0);
+               if (__predict_false(pg == NULL)) {
+                       if (waitok) {
+                               uvm_wait("plpg");
+                               goto again;
+                       } else
+                               return (0);
+               }
+               va = PMAP_MAP_POOLPAGE(VM_PAGE_TO_PHYS(pg));
+               if (__predict_false(va == 0))
+                       uvm_pagefree(pg);
+               return (va);
        }
-       va = PMAP_MAP_POOLPAGE(VM_PAGE_TO_PHYS(pg));
-       if (__predict_false(va == 0))
-               uvm_pagefree(pg);
-       return (va);
-#else
-       vaddr_t va;
-
-       va = uvm_km_alloc(map, PAGE_SIZE, 0,
+#endif /* PMAP_MAP_POOLPAGE */
+       va = uvm_km_alloc(map, size, 0,
            (waitok ? 0 : UVM_KMF_NOWAIT | UVM_KMF_TRYLOCK) | UVM_KMF_WIRED);
        return (va);
-#endif /* PMAP_MAP_POOLPAGE */
 }
 
 /*
@@ -761,40 +837,40 @@
 
 /* ARGSUSED */
 void
-uvm_km_free_poolpage_cache(struct vm_map *map, vaddr_t addr)
+uvm_km_free_poolpage_cache(struct vm_map *map, vaddr_t addr, size_t size)
 {
-#if defined(PMAP_UNMAP_POOLPAGE)
-       uvm_km_free_poolpage(map, addr);
-#else
        struct pool *pp;
+       int index;
+
+#if defined(PMAP_UNMAP_POOLPAGE)
+       if (size == PAGE_SIZE)
+               uvm_km_free_poolpage(map, addr, size);
+#endif /* PMAP_UNMAP_POOLPAGE */
 
        if ((map->flags & VM_MAP_VACACHE) == 0) {
-               uvm_km_free_poolpage(map, addr);
+               uvm_km_free_poolpage(map, addr, size);
                return;
        }
 
-       KASSERT(pmap_extract(pmap_kernel(), addr, NULL));
-       uvm_km_pgremove_intrsafe(map, addr, addr + PAGE_SIZE);
-       pmap_kremove(addr, PAGE_SIZE);
-#if defined(DEBUG)
-       pmap_update(pmap_kernel());
-#endif
-       KASSERT(!pmap_extract(pmap_kernel(), addr, NULL));
-       pp = &vm_map_to_kernel(map)->vmk_vacache;
+       uvm_km_pgremove_intrsafe(map, addr, addr + size);
+       pmap_kremove(addr, size);
+
+       index = (size >> PAGE_SHIFT) - 1;
+       pp = &vm_map_to_kernel(map)->vmk_vacache[index];
        pool_put(pp, (void *)addr);
-#endif
 }
 
 /* ARGSUSED */
 void
-uvm_km_free_poolpage(struct vm_map *map, vaddr_t addr)
+uvm_km_free_poolpage(struct vm_map *map, vaddr_t addr, size_t size)
 {
 #if defined(PMAP_UNMAP_POOLPAGE)
        paddr_t pa;
 
-       pa = PMAP_UNMAP_POOLPAGE(addr);
-       uvm_pagefree(PHYS_TO_VM_PAGE(pa));
-#else
-       uvm_km_free(map, addr, PAGE_SIZE, UVM_KMF_WIRED);
+       if (size == PAGE_SIZE) {
+               pa = PMAP_UNMAP_POOLPAGE(addr);
+               uvm_pagefree(PHYS_TO_VM_PAGE(pa));
+       } else
 #endif /* PMAP_UNMAP_POOLPAGE */
+       uvm_km_free(map, addr, size, UVM_KMF_WIRED);
 }
Index: sys/uvm/uvm_km.h
===================================================================
RCS file: /cvsroot/src/sys/uvm/uvm_km.h,v
retrieving revision 1.19
diff -u -r1.19 uvm_km.h
--- sys/uvm/uvm_km.h    2 Feb 2011 15:13:34 -0000       1.19
+++ sys/uvm/uvm_km.h    4 Feb 2011 15:37:18 -0000
@@ -40,7 +40,9 @@
  * prototypes
  */
 
-void uvm_km_init(vaddr_t, vaddr_t);
+void uvm_km_bootstrap(vaddr_t, vaddr_t);
+void uvm_km_setupkmemsize(void);
+void uvm_km_init(void);
 void uvm_km_pgremove(vaddr_t, vaddr_t);
 void uvm_km_pgremove_intrsafe(struct vm_map *, vaddr_t, vaddr_t);
 #if defined(DEBUG)
Index: sys/uvm/uvm_kmguard.c
===================================================================
RCS file: /cvsroot/src/sys/uvm/uvm_kmguard.c,v
retrieving revision 1.4
diff -u -r1.4 uvm_kmguard.c
--- sys/uvm/uvm_kmguard.c       2 Nov 2010 20:49:48 -0000       1.4
+++ sys/uvm/uvm_kmguard.c       4 Feb 2011 15:37:18 -0000
@@ -41,7 +41,6 @@
 __KERNEL_RCSID(0, "$NetBSD: uvm_kmguard.c,v 1.4 2010/11/02 20:49:48 skrll Exp 
$");
 
 #include <sys/param.h>
-#include <sys/malloc.h>
 #include <sys/systm.h>
 #include <sys/proc.h>
 #include <sys/pool.h>
Index: sys/uvm/uvm_loan.c
===================================================================
RCS file: /cvsroot/src/sys/uvm/uvm_loan.c,v
retrieving revision 1.78
diff -u -r1.78 uvm_loan.c
--- sys/uvm/uvm_loan.c  2 Feb 2011 15:13:34 -0000       1.78
+++ sys/uvm/uvm_loan.c  4 Feb 2011 15:37:18 -0000
@@ -38,7 +38,6 @@
 #include <sys/systm.h>
 #include <sys/kernel.h>
 #include <sys/proc.h>
-#include <sys/malloc.h>
 #include <sys/mman.h>
 
 #include <uvm/uvm.h>
Index: sys/uvm/uvm_map.c
===================================================================
RCS file: /cvsroot/src/sys/uvm/uvm_map.c,v
retrieving revision 1.295
diff -u -r1.295 uvm_map.c
--- sys/uvm/uvm_map.c   2 Feb 2011 15:25:27 -0000       1.295
+++ sys/uvm/uvm_map.c   4 Feb 2011 15:37:21 -0000
@@ -77,7 +77,6 @@
 #include <sys/systm.h>
 #include <sys/mman.h>
 #include <sys/proc.h>
-#include <sys/malloc.h>
 #include <sys/pool.h>
 #include <sys/kernel.h>
 #include <sys/mount.h>
@@ -154,9 +153,6 @@
 
 static struct pool_cache uvm_map_entry_cache;
 
-MALLOC_DEFINE(M_VMMAP, "VM map", "VM map structures");
-MALLOC_DEFINE(M_VMPMAP, "VM pmap", "VM pmap");
-
 #ifdef PMAP_GROWKERNEL
 /*
  * This global represents the end of the kernel virtual address
@@ -1032,7 +1028,14 @@
         */
 
        mutex_init(&uvm_kentry_lock, MUTEX_DRIVER, IPL_VM);
+}
 
+/*
+ * uvm_map_init_caches: init mapping system caches.
+ */
+void
+uvm_map_init_caches(void)
+{ 
        /*
         * initialize caches.
         */
@@ -5061,21 +5064,6 @@
 }
 
 /*
- * uvm_map_create: create map
- */
-
-struct vm_map *
-uvm_map_create(pmap_t pmap, vaddr_t vmin, vaddr_t vmax, int flags)
-{
-       struct vm_map *result;
-
-       result = malloc(sizeof(struct vm_map), M_VMMAP, M_WAITOK);
-       uvm_map_setup(result, vmin, vmax, flags);
-       result->pmap = pmap;
-       return(result);
-}
-
-/*
  * uvm_map_setup: init map
  *
  * => map must not be in service yet.
Index: sys/uvm/uvm_map.h
===================================================================
RCS file: /cvsroot/src/sys/uvm/uvm_map.h,v
retrieving revision 1.66
diff -u -r1.66 uvm_map.h
--- sys/uvm/uvm_map.h   2 Feb 2011 15:25:27 -0000       1.66
+++ sys/uvm/uvm_map.h   4 Feb 2011 15:37:21 -0000
@@ -225,6 +225,8 @@
 
 #include <sys/callback.h>
 
+/* we cache up to 4 times PAGE_SIZE va ranges */
+#define VMK_VACACHE_COUNT 4 
 struct vm_map_kernel {
        struct vm_map vmk_map;
        LIST_HEAD(, uvm_kmapent_hdr) vmk_kentry_free;
@@ -233,10 +235,9 @@
                        /* Merged entries, kept for later splitting */
 
        struct callback_head vmk_reclaim_callback;
-#if !defined(PMAP_MAP_POOLPAGE)
-       struct pool vmk_vacache; /* kva cache */
-       struct pool_allocator vmk_vacache_allocator; /* ... and its allocator */
-#endif
+       struct pool vmk_vacache[VMK_VACACHE_COUNT]; /* kva cache */
+       struct pool_allocator vmk_vacache_allocator[VMK_VACACHE_COUNT]; /* ... 
and its allocator */
+       char vmk_vacache_name[VMK_VACACHE_COUNT][14];
 };
 #endif /* defined(_KERNEL) */
 
@@ -298,7 +299,6 @@
                    vaddr_t, struct uvm_mapent_reservation *);
 void           uvm_map_clip_end(struct vm_map *, struct vm_map_entry *,
                    vaddr_t, struct uvm_mapent_reservation *);
-struct vm_map  *uvm_map_create(pmap_t, vaddr_t, vaddr_t, int);
 int            uvm_map_extract(struct vm_map *, vaddr_t, vsize_t,
                    struct vm_map *, vaddr_t *, int);
 struct vm_map_entry *
@@ -308,6 +308,7 @@
                    vm_inherit_t);
 int            uvm_map_advice(struct vm_map *, vaddr_t, vaddr_t, int);
 void           uvm_map_init(void);
+void           uvm_map_init_caches(void);
 bool           uvm_map_lookup_entry(struct vm_map *, vaddr_t,
                    struct vm_map_entry **);
 void           uvm_map_reference(struct vm_map *);
Index: sys/uvm/uvm_mmap.c
===================================================================
RCS file: /cvsroot/src/sys/uvm/uvm_mmap.c,v
retrieving revision 1.134
diff -u -r1.134 uvm_mmap.c
--- sys/uvm/uvm_mmap.c  2 Feb 2011 20:07:25 -0000       1.134
+++ sys/uvm/uvm_mmap.c  4 Feb 2011 15:37:21 -0000
@@ -60,7 +60,6 @@
 #include <sys/mman.h>
 #include <sys/mount.h>
 #include <sys/proc.h>
-#include <sys/malloc.h>
 #include <sys/vnode.h>
 #include <sys/conf.h>
 #include <sys/stat.h>
Index: sys/uvm/uvm_page.c
===================================================================
RCS file: /cvsroot/src/sys/uvm/uvm_page.c,v
retrieving revision 1.171
diff -u -r1.171 uvm_page.c
--- sys/uvm/uvm_page.c  2 Feb 2011 17:53:42 -0000       1.171
+++ sys/uvm/uvm_page.c  4 Feb 2011 15:37:22 -0000
@@ -74,7 +74,6 @@
 
 #include <sys/param.h>
 #include <sys/systm.h>
-#include <sys/malloc.h>
 #include <sys/sched.h>
 #include <sys/kernel.h>
 #include <sys/vnode.h>
@@ -136,9 +135,7 @@
  * uvm_pageboot_alloc().
  */
 
-static bool have_recolored_pages /* = false */;
-
-MALLOC_DEFINE(M_VMPAGE, "VM page", "VM page");
+static size_t recolored_pages_memsize /* = 0 */;
 
 #ifdef DEBUG
 vaddr_t uvm_zerocheckkva;
@@ -765,7 +762,7 @@
 
        /*
         * check to see if this is a "preload" (i.e. uvm_page_init hasn't been
-        * called yet, so malloc is not available).
+        * called yet, so kmem is not available).
         */
 
        for (lcv = 0 ; lcv < vm_nphysmem ; lcv++) {
@@ -775,7 +772,7 @@
        preload = (lcv == vm_nphysmem);
 
        /*
-        * if VM is already running, attempt to malloc() vm_page structures
+        * if VM is already running, attempt to kmem_alloc vm_page structures
         */
 
        if (!preload) {
@@ -983,6 +980,7 @@
        struct pgfreelist gpgfl, pgfl;
        struct vm_page *pg;
        vsize_t bucketcount;
+       size_t bucketmemsize;
        int lcv, color, i, ocolors;
        struct uvm_cpu *ucpu;
 
@@ -995,8 +993,8 @@
        }
 
        bucketcount = newncolors * VM_NFREELIST;
-       bucketarray = malloc(bucketcount * sizeof(struct pgflbucket) * 2,
-           M_VMPAGE, M_NOWAIT);
+       bucketmemsize = bucketcount * sizeof(struct pgflbucket) * 2;
+       bucketarray = kmem_alloc(bucketmemsize, KM_SLEEP);
        cpuarray = bucketarray + bucketcount;
        if (bucketarray == NULL) {
                printf("WARNING: unable to allocate %ld page color buckets\n",
@@ -1009,7 +1007,7 @@
        /* Make sure we should still do this. */
        if (newncolors <= uvmexp.ncolors) {
                mutex_spin_exit(&uvm_fpageqlock);
-               free(bucketarray, M_VMPAGE);
+               kmem_free(bucketarray, bucketmemsize);
                return;
        }
 
@@ -1045,13 +1043,13 @@
                ucpu->page_free[lcv].pgfl_buckets = pgfl.pgfl_buckets;
        }
 
-       if (have_recolored_pages) {
+       if (recolored_pages_memsize) {
                mutex_spin_exit(&uvm_fpageqlock);
-               free(oldbucketarray, M_VMPAGE);
+               kmem_free(oldbucketarray, recolored_pages_memsize);
                return;
        }
 
-       have_recolored_pages = true;
+       recolored_pages_memsize = bucketmemsize;
        mutex_spin_exit(&uvm_fpageqlock);
 }
 
@@ -1078,8 +1076,8 @@
 
        /* Configure this CPU's free lists. */
        bucketcount = uvmexp.ncolors * VM_NFREELIST;
-       bucketarray = malloc(bucketcount * sizeof(struct pgflbucket),
-           M_VMPAGE, M_WAITOK);
+       bucketarray = kmem_alloc(bucketcount * sizeof(struct pgflbucket),
+           KM_SLEEP);
        ucpu = kmem_zalloc(sizeof(*ucpu), KM_SLEEP);
        uvm.cpus[cpu_index(ci)] = ucpu;
        ci->ci_data.cpu_uvm = ucpu;
Index: sys/uvm/uvm_pager.c
===================================================================
RCS file: /cvsroot/src/sys/uvm/uvm_pager.c,v
retrieving revision 1.99
diff -u -r1.99 uvm_pager.c
--- sys/uvm/uvm_pager.c 2 Feb 2011 15:13:34 -0000       1.99
+++ sys/uvm/uvm_pager.c 4 Feb 2011 15:37:22 -0000
@@ -41,7 +41,6 @@
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/proc.h>
-#include <sys/malloc.h>
 #include <sys/vnode.h>
 #include <sys/buf.h>
 
Index: sys/uvm/uvm_pglist.c
===================================================================
RCS file: /cvsroot/src/sys/uvm/uvm_pglist.c,v
retrieving revision 1.60
diff -u -r1.60 uvm_pglist.c
--- sys/uvm/uvm_pglist.c        26 Jan 2011 08:49:48 -0000      1.60
+++ sys/uvm/uvm_pglist.c        4 Feb 2011 15:37:22 -0000
@@ -39,7 +39,6 @@
 
 #include <sys/param.h>
 #include <sys/systm.h>
-#include <sys/malloc.h>
 #include <sys/proc.h>
 
 #include <uvm/uvm.h>
Index: sys/uvm/uvm_stat.h
===================================================================
RCS file: /cvsroot/src/sys/uvm/uvm_stat.h,v
retrieving revision 1.48
diff -u -r1.48 uvm_stat.h
--- sys/uvm/uvm_stat.h  2 Feb 2011 15:13:34 -0000       1.48
+++ sys/uvm/uvm_stat.h  4 Feb 2011 15:37:23 -0000
@@ -37,7 +37,7 @@
 #include <sys/queue.h>
 #ifdef UVMHIST
 #include <sys/cpu.h>
-#include <sys/malloc.h>
+#include <sys/kmem.h>
 #endif
 
 /*
@@ -65,7 +65,7 @@
        LIST_ENTRY(uvm_history) list;   /* link on list of all histories */
        unsigned int n;                 /* number of entries */
        unsigned int f;                 /* next free one */
-       struct uvm_history_ent *e;      /* the malloc'd entries */
+       struct uvm_history_ent *e;      /* the kmem_alloc'd entries */
 };
 
 LIST_HEAD(uvm_history_head, uvm_history);
@@ -114,8 +114,7 @@
        (NAME).n = (N); \
        (NAME).f = 0; \
        (NAME).e = (struct uvm_history_ent *) \
-               malloc(sizeof(struct uvm_history_ent) * (N), M_TEMP, \
-                   M_WAITOK); \
+               kmem_alloc(sizeof(struct uvm_history_ent) * (N), KM_SLEEP);
        memset((NAME).e, 0, sizeof(struct uvm_history_ent) * (N)); \
        LIST_INSERT_HEAD(&uvm_histories, &(NAME), list); \
 } while (/*CONSTCOND*/ 0)
Index: sys/uvm/uvm_swap.c
===================================================================
RCS file: /cvsroot/src/sys/uvm/uvm_swap.c,v
retrieving revision 1.153
diff -u -r1.153 uvm_swap.c
--- sys/uvm/uvm_swap.c  19 Nov 2010 06:44:47 -0000      1.153
+++ sys/uvm/uvm_swap.c  4 Feb 2011 15:37:23 -0000
@@ -46,13 +46,13 @@
 #include <sys/disklabel.h>
 #include <sys/errno.h>
 #include <sys/kernel.h>
-#include <sys/malloc.h>
 #include <sys/vnode.h>
 #include <sys/file.h>
 #include <sys/vmem.h>
 #include <sys/blist.h>
 #include <sys/mount.h>
 #include <sys/pool.h>
+#include <sys/kmem.h>
 #include <sys/syscallargs.h>
 #include <sys/swap.h>
 #include <sys/kauth.h>
@@ -208,7 +208,6 @@
 /*
  * local variables
  */
-MALLOC_DEFINE(M_VMSWAP, "VM swap", "VM swap structures");
 static vmem_t *swapmap;        /* controls the mapping of /dev/drum */
 
 /* list of all active swap devices [by priority] */
@@ -307,8 +306,8 @@
  * swaplist_insert: insert swap device "sdp" into the global list
  *
  * => caller must hold both swap_syscall_lock and uvm_swap_data_lock
- * => caller must provide a newly malloc'd swappri structure (we will
- *     FREE it if we don't need it... this it to prevent malloc blocking
+ * => caller must provide a newly kmem_alloc'd swappri structure (we will
+ *     FREE it if we don't need it... this it to prevent kmem_alloc blocking
  *     here while adding swap)
  */
 static void
@@ -344,7 +343,7 @@
                        LIST_INSERT_HEAD(&swap_priority, spp, spi_swappri);
        } else {
                /* we don't need a new priority structure, free it */
-               free(newspp, M_VMSWAP);
+               kmem_free(newspp, sizeof(*newspp));
        }
 
        /*
@@ -405,7 +404,7 @@
                    (void *)&spp->spi_swapdev)
                        continue;
                LIST_REMOVE(spp, spi_swappri);
-               free(spp, M_VMSWAP);
+               kmem_free(spp, sizeof(*spp));
        }
 }
 
@@ -467,7 +466,7 @@
         */
        rw_enter(&swap_syscall_lock, RW_WRITER);
 
-       userpath = malloc(SWAP_PATH_MAX, M_TEMP, M_WAITOK);
+       userpath = kmem_alloc(SWAP_PATH_MAX, KM_SLEEP);
        /*
         * we handle the non-priv NSWAP and STATS request first.
         *
@@ -511,12 +510,12 @@
                else
 #endif
                        len = sizeof(struct swapent) * misc;
-               sep = (struct swapent *)malloc(len, M_TEMP, M_WAITOK);
+               sep = (struct swapent *)kmem_alloc(len, KM_SLEEP);
 
                uvm_swap_stats_locked(SCARG(uap, cmd), sep, misc, retval);
                error = copyout(sep, SCARG(uap, arg), len);
 
-               free(sep, M_TEMP);
+               kmem_free(sep, len);
                UVMHIST_LOG(pdhist, "<- done SWAP_STATS", 0, 0, 0, 0);
                goto out;
        }
@@ -615,7 +614,7 @@
                 * any empty priority structures.
                 */
                priority = SCARG(uap, misc);
-               spp = malloc(sizeof *spp, M_VMSWAP, M_WAITOK);
+               spp = kmem_alloc(sizeof *spp, KM_SLEEP);
                mutex_enter(&uvm_swap_data_lock);
                if ((sdp = swaplist_find(vp, true)) == NULL) {
                        error = ENOENT;
@@ -625,7 +624,7 @@
                }
                mutex_exit(&uvm_swap_data_lock);
                if (error)
-                       free(spp, M_VMSWAP);
+                       kmem_free(spp, sizeof(*spp));
                break;
 
        case SWAP_ON:
@@ -638,8 +637,8 @@
                 */
 
                priority = SCARG(uap, misc);
-               sdp = malloc(sizeof *sdp, M_VMSWAP, M_WAITOK);
-               spp = malloc(sizeof *spp, M_VMSWAP, M_WAITOK);
+               sdp = kmem_alloc(sizeof *sdp, KM_SLEEP);
+               spp = kmem_alloc(sizeof *spp, KM_SLEEP);
                memset(sdp, 0, sizeof(*sdp));
                sdp->swd_flags = SWF_FAKE;
                sdp->swd_vp = vp;
@@ -650,15 +649,15 @@
                        error = EBUSY;
                        mutex_exit(&uvm_swap_data_lock);
                        bufq_free(sdp->swd_tab);
-                       free(sdp, M_VMSWAP);
-                       free(spp, M_VMSWAP);
+                       kmem_free(sdp, sizeof(*sdp));
+                       kmem_free(spp, sizeof(*spp));
                        break;
                }
                swaplist_insert(sdp, spp, priority);
                mutex_exit(&uvm_swap_data_lock);
 
                sdp->swd_pathlen = len;
-               sdp->swd_path = malloc(sdp->swd_pathlen, M_VMSWAP, M_WAITOK);
+               sdp->swd_path = kmem_alloc(sdp->swd_pathlen, KM_SLEEP);
                if (copystr(userpath, sdp->swd_path, sdp->swd_pathlen, 0) != 0)
                        panic("swapctl: copystr");
 
@@ -675,8 +674,8 @@
                        swaplist_trim();
                        mutex_exit(&uvm_swap_data_lock);
                        bufq_free(sdp->swd_tab);
-                       free(sdp->swd_path, M_VMSWAP);
-                       free(sdp, M_VMSWAP);
+                       kmem_free(sdp->swd_path, sdp->swd_pathlen);
+                       kmem_free(sdp, sizeof(*sdp));
                        break;
                }
                break;
@@ -715,7 +714,7 @@
        vput(vp);
 
 out:
-       free(userpath, M_TEMP);
+       kmem_free(userpath, SWAP_PATH_MAX);
        rw_exit(&swap_syscall_lock);
 
        UVMHIST_LOG(pdhist, "<- done!  error=%d", error, 0, 0, 0);
@@ -1112,7 +1111,7 @@
        vmem_free(swapmap, sdp->swd_drumoffset, sdp->swd_drumsize);
        blist_destroy(sdp->swd_blist);
        bufq_free(sdp->swd_tab);
-       free(sdp, M_VMSWAP);
+       kmem_free(sdp, sizeof(*sdp));
        return (0);
 }
 
Index: sys/uvm/uvm_vnode.c
===================================================================
RCS file: /cvsroot/src/sys/uvm/uvm_vnode.c,v
retrieving revision 1.94
diff -u -r1.94 uvm_vnode.c
--- sys/uvm/uvm_vnode.c 2 Feb 2011 20:07:25 -0000       1.94
+++ sys/uvm/uvm_vnode.c 4 Feb 2011 15:37:24 -0000
@@ -53,7 +53,6 @@
 #include <sys/systm.h>
 #include <sys/kernel.h>
 #include <sys/proc.h>
-#include <sys/malloc.h>
 #include <sys/vnode.h>
 #include <sys/disklabel.h>
 #include <sys/ioctl.h>
Index: usr.bin/vmstat/vmstat.c
===================================================================
RCS file: /cvsroot/src/usr.bin/vmstat/vmstat.c,v
retrieving revision 1.178
diff -u -r1.178 vmstat.c
--- usr.bin/vmstat/vmstat.c     31 Jan 2011 19:41:19 -0000      1.178
+++ usr.bin/vmstat/vmstat.c     4 Feb 2011 15:37:29 -0000
@@ -160,23 +160,19 @@
        { .n_name = "_stathz" },
 #define        X_NCHSTATS      3
        { .n_name = "_nchstats" },
-#define        X_KMEMSTAT      4
-       { .n_name = "_kmemstatistics" },
-#define        X_KMEMBUCKETS   5
-       { .n_name = "_kmembuckets" },
-#define        X_ALLEVENTS     6
+#define        X_ALLEVENTS     4
        { .n_name = "_allevents" },
-#define        X_POOLHEAD      7
+#define        X_POOLHEAD      5
        { .n_name = "_pool_head" },
-#define        X_UVMEXP        8
+#define        X_UVMEXP        6
        { .n_name = "_uvmexp" },
-#define        X_TIME_SECOND   9
+#define        X_TIME_SECOND   7
        { .n_name = "_time_second" },
-#define X_TIME         10
+#define X_TIME         8
        { .n_name = "_time" },
-#define X_CPU_QUEUE    11
+#define X_CPU_QUEUE    9
        { .n_name = "_cpu_queue" },
-#define        X_NL_SIZE       12
+#define        X_NL_SIZE       10
        { .n_name = NULL },
 };
 
@@ -301,7 +297,6 @@
 void   doevcnt(int verbose, int type);
 void   dohashstat(int, int, const char *);
 void   dointr(int verbose);
-void   domem(void);
 void   dopool(int, int);
 void   dopoolcache(void);
 void   dosum(void);
@@ -492,7 +487,6 @@
                                (void)putchar('\n');
                        }
                        if (todo & MEMSTAT) {
-                               domem();
                                dopool(verbose, wide);
                                (void)putchar('\n');
                        }
@@ -1224,120 +1218,6 @@
                    "Total", counttotal, counttotal / uptime);
 }
 
-static char memname[64];
-
-void
-domem(void)
-{
-       struct kmembuckets *kp;
-       struct malloc_type ks, *ksp;
-       int i, j;
-       int len, size, first;
-       long totuse = 0, totfree = 0, totreq = 0;
-       struct kmembuckets buckets[MINBUCKET + 16];
-
-       getnlist(MEMSTAT);
-       kread(namelist, X_KMEMBUCKETS, buckets, sizeof(buckets));
-       for (first = 1, i = MINBUCKET, kp = &buckets[i]; i < MINBUCKET + 16;
-           i++, kp++) {
-               if (kp->kb_calls == 0)
-                       continue;
-               if (first) {
-                       (void)printf("Memory statistics by bucket size\n");
-                       (void)printf(
-                "    Size   In Use   Free   Requests  HighWater  Couldfree\n");
-                       first = 0;
-               }
-               size = 1 << i;
-               (void)printf("%8d %8ld %6ld %10ld %7ld %10ld\n", size,
-                   kp->kb_total - kp->kb_totalfree,
-                   kp->kb_totalfree, kp->kb_calls,
-                   kp->kb_highwat, kp->kb_couldfree);
-               totfree += size * kp->kb_totalfree;
-       }
-
-       /*
-        * If kmem statistics are not being gathered by the kernel,
-        * first will still be 1.
-        */
-       if (first) {
-               warnx("Kmem statistics are not being gathered by the kernel.");
-               return;
-       }
-
-       (void)printf("\nMemory usage type by bucket size\n");
-       (void)printf("    Size  Type(s)\n");
-       kp = &buckets[MINBUCKET];
-       for (j =  1 << MINBUCKET; j < 1 << (MINBUCKET + 16); j <<= 1, kp++) {
-               if (kp->kb_calls == 0)
-                       continue;
-               first = 1;
-               len = 8;
-               for (kread(namelist, X_KMEMSTAT, &ksp, sizeof(ksp));
-                    ksp != NULL; ksp = ks.ks_next) {
-                       deref_kptr(ksp, &ks, sizeof(ks), "malloc type");
-                       if (ks.ks_calls == 0)
-                               continue;
-                       if ((ks.ks_size & j) == 0)
-                               continue;
-                       deref_kptr(ks.ks_shortdesc, memname,
-                           sizeof(memname), "malloc type name");
-                       len += 2 + strlen(memname);
-                       if (first)
-                               (void)printf("%8d  %s", j, memname);
-                       else
-                               (void)printf(",");
-                       if (len >= 80) {
-                               (void)printf("\n\t ");
-                               len = 10 + strlen(memname);
-                       }
-                       if (!first)
-                               (void)printf(" %s", memname);
-                       first = 0;
-               }
-               (void)putchar('\n');
-       }
-
-       (void)printf(
-           "\nMemory statistics by type                                Type  
Kern\n");
-       (void)printf(
-"           Type InUse  MemUse HighUse   Limit   Requests Limit Limit 
Size(s)\n");
-       for (kread(namelist, X_KMEMSTAT, &ksp, sizeof(ksp));
-            ksp != NULL; ksp = ks.ks_next) {
-               deref_kptr(ksp, &ks, sizeof(ks), "malloc type");
-               if (ks.ks_calls == 0)
-                       continue;
-               deref_kptr(ks.ks_shortdesc, memname,
-                   sizeof(memname), "malloc type name");
-               (void)printf("%15s %5ld %6ldK %6ldK %6ldK %10ld %5u %5u",
-                   memname,
-                   ks.ks_inuse, howmany(ks.ks_memuse, KILO),
-                   howmany(ks.ks_maxused, KILO),
-                   howmany(ks.ks_limit, KILO), ks.ks_calls,
-                   ks.ks_limblocks, ks.ks_mapblocks);
-               first = 1;
-               for (j = 1 << MINBUCKET, i = MINBUCKET;
-                    j < 1 << (MINBUCKET + 16);
-                    j <<= 1, i++)
-               {
-                       if ((ks.ks_size & j) == 0)
-                               continue;
-                       if (first)
-                               (void)printf(" %d", j);
-                       else
-                               (void)printf(",%d", j);
-                       first = 0;
-                       (void)printf(":%u", ks.ks_active[i - MINBUCKET]);
-               }
-               (void)printf("\n");
-               totuse += ks.ks_memuse;
-               totreq += ks.ks_calls;
-       }
-       (void)printf("\nMemory totals:  In Use    Free    Requests\n");
-       (void)printf("              %7ldK %6ldK    %8ld\n\n",
-           howmany(totuse, KILO), howmany(totfree, KILO), totreq);
-}
-
 void
 dopool(int verbose, int wide)
 {


Home | Main Index | Thread Index | Old Index