summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorAngelos D. Keromytis <angelos@cvs.openbsd.org>2001-05-11 06:38:48 +0000
committerAngelos D. Keromytis <angelos@cvs.openbsd.org>2001-05-11 06:38:48 +0000
commita57e2bf28c9cf5e3d3f68b5bca43944672b554ae (patch)
tree1972012924481e0241799cbd770a17b509792308 /sys
parent42b3d449cd7394f4e614b3144ace06cc1b037f18 (diff)
kmemstats, nselcoll, forkstat, and nchstats structures through
sysctl. deraadt@ ok
Diffstat (limited to 'sys')
-rw-r--r--sys/kern/kern_malloc.c51
-rw-r--r--sys/kern/kern_sysctl.c18
2 files changed, 65 insertions, 4 deletions
diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c
index b276f6e74e2..d360046fbb8 100644
--- a/sys/kern/kern_malloc.c
+++ b/sys/kern/kern_malloc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_malloc.c,v 1.27 2001/05/06 00:47:46 art Exp $ */
+/* $OpenBSD: kern_malloc.c,v 1.28 2001/05/11 06:38:47 angelos Exp $ */
/* $NetBSD: kern_malloc.c,v 1.15.4.2 1996/06/13 17:10:56 cgd Exp $ */
/*
@@ -62,6 +62,7 @@ char buckstring[16 * sizeof("123456,")];
int buckstring_init = 0;
#if defined(KMEMSTATS) || defined(DIAGNOSTIC) || defined(FFS_SOFTUPDATES)
char *memname[] = INITKMEMNAMES;
+char *memall = NULL;
#endif
#ifdef MALLOC_DEBUG
@@ -487,7 +488,8 @@ sysctl_malloc(name, namelen, oldp, oldlenp, newp, newlen)
struct kmembuckets kb;
int i, siz;
- if (namelen != 2 && name[0] != KERN_MALLOC_BUCKETS)
+ if (namelen != 2 && name[0] != KERN_MALLOC_BUCKETS &&
+ name[0] != KERN_MALLOC_KMEMNAMES)
return (ENOTDIR); /* overloaded */
switch (name[0]) {
@@ -509,6 +511,51 @@ sysctl_malloc(name, namelen, oldp, oldlenp, newp, newlen)
kb.kb_next = kb.kb_last = 0;
return (sysctl_rdstruct(oldp, oldlenp, newp, &kb,
sizeof(kb)));
+ case KERN_MALLOC_KMEMSTATS:
+#ifdef KMEMSTATS
+ if ((name[1] < 0) || (name[1] >= M_LAST))
+ return (EINVAL);
+ return (sysctl_rdstruct(oldp, oldlenp, newp,
+ &kmemstats[name[1]],
+ sizeof(struct kmemstats)));
+#else
+ return (EOPNOTSUPP);
+#endif
+ case KERN_MALLOC_KMEMNAMES:
+#if defined(KMEMSTATS) || defined(DIAGNOSTIC) || defined(FFS_SOFTUPDATES)
+ /*
+ * XXX We should use a spinlock here, since
+ * multiple processes could conceivably be "stuck"
+ * waiting for memory to become available.
+ */
+ if (memall == NULL) {
+ int totlen;
+
+ /* Figure out how large a buffer we need */
+ for (totlen = 1, i = 0; i < M_LAST; i++)
+ if (memname[i])
+ totlen += strlen(memname[i]) + 1;
+ else
+ totlen++;
+
+ memall = malloc(totlen + M_LAST, M_TEMP, M_WAITOK);
+ bzero(memall, totlen + M_LAST);
+
+ for (siz = 0, i = 0; i < M_LAST; i++)
+ siz += sprintf(memall + siz, "%s,",
+ memname[i] ? memname[i] : "");
+
+ memall[siz - 1] = '\0'; /* Remove trailing comma */
+
+ /* Now, convert all spaces to underscores */
+ for (i = 0; i < totlen; i++)
+ if (memall[i] == ' ')
+ memall[i] = '_';
+ }
+ return (sysctl_rdstring(oldp, oldlenp, newp, memall));
+#else
+ return (EOPNOTSUPP);
+#endif
default:
return (EOPNOTSUPP);
}
diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c
index 9ee8ca8ba93..2fca22b52df 100644
--- a/sys/kern/kern_sysctl.c
+++ b/sys/kern/kern_sysctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_sysctl.c,v 1.42 2001/05/07 22:16:35 art Exp $ */
+/* $OpenBSD: kern_sysctl.c,v 1.43 2001/05/11 06:38:47 angelos Exp $ */
/* $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $ */
/*-
@@ -60,6 +60,8 @@
#include <sys/sysctl.h>
#include <sys/msgbuf.h>
#include <sys/dkstat.h>
+#include <sys/vmmeter.h>
+#include <sys/namei.h>
#if defined(UVM)
#include <uvm/uvm_extern.h>
@@ -73,6 +75,10 @@
#include <ddb/db_var.h>
#endif
+extern struct forkstat forkstat;
+extern struct nchstats nchstats;
+extern int nselcoll;
+
/*
* Lock to avoid too many processes vslocking a large amount of memory
* at the same time.
@@ -237,7 +243,7 @@ kern_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
/* all sysctl names at this level are terminal */
if (namelen != 1 && !(name[0] == KERN_PROC || name[0] == KERN_PROF ||
- name[0] == KERN_MALLOCSTATS))
+ name[0] == KERN_MALLOCSTATS))
return (ENOTDIR); /* overloaded */
switch (name[0]) {
@@ -259,6 +265,8 @@ kern_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
return (sysctl_int(oldp, oldlenp, newp, newlen, &maxfiles));
case KERN_ARGMAX:
return (sysctl_rdint(oldp, oldlenp, newp, ARG_MAX));
+ case KERN_NSELCOLL:
+ return (sysctl_rdint(oldp, oldlenp, newp, nselcoll));
case KERN_SECURELVL:
level = securelevel;
if ((error = sysctl_int(oldp, oldlenp, newp, newlen, &level)) ||
@@ -367,6 +375,12 @@ kern_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
case KERN_CPTIME:
return (sysctl_rdstruct(oldp, oldlenp, newp, &cp_time,
sizeof(cp_time)));
+ case KERN_NCHSTATS:
+ return (sysctl_rdstruct(oldp, oldlenp, newp, &nchstats,
+ sizeof(struct nchstats)));
+ case KERN_FORKSTAT:
+ return (sysctl_rdstruct(oldp, oldlenp, newp, &forkstat,
+ sizeof(struct forkstat)));
default:
return (EOPNOTSUPP);
}