Fix bugs in the vm_map_entry reservation and zalloc code. This code is a bit
authorMatthew Dillon <dillon@dragonflybsd.org>
Tue, 26 Oct 2004 04:33:11 +0000 (04:33 +0000)
committerMatthew Dillon <dillon@dragonflybsd.org>
Tue, 26 Oct 2004 04:33:11 +0000 (04:33 +0000)
commitc4ae567f81d248a86c02506787f89d0d7ecf9007
treede95b5c10fc1b65a25f8dd6ab8080c4d267492c3
parentff8e0d007e5af0b8b66124aa15ca114eccd26bce
Fix bugs in the vm_map_entry reservation and zalloc code.  This code is a bit
sticky because zalloc must be able to call kmem_alloc*() in order to extend
mapentzone to allocate a new chunk of vm_map_entry structures, and
kmem_alloc*() *needs* two vm_map_entry structures in order to map the new
data block into the kernel.  To avoid a chicken-and-egg recursion there must
already be some vm_map_entry structures available for kmem_alloc*() to use.

To ensure that structures are available the vm_map_entry cache maintains
a 'reserve'.  This cache is initially populated from the vm_map_entry's
allocated via zbootinit() in vm_map.c.  However, since this is a per-cpu
cache there are situations where the vm_map subsystem will be used on other
cpus before the cache can be populated on those cpus, but after the static
zbootinit structures have all been used up.  To fix this we statically
allocate two vm_map_entry structures for each cpu which is sufficient for
zalloc to call kmem_alloc*() to allocate the remainder of the reserve.
Having a lot preloaded modules seems to be able to trigger the bug.

Also get rid of gd_vme_kdeficit which was a confusing methodology to
keep track of kernel reservations.  Now we just have gd_vme_avail and
a negative count indicates a deficit (the reserve is being dug into).

From-panic-reported-by: Adam K Kirchhoff <adamk@voicenet.com>
sys/sys/globaldata.h
sys/vm/vm_map.c
sys/vm/vm_zone.c
sys/vm/vm_zone.h