Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Extend struct malloc_type to count the number of active allo...
details: https://anonhg.NetBSD.org/src/rev/c728c81d2ac4
branches: trunk
changeset: 753632:c728c81d2ac4
user: he <he%NetBSD.org@localhost>
date: Mon Apr 05 07:16:12 2010 +0000
description:
Extend struct malloc_type to count the number of active allocations
per size, and make vmstat report this information under the "Memory
statistics by type" display, which is only printed when the kernel
has been compiled with KMEMSTATS defined, like this:
Memory statistics by type Type Kern
Type InUse MemUse HighUse Limit Requests Limit Limit Size(s)
wapbl 15 4192K 4192K 78644K 376426 0 0 32:0,256:3,512:6,131072:1,262144:2,524288:3
Since struct malloc_type is user-visible and is changed, bump kernel
revision to 5.99.26.
While it is true that malloc(9) is in general on the path of slowly
being replaced by kmem(9) (kmem_alloc/kmem_free), there remains a
lot of points of usage of malloc/free, and this could aid in finding
any leaks. (It helped finding the leak fixed in PR#42661.)
This was discussed with and somewhat hestitantly OKed by rmind@
diffstat:
sys/kern/kern_malloc.c | 7 +++++--
sys/sys/mallocvar.h | 4 ++--
sys/sys/param.h | 4 ++--
usr.bin/vmstat/vmstat.c | 10 +++++++---
4 files changed, 16 insertions(+), 9 deletions(-)
diffs (116 lines):
diff -r c0af5ee9d1f3 -r c728c81d2ac4 sys/kern/kern_malloc.c
--- a/sys/kern/kern_malloc.c Sun Apr 04 23:38:55 2010 +0000
+++ b/sys/kern/kern_malloc.c Mon Apr 05 07:16:12 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_malloc.c,v 1.128 2010/01/22 08:32:05 hubertf Exp $ */
+/* $NetBSD: kern_malloc.c,v 1.129 2010/04/05 07:16:13 he Exp $ */
/*
* Copyright (c) 1987, 1991, 1993
@@ -66,7 +66,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_malloc.c,v 1.128 2010/01/22 08:32:05 hubertf Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_malloc.c,v 1.129 2010/04/05 07:16:13 he Exp $");
#include <sys/param.h>
#include <sys/proc.h>
@@ -371,6 +371,7 @@
&malloc_lock);
}
ksp->ks_size |= 1 << indx;
+ ksp->ks_active[indx]++;
#endif
#ifdef DIAGNOSTIC
copysize = 1 << indx < MAX_COPY ? 1 << indx : MAX_COPY;
@@ -604,6 +605,7 @@
#ifdef KMEMSTATS
size = kup->ku_pagecnt << PGSHIFT;
ksp->ks_memuse -= size;
+ ksp->ks_active[kup->ku_indx]--;
kup->ku_indx = 0;
kup->ku_pagecnt = 0;
if (ksp->ks_memuse + size >= ksp->ks_limit &&
@@ -660,6 +662,7 @@
}
kbp->kb_totalfree++;
ksp->ks_memuse -= size;
+ ksp->ks_active[kup->ku_indx]--;
if (ksp->ks_memuse + size >= ksp->ks_limit &&
ksp->ks_memuse < ksp->ks_limit)
wakeup((void *)ksp);
diff -r c0af5ee9d1f3 -r c728c81d2ac4 sys/sys/mallocvar.h
--- a/sys/sys/mallocvar.h Sun Apr 04 23:38:55 2010 +0000
+++ b/sys/sys/mallocvar.h Mon Apr 05 07:16:12 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mallocvar.h,v 1.7 2007/11/07 16:12:25 matt Exp $ */
+/* $NetBSD: mallocvar.h,v 1.8 2010/04/05 07:16:12 he Exp $ */
/*
* Copyright (c) 1987, 1993
@@ -56,7 +56,7 @@
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_long ks_spare;
+ u_int ks_active[32]; /* number of active allocations per size */
};
#ifdef _KERNEL
diff -r c0af5ee9d1f3 -r c728c81d2ac4 sys/sys/param.h
--- a/sys/sys/param.h Sun Apr 04 23:38:55 2010 +0000
+++ b/sys/sys/param.h Mon Apr 05 07:16:12 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: param.h,v 1.360 2010/03/29 13:41:06 pooka Exp $ */
+/* $NetBSD: param.h,v 1.361 2010/04/05 07:16:12 he Exp $ */
/*-
* Copyright (c) 1982, 1986, 1989, 1993
@@ -63,7 +63,7 @@
* 2.99.9 (299000900)
*/
-#define __NetBSD_Version__ 599002500 /* NetBSD 5.99.25 */
+#define __NetBSD_Version__ 599002600 /* NetBSD 5.99.26 */
#define __NetBSD_Prereq__(M,m,p) (((((M) * 100000000) + \
(m) * 1000000) + (p) * 100) <= __NetBSD_Version__)
diff -r c0af5ee9d1f3 -r c728c81d2ac4 usr.bin/vmstat/vmstat.c
--- a/usr.bin/vmstat/vmstat.c Sun Apr 04 23:38:55 2010 +0000
+++ b/usr.bin/vmstat/vmstat.c Mon Apr 05 07:16:12 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vmstat.c,v 1.166 2009/10/21 21:12:07 rmind Exp $ */
+/* $NetBSD: vmstat.c,v 1.167 2010/04/05 07:16:13 he Exp $ */
/*-
* Copyright (c) 1998, 2000, 2001, 2007 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
#if 0
static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 3/1/95";
#else
-__RCSID("$NetBSD: vmstat.c,v 1.166 2009/10/21 21:12:07 rmind Exp $");
+__RCSID("$NetBSD: vmstat.c,v 1.167 2010/04/05 07:16:13 he Exp $");
#endif
#endif /* not lint */
@@ -1172,7 +1172,10 @@
howmany(ks.ks_limit, KILO), ks.ks_calls,
ks.ks_limblocks, ks.ks_mapblocks);
first = 1;
- for (j = 1 << MINBUCKET; j < 1 << (MINBUCKET + 16); j <<= 1) {
+ for (j = 1 << MINBUCKET, i = MINBUCKET;
+ j < 1 << (MINBUCKET + 16);
+ j <<= 1, i++)
+ {
if ((ks.ks_size & j) == 0)
continue;
if (first)
@@ -1180,6 +1183,7 @@
else
(void)printf(",%d", j);
first = 0;
+ (void)printf(":%u", ks.ks_active[i]);
}
(void)printf("\n");
totuse += ks.ks_memuse;
Home |
Main Index |
Thread Index |
Old Index