patches to make kernel malloc() retryable. from <MDICKSON@CSI.compuserve.com>

This commit is contained in:
deraadt 1993-05-27 14:34:29 +00:00
parent a17c1c267a
commit ada4945e6b
2 changed files with 19 additions and 9 deletions

View File

@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* from: @(#)kern_malloc.c 7.25 (Berkeley) 5/8/91
* $Id: kern_malloc.c,v 1.3 1993/05/25 18:04:25 cgd Exp $
* $Id: kern_malloc.c,v 1.4 1993/05/27 14:35:22 deraadt Exp $
*/
#include "param.h"
@ -70,6 +70,8 @@ malloc(size, type, flags)
indx = BUCKETINDX(size);
kbp = &bucket[indx];
s = splimp();
retrymalloc:
#ifdef KMEMSTATS
while (ksp->ks_memuse >= ksp->ks_limit) {
if (flags & M_NOWAIT) {
@ -90,8 +92,16 @@ malloc(size, type, flags)
va = (caddr_t) kmem_malloc(kmem_map, (vm_size_t)ctob(npg),
!(flags & M_NOWAIT));
if (va == NULL) {
splx(s);
return ((void *) NULL);
if (flags & M_NOWAIT) {
splx(s);
return ((void *) NULL);
}
#ifdef KMEMSTATS
if (ksp->ks_mapblocks < 65535)
ksp->ks_mapblocks++;
#endif
tsleep((caddr_t)kmem_map, PSWP+2, "kern_malloc", 0);
goto retrymalloc;
}
#ifdef KMEMSTATS
kbp->kb_total += kbp->kb_elmpercl;
@ -199,6 +209,7 @@ free(addr, type)
ksp->ks_inuse--;
kbp->kb_total -= 1;
#endif
wakeup((caddr_t)kmem_map);
splx(s);
return;
}
@ -218,6 +229,7 @@ free(addr, type)
#endif
*(caddr_t *)addr = kbp->kb_next;
kbp->kb_next = addr;
wakeup((caddr_t)kmem_map);
splx(s);
}

View File

@ -34,7 +34,7 @@
* SUCH DAMAGE.
*
* from: @(#)vm_kern.c 7.4 (Berkeley) 5/7/91
* $Id: vm_kern.c,v 1.4 1993/05/20 03:59:25 cgd Exp $
* $Id: vm_kern.c,v 1.5 1993/05/27 14:34:29 deraadt Exp $
*
*
* Copyright (c) 1987, 1990 Carnegie-Mellon University.
@ -363,8 +363,8 @@ kmem_malloc(map, size, canwait)
vm_page_t m;
extern vm_object_t kmem_object;
if (map != kmem_map && map != mb_map)
panic("kern_malloc_alloc: map != {kmem,mb}_map");
if (map != kmem_map && map != mb_map && map != buffer_map)
panic("kern_malloc_alloc: map != {kmem,mb,buffer}_map");
size = round_page(size);
addr = vm_map_min(map);
@ -372,9 +372,7 @@ kmem_malloc(map, size, canwait)
if (vm_map_find(map, NULL, (vm_offset_t)0,
&addr, size, TRUE) != KERN_SUCCESS) {
if (canwait) { /* XXX -- then we should wait */
if (map == kmem_map)
panic("kmem_malloc: kmem_map too small (should wait)");
else if (map == mb_map)
if (map == mb_map)
panic("kmem_malloc: mb_map too small (should wait)");
}
return 0;