Home | History | Annotate | Line # | Download | only in uvm
uvm_km.c revision 1.108.2.1
      1  1.108.2.1    cherry /*	$NetBSD: uvm_km.c,v 1.108.2.1 2011/06/23 14:20:35 cherry Exp $	*/
      2        1.1       mrg 
      3       1.47       chs /*
      4        1.1       mrg  * Copyright (c) 1997 Charles D. Cranor and Washington University.
      5       1.47       chs  * Copyright (c) 1991, 1993, The Regents of the University of California.
      6        1.1       mrg  *
      7        1.1       mrg  * All rights reserved.
      8        1.1       mrg  *
      9        1.1       mrg  * This code is derived from software contributed to Berkeley by
     10        1.1       mrg  * The Mach Operating System project at Carnegie-Mellon University.
     11        1.1       mrg  *
     12        1.1       mrg  * Redistribution and use in source and binary forms, with or without
     13        1.1       mrg  * modification, are permitted provided that the following conditions
     14        1.1       mrg  * are met:
     15        1.1       mrg  * 1. Redistributions of source code must retain the above copyright
     16        1.1       mrg  *    notice, this list of conditions and the following disclaimer.
     17        1.1       mrg  * 2. Redistributions in binary form must reproduce the above copyright
     18        1.1       mrg  *    notice, this list of conditions and the following disclaimer in the
     19        1.1       mrg  *    documentation and/or other materials provided with the distribution.
     20      1.108     chuck  * 3. Neither the name of the University nor the names of its contributors
     21        1.1       mrg  *    may be used to endorse or promote products derived from this software
     22        1.1       mrg  *    without specific prior written permission.
     23        1.1       mrg  *
     24        1.1       mrg  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     25        1.1       mrg  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     26        1.1       mrg  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     27        1.1       mrg  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     28        1.1       mrg  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     29        1.1       mrg  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     30        1.1       mrg  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     31        1.1       mrg  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32        1.1       mrg  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     33        1.1       mrg  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     34        1.1       mrg  * SUCH DAMAGE.
     35        1.1       mrg  *
     36        1.1       mrg  *	@(#)vm_kern.c   8.3 (Berkeley) 1/12/94
     37        1.4       mrg  * from: Id: uvm_km.c,v 1.1.2.14 1998/02/06 05:19:27 chs Exp
     38        1.1       mrg  *
     39        1.1       mrg  *
     40        1.1       mrg  * Copyright (c) 1987, 1990 Carnegie-Mellon University.
     41        1.1       mrg  * All rights reserved.
     42       1.47       chs  *
     43        1.1       mrg  * Permission to use, copy, modify and distribute this software and
     44        1.1       mrg  * its documentation is hereby granted, provided that both the copyright
     45        1.1       mrg  * notice and this permission notice appear in all copies of the
     46        1.1       mrg  * software, derivative works or modified versions, and any portions
     47        1.1       mrg  * thereof, and that both notices appear in supporting documentation.
     48       1.47       chs  *
     49       1.47       chs  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     50       1.47       chs  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     51        1.1       mrg  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     52       1.47       chs  *
     53        1.1       mrg  * Carnegie Mellon requests users of this software to return to
     54        1.1       mrg  *
     55        1.1       mrg  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     56        1.1       mrg  *  School of Computer Science
     57        1.1       mrg  *  Carnegie Mellon University
     58        1.1       mrg  *  Pittsburgh PA 15213-3890
     59        1.1       mrg  *
     60        1.1       mrg  * any improvements or extensions that they make and grant Carnegie the
     61        1.1       mrg  * rights to redistribute these changes.
     62        1.1       mrg  */
     63        1.6       mrg 
     64        1.1       mrg /*
     65        1.1       mrg  * uvm_km.c: handle kernel memory allocation and management
     66        1.1       mrg  */
     67        1.1       mrg 
     68        1.7     chuck /*
     69        1.7     chuck  * overview of kernel memory management:
     70        1.7     chuck  *
     71        1.7     chuck  * the kernel virtual address space is mapped by "kernel_map."   kernel_map
     72       1.62   thorpej  * starts at VM_MIN_KERNEL_ADDRESS and goes to VM_MAX_KERNEL_ADDRESS.
     73       1.62   thorpej  * note that VM_MIN_KERNEL_ADDRESS is equal to vm_map_min(kernel_map).
     74        1.7     chuck  *
     75       1.47       chs  * the kernel_map has several "submaps."   submaps can only appear in
     76        1.7     chuck  * the kernel_map (user processes can't use them).   submaps "take over"
     77        1.7     chuck  * the management of a sub-range of the kernel's address space.  submaps
     78        1.7     chuck  * are typically allocated at boot time and are never released.   kernel
     79       1.47       chs  * virtual address space that is mapped by a submap is locked by the
     80        1.7     chuck  * submap's lock -- not the kernel_map's lock.
     81        1.7     chuck  *
     82        1.7     chuck  * thus, the useful feature of submaps is that they allow us to break
     83        1.7     chuck  * up the locking and protection of the kernel address space into smaller
     84        1.7     chuck  * chunks.
     85        1.7     chuck  *
     86        1.7     chuck  * the vm system has several standard kernel submaps, including:
     87        1.7     chuck  *   kmem_map => contains only wired kernel memory for the kernel
     88       1.97        ad  *		malloc.
     89        1.7     chuck  *   pager_map => used to map "buf" structures into kernel space
     90        1.7     chuck  *   exec_map => used during exec to handle exec args
     91        1.7     chuck  *   etc...
     92        1.7     chuck  *
     93        1.7     chuck  * the kernel allocates its private memory out of special uvm_objects whose
     94        1.7     chuck  * reference count is set to UVM_OBJ_KERN (thus indicating that the objects
     95        1.7     chuck  * are "special" and never die).   all kernel objects should be thought of
     96       1.47       chs  * as large, fixed-sized, sparsely populated uvm_objects.   each kernel
     97       1.62   thorpej  * object is equal to the size of kernel virtual address space (i.e. the
     98       1.62   thorpej  * value "VM_MAX_KERNEL_ADDRESS - VM_MIN_KERNEL_ADDRESS").
     99        1.7     chuck  *
    100      1.101     pooka  * note that just because a kernel object spans the entire kernel virtual
    101        1.7     chuck  * address space doesn't mean that it has to be mapped into the entire space.
    102       1.47       chs  * large chunks of a kernel object's space go unused either because
    103       1.47       chs  * that area of kernel VM is unmapped, or there is some other type of
    104        1.7     chuck  * object mapped into that range (e.g. a vnode).    for submap's kernel
    105        1.7     chuck  * objects, the only part of the object that can ever be populated is the
    106        1.7     chuck  * offsets that are managed by the submap.
    107        1.7     chuck  *
    108        1.7     chuck  * note that the "offset" in a kernel object is always the kernel virtual
    109       1.62   thorpej  * address minus the VM_MIN_KERNEL_ADDRESS (aka vm_map_min(kernel_map)).
    110        1.7     chuck  * example:
    111       1.62   thorpej  *   suppose VM_MIN_KERNEL_ADDRESS is 0xf8000000 and the kernel does a
    112        1.7     chuck  *   uvm_km_alloc(kernel_map, PAGE_SIZE) [allocate 1 wired down page in the
    113        1.7     chuck  *   kernel map].    if uvm_km_alloc returns virtual address 0xf8235000,
    114        1.7     chuck  *   then that means that the page at offset 0x235000 in kernel_object is
    115       1.47       chs  *   mapped at 0xf8235000.
    116        1.7     chuck  *
    117        1.7     chuck  * kernel object have one other special property: when the kernel virtual
    118        1.7     chuck  * memory mapping them is unmapped, the backing memory in the object is
    119        1.7     chuck  * freed right away.   this is done with the uvm_km_pgremove() function.
    120        1.7     chuck  * this has to be done because there is no backing store for kernel pages
    121        1.7     chuck  * and no need to save them after they are no longer referenced.
    122        1.7     chuck  */
    123       1.55     lukem 
    124       1.55     lukem #include <sys/cdefs.h>
    125  1.108.2.1    cherry __KERNEL_RCSID(0, "$NetBSD: uvm_km.c,v 1.108.2.1 2011/06/23 14:20:35 cherry Exp $");
    126       1.55     lukem 
    127       1.55     lukem #include "opt_uvmhist.h"
    128        1.7     chuck 
    129        1.1       mrg #include <sys/param.h>
    130       1.71      yamt #include <sys/malloc.h>
    131        1.1       mrg #include <sys/systm.h>
    132        1.1       mrg #include <sys/proc.h>
    133       1.72      yamt #include <sys/pool.h>
    134        1.1       mrg 
    135        1.1       mrg #include <uvm/uvm.h>
    136        1.1       mrg 
    137        1.1       mrg /*
    138        1.1       mrg  * global data structures
    139        1.1       mrg  */
    140        1.1       mrg 
    141       1.49       chs struct vm_map *kernel_map = NULL;
    142        1.1       mrg 
    143        1.1       mrg /*
    144        1.1       mrg  * local data structues
    145        1.1       mrg  */
    146        1.1       mrg 
    147       1.71      yamt static struct vm_map_kernel	kernel_map_store;
    148       1.70      yamt static struct vm_map_entry	kernel_first_mapent_store;
    149        1.1       mrg 
    150       1.72      yamt #if !defined(PMAP_MAP_POOLPAGE)
    151       1.72      yamt 
    152       1.72      yamt /*
    153       1.72      yamt  * kva cache
    154       1.72      yamt  *
    155       1.72      yamt  * XXX maybe it's better to do this at the uvm_map layer.
    156       1.72      yamt  */
    157       1.72      yamt 
    158       1.72      yamt #define	KM_VACACHE_SIZE	(32 * PAGE_SIZE) /* XXX tune */
    159       1.72      yamt 
    160       1.72      yamt static void *km_vacache_alloc(struct pool *, int);
    161       1.72      yamt static void km_vacache_free(struct pool *, void *);
    162       1.72      yamt static void km_vacache_init(struct vm_map *, const char *, size_t);
    163       1.72      yamt 
    164       1.72      yamt /* XXX */
    165       1.72      yamt #define	KM_VACACHE_POOL_TO_MAP(pp) \
    166       1.72      yamt 	((struct vm_map *)((char *)(pp) - \
    167       1.72      yamt 	    offsetof(struct vm_map_kernel, vmk_vacache)))
    168       1.72      yamt 
    169       1.72      yamt static void *
    170       1.72      yamt km_vacache_alloc(struct pool *pp, int flags)
    171       1.72      yamt {
    172       1.72      yamt 	vaddr_t va;
    173       1.72      yamt 	size_t size;
    174       1.72      yamt 	struct vm_map *map;
    175       1.72      yamt 	size = pp->pr_alloc->pa_pagesz;
    176       1.72      yamt 
    177       1.72      yamt 	map = KM_VACACHE_POOL_TO_MAP(pp);
    178       1.72      yamt 
    179       1.73      yamt 	va = vm_map_min(map); /* hint */
    180       1.72      yamt 	if (uvm_map(map, &va, size, NULL, UVM_UNKNOWN_OFFSET, size,
    181       1.74      yamt 	    UVM_MAPFLAG(UVM_PROT_ALL, UVM_PROT_ALL, UVM_INH_NONE,
    182       1.72      yamt 	    UVM_ADV_RANDOM, UVM_FLAG_QUANTUM |
    183       1.88      yamt 	    ((flags & PR_WAITOK) ? UVM_FLAG_WAITVA :
    184       1.88      yamt 	    UVM_FLAG_TRYLOCK | UVM_FLAG_NOWAIT))))
    185       1.72      yamt 		return NULL;
    186       1.72      yamt 
    187       1.72      yamt 	return (void *)va;
    188       1.72      yamt }
    189       1.72      yamt 
    190       1.72      yamt static void
    191       1.72      yamt km_vacache_free(struct pool *pp, void *v)
    192       1.72      yamt {
    193       1.72      yamt 	vaddr_t va = (vaddr_t)v;
    194       1.72      yamt 	size_t size = pp->pr_alloc->pa_pagesz;
    195       1.72      yamt 	struct vm_map *map;
    196       1.72      yamt 
    197       1.72      yamt 	map = KM_VACACHE_POOL_TO_MAP(pp);
    198       1.78      yamt 	uvm_unmap1(map, va, va + size, UVM_FLAG_QUANTUM|UVM_FLAG_VAONLY);
    199       1.72      yamt }
    200       1.72      yamt 
    201       1.72      yamt /*
    202       1.72      yamt  * km_vacache_init: initialize kva cache.
    203       1.72      yamt  */
    204       1.72      yamt 
    205       1.72      yamt static void
    206       1.72      yamt km_vacache_init(struct vm_map *map, const char *name, size_t size)
    207       1.72      yamt {
    208       1.72      yamt 	struct vm_map_kernel *vmk;
    209       1.72      yamt 	struct pool *pp;
    210       1.72      yamt 	struct pool_allocator *pa;
    211       1.94        ad 	int ipl;
    212       1.72      yamt 
    213       1.72      yamt 	KASSERT(VM_MAP_IS_KERNEL(map));
    214       1.72      yamt 	KASSERT(size < (vm_map_max(map) - vm_map_min(map)) / 2); /* sanity */
    215       1.72      yamt 
    216       1.97        ad 
    217       1.72      yamt 	vmk = vm_map_to_kernel(map);
    218       1.72      yamt 	pp = &vmk->vmk_vacache;
    219       1.72      yamt 	pa = &vmk->vmk_vacache_allocator;
    220       1.72      yamt 	memset(pa, 0, sizeof(*pa));
    221       1.72      yamt 	pa->pa_alloc = km_vacache_alloc;
    222       1.72      yamt 	pa->pa_free = km_vacache_free;
    223       1.72      yamt 	pa->pa_pagesz = (unsigned int)size;
    224       1.88      yamt 	pa->pa_backingmap = map;
    225       1.88      yamt 	pa->pa_backingmapptr = NULL;
    226       1.94        ad 
    227       1.94        ad 	if ((map->flags & VM_MAP_INTRSAFE) != 0)
    228       1.94        ad 		ipl = IPL_VM;
    229       1.94        ad 	else
    230       1.94        ad 		ipl = IPL_NONE;
    231       1.94        ad 
    232       1.94        ad 	pool_init(pp, PAGE_SIZE, 0, 0, PR_NOTOUCH | PR_RECURSIVE, name, pa,
    233       1.94        ad 	    ipl);
    234       1.72      yamt }
    235       1.72      yamt 
    236       1.72      yamt void
    237       1.72      yamt uvm_km_vacache_init(struct vm_map *map, const char *name, size_t size)
    238       1.72      yamt {
    239       1.72      yamt 
    240       1.72      yamt 	map->flags |= VM_MAP_VACACHE;
    241       1.72      yamt 	if (size == 0)
    242       1.72      yamt 		size = KM_VACACHE_SIZE;
    243       1.72      yamt 	km_vacache_init(map, name, size);
    244       1.72      yamt }
    245       1.72      yamt 
    246       1.72      yamt #else /* !defined(PMAP_MAP_POOLPAGE) */
    247       1.72      yamt 
    248       1.72      yamt void
    249       1.92      yamt uvm_km_vacache_init(struct vm_map *map, const char *name, size_t size)
    250       1.72      yamt {
    251       1.72      yamt 
    252       1.72      yamt 	/* nothing */
    253       1.72      yamt }
    254       1.72      yamt 
    255       1.72      yamt #endif /* !defined(PMAP_MAP_POOLPAGE) */
    256       1.72      yamt 
    257       1.88      yamt void
    258       1.92      yamt uvm_km_va_drain(struct vm_map *map, uvm_flag_t flags)
    259       1.88      yamt {
    260       1.88      yamt 	struct vm_map_kernel *vmk = vm_map_to_kernel(map);
    261       1.88      yamt 
    262       1.88      yamt 	callback_run_roundrobin(&vmk->vmk_reclaim_callback, NULL);
    263       1.88      yamt }
    264       1.88      yamt 
    265        1.1       mrg /*
    266        1.1       mrg  * uvm_km_init: init kernel maps and objects to reflect reality (i.e.
    267        1.1       mrg  * KVM already allocated for text, data, bss, and static data structures).
    268        1.1       mrg  *
    269       1.62   thorpej  * => KVM is defined by VM_MIN_KERNEL_ADDRESS/VM_MAX_KERNEL_ADDRESS.
    270       1.82  christos  *    we assume that [vmin -> start] has already been allocated and that
    271       1.62   thorpej  *    "end" is the end.
    272        1.1       mrg  */
    273        1.1       mrg 
    274        1.8       mrg void
    275       1.83   thorpej uvm_km_init(vaddr_t start, vaddr_t end)
    276        1.1       mrg {
    277       1.62   thorpej 	vaddr_t base = VM_MIN_KERNEL_ADDRESS;
    278       1.27   thorpej 
    279       1.27   thorpej 	/*
    280       1.27   thorpej 	 * next, init kernel memory objects.
    281        1.8       mrg 	 */
    282        1.1       mrg 
    283        1.8       mrg 	/* kernel_object: for pageable anonymous kernel memory */
    284       1.34       chs 	uao_init();
    285       1.95        ad 	uvm_kernel_object = uao_create(VM_MAX_KERNEL_ADDRESS -
    286       1.62   thorpej 				 VM_MIN_KERNEL_ADDRESS, UAO_FLAG_KERNOBJ);
    287        1.1       mrg 
    288       1.24   thorpej 	/*
    289       1.56   thorpej 	 * init the map and reserve any space that might already
    290       1.56   thorpej 	 * have been allocated kernel space before installing.
    291        1.8       mrg 	 */
    292        1.1       mrg 
    293       1.71      yamt 	uvm_map_setup_kernel(&kernel_map_store, base, end, VM_MAP_PAGEABLE);
    294       1.71      yamt 	kernel_map_store.vmk_map.pmap = pmap_kernel();
    295       1.70      yamt 	if (start != base) {
    296       1.70      yamt 		int error;
    297       1.70      yamt 		struct uvm_map_args args;
    298       1.70      yamt 
    299       1.71      yamt 		error = uvm_map_prepare(&kernel_map_store.vmk_map,
    300       1.71      yamt 		    base, start - base,
    301       1.70      yamt 		    NULL, UVM_UNKNOWN_OFFSET, 0,
    302       1.62   thorpej 		    UVM_MAPFLAG(UVM_PROT_ALL, UVM_PROT_ALL, UVM_INH_NONE,
    303       1.70      yamt 		    		UVM_ADV_RANDOM, UVM_FLAG_FIXED), &args);
    304       1.70      yamt 		if (!error) {
    305       1.70      yamt 			kernel_first_mapent_store.flags =
    306       1.70      yamt 			    UVM_MAP_KERNEL | UVM_MAP_FIRST;
    307       1.71      yamt 			error = uvm_map_enter(&kernel_map_store.vmk_map, &args,
    308       1.70      yamt 			    &kernel_first_mapent_store);
    309       1.70      yamt 		}
    310       1.70      yamt 
    311       1.70      yamt 		if (error)
    312       1.70      yamt 			panic(
    313       1.70      yamt 			    "uvm_km_init: could not reserve space for kernel");
    314       1.70      yamt 	}
    315       1.47       chs 
    316        1.8       mrg 	/*
    317        1.8       mrg 	 * install!
    318        1.8       mrg 	 */
    319        1.8       mrg 
    320       1.71      yamt 	kernel_map = &kernel_map_store.vmk_map;
    321       1.72      yamt 	uvm_km_vacache_init(kernel_map, "kvakernel", 0);
    322        1.1       mrg }
    323        1.1       mrg 
    324        1.1       mrg /*
    325        1.1       mrg  * uvm_km_suballoc: allocate a submap in the kernel map.   once a submap
    326        1.1       mrg  * is allocated all references to that area of VM must go through it.  this
    327        1.1       mrg  * allows the locking of VAs in kernel_map to be broken up into regions.
    328        1.1       mrg  *
    329       1.82  christos  * => if `fixed' is true, *vmin specifies where the region described
    330        1.5   thorpej  *      by the submap must start
    331        1.1       mrg  * => if submap is non NULL we use that as the submap, otherwise we
    332        1.1       mrg  *	alloc a new map
    333        1.1       mrg  */
    334       1.78      yamt 
    335        1.8       mrg struct vm_map *
    336       1.83   thorpej uvm_km_suballoc(struct vm_map *map, vaddr_t *vmin /* IN/OUT */,
    337       1.93   thorpej     vaddr_t *vmax /* OUT */, vsize_t size, int flags, bool fixed,
    338       1.83   thorpej     struct vm_map_kernel *submap)
    339        1.8       mrg {
    340        1.8       mrg 	int mapflags = UVM_FLAG_NOMERGE | (fixed ? UVM_FLAG_FIXED : 0);
    341        1.1       mrg 
    342       1.71      yamt 	KASSERT(vm_map_pmap(map) == pmap_kernel());
    343       1.71      yamt 
    344        1.8       mrg 	size = round_page(size);	/* round up to pagesize */
    345       1.87      yamt 	size += uvm_mapent_overhead(size, flags);
    346        1.1       mrg 
    347        1.8       mrg 	/*
    348        1.8       mrg 	 * first allocate a blank spot in the parent map
    349        1.8       mrg 	 */
    350        1.8       mrg 
    351       1.82  christos 	if (uvm_map(map, vmin, size, NULL, UVM_UNKNOWN_OFFSET, 0,
    352        1.8       mrg 	    UVM_MAPFLAG(UVM_PROT_ALL, UVM_PROT_ALL, UVM_INH_NONE,
    353       1.43       chs 	    UVM_ADV_RANDOM, mapflags)) != 0) {
    354        1.8       mrg 	       panic("uvm_km_suballoc: unable to allocate space in parent map");
    355        1.8       mrg 	}
    356        1.8       mrg 
    357        1.8       mrg 	/*
    358       1.82  christos 	 * set VM bounds (vmin is filled in by uvm_map)
    359        1.8       mrg 	 */
    360        1.1       mrg 
    361       1.82  christos 	*vmax = *vmin + size;
    362        1.5   thorpej 
    363        1.8       mrg 	/*
    364        1.8       mrg 	 * add references to pmap and create or init the submap
    365        1.8       mrg 	 */
    366        1.1       mrg 
    367        1.8       mrg 	pmap_reference(vm_map_pmap(map));
    368        1.8       mrg 	if (submap == NULL) {
    369       1.71      yamt 		submap = malloc(sizeof(*submap), M_VMMAP, M_WAITOK);
    370        1.8       mrg 		if (submap == NULL)
    371        1.8       mrg 			panic("uvm_km_suballoc: unable to create submap");
    372        1.8       mrg 	}
    373       1.82  christos 	uvm_map_setup_kernel(submap, *vmin, *vmax, flags);
    374       1.71      yamt 	submap->vmk_map.pmap = vm_map_pmap(map);
    375        1.1       mrg 
    376        1.8       mrg 	/*
    377        1.8       mrg 	 * now let uvm_map_submap plug in it...
    378        1.8       mrg 	 */
    379        1.1       mrg 
    380       1.82  christos 	if (uvm_map_submap(map, *vmin, *vmax, &submap->vmk_map) != 0)
    381        1.8       mrg 		panic("uvm_km_suballoc: submap allocation failed");
    382        1.1       mrg 
    383       1.71      yamt 	return(&submap->vmk_map);
    384        1.1       mrg }
    385        1.1       mrg 
    386        1.1       mrg /*
    387        1.1       mrg  * uvm_km_pgremove: remove pages from a kernel uvm_object.
    388        1.1       mrg  *
    389        1.1       mrg  * => when you unmap a part of anonymous kernel memory you want to toss
    390        1.1       mrg  *    the pages right away.    (this gets called from uvm_unmap_...).
    391        1.1       mrg  */
    392        1.1       mrg 
    393        1.8       mrg void
    394       1.83   thorpej uvm_km_pgremove(vaddr_t startva, vaddr_t endva)
    395        1.1       mrg {
    396       1.95        ad 	struct uvm_object * const uobj = uvm_kernel_object;
    397       1.78      yamt 	const voff_t start = startva - vm_map_min(kernel_map);
    398       1.78      yamt 	const voff_t end = endva - vm_map_min(kernel_map);
    399       1.53       chs 	struct vm_page *pg;
    400       1.52       chs 	voff_t curoff, nextoff;
    401       1.53       chs 	int swpgonlydelta = 0;
    402        1.8       mrg 	UVMHIST_FUNC("uvm_km_pgremove"); UVMHIST_CALLED(maphist);
    403        1.1       mrg 
    404       1.78      yamt 	KASSERT(VM_MIN_KERNEL_ADDRESS <= startva);
    405       1.78      yamt 	KASSERT(startva < endva);
    406       1.86      yamt 	KASSERT(endva <= VM_MAX_KERNEL_ADDRESS);
    407       1.78      yamt 
    408  1.108.2.1    cherry 	mutex_enter(uobj->vmobjlock);
    409        1.3       chs 
    410       1.52       chs 	for (curoff = start; curoff < end; curoff = nextoff) {
    411       1.52       chs 		nextoff = curoff + PAGE_SIZE;
    412       1.52       chs 		pg = uvm_pagelookup(uobj, curoff);
    413       1.53       chs 		if (pg != NULL && pg->flags & PG_BUSY) {
    414       1.52       chs 			pg->flags |= PG_WANTED;
    415  1.108.2.1    cherry 			UVM_UNLOCK_AND_WAIT(pg, uobj->vmobjlock, 0,
    416       1.52       chs 				    "km_pgrm", 0);
    417  1.108.2.1    cherry 			mutex_enter(uobj->vmobjlock);
    418       1.52       chs 			nextoff = curoff;
    419        1.8       mrg 			continue;
    420       1.52       chs 		}
    421        1.8       mrg 
    422       1.52       chs 		/*
    423       1.52       chs 		 * free the swap slot, then the page.
    424       1.52       chs 		 */
    425        1.8       mrg 
    426       1.53       chs 		if (pg == NULL &&
    427       1.64        pk 		    uao_find_swslot(uobj, curoff >> PAGE_SHIFT) > 0) {
    428       1.53       chs 			swpgonlydelta++;
    429       1.53       chs 		}
    430       1.52       chs 		uao_dropswap(uobj, curoff >> PAGE_SHIFT);
    431       1.53       chs 		if (pg != NULL) {
    432       1.97        ad 			mutex_enter(&uvm_pageqlock);
    433       1.53       chs 			uvm_pagefree(pg);
    434       1.97        ad 			mutex_exit(&uvm_pageqlock);
    435       1.53       chs 		}
    436        1.8       mrg 	}
    437  1.108.2.1    cherry 	mutex_exit(uobj->vmobjlock);
    438        1.8       mrg 
    439       1.54       chs 	if (swpgonlydelta > 0) {
    440       1.95        ad 		mutex_enter(&uvm_swap_data_lock);
    441       1.54       chs 		KASSERT(uvmexp.swpgonly >= swpgonlydelta);
    442       1.54       chs 		uvmexp.swpgonly -= swpgonlydelta;
    443       1.95        ad 		mutex_exit(&uvm_swap_data_lock);
    444       1.54       chs 	}
    445       1.24   thorpej }
    446       1.24   thorpej 
    447       1.24   thorpej 
    448       1.24   thorpej /*
    449       1.78      yamt  * uvm_km_pgremove_intrsafe: like uvm_km_pgremove(), but for non object backed
    450       1.78      yamt  *    regions.
    451       1.24   thorpej  *
    452       1.24   thorpej  * => when you unmap a part of anonymous kernel memory you want to toss
    453       1.52       chs  *    the pages right away.    (this is called from uvm_unmap_...).
    454       1.24   thorpej  * => none of the pages will ever be busy, and none of them will ever
    455       1.52       chs  *    be on the active or inactive queues (because they have no object).
    456       1.24   thorpej  */
    457       1.24   thorpej 
    458       1.24   thorpej void
    459      1.102        ad uvm_km_pgremove_intrsafe(struct vm_map *map, vaddr_t start, vaddr_t end)
    460       1.24   thorpej {
    461       1.52       chs 	struct vm_page *pg;
    462       1.52       chs 	paddr_t pa;
    463       1.24   thorpej 	UVMHIST_FUNC("uvm_km_pgremove_intrsafe"); UVMHIST_CALLED(maphist);
    464       1.24   thorpej 
    465      1.102        ad 	KASSERT(VM_MAP_IS_KERNEL(map));
    466      1.102        ad 	KASSERT(vm_map_min(map) <= start);
    467       1.78      yamt 	KASSERT(start < end);
    468      1.102        ad 	KASSERT(end <= vm_map_max(map));
    469       1.78      yamt 
    470       1.52       chs 	for (; start < end; start += PAGE_SIZE) {
    471       1.52       chs 		if (!pmap_extract(pmap_kernel(), start, &pa)) {
    472       1.24   thorpej 			continue;
    473       1.40       chs 		}
    474       1.52       chs 		pg = PHYS_TO_VM_PAGE(pa);
    475       1.52       chs 		KASSERT(pg);
    476       1.52       chs 		KASSERT(pg->uobject == NULL && pg->uanon == NULL);
    477       1.52       chs 		uvm_pagefree(pg);
    478       1.24   thorpej 	}
    479        1.1       mrg }
    480        1.1       mrg 
    481       1.78      yamt #if defined(DEBUG)
    482       1.78      yamt void
    483      1.102        ad uvm_km_check_empty(struct vm_map *map, vaddr_t start, vaddr_t end)
    484       1.78      yamt {
    485      1.102        ad 	struct vm_page *pg;
    486       1.78      yamt 	vaddr_t va;
    487       1.78      yamt 	paddr_t pa;
    488       1.78      yamt 
    489      1.102        ad 	KDASSERT(VM_MAP_IS_KERNEL(map));
    490      1.102        ad 	KDASSERT(vm_map_min(map) <= start);
    491       1.78      yamt 	KDASSERT(start < end);
    492      1.102        ad 	KDASSERT(end <= vm_map_max(map));
    493       1.78      yamt 
    494       1.78      yamt 	for (va = start; va < end; va += PAGE_SIZE) {
    495       1.78      yamt 		if (pmap_extract(pmap_kernel(), va, &pa)) {
    496       1.81    simonb 			panic("uvm_km_check_empty: va %p has pa 0x%llx",
    497       1.81    simonb 			    (void *)va, (long long)pa);
    498       1.78      yamt 		}
    499      1.102        ad 		if ((map->flags & VM_MAP_INTRSAFE) == 0) {
    500  1.108.2.1    cherry 			mutex_enter(uvm_kernel_object->vmobjlock);
    501       1.96        ad 			pg = uvm_pagelookup(uvm_kernel_object,
    502       1.78      yamt 			    va - vm_map_min(kernel_map));
    503  1.108.2.1    cherry 			mutex_exit(uvm_kernel_object->vmobjlock);
    504       1.78      yamt 			if (pg) {
    505       1.78      yamt 				panic("uvm_km_check_empty: "
    506       1.78      yamt 				    "has page hashed at %p", (const void *)va);
    507       1.78      yamt 			}
    508       1.78      yamt 		}
    509       1.78      yamt 	}
    510       1.78      yamt }
    511       1.78      yamt #endif /* defined(DEBUG) */
    512        1.1       mrg 
    513        1.1       mrg /*
    514       1.78      yamt  * uvm_km_alloc: allocate an area of kernel memory.
    515        1.1       mrg  *
    516       1.78      yamt  * => NOTE: we can return 0 even if we can wait if there is not enough
    517        1.1       mrg  *	free VM space in the map... caller should be prepared to handle
    518        1.1       mrg  *	this case.
    519        1.1       mrg  * => we return KVA of memory allocated
    520        1.1       mrg  */
    521        1.1       mrg 
    522       1.14       eeh vaddr_t
    523       1.83   thorpej uvm_km_alloc(struct vm_map *map, vsize_t size, vsize_t align, uvm_flag_t flags)
    524        1.1       mrg {
    525       1.14       eeh 	vaddr_t kva, loopva;
    526       1.14       eeh 	vaddr_t offset;
    527       1.44   thorpej 	vsize_t loopsize;
    528        1.8       mrg 	struct vm_page *pg;
    529       1.78      yamt 	struct uvm_object *obj;
    530       1.78      yamt 	int pgaflags;
    531       1.89  drochner 	vm_prot_t prot;
    532       1.78      yamt 	UVMHIST_FUNC(__func__); UVMHIST_CALLED(maphist);
    533        1.1       mrg 
    534       1.40       chs 	KASSERT(vm_map_pmap(map) == pmap_kernel());
    535       1.78      yamt 	KASSERT((flags & UVM_KMF_TYPEMASK) == UVM_KMF_WIRED ||
    536       1.78      yamt 		(flags & UVM_KMF_TYPEMASK) == UVM_KMF_PAGEABLE ||
    537       1.78      yamt 		(flags & UVM_KMF_TYPEMASK) == UVM_KMF_VAONLY);
    538        1.1       mrg 
    539        1.8       mrg 	/*
    540        1.8       mrg 	 * setup for call
    541        1.8       mrg 	 */
    542        1.8       mrg 
    543       1.78      yamt 	kva = vm_map_min(map);	/* hint */
    544        1.8       mrg 	size = round_page(size);
    545       1.95        ad 	obj = (flags & UVM_KMF_PAGEABLE) ? uvm_kernel_object : NULL;
    546       1.78      yamt 	UVMHIST_LOG(maphist,"  (map=0x%x, obj=0x%x, size=0x%x, flags=%d)",
    547       1.78      yamt 		    map, obj, size, flags);
    548        1.1       mrg 
    549        1.8       mrg 	/*
    550        1.8       mrg 	 * allocate some virtual space
    551        1.8       mrg 	 */
    552        1.8       mrg 
    553       1.78      yamt 	if (__predict_false(uvm_map(map, &kva, size, obj, UVM_UNKNOWN_OFFSET,
    554       1.78      yamt 	    align, UVM_MAPFLAG(UVM_PROT_ALL, UVM_PROT_ALL, UVM_INH_NONE,
    555       1.78      yamt 	    UVM_ADV_RANDOM,
    556       1.78      yamt 	    (flags & (UVM_KMF_TRYLOCK | UVM_KMF_NOWAIT | UVM_KMF_WAITVA))
    557       1.78      yamt 	    | UVM_FLAG_QUANTUM)) != 0)) {
    558        1.8       mrg 		UVMHIST_LOG(maphist, "<- done (no VM)",0,0,0,0);
    559        1.8       mrg 		return(0);
    560        1.8       mrg 	}
    561        1.8       mrg 
    562        1.8       mrg 	/*
    563        1.8       mrg 	 * if all we wanted was VA, return now
    564        1.8       mrg 	 */
    565        1.8       mrg 
    566       1.78      yamt 	if (flags & (UVM_KMF_VAONLY | UVM_KMF_PAGEABLE)) {
    567        1.8       mrg 		UVMHIST_LOG(maphist,"<- done valloc (kva=0x%x)", kva,0,0,0);
    568        1.8       mrg 		return(kva);
    569        1.8       mrg 	}
    570       1.40       chs 
    571        1.8       mrg 	/*
    572        1.8       mrg 	 * recover object offset from virtual address
    573        1.8       mrg 	 */
    574        1.8       mrg 
    575        1.8       mrg 	offset = kva - vm_map_min(kernel_map);
    576        1.8       mrg 	UVMHIST_LOG(maphist, "  kva=0x%x, offset=0x%x", kva, offset,0,0);
    577        1.8       mrg 
    578        1.8       mrg 	/*
    579        1.8       mrg 	 * now allocate and map in the memory... note that we are the only ones
    580        1.8       mrg 	 * whom should ever get a handle on this area of VM.
    581        1.8       mrg 	 */
    582        1.8       mrg 
    583        1.8       mrg 	loopva = kva;
    584       1.44   thorpej 	loopsize = size;
    585       1.78      yamt 
    586      1.107      matt 	pgaflags = UVM_FLAG_COLORMATCH;
    587      1.103        ad 	if (flags & UVM_KMF_NOWAIT)
    588      1.103        ad 		pgaflags |= UVM_PGA_USERESERVE;
    589       1.78      yamt 	if (flags & UVM_KMF_ZERO)
    590       1.78      yamt 		pgaflags |= UVM_PGA_ZERO;
    591       1.89  drochner 	prot = VM_PROT_READ | VM_PROT_WRITE;
    592       1.89  drochner 	if (flags & UVM_KMF_EXEC)
    593       1.89  drochner 		prot |= VM_PROT_EXECUTE;
    594       1.44   thorpej 	while (loopsize) {
    595       1.78      yamt 		KASSERT(!pmap_extract(pmap_kernel(), loopva, NULL));
    596       1.78      yamt 
    597      1.107      matt 		pg = uvm_pagealloc_strat(NULL, offset, NULL, pgaflags,
    598      1.107      matt #ifdef UVM_KM_VMFREELIST
    599      1.107      matt 		   UVM_PGA_STRAT_ONLY, UVM_KM_VMFREELIST
    600      1.107      matt #else
    601      1.107      matt 		   UVM_PGA_STRAT_NORMAL, 0
    602      1.107      matt #endif
    603      1.107      matt 		   );
    604       1.47       chs 
    605        1.8       mrg 		/*
    606        1.8       mrg 		 * out of memory?
    607        1.8       mrg 		 */
    608        1.8       mrg 
    609       1.35   thorpej 		if (__predict_false(pg == NULL)) {
    610       1.58       chs 			if ((flags & UVM_KMF_NOWAIT) ||
    611       1.80      yamt 			    ((flags & UVM_KMF_CANFAIL) && !uvm_reclaimable())) {
    612        1.8       mrg 				/* free everything! */
    613       1.78      yamt 				uvm_km_free(map, kva, size,
    614       1.78      yamt 				    flags & UVM_KMF_TYPEMASK);
    615       1.58       chs 				return (0);
    616        1.8       mrg 			} else {
    617        1.8       mrg 				uvm_wait("km_getwait2");	/* sleep here */
    618        1.8       mrg 				continue;
    619        1.8       mrg 			}
    620        1.8       mrg 		}
    621       1.47       chs 
    622       1.78      yamt 		pg->flags &= ~PG_BUSY;	/* new page */
    623       1.78      yamt 		UVM_PAGE_OWN(pg, NULL);
    624       1.78      yamt 
    625        1.8       mrg 		/*
    626       1.52       chs 		 * map it in
    627        1.8       mrg 		 */
    628       1.40       chs 
    629      1.104    cegger 		pmap_kenter_pa(loopva, VM_PAGE_TO_PHYS(pg),
    630      1.106    cegger 		    prot, PMAP_KMPAGE);
    631        1.8       mrg 		loopva += PAGE_SIZE;
    632        1.8       mrg 		offset += PAGE_SIZE;
    633       1.44   thorpej 		loopsize -= PAGE_SIZE;
    634        1.8       mrg 	}
    635       1.69  junyoung 
    636       1.51     chris        	pmap_update(pmap_kernel());
    637       1.69  junyoung 
    638        1.8       mrg 	UVMHIST_LOG(maphist,"<- done (kva=0x%x)", kva,0,0,0);
    639        1.8       mrg 	return(kva);
    640        1.1       mrg }
    641        1.1       mrg 
    642        1.1       mrg /*
    643        1.1       mrg  * uvm_km_free: free an area of kernel memory
    644        1.1       mrg  */
    645        1.1       mrg 
    646        1.8       mrg void
    647       1.83   thorpej uvm_km_free(struct vm_map *map, vaddr_t addr, vsize_t size, uvm_flag_t flags)
    648        1.8       mrg {
    649        1.1       mrg 
    650       1.78      yamt 	KASSERT((flags & UVM_KMF_TYPEMASK) == UVM_KMF_WIRED ||
    651       1.78      yamt 		(flags & UVM_KMF_TYPEMASK) == UVM_KMF_PAGEABLE ||
    652       1.78      yamt 		(flags & UVM_KMF_TYPEMASK) == UVM_KMF_VAONLY);
    653       1.78      yamt 	KASSERT((addr & PAGE_MASK) == 0);
    654       1.40       chs 	KASSERT(vm_map_pmap(map) == pmap_kernel());
    655        1.1       mrg 
    656        1.8       mrg 	size = round_page(size);
    657        1.1       mrg 
    658  1.108.2.1    cherry 
    659       1.78      yamt 	if (flags & UVM_KMF_PAGEABLE) {
    660  1.108.2.1    cherry 		/*
    661  1.108.2.1    cherry 		 * No need to lock for pmap, since the kernel is always
    662  1.108.2.1    cherry 		 * self-consistent.  The pages cannot be in use elsewhere.
    663  1.108.2.1    cherry 		 */
    664       1.78      yamt 		uvm_km_pgremove(addr, addr + size);
    665       1.78      yamt 		pmap_remove(pmap_kernel(), addr, addr + size);
    666  1.108.2.1    cherry 
    667       1.78      yamt 	} else if (flags & UVM_KMF_WIRED) {
    668  1.108.2.1    cherry 		/*
    669  1.108.2.1    cherry 		 * Note: uvm_km_pgremove_intrsafe() extracts mapping, thus
    670  1.108.2.1    cherry 		 * remove it after.  See comment below about KVA visibility.
    671  1.108.2.1    cherry 		 */
    672      1.102        ad 		uvm_km_pgremove_intrsafe(map, addr, addr + size);
    673       1.78      yamt 		pmap_kremove(addr, size);
    674        1.8       mrg 	}
    675       1.99      yamt 
    676       1.99      yamt 	/*
    677  1.108.2.1    cherry 	 * Note: uvm_unmap_remove() calls pmap_update() for us, before
    678  1.108.2.1    cherry 	 * KVA becomes globally available.
    679       1.99      yamt 	 */
    680        1.8       mrg 
    681       1.78      yamt 	uvm_unmap1(map, addr, addr + size, UVM_FLAG_QUANTUM|UVM_FLAG_VAONLY);
    682       1.66        pk }
    683       1.66        pk 
    684       1.10   thorpej /* Sanity; must specify both or none. */
    685       1.10   thorpej #if (defined(PMAP_MAP_POOLPAGE) || defined(PMAP_UNMAP_POOLPAGE)) && \
    686       1.10   thorpej     (!defined(PMAP_MAP_POOLPAGE) || !defined(PMAP_UNMAP_POOLPAGE))
    687       1.10   thorpej #error Must specify MAP and UNMAP together.
    688       1.10   thorpej #endif
    689       1.10   thorpej 
    690       1.10   thorpej /*
    691       1.10   thorpej  * uvm_km_alloc_poolpage: allocate a page for the pool allocator
    692       1.10   thorpej  *
    693       1.10   thorpej  * => if the pmap specifies an alternate mapping method, we use it.
    694       1.10   thorpej  */
    695       1.10   thorpej 
    696       1.11   thorpej /* ARGSUSED */
    697       1.14       eeh vaddr_t
    698       1.93   thorpej uvm_km_alloc_poolpage_cache(struct vm_map *map, bool waitok)
    699       1.72      yamt {
    700       1.72      yamt #if defined(PMAP_MAP_POOLPAGE)
    701       1.78      yamt 	return uvm_km_alloc_poolpage(map, waitok);
    702       1.72      yamt #else
    703       1.72      yamt 	struct vm_page *pg;
    704       1.72      yamt 	struct pool *pp = &vm_map_to_kernel(map)->vmk_vacache;
    705       1.72      yamt 	vaddr_t va;
    706       1.72      yamt 
    707       1.72      yamt 	if ((map->flags & VM_MAP_VACACHE) == 0)
    708       1.78      yamt 		return uvm_km_alloc_poolpage(map, waitok);
    709       1.72      yamt 
    710       1.72      yamt 	va = (vaddr_t)pool_get(pp, waitok ? PR_WAITOK : PR_NOWAIT);
    711       1.72      yamt 	if (va == 0)
    712       1.72      yamt 		return 0;
    713       1.72      yamt 	KASSERT(!pmap_extract(pmap_kernel(), va, NULL));
    714       1.72      yamt again:
    715      1.103        ad 	pg = uvm_pagealloc(NULL, 0, NULL, waitok ? 0 : UVM_PGA_USERESERVE);
    716       1.72      yamt 	if (__predict_false(pg == NULL)) {
    717       1.72      yamt 		if (waitok) {
    718       1.72      yamt 			uvm_wait("plpg");
    719       1.72      yamt 			goto again;
    720       1.72      yamt 		} else {
    721       1.72      yamt 			pool_put(pp, (void *)va);
    722       1.72      yamt 			return 0;
    723       1.72      yamt 		}
    724       1.72      yamt 	}
    725      1.100      matt 	pmap_kenter_pa(va, VM_PAGE_TO_PHYS(pg),
    726      1.106    cegger 	    VM_PROT_READ|VM_PROT_WRITE, PMAP_KMPAGE);
    727       1.72      yamt 	pmap_update(pmap_kernel());
    728       1.72      yamt 
    729       1.72      yamt 	return va;
    730       1.72      yamt #endif /* PMAP_MAP_POOLPAGE */
    731       1.72      yamt }
    732       1.72      yamt 
    733       1.72      yamt vaddr_t
    734       1.93   thorpej uvm_km_alloc_poolpage(struct vm_map *map, bool waitok)
    735       1.10   thorpej {
    736       1.10   thorpej #if defined(PMAP_MAP_POOLPAGE)
    737       1.10   thorpej 	struct vm_page *pg;
    738       1.14       eeh 	vaddr_t va;
    739       1.10   thorpej 
    740      1.107      matt 
    741       1.15   thorpej  again:
    742      1.107      matt #ifdef PMAP_ALLOC_POOLPAGE
    743      1.107      matt 	pg = PMAP_ALLOC_POOLPAGE(waitok ? 0 : UVM_PGA_USERESERVE);
    744      1.107      matt #else
    745      1.103        ad 	pg = uvm_pagealloc(NULL, 0, NULL, waitok ? 0 : UVM_PGA_USERESERVE);
    746      1.107      matt #endif
    747       1.35   thorpej 	if (__predict_false(pg == NULL)) {
    748       1.15   thorpej 		if (waitok) {
    749       1.15   thorpej 			uvm_wait("plpg");
    750       1.15   thorpej 			goto again;
    751       1.15   thorpej 		} else
    752       1.15   thorpej 			return (0);
    753       1.15   thorpej 	}
    754       1.10   thorpej 	va = PMAP_MAP_POOLPAGE(VM_PAGE_TO_PHYS(pg));
    755       1.35   thorpej 	if (__predict_false(va == 0))
    756       1.10   thorpej 		uvm_pagefree(pg);
    757       1.10   thorpej 	return (va);
    758       1.10   thorpej #else
    759       1.14       eeh 	vaddr_t va;
    760       1.16   thorpej 
    761       1.78      yamt 	va = uvm_km_alloc(map, PAGE_SIZE, 0,
    762       1.78      yamt 	    (waitok ? 0 : UVM_KMF_NOWAIT | UVM_KMF_TRYLOCK) | UVM_KMF_WIRED);
    763       1.10   thorpej 	return (va);
    764       1.10   thorpej #endif /* PMAP_MAP_POOLPAGE */
    765       1.10   thorpej }
    766       1.10   thorpej 
    767       1.10   thorpej /*
    768       1.10   thorpej  * uvm_km_free_poolpage: free a previously allocated pool page
    769       1.10   thorpej  *
    770       1.10   thorpej  * => if the pmap specifies an alternate unmapping method, we use it.
    771       1.10   thorpej  */
    772       1.10   thorpej 
    773       1.11   thorpej /* ARGSUSED */
    774       1.10   thorpej void
    775       1.83   thorpej uvm_km_free_poolpage_cache(struct vm_map *map, vaddr_t addr)
    776       1.72      yamt {
    777       1.72      yamt #if defined(PMAP_UNMAP_POOLPAGE)
    778       1.78      yamt 	uvm_km_free_poolpage(map, addr);
    779       1.72      yamt #else
    780       1.72      yamt 	struct pool *pp;
    781       1.72      yamt 
    782       1.72      yamt 	if ((map->flags & VM_MAP_VACACHE) == 0) {
    783       1.78      yamt 		uvm_km_free_poolpage(map, addr);
    784       1.72      yamt 		return;
    785       1.72      yamt 	}
    786       1.72      yamt 
    787       1.72      yamt 	KASSERT(pmap_extract(pmap_kernel(), addr, NULL));
    788      1.102        ad 	uvm_km_pgremove_intrsafe(map, addr, addr + PAGE_SIZE);
    789       1.72      yamt 	pmap_kremove(addr, PAGE_SIZE);
    790       1.72      yamt #if defined(DEBUG)
    791       1.72      yamt 	pmap_update(pmap_kernel());
    792       1.72      yamt #endif
    793       1.72      yamt 	KASSERT(!pmap_extract(pmap_kernel(), addr, NULL));
    794       1.72      yamt 	pp = &vm_map_to_kernel(map)->vmk_vacache;
    795       1.72      yamt 	pool_put(pp, (void *)addr);
    796       1.72      yamt #endif
    797       1.72      yamt }
    798       1.72      yamt 
    799       1.72      yamt /* ARGSUSED */
    800       1.72      yamt void
    801       1.83   thorpej uvm_km_free_poolpage(struct vm_map *map, vaddr_t addr)
    802       1.10   thorpej {
    803       1.10   thorpej #if defined(PMAP_UNMAP_POOLPAGE)
    804       1.14       eeh 	paddr_t pa;
    805       1.10   thorpej 
    806       1.10   thorpej 	pa = PMAP_UNMAP_POOLPAGE(addr);
    807       1.10   thorpej 	uvm_pagefree(PHYS_TO_VM_PAGE(pa));
    808       1.10   thorpej #else
    809       1.78      yamt 	uvm_km_free(map, addr, PAGE_SIZE, UVM_KMF_WIRED);
    810       1.10   thorpej #endif /* PMAP_UNMAP_POOLPAGE */
    811        1.1       mrg }
    812