vm_kern.c (91946) | vm_kern.c (92029) |
---|---|
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 * | 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_kern.c 91946 2002-03-09 16:24:27Z tegge $ | 64 * $FreeBSD: head/sys/vm/vm_kern.c 92029 2002-03-10 21:52:48Z eivind $ |
65 */ 66 67/* 68 * Kernel memory management. 69 */ 70 71#include <sys/param.h> 72#include <sys/systm.h> --- 19 unchanged lines hidden (view full) --- 92vm_map_t buffer_map=0; 93 94/* 95 * kmem_alloc_pageable: 96 * 97 * Allocate pageable memory to the kernel's address map. 98 * "map" must be kernel_map or a submap of kernel_map. 99 */ | 65 */ 66 67/* 68 * Kernel memory management. 69 */ 70 71#include <sys/param.h> 72#include <sys/systm.h> --- 19 unchanged lines hidden (view full) --- 92vm_map_t buffer_map=0; 93 94/* 95 * kmem_alloc_pageable: 96 * 97 * Allocate pageable memory to the kernel's address map. 98 * "map" must be kernel_map or a submap of kernel_map. 99 */ |
100 | |
101vm_offset_t 102kmem_alloc_pageable(map, size) 103 vm_map_t map; 104 vm_size_t size; 105{ 106 vm_offset_t addr; 107 int result; 108 --- 9 unchanged lines hidden (view full) --- 118 return (addr); 119} 120 121/* 122 * kmem_alloc_nofault: 123 * 124 * Same as kmem_alloc_pageable, except that it create a nofault entry. 125 */ | 100vm_offset_t 101kmem_alloc_pageable(map, size) 102 vm_map_t map; 103 vm_size_t size; 104{ 105 vm_offset_t addr; 106 int result; 107 --- 9 unchanged lines hidden (view full) --- 117 return (addr); 118} 119 120/* 121 * kmem_alloc_nofault: 122 * 123 * Same as kmem_alloc_pageable, except that it create a nofault entry. 124 */ |
126 | |
127vm_offset_t 128kmem_alloc_nofault(map, size) 129 vm_map_t map; 130 vm_size_t size; 131{ 132 vm_offset_t addr; 133 int result; 134 --- 59 unchanged lines hidden (view full) --- 194 * pager_data_request. But the kmsg zone is empty, so we must 195 * kmem_alloc. 4) goto 1 5) Even if the kmsg zone is not empty: when 196 * we get the data back from the pager, it will be (very stale) 197 * non-zero data. kmem_alloc is defined to return zero-filled memory. 198 * 199 * We're intentionally not activating the pages we allocate to prevent a 200 * race with page-out. vm_map_pageable will wire the pages. 201 */ | 125vm_offset_t 126kmem_alloc_nofault(map, size) 127 vm_map_t map; 128 vm_size_t size; 129{ 130 vm_offset_t addr; 131 int result; 132 --- 59 unchanged lines hidden (view full) --- 192 * pager_data_request. But the kmsg zone is empty, so we must 193 * kmem_alloc. 4) goto 1 5) Even if the kmsg zone is not empty: when 194 * we get the data back from the pager, it will be (very stale) 195 * non-zero data. kmem_alloc is defined to return zero-filled memory. 196 * 197 * We're intentionally not activating the pages we allocate to prevent a 198 * race with page-out. vm_map_pageable will wire the pages. 199 */ |
202 | |
203 for (i = 0; i < size; i += PAGE_SIZE) { 204 vm_page_t mem; 205 206 mem = vm_page_grab(kernel_object, OFF_TO_IDX(offset + i), 207 VM_ALLOC_ZERO | VM_ALLOC_RETRY); 208 if ((mem->flags & PG_ZERO) == 0) 209 vm_page_zero_fill(mem); 210 mem->valid = VM_PAGE_BITS_ALL; 211 vm_page_flag_clear(mem, PG_ZERO); 212 vm_page_wakeup(mem); 213 } 214 215 /* 216 * And finally, mark the data as non-pageable. 217 */ | 200 for (i = 0; i < size; i += PAGE_SIZE) { 201 vm_page_t mem; 202 203 mem = vm_page_grab(kernel_object, OFF_TO_IDX(offset + i), 204 VM_ALLOC_ZERO | VM_ALLOC_RETRY); 205 if ((mem->flags & PG_ZERO) == 0) 206 vm_page_zero_fill(mem); 207 mem->valid = VM_PAGE_BITS_ALL; 208 vm_page_flag_clear(mem, PG_ZERO); 209 vm_page_wakeup(mem); 210 } 211 212 /* 213 * And finally, mark the data as non-pageable. 214 */ |
218 | |
219 (void) vm_map_pageable(map, (vm_offset_t) addr, addr + size, FALSE); 220 221 return (addr); 222} 223 224/* 225 * kmem_free: 226 * --- 211 unchanged lines hidden (view full) --- 438/* 439 * kmem_alloc_wait: 440 * 441 * Allocates pageable memory from a sub-map of the kernel. If the submap 442 * has no room, the caller sleeps waiting for more memory in the submap. 443 * 444 * This routine may block. 445 */ | 215 (void) vm_map_pageable(map, (vm_offset_t) addr, addr + size, FALSE); 216 217 return (addr); 218} 219 220/* 221 * kmem_free: 222 * --- 211 unchanged lines hidden (view full) --- 434/* 435 * kmem_alloc_wait: 436 * 437 * Allocates pageable memory from a sub-map of the kernel. If the submap 438 * has no room, the caller sleeps waiting for more memory in the submap. 439 * 440 * This routine may block. 441 */ |
446 | |
447vm_offset_t 448kmem_alloc_wait(map, size) 449 vm_map_t map; 450 vm_size_t size; 451{ 452 vm_offset_t addr; 453 454 GIANT_REQUIRED; --- 44 unchanged lines hidden (view full) --- 499/* 500 * kmem_init: 501 * 502 * Create the kernel map; insert a mapping covering kernel text, 503 * data, bss, and all space allocated thus far (`boostrap' data). The 504 * new map will thus map the range between VM_MIN_KERNEL_ADDRESS and 505 * `start' as allocated, and the range between `start' and `end' as free. 506 */ | 442vm_offset_t 443kmem_alloc_wait(map, size) 444 vm_map_t map; 445 vm_size_t size; 446{ 447 vm_offset_t addr; 448 449 GIANT_REQUIRED; --- 44 unchanged lines hidden (view full) --- 494/* 495 * kmem_init: 496 * 497 * Create the kernel map; insert a mapping covering kernel text, 498 * data, bss, and all space allocated thus far (`boostrap' data). The 499 * new map will thus map the range between VM_MIN_KERNEL_ADDRESS and 500 * `start' as allocated, and the range between `start' and `end' as free. 501 */ |
507 | |
508void 509kmem_init(start, end) 510 vm_offset_t start, end; 511{ 512 vm_map_t m; 513 514 m = vm_map_create(kernel_pmap, VM_MIN_KERNEL_ADDRESS, end); 515 vm_map_lock(m); 516 /* N.B.: cannot use kgdb to debug, starting with this assignment ... */ 517 kernel_map = m; 518 kernel_map->system_map = 1; 519 (void) vm_map_insert(m, NULL, (vm_offset_t) 0, 520 VM_MIN_KERNEL_ADDRESS, start, VM_PROT_ALL, VM_PROT_ALL, 0); 521 /* ... and ending with the completion of the above `insert' */ 522 vm_map_unlock(m); 523} | 502void 503kmem_init(start, end) 504 vm_offset_t start, end; 505{ 506 vm_map_t m; 507 508 m = vm_map_create(kernel_pmap, VM_MIN_KERNEL_ADDRESS, end); 509 vm_map_lock(m); 510 /* N.B.: cannot use kgdb to debug, starting with this assignment ... */ 511 kernel_map = m; 512 kernel_map->system_map = 1; 513 (void) vm_map_insert(m, NULL, (vm_offset_t) 0, 514 VM_MIN_KERNEL_ADDRESS, start, VM_PROT_ALL, VM_PROT_ALL, 0); 515 /* ... and ending with the completion of the above `insert' */ 516 vm_map_unlock(m); 517} |