Follow christos' suggestions, and make ks_active a u_short, and
also only use 16 u_shorts instead of 32 ints. Also add panic() calls for under- and overflow of the ks_active members under DIAGNOSTIC. The MAXBUCKET constant ended up in sys/mallocvar.h and not sys/param.h, as the latter caused build problems. Ride the kernel revision bump of my previous change.
This commit is contained in:
parent
1bc7bb47a0
commit
d399695a05
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: kern_malloc.c,v 1.129 2010/04/05 07:16:13 he Exp $ */
|
||||
/* $NetBSD: kern_malloc.c,v 1.130 2010/04/05 08:03:42 he Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1987, 1991, 1993
|
||||
@ -66,7 +66,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: kern_malloc.c,v 1.129 2010/04/05 07:16:13 he Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: kern_malloc.c,v 1.130 2010/04/05 08:03:42 he Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/proc.h>
|
||||
@ -371,7 +371,11 @@ kern_malloc(unsigned long size, struct malloc_type *ksp, int flags)
|
||||
&malloc_lock);
|
||||
}
|
||||
ksp->ks_size |= 1 << indx;
|
||||
ksp->ks_active[indx]++;
|
||||
#ifdef DIAGNOSTIC
|
||||
if (ksp->ks_active[indx - MINBUCKET] == USHRT_MAX)
|
||||
panic("too many allocations in bucket");
|
||||
#endif
|
||||
ksp->ks_active[indx - MINBUCKET]++;
|
||||
#endif
|
||||
#ifdef DIAGNOSTIC
|
||||
copysize = 1 << indx < MAX_COPY ? 1 << indx : MAX_COPY;
|
||||
@ -605,7 +609,11 @@ kern_free(void *addr, struct malloc_type *ksp)
|
||||
#ifdef KMEMSTATS
|
||||
size = kup->ku_pagecnt << PGSHIFT;
|
||||
ksp->ks_memuse -= size;
|
||||
ksp->ks_active[kup->ku_indx]--;
|
||||
#ifdef DIAGNOSTIC
|
||||
if (ksp->ks_active[kup->ku_indx - MINBUCKET] == 0)
|
||||
panic("no active allocation(1), probably double free");
|
||||
#endif
|
||||
ksp->ks_active[kup->ku_indx - MINBUCKET]--;
|
||||
kup->ku_indx = 0;
|
||||
kup->ku_pagecnt = 0;
|
||||
if (ksp->ks_memuse + size >= ksp->ks_limit &&
|
||||
@ -662,7 +670,11 @@ kern_free(void *addr, struct malloc_type *ksp)
|
||||
}
|
||||
kbp->kb_totalfree++;
|
||||
ksp->ks_memuse -= size;
|
||||
ksp->ks_active[kup->ku_indx]--;
|
||||
#ifdef DIAGNOSTIC
|
||||
if (ksp->ks_active[kup->ku_indx - MINBUCKET] == 0)
|
||||
panic("no active allocation(2), probably double free");
|
||||
#endif
|
||||
ksp->ks_active[kup->ku_indx - MINBUCKET]--;
|
||||
if (ksp->ks_memuse + size >= ksp->ks_limit &&
|
||||
ksp->ks_memuse < ksp->ks_limit)
|
||||
wakeup((void *)ksp);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: mallocvar.h,v 1.8 2010/04/05 07:16:12 he Exp $ */
|
||||
/* $NetBSD: mallocvar.h,v 1.9 2010/04/05 08:03:41 he Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1987, 1993
|
||||
@ -38,6 +38,7 @@
|
||||
|
||||
#define M_MAGIC 877983977
|
||||
|
||||
#define MAXBUCKET 15
|
||||
/*
|
||||
* This structure describes a type of malloc'd memory and carries
|
||||
* allocation statistics for that memory.
|
||||
@ -56,7 +57,7 @@ struct malloc_type {
|
||||
u_long ks_maxused; /* maximum number ever used */
|
||||
u_long ks_limit; /* most that are allowed to exist */
|
||||
u_long ks_size; /* sizes of this thing that are allocated */
|
||||
u_int ks_active[32]; /* number of active allocations per size */
|
||||
u_short ks_active[MAXBUCKET+1]; /* number of active allocations per size */
|
||||
};
|
||||
|
||||
#ifdef _KERNEL
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: vmstat.c,v 1.167 2010/04/05 07:16:13 he Exp $ */
|
||||
/* $NetBSD: vmstat.c,v 1.168 2010/04/05 08:03:42 he Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc.
|
||||
@ -70,7 +70,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1986, 1991, 1993\
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 3/1/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: vmstat.c,v 1.167 2010/04/05 07:16:13 he Exp $");
|
||||
__RCSID("$NetBSD: vmstat.c,v 1.168 2010/04/05 08:03:42 he Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -1183,7 +1183,7 @@ domem(void)
|
||||
else
|
||||
(void)printf(",%d", j);
|
||||
first = 0;
|
||||
(void)printf(":%u", ks.ks_active[i]);
|
||||
(void)printf(":%u", ks.ks_active[i - MINBUCKET]);
|
||||
}
|
||||
(void)printf("\n");
|
||||
totuse += ks.ks_memuse;
|
||||
|
Loading…
Reference in New Issue
Block a user