From: Matthew Dillon Date: Wed, 17 Nov 2004 23:36:21 +0000 (+0000) Subject: Remove unused junk from the slab allocator. X-Git-Tag: v2.0.1~9701 X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/c397c465e5a4fa26b37f6d5f9e48e651a99142df Remove unused junk from the slab allocator. Remove M_FAILSAFE and M_INTALLOC. M_FAILSAFE was a double check for interrupt-time allocations but using it was problematic at best and as a consequence it was never used. M_INTALLOC was a macro that used M_FAILSAFE and was also never used. The standard M_ flags for interrupt time allocations are M_INTNOWAIT and M_INTWAIT. --- diff --git a/sys/kern/kern_slaballoc.c b/sys/kern/kern_slaballoc.c index ff9d31b600..80a50b4a78 100644 --- a/sys/kern/kern_slaballoc.c +++ b/sys/kern/kern_slaballoc.c @@ -33,7 +33,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/kern/kern_slaballoc.c,v 1.24 2004/07/29 08:50:09 dillon Exp $ + * $DragonFly: src/sys/kern/kern_slaballoc.c,v 1.25 2004/11/17 23:36:17 dillon Exp $ * * This module implements a slab allocator drop-in replacement for the * kernel malloc(). @@ -123,7 +123,6 @@ static int ZoneSize; static int ZoneLimit; static int ZonePageCount; -static int ZonePageLimit; static int ZoneMask; static struct malloc_type *kmemstatistics; static struct kmemusage *kmemusage; @@ -194,7 +193,6 @@ kmeminit(void *dummy) if (ZoneLimit > ZALLOC_ZONE_LIMIT) ZoneLimit = ZALLOC_ZONE_LIMIT; ZoneMask = ZoneSize - 1; - ZonePageLimit = PAGE_SIZE * 4; ZonePageCount = ZoneSize / PAGE_SIZE; npg = (VM_MAX_KERNEL_ADDRESS - VM_MIN_KERNEL_ADDRESS) / PAGE_SIZE; @@ -344,11 +342,6 @@ zoneindex(unsigned long *bytes) * M_ZERO - zero the returned memory. * M_USE_RESERVE - allow greater drawdown of the free list * M_USE_INTERRUPT_RESERVE - allow the freelist to be exhausted - * - * M_FAILSAFE - Failsafe allocation, when the allocation must - * succeed attemp to get out of any preemption context - * and allocate from the cache, else block (even though - * we might be blocking from an interrupt), or panic. */ void * malloc(unsigned long size, struct malloc_type *type, int flags) @@ -870,9 +863,9 @@ free(void *ptr, struct malloc_type *type) * after the new space is made available. * * Interrupt code which has preempted other code is not allowed to - * message with CACHE pages, but if M_FAILSAFE is set we can do a - * yield to become non-preempting and try again inclusive of - * cache pages. + * use PQ_CACHE pages. However, if an interrupt thread is run + * non-preemptively or blocks and then runs non-preemptively, then + * it is free to use PQ_CACHE pages. */ static void * kmem_slab_alloc(vm_size_t size, vm_offset_t align, int flags) @@ -899,7 +892,7 @@ kmem_slab_alloc(vm_size_t size, vm_offset_t align, int flags) panic("kmem_slab_alloc(): kernel_map ran out of space!"); crit_exit(); vm_map_entry_release(count); - if ((flags & (M_FAILSAFE|M_NULLOK)) == M_FAILSAFE) + if ((flags & M_NULLOK) == 0) panic("kmem_slab_alloc(): kernel_map ran out of space!"); return(NULL); } @@ -929,11 +922,14 @@ kmem_slab_alloc(vm_size_t size, vm_offset_t align, int flags) panic("kmem_slab_alloc: bad flags %08x (%p)", flags, ((int **)&size)[-1]); /* - * Never set VM_ALLOC_NORMAL during a preemption because this allows - * allocation out of the VM page cache and could cause mainline kernel - * code working on VM objects to get confused. + * VM_ALLOC_NORMAL can only be set if we are not preempting. + * + * VM_ALLOC_SYSTEM is automatically set if we are preempting and + * M_WAITOK was specified as an alternative (i.e. M_USE_RESERVE is + * implied in this case), though I'm sure if we really need to do + * that. */ - if (flags & (M_FAILSAFE|M_WAITOK)) { + if (flags & M_WAITOK) { if (td->td_preempted) { vmflags |= VM_ALLOC_SYSTEM; } else { @@ -946,23 +942,15 @@ kmem_slab_alloc(vm_size_t size, vm_offset_t align, int flags) /* * If the allocation failed we either return NULL or we retry. * - * If M_WAITOK or M_FAILSAFE is set we retry. Note that M_WAITOK - * (and M_FAILSAFE) can be specified from an interrupt. M_FAILSAFE - * generates a warning or a panic. - * - * If we are preempting a thread we yield instead of block. Both - * gets us out from under a preemption but yielding will get cpu - * back more quicker. Livelock does not occur because we will not - * be preempting anyone the second time around. - * + * If M_WAITOK is specified we wait for more memory and retry. + * If M_WAITOK is specified from a preemption we yield instead of + * wait. Livelock will not occur because the interrupt thread + * will not be preempting anyone the second time around after the + * yield. */ if (m == NULL) { - if (flags & (M_FAILSAFE|M_WAITOK)) { + if (flags & M_WAITOK) { if (td->td_preempted) { - if (flags & M_FAILSAFE) { - printf("malloc: M_WAITOK from preemption would block" - " try failsafe yield/block\n"); - } vm_map_unlock(map); lwkt_yield(); vm_map_lock(map); diff --git a/sys/sys/malloc.h b/sys/sys/malloc.h index abf9d90ddd..bc95bed046 100644 --- a/sys/sys/malloc.h +++ b/sys/sys/malloc.h @@ -32,7 +32,7 @@ * * @(#)malloc.h 8.5 (Berkeley) 5/3/95 * $FreeBSD: src/sys/sys/malloc.h,v 1.48.2.2 2002/03/16 02:19:16 archie Exp $ - * $DragonFly: src/sys/sys/malloc.h,v 1.19 2004/07/29 08:50:07 dillon Exp $ + * $DragonFly: src/sys/sys/malloc.h,v 1.20 2004/11/17 23:36:19 dillon Exp $ */ #ifndef _SYS_MALLOC_H_ @@ -67,32 +67,25 @@ #define M_PASSIVE_ZERO 0x0800 /* (internal to the slab code only) */ #define M_USE_INTERRUPT_RESERVE \ 0x1000 /* can exhaust free list entirely */ -#define M_FAILSAFE 0x2000 /* failsafe allocation attempt */ /* * M_NOWAIT has to be a set of flags for equivalence to prior use. * - * M_INTALLOC should be used for any critical infrastructure allocations - * made from interrupts. - * * M_SYSALLOC should be used for any critical infrastructure allocations * made by the kernel proper. * - * NOTE ON DRAGONFLY USE OF M_NOWAIT. M_NOWAIT has traditionally been used - * when we did not wish to break spl protections or when we allocate memory - * from interrupts. For the spl protection case we intend to move all - * such allocations outside of the spl blocks. + * M_INTNOWAIT should be used for any critical infrastructure allocations + * made by interrupts. Such allocations can still fail but will not fail + * as often as M_NOWAIT. + * + * NOTE ON DRAGONFLY USE OF M_NOWAIT. In FreeBSD M_NOWAIT allocations + * almost always succeed. In DragonFly, however, there is a good chance + * that an allocation will fail. M_NOWAIT should only be used when + * allocations can fail without any serious detriment to the system. * - * For the interrupt case the issue comes down to whether it is possible - * to allocate out of the VM page cache. Since interrupts are threads it - * is theoretically possible to allocate out of the VM page cache as long - * as we determine that we are not preempting another thread. This is a - * simple td->td_preempted check. In DFly we can also theoretically do - * an lwkt_yield() to force the interrupt thread to be rescheduled (so it - * is no longer preempting a thread) and then allocate out of the cache. - * This is what the M_FAILSAFE flag does in M_INTALLOC and this is why - * M_INTALLOC should be used in interrupt-related situations where the - * allocation must absolutely succeed for the health of the machine. + * Note that allocations made from (preempted) interrupts will attempt to + * use pages from the VM PAGE CACHE (PQ_CACHE) (i.e. those associated with + * objects). This is automatic. */ #define M_INTNOWAIT (M_RNOWAIT|M_USE_RESERVE|M_USE_INTERRUPT_RESERVE) @@ -101,7 +94,6 @@ #define M_SYSWAIT (M_WAITOK|M_USE_RESERVE) #define M_NOWAIT M_INTNOWAIT -#define M_INTALLOC (M_INTNOWAIT|M_FAILSAFE) #define M_SYSALLOC M_SYSWAIT #define M_MAGIC 877983977 /* time when first defined :-) */ diff --git a/sys/vm/vm_kern.c b/sys/vm/vm_kern.c index 71a663c350..6ab9c358cd 100644 --- a/sys/vm/vm_kern.c +++ b/sys/vm/vm_kern.c @@ -62,7 +62,7 @@ * rights to redistribute these changes. * * $FreeBSD: src/sys/vm/vm_kern.c,v 1.61.2.2 2002/03/12 18:25:26 tegge Exp $ - * $DragonFly: src/sys/vm/vm_kern.c,v 1.18 2004/07/31 07:52:51 dillon Exp $ + * $DragonFly: src/sys/vm/vm_kern.c,v 1.19 2004/11/17 23:36:21 dillon Exp $ */ /* @@ -307,16 +307,15 @@ kmem_malloc(vm_map_t map, vm_size_t size, int flags) /* * Locate sufficient space in the map. This will give us the final * virtual address for the new memory, and thus will tell us the - * offset within the kernel map. + * offset within the kernel map. If we are unable to allocate space + * and neither RNOWAIT or NULLOK is set, we panic. */ count = vm_map_entry_reserve(MAP_RESERVE_COUNT); vm_map_lock(map); if (vm_map_findspace(map, vm_map_min(map), size, 1, &addr)) { vm_map_unlock(map); vm_map_entry_release(count); - if ((flags & (M_RNOWAIT|M_NULLOK)) == 0 || - (flags & (M_FAILSAFE|M_NULLOK)) == M_FAILSAFE - ) { + if ((flags & (M_RNOWAIT|M_NULLOK)) == 0) { panic("kmem_malloc(%ld): kernel_map too small: " "%ld total allocated", (long)size, (long)map->size); @@ -340,7 +339,12 @@ kmem_malloc(vm_map_t map, vm_size_t size, int flags) printf("kmem_malloc: bad flags %08x (%p)\n", flags, ((int **)&map)[-1]); if (flags & M_USE_INTERRUPT_RESERVE) vmflags |= VM_ALLOC_INTERRUPT; - if (flags & (M_FAILSAFE|M_WAITOK)) { + + /* + * Only allocate PQ_CACHE pages for M_WAITOK requests and + * then only if we are not preempting. + */ + if (flags & M_WAITOK) { if (td->td_preempted) { wanted_reserve = 1; } else { @@ -352,23 +356,19 @@ kmem_malloc(vm_map_t map, vm_size_t size, int flags) m = vm_page_alloc(kmem_object, OFF_TO_IDX(offset + i), vmflags); /* - * Ran out of space, free everything up and return. Don't need + * Ran out of space, free everything up and return. Don't need * to lock page queues here as we know that the pages we got * aren't on any queues. * - * If M_WAITOK or M_FAILSAFE is set we can yield or block. + * If M_WAITOK is set we can yield or block. */ if (m == NULL) { - if (flags & (M_FAILSAFE|M_WAITOK)) { + if (flags & M_WAITOK) { if (wanted_reserve) { - if (flags & M_FAILSAFE) - printf("kmem_malloc: no memory, try failsafe\n"); vm_map_unlock(map); lwkt_yield(); vm_map_lock(map); } else { - if (flags & M_FAILSAFE) - printf("kmem_malloc: no memory, block even though we shouldn't\n"); vm_map_unlock(map); vm_wait(); vm_map_lock(map);