From 3130798e2b2e4152e1f8566a70736c3ca28fd94a Mon Sep 17 00:00:00 2001 From: dyson Date: Sat, 18 May 1996 22:33:13 +0000 Subject: Minor performance improvement to kern_malloc.c that increases the probability of reuse of recently freed memory. This improves cache hit stats on cached memory, and improves at least fork speed consistancy. --- sys/kern/kern_malloc.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'sys/kern/kern_malloc.c') diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c index b348a3c..5375d6d 100644 --- a/sys/kern/kern_malloc.c +++ b/sys/kern/kern_malloc.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)kern_malloc.c 8.3 (Berkeley) 1/4/94 - * $Id: kern_malloc.c,v 1.21 1996/05/02 14:20:20 phk Exp $ + * $Id: kern_malloc.c,v 1.22 1996/05/10 19:28:48 wollman Exp $ */ #include @@ -351,12 +351,28 @@ free(addr, type) wakeup((caddr_t)ksp); ksp->ks_inuse--; #endif +#ifdef OLD_MALLOC_MEMORY_POLICY if (kbp->kb_next == NULL) kbp->kb_next = addr; else ((struct freelist *)kbp->kb_last)->next = addr; freep->next = NULL; kbp->kb_last = addr; +#else + /* + * Return memory to the head of the queue for quick reuse. This + * can improve performance by improving the probability of the + * item being in the cache when it is reused. + */ + if (kbp->kb_next == NULL) { + kbp->kb_next = addr; + kbp->kb_last = addr; + freep->next = NULL; + } else { + freep->next = kbp->kb_next; + kbp->kb_next = addr; + } +#endif splx(s); } -- cgit v1.1