Deleted Added
sdiff udiff text old ( 92588 ) new ( 92654 )
full compact
1/*
2 * Copyright (c) 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * The Mach Operating System project at Carnegie-Mellon University.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 47 unchanged lines hidden (view full) ---

56 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
57 * School of Computer Science
58 * Carnegie Mellon University
59 * Pittsburgh PA 15213-3890
60 *
61 * any improvements or extensions that they make and grant Carnegie the
62 * rights to redistribute these changes.
63 *
64 * $FreeBSD: head/sys/vm/vm_map.c 92588 2002-03-18 15:08:09Z green $
65 */
66
67/*
68 * Virtual memory mapping module.
69 */
70
71#include <sys/param.h>
72#include <sys/systm.h>

--- 10 unchanged lines hidden (view full) ---

83#include <vm/vm_param.h>
84#include <vm/pmap.h>
85#include <vm/vm_map.h>
86#include <vm/vm_page.h>
87#include <vm/vm_object.h>
88#include <vm/vm_pager.h>
89#include <vm/vm_kern.h>
90#include <vm/vm_extern.h>
91#include <vm/vm_zone.h>
92#include <vm/swap_pager.h>
93
94/*
95 * Virtual memory maps provide for the mapping, protection,
96 * and sharing of virtual memory objects. In addition,
97 * this module provides for an efficient virtual copy of
98 * memory from one map to another.
99 *

--- 26 unchanged lines hidden (view full) ---

126 *
127 * - The kernel map and kmem submap are allocated statically.
128 * - Kernel map entries are allocated out of a static pool.
129 *
130 * These restrictions are necessary since malloc() uses the
131 * maps and requires map entries.
132 */
133
134static struct vm_zone kmapentzone_store, mapentzone_store, mapzone_store;
135static vm_zone_t mapentzone, kmapentzone, mapzone, vmspace_zone;
136static struct vm_object kmapentobj, mapentobj, mapobj;
137
138static struct vm_map_entry map_entry_init[MAX_MAPENT];
139static struct vm_map_entry kmap_entry_init[MAX_KMAPENT];
140static struct vm_map map_init[MAX_KMAP];
141
142void
143vm_map_startup(void)
144{
145 mapzone = &mapzone_store;
146 zbootinit(mapzone, "MAP", sizeof (struct vm_map),
147 map_init, MAX_KMAP);
148 kmapentzone = &kmapentzone_store;
149 zbootinit(kmapentzone, "KMAP ENTRY", sizeof (struct vm_map_entry),
150 kmap_entry_init, MAX_KMAPENT);
151 mapentzone = &mapentzone_store;
152 zbootinit(mapentzone, "MAP ENTRY", sizeof (struct vm_map_entry),
153 map_entry_init, MAX_MAPENT);
154}
155
156/*
157 * Allocate a vmspace structure, including a vm_map and pmap,
158 * and initialize those structures. The refcnt is set to 1.
159 * The remaining fields must be initialized by the caller.
160 */
161struct vmspace *
162vmspace_alloc(min, max)
163 vm_offset_t min, max;
164{
165 struct vmspace *vm;
166
167 GIANT_REQUIRED;
168 vm = zalloc(vmspace_zone);
169 CTR1(KTR_VM, "vmspace_alloc: %p", vm);
170 vm_map_init(&vm->vm_map, min, max);
171 pmap_pinit(vmspace_pmap(vm));
172 vm->vm_map.pmap = vmspace_pmap(vm); /* XXX */
173 vm->vm_refcnt = 1;
174 vm->vm_shm = NULL;
175 vm->vm_freer = NULL;
176 return (vm);
177}
178
179void
180vm_init2(void)
181{
182 zinitna(kmapentzone, &kmapentobj,
183 NULL, 0, cnt.v_page_count / 4, ZONE_INTERRUPT, 1);
184 zinitna(mapentzone, &mapentobj,
185 NULL, 0, 0, 0, 1);
186 zinitna(mapzone, &mapobj,
187 NULL, 0, 0, 0, 1);
188 vmspace_zone = zinit("VMSPACE", sizeof (struct vmspace), 0, 0, 3);
189 pmap_init2();
190 vm_object_init2();
191}
192
193static __inline void
194vmspace_dofree(struct vmspace *vm)
195{
196 CTR1(KTR_VM, "vmspace_free: %p", vm);
197 /*
198 * Lock the map, to wait out all other references to it.
199 * Delete all of the mappings and pages they hold, then call
200 * the pmap module to reclaim anything left.
201 */
202 vm_map_lock(&vm->vm_map);
203 (void) vm_map_delete(&vm->vm_map, vm->vm_map.min_offset,
204 vm->vm_map.max_offset);
205 vm_map_unlock(&vm->vm_map);
206 pmap_release(vmspace_pmap(vm));
207 vm_map_destroy(&vm->vm_map);
208 zfree(vmspace_zone, vm);
209}
210
211void
212vmspace_free(struct vmspace *vm)
213{
214 GIANT_REQUIRED;
215
216 if (vm->vm_refcnt == 0)

--- 168 unchanged lines hidden (view full) ---

385 */
386vm_map_t
387vm_map_create(pmap_t pmap, vm_offset_t min, vm_offset_t max)
388{
389 vm_map_t result;
390
391 GIANT_REQUIRED;
392
393 result = zalloc(mapzone);
394 CTR1(KTR_VM, "vm_map_create: %p", result);
395 vm_map_init(result, min, max);
396 result->pmap = pmap;
397 return (result);
398}
399
400/*
401 * Initialize an existing vm_map structure
402 * such as that in the vmspace structure.
403 * The pmap is set elsewhere.
404 */
405void
406vm_map_init(vm_map_t map, vm_offset_t min, vm_offset_t max)
407{
408 GIANT_REQUIRED;
409
410 map->header.next = map->header.prev = &map->header;
411 map->nentries = 0;
412 map->size = 0;
413 map->system_map = 0;
414 map->infork = 0;
415 map->min_offset = min;
416 map->max_offset = max;
417 map->first_free = &map->header;
418 map->hint = &map->header;
419 map->timestamp = 0;
420 lockinit(&map->lock, PVM, "thrd_sleep", 0, LK_NOPAUSE);
421}
422
423void
424vm_map_destroy(map)
425 struct vm_map *map;
426{
427 GIANT_REQUIRED;
428 lockdestroy(&map->lock);
429}
430
431/*
432 * vm_map_entry_dispose: [ internal use only ]
433 *
434 * Inverse of vm_map_entry_create.
435 */
436static void
437vm_map_entry_dispose(vm_map_t map, vm_map_entry_t entry)
438{
439 zfree((map->system_map || !mapentzone) ? kmapentzone : mapentzone, entry);
440}
441
442/*
443 * vm_map_entry_create: [ internal use only ]
444 *
445 * Allocates a VM map entry for insertion.
446 * No entry fields are filled in.
447 */
448static vm_map_entry_t
449vm_map_entry_create(vm_map_t map)
450{
451 vm_map_entry_t new_entry;
452
453 new_entry = zalloc((map->system_map || !mapentzone) ?
454 kmapentzone : mapentzone);
455 if (new_entry == NULL)
456 panic("vm_map_entry_create: kernel resources exhausted");
457 return (new_entry);
458}
459
460/*
461 * vm_map_entry_{un,}link:
462 *

--- 2805 unchanged lines hidden ---