vm_kern.c revision 70478
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 70478 2000-12-29 13:05:22Z alfred $
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;
1045455Sdg	register vm_size_t size;
1051541Srgrimes{
1065455Sdg	vm_offset_t addr;
1075455Sdg	register 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;
12847841Sdt	register vm_size_t size;
12947841Sdt{
13047841Sdt	vm_offset_t addr;
13147841Sdt	register 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)
1495455Sdg	register vm_map_t map;
1505455Sdg	register vm_size_t size;
1511541Srgrimes{
1525455Sdg	vm_offset_t addr;
1535455Sdg	register vm_offset_t offset;
1545455Sdg	vm_offset_t i;
1551541Srgrimes
1561541Srgrimes	size = round_page(size);
1571541Srgrimes
1581541Srgrimes	/*
1595455Sdg	 * Use the kernel object for wired-down kernel pages. Assume that no
1605455Sdg	 * region of the kernel object is referenced more than once.
1611541Srgrimes	 */
1621541Srgrimes
1631541Srgrimes	/*
1645455Sdg	 * Locate sufficient space in the map.  This will give us the final
1655455Sdg	 * virtual address for the new memory, and thus will tell us the
1665455Sdg	 * offset within the kernel map.
1671541Srgrimes	 */
1681541Srgrimes	vm_map_lock(map);
16933758Sdyson	if (vm_map_findspace(map, vm_map_min(map), size, &addr)) {
1701541Srgrimes		vm_map_unlock(map);
1711541Srgrimes		return (0);
1721541Srgrimes	}
1731541Srgrimes	offset = addr - VM_MIN_KERNEL_ADDRESS;
1741541Srgrimes	vm_object_reference(kernel_object);
17513490Sdyson	vm_map_insert(map, kernel_object, offset, addr, addr + size,
17613490Sdyson		VM_PROT_ALL, VM_PROT_ALL, 0);
1771541Srgrimes	vm_map_unlock(map);
1781541Srgrimes
1791541Srgrimes	/*
1805455Sdg	 * Guarantee that there are pages already in this object before
1815455Sdg	 * calling vm_map_pageable.  This is to prevent the following
1825455Sdg	 * scenario:
1838876Srgrimes	 *
1845455Sdg	 * 1) Threads have swapped out, so that there is a pager for the
1855455Sdg	 * kernel_object. 2) The kmsg zone is empty, and so we are
1865455Sdg	 * kmem_allocing a new page for it. 3) vm_map_pageable calls vm_fault;
1875455Sdg	 * there is no page, but there is a pager, so we call
1885455Sdg	 * pager_data_request.  But the kmsg zone is empty, so we must
1895455Sdg	 * kmem_alloc. 4) goto 1 5) Even if the kmsg zone is not empty: when
1905455Sdg	 * we get the data back from the pager, it will be (very stale)
1915455Sdg	 * non-zero data.  kmem_alloc is defined to return zero-filled memory.
1928876Srgrimes	 *
1935455Sdg	 * We're intentionally not activating the pages we allocate to prevent a
1945455Sdg	 * race with page-out.  vm_map_pageable will wire the pages.
1951541Srgrimes	 */
1961541Srgrimes
1975455Sdg	for (i = 0; i < size; i += PAGE_SIZE) {
1985455Sdg		vm_page_t mem;
1991541Srgrimes
20033109Sdyson		mem = vm_page_grab(kernel_object, OFF_TO_IDX(offset + i),
20133109Sdyson				VM_ALLOC_ZERO | VM_ALLOC_RETRY);
20210548Sdyson		if ((mem->flags & PG_ZERO) == 0)
20310548Sdyson			vm_page_zero_fill(mem);
2046585Sdg		mem->valid = VM_PAGE_BITS_ALL;
20542957Sdillon		vm_page_flag_clear(mem, PG_ZERO);
20642957Sdillon		vm_page_wakeup(mem);
2071541Srgrimes	}
2085455Sdg
2091541Srgrimes	/*
2105455Sdg	 * And finally, mark the data as non-pageable.
2111541Srgrimes	 */
2121541Srgrimes
2131541Srgrimes	(void) vm_map_pageable(map, (vm_offset_t) addr, addr + size, FALSE);
2141541Srgrimes
2155455Sdg	return (addr);
2161541Srgrimes}
2171541Srgrimes
2181541Srgrimes/*
2191541Srgrimes *	kmem_free:
2201541Srgrimes *
2211541Srgrimes *	Release a region of kernel virtual memory allocated
2221541Srgrimes *	with kmem_alloc, and return the physical pages
2231541Srgrimes *	associated with that region.
22442957Sdillon *
22542957Sdillon *	This routine may not block on kernel maps.
2261541Srgrimes */
2278876Srgrimesvoid
2285455Sdgkmem_free(map, addr, size)
2295455Sdg	vm_map_t map;
2305455Sdg	register vm_offset_t addr;
2315455Sdg	vm_size_t size;
2321541Srgrimes{
2331541Srgrimes	(void) vm_map_remove(map, trunc_page(addr), round_page(addr + size));
2341541Srgrimes}
2351541Srgrimes
2361541Srgrimes/*
2371541Srgrimes *	kmem_suballoc:
2381541Srgrimes *
2391541Srgrimes *	Allocates a map to manage a subrange
2401541Srgrimes *	of the kernel virtual address space.
2411541Srgrimes *
2421541Srgrimes *	Arguments are as follows:
2431541Srgrimes *
2441541Srgrimes *	parent		Map to take range from
2451541Srgrimes *	size		Size of range to find
2461541Srgrimes *	min, max	Returned endpoints of map
2471541Srgrimes *	pageable	Can the region be paged
2481541Srgrimes */
2498876Srgrimesvm_map_t
25032702Sdysonkmem_suballoc(parent, min, max, size)
25170478Salfred	vm_map_t parent;
2525455Sdg	vm_offset_t *min, *max;
25370478Salfred	vm_size_t size;
2541541Srgrimes{
25570478Salfred	int ret;
2565455Sdg	vm_map_t result;
2571541Srgrimes
2581541Srgrimes	size = round_page(size);
2591541Srgrimes
2601541Srgrimes	*min = (vm_offset_t) vm_map_min(parent);
2611541Srgrimes	ret = vm_map_find(parent, NULL, (vm_offset_t) 0,
26213490Sdyson	    min, size, TRUE, VM_PROT_ALL, VM_PROT_ALL, 0);
2631541Srgrimes	if (ret != KERN_SUCCESS) {
2641541Srgrimes		printf("kmem_suballoc: bad status return of %d.\n", ret);
2651541Srgrimes		panic("kmem_suballoc");
2661541Srgrimes	}
2671541Srgrimes	*max = *min + size;
2681541Srgrimes	pmap_reference(vm_map_pmap(parent));
26932702Sdyson	result = vm_map_create(vm_map_pmap(parent), *min, *max);
2701541Srgrimes	if (result == NULL)
2711541Srgrimes		panic("kmem_suballoc: cannot create submap");
27270478Salfred	if (vm_map_submap(parent, *min, *max, result) != KERN_SUCCESS)
2731541Srgrimes		panic("kmem_suballoc: unable to change range to submap");
2745455Sdg	return (result);
2751541Srgrimes}
2761541Srgrimes
2771541Srgrimes/*
27842957Sdillon *	kmem_malloc:
2791541Srgrimes *
28042957Sdillon * 	Allocate wired-down memory in the kernel's address map for the higher
28142957Sdillon * 	level kernel memory allocator (kern/kern_malloc.c).  We cannot use
28242957Sdillon * 	kmem_alloc() because we may need to allocate memory at interrupt
28342957Sdillon * 	level where we cannot block (canwait == FALSE).
2841541Srgrimes *
28542957Sdillon * 	This routine has its own private kernel submap (kmem_map) and object
28642957Sdillon * 	(kmem_object).  This, combined with the fact that only malloc uses
28742957Sdillon * 	this routine, ensures that we will never block in map or object waits.
2881541Srgrimes *
28942957Sdillon * 	Note that this still only works in a uni-processor environment and
29042957Sdillon * 	when called at splhigh().
29142957Sdillon *
29242957Sdillon * 	We don't worry about expanding the map (adding entries) since entries
29342957Sdillon * 	for wired maps are statically allocated.
29442957Sdillon *
29542957Sdillon *	NOTE:  This routine is not supposed to block if M_NOWAIT is set, but
29642957Sdillon *	I have not verified that it actually does not block.
2971541Srgrimes */
2981541Srgrimesvm_offset_t
29942957Sdillonkmem_malloc(map, size, flags)
3005455Sdg	register vm_map_t map;
3015455Sdg	register vm_size_t size;
30242957Sdillon	int flags;
3031541Srgrimes{
3045455Sdg	register vm_offset_t offset, i;
3055455Sdg	vm_map_entry_t entry;
3065455Sdg	vm_offset_t addr;
3075455Sdg	vm_page_t m;
3081541Srgrimes
30921737Sdg	if (map != kmem_map && map != mb_map)
31021737Sdg		panic("kmem_malloc: map != {kmem,mb}_map");
3111541Srgrimes
3121541Srgrimes	size = round_page(size);
3131541Srgrimes	addr = vm_map_min(map);
3141541Srgrimes
3151541Srgrimes	/*
3165455Sdg	 * Locate sufficient space in the map.  This will give us the final
3175455Sdg	 * virtual address for the new memory, and thus will tell us the
3185455Sdg	 * offset within the kernel map.
3191541Srgrimes	 */
3201541Srgrimes	vm_map_lock(map);
32133758Sdyson	if (vm_map_findspace(map, vm_map_min(map), size, &addr)) {
3221541Srgrimes		vm_map_unlock(map);
3237066Sdg		if (map == mb_map) {
3247066Sdg			mb_map_full = TRUE;
32536677Sdg			printf("Out of mbuf clusters - adjust NMBCLUSTERS or increase maxusers!\n");
3267066Sdg			return (0);
3277066Sdg		}
32842957Sdillon		if ((flags & M_NOWAIT) == 0)
32948409Speter			panic("kmem_malloc(%ld): kmem_map too small: %ld total allocated",
33048409Speter				(long)size, (long)map->size);
3311541Srgrimes		return (0);
3321541Srgrimes	}
33315367Sdyson	offset = addr - VM_MIN_KERNEL_ADDRESS;
3341541Srgrimes	vm_object_reference(kmem_object);
33513490Sdyson	vm_map_insert(map, kmem_object, offset, addr, addr + size,
33613490Sdyson		VM_PROT_ALL, VM_PROT_ALL, 0);
3371541Srgrimes
3381541Srgrimes	for (i = 0; i < size; i += PAGE_SIZE) {
33942957Sdillon		/*
34042957Sdillon		 * Note: if M_NOWAIT specified alone, allocate from
34142957Sdillon		 * interrupt-safe queues only (just the free list).  If
34242957Sdillon		 * M_ASLEEP or M_USE_RESERVE is also specified, we can also
34342957Sdillon		 * allocate from the cache.  Neither of the latter two
34442957Sdillon		 * flags may be specified from an interrupt since interrupts
34542957Sdillon		 * are not allowed to mess with the cache queue.
34642957Sdillon		 */
34715809Sdysonretry:
34812767Sdyson		m = vm_page_alloc(kmem_object, OFF_TO_IDX(offset + i),
34942957Sdillon		    ((flags & (M_NOWAIT|M_ASLEEP|M_USE_RESERVE)) == M_NOWAIT) ?
35042957Sdillon			VM_ALLOC_INTERRUPT :
35142957Sdillon			VM_ALLOC_SYSTEM);
3521541Srgrimes
3531541Srgrimes		/*
3545455Sdg		 * Ran out of space, free everything up and return. Don't need
3555455Sdg		 * to lock page queues here as we know that the pages we got
3565455Sdg		 * aren't on any queues.
3571541Srgrimes		 */
3581541Srgrimes		if (m == NULL) {
35942957Sdillon			if ((flags & M_NOWAIT) == 0) {
36044793Salc				vm_map_unlock(map);
36115809Sdyson				VM_WAIT;
36244793Salc				vm_map_lock(map);
36315809Sdyson				goto retry;
36415809Sdyson			}
3651541Srgrimes			vm_map_delete(map, addr, addr + size);
3661541Srgrimes			vm_map_unlock(map);
36742957Sdillon			if (flags & M_ASLEEP) {
36842957Sdillon				VM_AWAIT;
36942957Sdillon			}
3705455Sdg			return (0);
3711541Srgrimes		}
37238799Sdfr		vm_page_flag_clear(m, PG_ZERO);
3736585Sdg		m->valid = VM_PAGE_BITS_ALL;
3741541Srgrimes	}
3751541Srgrimes
3761541Srgrimes	/*
3775455Sdg	 * Mark map entry as non-pageable. Assert: vm_map_insert() will never
3785455Sdg	 * be able to extend the previous entry so there will be a new entry
3795455Sdg	 * exactly corresponding to this address range and it will have
3805455Sdg	 * wired_count == 0.
3811541Srgrimes	 */
3821541Srgrimes	if (!vm_map_lookup_entry(map, addr, &entry) ||
3831541Srgrimes	    entry->start != addr || entry->end != addr + size ||
38444793Salc	    entry->wired_count != 0)
3851541Srgrimes		panic("kmem_malloc: entry not found or misaligned");
38644793Salc	entry->wired_count = 1;
3871541Srgrimes
38820993Sdyson	vm_map_simplify_entry(map, entry);
38920993Sdyson
3901541Srgrimes	/*
3915455Sdg	 * Loop thru pages, entering them in the pmap. (We cannot add them to
3925455Sdg	 * the wired count without wrapping the vm_page_queue_lock in
3935455Sdg	 * splimp...)
3941541Srgrimes	 */
3951541Srgrimes	for (i = 0; i < size; i += PAGE_SIZE) {
39612767Sdyson		m = vm_page_lookup(kmem_object, OFF_TO_IDX(offset + i));
39713490Sdyson		vm_page_wire(m);
39838799Sdfr		vm_page_wakeup(m);
39942957Sdillon		/*
40042957Sdillon		 * Because this is kernel_pmap, this call will not block.
40142957Sdillon		 */
40260755Speter		pmap_enter(kernel_pmap, addr + i, m, VM_PROT_ALL, 1);
40338799Sdfr		vm_page_flag_set(m, PG_MAPPED | PG_WRITEABLE | PG_REFERENCED);
4041541Srgrimes	}
4051541Srgrimes	vm_map_unlock(map);
4061541Srgrimes
4075455Sdg	return (addr);
4081541Srgrimes}
4091541Srgrimes
4101541Srgrimes/*
41142957Sdillon *	kmem_alloc_wait:
4121541Srgrimes *
4131541Srgrimes *	Allocates pageable memory from a sub-map of the kernel.  If the submap
4141541Srgrimes *	has no room, the caller sleeps waiting for more memory in the submap.
4151541Srgrimes *
41642957Sdillon *	This routine may block.
4171541Srgrimes */
41842957Sdillon
4198876Srgrimesvm_offset_t
4205455Sdgkmem_alloc_wait(map, size)
4215455Sdg	vm_map_t map;
4225455Sdg	vm_size_t size;
4231541Srgrimes{
4245455Sdg	vm_offset_t addr;
4251541Srgrimes
4261541Srgrimes	size = round_page(size);
4271541Srgrimes
4281541Srgrimes	for (;;) {
4291541Srgrimes		/*
4305455Sdg		 * To make this work for more than one map, use the map's lock
4315455Sdg		 * to lock out sleepers/wakers.
4321541Srgrimes		 */
4331541Srgrimes		vm_map_lock(map);
43433758Sdyson		if (vm_map_findspace(map, vm_map_min(map), size, &addr) == 0)
4351541Srgrimes			break;
4361541Srgrimes		/* no space now; see if we can ever get space */
4371541Srgrimes		if (vm_map_max(map) - vm_map_min(map) < size) {
4381541Srgrimes			vm_map_unlock(map);
4391541Srgrimes			return (0);
4401541Srgrimes		}
4411541Srgrimes		vm_map_unlock(map);
4429507Sdg		tsleep(map, PVM, "kmaw", 0);
4431541Srgrimes	}
44413490Sdyson	vm_map_insert(map, NULL, (vm_offset_t) 0, addr, addr + size, VM_PROT_ALL, VM_PROT_ALL, 0);
4451541Srgrimes	vm_map_unlock(map);
4461541Srgrimes	return (addr);
4471541Srgrimes}
4481541Srgrimes
4491541Srgrimes/*
45042957Sdillon *	kmem_free_wakeup:
4511541Srgrimes *
4529507Sdg *	Returns memory to a submap of the kernel, and wakes up any processes
4531541Srgrimes *	waiting for memory in that map.
4541541Srgrimes */
4558876Srgrimesvoid
4565455Sdgkmem_free_wakeup(map, addr, size)
4575455Sdg	vm_map_t map;
4585455Sdg	vm_offset_t addr;
4595455Sdg	vm_size_t size;
4601541Srgrimes{
4611541Srgrimes	vm_map_lock(map);
4621541Srgrimes	(void) vm_map_delete(map, trunc_page(addr), round_page(addr + size));
4639507Sdg	wakeup(map);
4641541Srgrimes	vm_map_unlock(map);
4651541Srgrimes}
4661541Srgrimes
4671541Srgrimes/*
46842957Sdillon * 	kmem_init:
46942957Sdillon *
47042957Sdillon *	Create the kernel map; insert a mapping covering kernel text,
47142957Sdillon *	data, bss, and all space allocated thus far (`boostrap' data).  The
47242957Sdillon *	new map will thus map the range between VM_MIN_KERNEL_ADDRESS and
47342957Sdillon *	`start' as allocated, and the range between `start' and `end' as free.
4741541Srgrimes */
47542957Sdillon
4768876Srgrimesvoid
4775455Sdgkmem_init(start, end)
4781541Srgrimes	vm_offset_t start, end;
4791541Srgrimes{
4801541Srgrimes	register vm_map_t m;
4811541Srgrimes
48232702Sdyson	m = vm_map_create(kernel_pmap, VM_MIN_KERNEL_ADDRESS, end);
4831541Srgrimes	vm_map_lock(m);
4841541Srgrimes	/* N.B.: cannot use kgdb to debug, starting with this assignment ... */
4851541Srgrimes	kernel_map = m;
48627899Sdyson	kernel_map->system_map = 1;
4875455Sdg	(void) vm_map_insert(m, NULL, (vm_offset_t) 0,
48813490Sdyson	    VM_MIN_KERNEL_ADDRESS, start, VM_PROT_ALL, VM_PROT_ALL, 0);
4891541Srgrimes	/* ... and ending with the completion of the above `insert' */
4901541Srgrimes	vm_map_unlock(m);
4911541Srgrimes}
492