vm_kern.c revision 71571
15455Sdg/*
21541Srgrimes * Copyright (c) 1991, 1993
31541Srgrimes *	The Regents of the University of California.  All rights reserved.
41541Srgrimes *
51541Srgrimes * This code is derived from software contributed to Berkeley by
61541Srgrimes * The Mach Operating System project at Carnegie-Mellon University.
71541Srgrimes *
81541Srgrimes * Redistribution and use in source and binary forms, with or without
91541Srgrimes * modification, are permitted provided that the following conditions
101541Srgrimes * are met:
111541Srgrimes * 1. Redistributions of source code must retain the above copyright
121541Srgrimes *    notice, this list of conditions and the following disclaimer.
131541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
141541Srgrimes *    notice, this list of conditions and the following disclaimer in the
151541Srgrimes *    documentation and/or other materials provided with the distribution.
161541Srgrimes * 3. All advertising materials mentioning features or use of this software
1758705Scharnier *    must display the following acknowledgement:
181541Srgrimes *	This product includes software developed by the University of
191541Srgrimes *	California, Berkeley and its contributors.
201541Srgrimes * 4. Neither the name of the University nor the names of its contributors
211541Srgrimes *    may be used to endorse or promote products derived from this software
221541Srgrimes *    without specific prior written permission.
231541Srgrimes *
241541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
251541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
261541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
271541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
281541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
291541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
301541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
311541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
321541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
331541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
341541Srgrimes * SUCH DAMAGE.
351541Srgrimes *
361817Sdg *	from: @(#)vm_kern.c	8.3 (Berkeley) 1/12/94
371541Srgrimes *
381541Srgrimes *
391541Srgrimes * Copyright (c) 1987, 1990 Carnegie-Mellon University.
401541Srgrimes * All rights reserved.
411541Srgrimes *
421541Srgrimes * Authors: Avadis Tevanian, Jr., Michael Wayne Young
435455Sdg *
441541Srgrimes * Permission to use, copy, modify and distribute this software and
451541Srgrimes * its documentation is hereby granted, provided that both the copyright
461541Srgrimes * notice and this permission notice appear in all copies of the
471541Srgrimes * software, derivative works or modified versions, and any portions
481541Srgrimes * thereof, and that both notices appear in supporting documentation.
495455Sdg *
505455Sdg * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
515455Sdg * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
521541Srgrimes * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
535455Sdg *
541541Srgrimes * Carnegie Mellon requests users of this software to return to
551541Srgrimes *
561541Srgrimes *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
571541Srgrimes *  School of Computer Science
581541Srgrimes *  Carnegie Mellon University
591541Srgrimes *  Pittsburgh PA 15213-3890
601541Srgrimes *
611541Srgrimes * any improvements or extensions that they make and grant Carnegie the
621541Srgrimes * rights to redistribute these changes.
631817Sdg *
6450477Speter * $FreeBSD: head/sys/vm/vm_kern.c 71571 2001-01-24 11:27:29Z jhb $
651541Srgrimes */
661541Srgrimes
671541Srgrimes/*
681541Srgrimes *	Kernel memory management.
691541Srgrimes */
701541Srgrimes
711541Srgrimes#include <sys/param.h>
721541Srgrimes#include <sys/systm.h>
732112Swollman#include <sys/proc.h>
746129Sdg#include <sys/malloc.h>
751541Srgrimes
761541Srgrimes#include <vm/vm.h>
7712662Sdg#include <vm/vm_param.h>
7822521Sdyson#include <sys/lock.h>
7912662Sdg#include <vm/pmap.h>
8012662Sdg#include <vm/vm_map.h>
8112662Sdg#include <vm/vm_object.h>
821541Srgrimes#include <vm/vm_page.h>
831541Srgrimes#include <vm/vm_pageout.h>
8412726Sbde#include <vm/vm_extern.h>
851541Srgrimes
8619830Sdysonvm_map_t kernel_map=0;
8719830Sdysonvm_map_t kmem_map=0;
8819830Sdysonvm_map_t exec_map=0;
8919830Sdysonvm_map_t clean_map=0;
9019830Sdysonvm_map_t buffer_map=0;
9119830Sdysonvm_map_t mb_map=0;
9219830Sdysonint mb_map_full=0;
932112Swollman
941541Srgrimes/*
951541Srgrimes *	kmem_alloc_pageable:
961541Srgrimes *
971541Srgrimes *	Allocate pageable memory to the kernel's address map.
9812259Sdg *	"map" must be kernel_map or a submap of kernel_map.
991541Srgrimes */
1001541Srgrimes
1018876Srgrimesvm_offset_t
1025455Sdgkmem_alloc_pageable(map, size)
1035455Sdg	vm_map_t map;
10470480Salfred	vm_size_t size;
1051541Srgrimes{
1065455Sdg	vm_offset_t addr;
10770480Salfred	int result;
1081541Srgrimes
1091541Srgrimes	size = round_page(size);
1101541Srgrimes	addr = vm_map_min(map);
1111541Srgrimes	result = vm_map_find(map, NULL, (vm_offset_t) 0,
11213490Sdyson	    &addr, size, TRUE, VM_PROT_ALL, VM_PROT_ALL, 0);
1131541Srgrimes	if (result != KERN_SUCCESS) {
1145455Sdg		return (0);
1151541Srgrimes	}
1165455Sdg	return (addr);
1171541Srgrimes}
1181541Srgrimes
1191541Srgrimes/*
12047841Sdt *	kmem_alloc_nofault:
12147841Sdt *
12247841Sdt *	Same as kmem_alloc_pageable, except that it create a nofault entry.
12347841Sdt */
12447841Sdt
12547841Sdtvm_offset_t
12647841Sdtkmem_alloc_nofault(map, size)
12747841Sdt	vm_map_t map;
12870480Salfred	vm_size_t size;
12947841Sdt{
13047841Sdt	vm_offset_t addr;
13170480Salfred	int result;
13247841Sdt
13347841Sdt	size = round_page(size);
13447841Sdt	addr = vm_map_min(map);
13547841Sdt	result = vm_map_find(map, NULL, (vm_offset_t) 0,
13647841Sdt	    &addr, size, TRUE, VM_PROT_ALL, VM_PROT_ALL, MAP_NOFAULT);
13747841Sdt	if (result != KERN_SUCCESS) {
13847841Sdt		return (0);
13947841Sdt	}
14047841Sdt	return (addr);
14147841Sdt}
14247841Sdt
14347841Sdt/*
1441541Srgrimes *	Allocate wired-down memory in the kernel's address map
1451541Srgrimes *	or a submap.
1461541Srgrimes */
1478876Srgrimesvm_offset_t
1485455Sdgkmem_alloc(map, size)
14970480Salfred	vm_map_t map;
15070480Salfred	vm_size_t size;
1511541Srgrimes{
1525455Sdg	vm_offset_t addr;
15370480Salfred	vm_offset_t offset;
1545455Sdg	vm_offset_t i;
1551541Srgrimes
15671571Sjhb	mtx_assert(&Giant, MA_OWNED);
1571541Srgrimes	size = round_page(size);
1581541Srgrimes
1591541Srgrimes	/*
1605455Sdg	 * Use the kernel object for wired-down kernel pages. Assume that no
1615455Sdg	 * region of the kernel object is referenced more than once.
1621541Srgrimes	 */
1631541Srgrimes
1641541Srgrimes	/*
1655455Sdg	 * Locate sufficient space in the map.  This will give us the final
1665455Sdg	 * virtual address for the new memory, and thus will tell us the
1675455Sdg	 * offset within the kernel map.
1681541Srgrimes	 */
1691541Srgrimes	vm_map_lock(map);
17033758Sdyson	if (vm_map_findspace(map, vm_map_min(map), size, &addr)) {
1711541Srgrimes		vm_map_unlock(map);
1721541Srgrimes		return (0);
1731541Srgrimes	}
1741541Srgrimes	offset = addr - VM_MIN_KERNEL_ADDRESS;
1751541Srgrimes	vm_object_reference(kernel_object);
17613490Sdyson	vm_map_insert(map, kernel_object, offset, addr, addr + size,
17713490Sdyson		VM_PROT_ALL, VM_PROT_ALL, 0);
1781541Srgrimes	vm_map_unlock(map);
1791541Srgrimes
1801541Srgrimes	/*
1815455Sdg	 * Guarantee that there are pages already in this object before
1825455Sdg	 * calling vm_map_pageable.  This is to prevent the following
1835455Sdg	 * scenario:
1848876Srgrimes	 *
1855455Sdg	 * 1) Threads have swapped out, so that there is a pager for the
1865455Sdg	 * kernel_object. 2) The kmsg zone is empty, and so we are
1875455Sdg	 * kmem_allocing a new page for it. 3) vm_map_pageable calls vm_fault;
1885455Sdg	 * there is no page, but there is a pager, so we call
1895455Sdg	 * pager_data_request.  But the kmsg zone is empty, so we must
1905455Sdg	 * kmem_alloc. 4) goto 1 5) Even if the kmsg zone is not empty: when
1915455Sdg	 * we get the data back from the pager, it will be (very stale)
1925455Sdg	 * non-zero data.  kmem_alloc is defined to return zero-filled memory.
1938876Srgrimes	 *
1945455Sdg	 * We're intentionally not activating the pages we allocate to prevent a
1955455Sdg	 * race with page-out.  vm_map_pageable will wire the pages.
1961541Srgrimes	 */
1971541Srgrimes
1985455Sdg	for (i = 0; i < size; i += PAGE_SIZE) {
1995455Sdg		vm_page_t mem;
2001541Srgrimes
20133109Sdyson		mem = vm_page_grab(kernel_object, OFF_TO_IDX(offset + i),
20233109Sdyson				VM_ALLOC_ZERO | VM_ALLOC_RETRY);
20310548Sdyson		if ((mem->flags & PG_ZERO) == 0)
20410548Sdyson			vm_page_zero_fill(mem);
2056585Sdg		mem->valid = VM_PAGE_BITS_ALL;
20642957Sdillon		vm_page_flag_clear(mem, PG_ZERO);
20742957Sdillon		vm_page_wakeup(mem);
2081541Srgrimes	}
2095455Sdg
2101541Srgrimes	/*
2115455Sdg	 * And finally, mark the data as non-pageable.
2121541Srgrimes	 */
2131541Srgrimes
2141541Srgrimes	(void) vm_map_pageable(map, (vm_offset_t) addr, addr + size, FALSE);
2151541Srgrimes
2165455Sdg	return (addr);
2171541Srgrimes}
2181541Srgrimes
2191541Srgrimes/*
2201541Srgrimes *	kmem_free:
2211541Srgrimes *
2221541Srgrimes *	Release a region of kernel virtual memory allocated
2231541Srgrimes *	with kmem_alloc, and return the physical pages
2241541Srgrimes *	associated with that region.
22542957Sdillon *
22642957Sdillon *	This routine may not block on kernel maps.
2271541Srgrimes */
2288876Srgrimesvoid
2295455Sdgkmem_free(map, addr, size)
2305455Sdg	vm_map_t map;
23170480Salfred	vm_offset_t addr;
2325455Sdg	vm_size_t size;
2331541Srgrimes{
23471571Sjhb
23571571Sjhb	mtx_assert(&Giant, MA_OWNED);
2361541Srgrimes	(void) vm_map_remove(map, trunc_page(addr), round_page(addr + size));
2371541Srgrimes}
2381541Srgrimes
2391541Srgrimes/*
2401541Srgrimes *	kmem_suballoc:
2411541Srgrimes *
2421541Srgrimes *	Allocates a map to manage a subrange
2431541Srgrimes *	of the kernel virtual address space.
2441541Srgrimes *
2451541Srgrimes *	Arguments are as follows:
2461541Srgrimes *
2471541Srgrimes *	parent		Map to take range from
24870480Salfred *	min, max	Returned endpoints of map
2491541Srgrimes *	size		Size of range to find
2501541Srgrimes */
2518876Srgrimesvm_map_t
25232702Sdysonkmem_suballoc(parent, min, max, size)
25370478Salfred	vm_map_t parent;
2545455Sdg	vm_offset_t *min, *max;
25570478Salfred	vm_size_t size;
2561541Srgrimes{
25770478Salfred	int ret;
2585455Sdg	vm_map_t result;
2591541Srgrimes
2601541Srgrimes	size = round_page(size);
2611541Srgrimes
2621541Srgrimes	*min = (vm_offset_t) vm_map_min(parent);
2631541Srgrimes	ret = vm_map_find(parent, NULL, (vm_offset_t) 0,
26413490Sdyson	    min, size, TRUE, VM_PROT_ALL, VM_PROT_ALL, 0);
2651541Srgrimes	if (ret != KERN_SUCCESS) {
2661541Srgrimes		printf("kmem_suballoc: bad status return of %d.\n", ret);
2671541Srgrimes		panic("kmem_suballoc");
2681541Srgrimes	}
2691541Srgrimes	*max = *min + size;
2701541Srgrimes	pmap_reference(vm_map_pmap(parent));
27132702Sdyson	result = vm_map_create(vm_map_pmap(parent), *min, *max);
2721541Srgrimes	if (result == NULL)
2731541Srgrimes		panic("kmem_suballoc: cannot create submap");
27470478Salfred	if (vm_map_submap(parent, *min, *max, result) != KERN_SUCCESS)
2751541Srgrimes		panic("kmem_suballoc: unable to change range to submap");
2765455Sdg	return (result);
2771541Srgrimes}
2781541Srgrimes
2791541Srgrimes/*
28042957Sdillon *	kmem_malloc:
2811541Srgrimes *
28242957Sdillon * 	Allocate wired-down memory in the kernel's address map for the higher
28342957Sdillon * 	level kernel memory allocator (kern/kern_malloc.c).  We cannot use
28442957Sdillon * 	kmem_alloc() because we may need to allocate memory at interrupt
28542957Sdillon * 	level where we cannot block (canwait == FALSE).
2861541Srgrimes *
28742957Sdillon * 	This routine has its own private kernel submap (kmem_map) and object
28842957Sdillon * 	(kmem_object).  This, combined with the fact that only malloc uses
28942957Sdillon * 	this routine, ensures that we will never block in map or object waits.
2901541Srgrimes *
29142957Sdillon * 	Note that this still only works in a uni-processor environment and
29242957Sdillon * 	when called at splhigh().
29342957Sdillon *
29442957Sdillon * 	We don't worry about expanding the map (adding entries) since entries
29542957Sdillon * 	for wired maps are statically allocated.
29642957Sdillon *
29742957Sdillon *	NOTE:  This routine is not supposed to block if M_NOWAIT is set, but
29842957Sdillon *	I have not verified that it actually does not block.
2991541Srgrimes */
3001541Srgrimesvm_offset_t
30142957Sdillonkmem_malloc(map, size, flags)
30270480Salfred	vm_map_t map;
30370480Salfred	vm_size_t size;
30442957Sdillon	int flags;
3051541Srgrimes{
30670480Salfred	vm_offset_t offset, i;
3075455Sdg	vm_map_entry_t entry;
3085455Sdg	vm_offset_t addr;
3095455Sdg	vm_page_t m;
3101541Srgrimes
31121737Sdg	if (map != kmem_map && map != mb_map)
31221737Sdg		panic("kmem_malloc: map != {kmem,mb}_map");
3131541Srgrimes
3141541Srgrimes	size = round_page(size);
3151541Srgrimes	addr = vm_map_min(map);
3161541Srgrimes
3171541Srgrimes	/*
3185455Sdg	 * Locate sufficient space in the map.  This will give us the final
3195455Sdg	 * virtual address for the new memory, and thus will tell us the
3205455Sdg	 * offset within the kernel map.
3211541Srgrimes	 */
3221541Srgrimes	vm_map_lock(map);
32333758Sdyson	if (vm_map_findspace(map, vm_map_min(map), size, &addr)) {
3241541Srgrimes		vm_map_unlock(map);
3257066Sdg		if (map == mb_map) {
3267066Sdg			mb_map_full = TRUE;
32736677Sdg			printf("Out of mbuf clusters - adjust NMBCLUSTERS or increase maxusers!\n");
3287066Sdg			return (0);
3297066Sdg		}
33042957Sdillon		if ((flags & M_NOWAIT) == 0)
33148409Speter			panic("kmem_malloc(%ld): kmem_map too small: %ld total allocated",
33248409Speter				(long)size, (long)map->size);
3331541Srgrimes		return (0);
3341541Srgrimes	}
33515367Sdyson	offset = addr - VM_MIN_KERNEL_ADDRESS;
3361541Srgrimes	vm_object_reference(kmem_object);
33713490Sdyson	vm_map_insert(map, kmem_object, offset, addr, addr + size,
33813490Sdyson		VM_PROT_ALL, VM_PROT_ALL, 0);
3391541Srgrimes
3401541Srgrimes	for (i = 0; i < size; i += PAGE_SIZE) {
34142957Sdillon		/*
34242957Sdillon		 * Note: if M_NOWAIT specified alone, allocate from
34342957Sdillon		 * interrupt-safe queues only (just the free list).  If
34442957Sdillon		 * M_ASLEEP or M_USE_RESERVE is also specified, we can also
34542957Sdillon		 * allocate from the cache.  Neither of the latter two
34642957Sdillon		 * flags may be specified from an interrupt since interrupts
34742957Sdillon		 * are not allowed to mess with the cache queue.
34842957Sdillon		 */
34915809Sdysonretry:
35012767Sdyson		m = vm_page_alloc(kmem_object, OFF_TO_IDX(offset + i),
35142957Sdillon		    ((flags & (M_NOWAIT|M_ASLEEP|M_USE_RESERVE)) == M_NOWAIT) ?
35242957Sdillon			VM_ALLOC_INTERRUPT :
35342957Sdillon			VM_ALLOC_SYSTEM);
3541541Srgrimes
3551541Srgrimes		/*
3565455Sdg		 * Ran out of space, free everything up and return. Don't need
3575455Sdg		 * to lock page queues here as we know that the pages we got
3585455Sdg		 * aren't on any queues.
3591541Srgrimes		 */
3601541Srgrimes		if (m == NULL) {
36142957Sdillon			if ((flags & M_NOWAIT) == 0) {
36244793Salc				vm_map_unlock(map);
36315809Sdyson				VM_WAIT;
36444793Salc				vm_map_lock(map);
36515809Sdyson				goto retry;
36615809Sdyson			}
3671541Srgrimes			vm_map_delete(map, addr, addr + size);
3681541Srgrimes			vm_map_unlock(map);
36942957Sdillon			if (flags & M_ASLEEP) {
37042957Sdillon				VM_AWAIT;
37142957Sdillon			}
3725455Sdg			return (0);
3731541Srgrimes		}
37438799Sdfr		vm_page_flag_clear(m, PG_ZERO);
3756585Sdg		m->valid = VM_PAGE_BITS_ALL;
3761541Srgrimes	}
3771541Srgrimes
3781541Srgrimes	/*
3795455Sdg	 * Mark map entry as non-pageable. Assert: vm_map_insert() will never
3805455Sdg	 * be able to extend the previous entry so there will be a new entry
3815455Sdg	 * exactly corresponding to this address range and it will have
3825455Sdg	 * wired_count == 0.
3831541Srgrimes	 */
3841541Srgrimes	if (!vm_map_lookup_entry(map, addr, &entry) ||
3851541Srgrimes	    entry->start != addr || entry->end != addr + size ||
38644793Salc	    entry->wired_count != 0)
3871541Srgrimes		panic("kmem_malloc: entry not found or misaligned");
38844793Salc	entry->wired_count = 1;
3891541Srgrimes
39020993Sdyson	vm_map_simplify_entry(map, entry);
39120993Sdyson
3921541Srgrimes	/*
3935455Sdg	 * Loop thru pages, entering them in the pmap. (We cannot add them to
3945455Sdg	 * the wired count without wrapping the vm_page_queue_lock in
3955455Sdg	 * splimp...)
3961541Srgrimes	 */
3971541Srgrimes	for (i = 0; i < size; i += PAGE_SIZE) {
39812767Sdyson		m = vm_page_lookup(kmem_object, OFF_TO_IDX(offset + i));
39913490Sdyson		vm_page_wire(m);
40038799Sdfr		vm_page_wakeup(m);
40142957Sdillon		/*
40242957Sdillon		 * Because this is kernel_pmap, this call will not block.
40342957Sdillon		 */
40460755Speter		pmap_enter(kernel_pmap, addr + i, m, VM_PROT_ALL, 1);
40538799Sdfr		vm_page_flag_set(m, PG_MAPPED | PG_WRITEABLE | PG_REFERENCED);
4061541Srgrimes	}
4071541Srgrimes	vm_map_unlock(map);
4081541Srgrimes
4095455Sdg	return (addr);
4101541Srgrimes}
4111541Srgrimes
4121541Srgrimes/*
41342957Sdillon *	kmem_alloc_wait:
4141541Srgrimes *
4151541Srgrimes *	Allocates pageable memory from a sub-map of the kernel.  If the submap
4161541Srgrimes *	has no room, the caller sleeps waiting for more memory in the submap.
4171541Srgrimes *
41842957Sdillon *	This routine may block.
4191541Srgrimes */
42042957Sdillon
4218876Srgrimesvm_offset_t
4225455Sdgkmem_alloc_wait(map, size)
4235455Sdg	vm_map_t map;
4245455Sdg	vm_size_t size;
4251541Srgrimes{
4265455Sdg	vm_offset_t addr;
4271541Srgrimes
4281541Srgrimes	size = round_page(size);
4291541Srgrimes
4301541Srgrimes	for (;;) {
4311541Srgrimes		/*
4325455Sdg		 * To make this work for more than one map, use the map's lock
4335455Sdg		 * to lock out sleepers/wakers.
4341541Srgrimes		 */
4351541Srgrimes		vm_map_lock(map);
43633758Sdyson		if (vm_map_findspace(map, vm_map_min(map), size, &addr) == 0)
4371541Srgrimes			break;
4381541Srgrimes		/* no space now; see if we can ever get space */
4391541Srgrimes		if (vm_map_max(map) - vm_map_min(map) < size) {
4401541Srgrimes			vm_map_unlock(map);
4411541Srgrimes			return (0);
4421541Srgrimes		}
4431541Srgrimes		vm_map_unlock(map);
4449507Sdg		tsleep(map, PVM, "kmaw", 0);
4451541Srgrimes	}
44613490Sdyson	vm_map_insert(map, NULL, (vm_offset_t) 0, addr, addr + size, VM_PROT_ALL, VM_PROT_ALL, 0);
4471541Srgrimes	vm_map_unlock(map);
4481541Srgrimes	return (addr);
4491541Srgrimes}
4501541Srgrimes
4511541Srgrimes/*
45242957Sdillon *	kmem_free_wakeup:
4531541Srgrimes *
4549507Sdg *	Returns memory to a submap of the kernel, and wakes up any processes
4551541Srgrimes *	waiting for memory in that map.
4561541Srgrimes */
4578876Srgrimesvoid
4585455Sdgkmem_free_wakeup(map, addr, size)
4595455Sdg	vm_map_t map;
4605455Sdg	vm_offset_t addr;
4615455Sdg	vm_size_t size;
4621541Srgrimes{
4631541Srgrimes	vm_map_lock(map);
4641541Srgrimes	(void) vm_map_delete(map, trunc_page(addr), round_page(addr + size));
4659507Sdg	wakeup(map);
4661541Srgrimes	vm_map_unlock(map);
4671541Srgrimes}
4681541Srgrimes
4691541Srgrimes/*
47042957Sdillon * 	kmem_init:
47142957Sdillon *
47242957Sdillon *	Create the kernel map; insert a mapping covering kernel text,
47342957Sdillon *	data, bss, and all space allocated thus far (`boostrap' data).  The
47442957Sdillon *	new map will thus map the range between VM_MIN_KERNEL_ADDRESS and
47542957Sdillon *	`start' as allocated, and the range between `start' and `end' as free.
4761541Srgrimes */
47742957Sdillon
4788876Srgrimesvoid
4795455Sdgkmem_init(start, end)
4801541Srgrimes	vm_offset_t start, end;
4811541Srgrimes{
48270480Salfred	vm_map_t m;
4831541Srgrimes
48432702Sdyson	m = vm_map_create(kernel_pmap, VM_MIN_KERNEL_ADDRESS, end);
4851541Srgrimes	vm_map_lock(m);
4861541Srgrimes	/* N.B.: cannot use kgdb to debug, starting with this assignment ... */
4871541Srgrimes	kernel_map = m;
48827899Sdyson	kernel_map->system_map = 1;
4895455Sdg	(void) vm_map_insert(m, NULL, (vm_offset_t) 0,
49013490Sdyson	    VM_MIN_KERNEL_ADDRESS, start, VM_PROT_ALL, VM_PROT_ALL, 0);
4911541Srgrimes	/* ... and ending with the completion of the above `insert' */
4921541Srgrimes	vm_map_unlock(m);
4931541Srgrimes}
494