diff options
author | attilio <attilio@FreeBSD.org> | 2011-05-13 20:58:48 +0000 |
---|---|---|
committer | attilio <attilio@FreeBSD.org> | 2011-05-13 20:58:48 +0000 |
commit | 9ff3491e673bf8c43598fcc1af408f5e7c80e854 (patch) | |
tree | f34ed698a1044eda15705db3b73ae0594bf0be71 /sys/vm/vm_kern.c | |
parent | a79fdc81aa4d25507b90e10fedbc38d5ad84ba4a (diff) | |
download | FreeBSD-src-9ff3491e673bf8c43598fcc1af408f5e7c80e854.zip FreeBSD-src-9ff3491e673bf8c43598fcc1af408f5e7c80e854.tar.gz |
MFC
Diffstat (limited to 'sys/vm/vm_kern.c')
-rw-r--r-- | sys/vm/vm_kern.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/sys/vm/vm_kern.c b/sys/vm/vm_kern.c index 0360af7..23884af 100644 --- a/sys/vm/vm_kern.c +++ b/sys/vm/vm_kern.c @@ -91,6 +91,9 @@ vm_map_t exec_map=0; vm_map_t pipe_map; vm_map_t buffer_map=0; +const void *zero_region; +CTASSERT((ZERO_REGION_SIZE & PAGE_MASK) == 0); + /* * kmem_alloc_nofault: * @@ -527,6 +530,32 @@ kmem_free_wakeup(map, addr, size) vm_map_unlock(map); } +static void +kmem_init_zero_region(void) +{ + vm_offset_t addr, i; + vm_page_t m; + int error; + + /* + * Map a single physical page of zeros to a larger virtual range. + * This requires less looping in places that want large amounts of + * zeros, while not using much more physical resources. + */ + addr = kmem_alloc_nofault(kernel_map, ZERO_REGION_SIZE); + m = vm_page_alloc(NULL, OFF_TO_IDX(addr - VM_MIN_KERNEL_ADDRESS), + VM_ALLOC_NOOBJ | VM_ALLOC_WIRED | VM_ALLOC_ZERO); + if ((m->flags & PG_ZERO) == 0) + pmap_zero_page(m); + for (i = 0; i < ZERO_REGION_SIZE; i += PAGE_SIZE) + pmap_qenter(addr + i, &m, 1); + error = vm_map_protect(kernel_map, addr, addr + ZERO_REGION_SIZE, + VM_PROT_READ, TRUE); + KASSERT(error == 0, ("error=%d", error)); + + zero_region = (const void *)addr; +} + /* * kmem_init: * @@ -555,6 +584,8 @@ kmem_init(start, end) start, VM_PROT_ALL, VM_PROT_ALL, MAP_NOFAULT); /* ... and ending with the completion of the above `insert' */ vm_map_unlock(m); + + kmem_init_zero_region(); } #ifdef DIAGNOSTIC |