summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorDavid Gwynne <dlg@cvs.openbsd.org>2014-07-02 00:12:35 +0000
committerDavid Gwynne <dlg@cvs.openbsd.org>2014-07-02 00:12:35 +0000
commitfc2138718cbe314f33c8e4e1bee24990ec7ce7d6 (patch)
treeb71b8d1c0bf5001d2ecf3db8b0999b33d6d680c5 /sys
parent7c85a362de06050fd3e9230c78ff7ca9e049c6c4 (diff)
info about pools is currently given to userland by copying each
pools struct out. however, struct pool in the kernel contains lots of things that userland probably isnt interested in, like actual mutexes, and probably shouldnt get easy access to, like pointers to kernel memory via all the lists/trees. this implements a kinfo_pool structure that has only the data that userland needs to know about. it cuts the sysctl code over to building it from struct pool as required and copying that out instead, and cuts userland over to only handling kinfo_pool. the only problem with this is vmstat, which can read kernel images via kvm, which needs some understanding of struct pool. to cope, the struct pool definition is guarded by if defined(_KERNEL) || defined(_LIBKVM) as inspired by sysctl which needs to do the same thing sometimes. struct pool itself is generally not visible to userland though, which is good. matthew@ suggested struct kinfo_pool instead of struct pool_info. the kinfo prefix has precedent. lots of people liked this.
Diffstat (limited to 'sys')
-rw-r--r--sys/kern/subr_pool.c35
-rw-r--r--sys/sys/pool.h29
2 files changed, 53 insertions, 11 deletions
diff --git a/sys/kern/subr_pool.c b/sys/kern/subr_pool.c
index 2dab25cbd76..b6fb87597e7 100644
--- a/sys/kern/subr_pool.c
+++ b/sys/kern/subr_pool.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: subr_pool.c,v 1.128 2014/05/19 14:30:03 tedu Exp $ */
+/* $OpenBSD: subr_pool.c,v 1.129 2014/07/02 00:12:34 dlg Exp $ */
/* $NetBSD: subr_pool.c,v 1.61 2001/09/26 07:14:56 chs Exp $ */
/*-
@@ -1422,7 +1422,8 @@ pool_walk(struct pool *pp, int full,
int
sysctl_dopool(int *name, u_int namelen, char *where, size_t *sizep)
{
- struct pool *pp, *foundpool = NULL;
+ struct kinfo_pool pi;
+ struct pool *pp;
size_t buflen = where != NULL ? *sizep : 0;
int npools = 0, s;
unsigned int lookfor;
@@ -1440,7 +1441,7 @@ sysctl_dopool(int *name, u_int namelen, char *where, size_t *sizep)
lookfor = name[1];
break;
case KERN_POOL_POOL:
- if (namelen != 2 || buflen != sizeof(struct pool))
+ if (namelen != 2 || buflen != sizeof(pi))
return (EINVAL);
lookfor = name[1];
break;
@@ -1452,28 +1453,42 @@ sysctl_dopool(int *name, u_int namelen, char *where, size_t *sizep)
SIMPLEQ_FOREACH(pp, &pool_head, pr_poollist) {
npools++;
- if (lookfor == pp->pr_serial) {
- foundpool = pp;
+ if (lookfor == pp->pr_serial)
break;
- }
}
splx(s);
- if (*name != KERN_POOL_NPOOLS && foundpool == NULL)
+ if (*name != KERN_POOL_NPOOLS && pp == NULL)
return (ENOENT);
switch (*name) {
case KERN_POOL_NPOOLS:
return copyout(&npools, where, buflen);
case KERN_POOL_NAME:
- len = strlen(foundpool->pr_wchan) + 1;
+ len = strlen(pp->pr_wchan) + 1;
if (*sizep < len)
return (ENOMEM);
*sizep = len;
- return copyout(foundpool->pr_wchan, where, len);
+ return copyout(pp->pr_wchan, where, len);
case KERN_POOL_POOL:
- return copyout(foundpool, where, buflen);
+ memset(&pi, 0, sizeof(pi));
+ pi.pr_size = pp->pr_size;
+ pi.pr_pgsize = pp->pr_alloc->pa_pagesz;
+ pi.pr_itemsperpage = pp->pr_itemsperpage;
+ pi.pr_minpages = pp->pr_minpages;
+ pi.pr_maxpages = pp->pr_maxpages;
+ pi.pr_hardlimit = pp->pr_hardlimit;
+ pi.pr_nout = pp->pr_nout;
+ pi.pr_nitems = pp->pr_nitems;
+ pi.pr_nget = pp->pr_nget;
+ pi.pr_nput = pp->pr_nput;
+ pi.pr_nfail = pp->pr_nfail;
+ pi.pr_npagealloc = pp->pr_npagealloc;
+ pi.pr_npagefree = pp->pr_npagefree;
+ pi.pr_hiwat = pp->pr_hiwat;
+ pi.pr_nidle = pp->pr_nidle;
+ return copyout(&pi, where, buflen);
}
/* NOTREACHED */
return (0); /* XXX - Stupid gcc */
diff --git a/sys/sys/pool.h b/sys/sys/pool.h
index d0fe9d1d6cd..eca7687b4f1 100644
--- a/sys/sys/pool.h
+++ b/sys/sys/pool.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: pool.h,v 1.44 2013/11/05 03:28:44 dlg Exp $ */
+/* $OpenBSD: pool.h,v 1.45 2014/07/02 00:12:34 dlg Exp $ */
/* $NetBSD: pool.h,v 1.27 2001/06/06 22:00:17 rafal Exp $ */
/*-
@@ -44,6 +44,30 @@
#define KERN_POOL_NAME 2
#define KERN_POOL_POOL 3
+struct kinfo_pool {
+ unsigned int pr_size; /* size of a pool item */
+ unsigned int pr_pgsize; /* size of a "page" */
+ unsigned int pr_itemsperpage; /* number of items per "page" */
+ unsigned int pr_minpages; /* same in page units */
+ unsigned int pr_maxpages; /* maximum # of idle pages to keep */
+ unsigned int pr_hardlimit; /* hard limit to number of allocated
+ items */
+
+ unsigned int pr_npages; /* # of pages allocated */
+ unsigned int pr_nout; /* # items currently allocated */
+ unsigned int pr_nitems; /* # items in the pool */
+
+ unsigned long pr_nget; /* # of successful requests */
+ unsigned long pr_nput; /* # of releases */
+ unsigned long pr_nfail; /* # of unsuccessful requests */
+ unsigned long pr_npagealloc; /* # of pages allocated */
+ unsigned long pr_npagefree; /* # of pages released */
+ unsigned int pr_hiwat; /* max # of pages in pool */
+ unsigned long pr_nidle; /* # of idle pages */
+};
+
+#if defined(_KERNEL) || defined(_LIBKVM)
+
#include <sys/queue.h>
#include <sys/time.h>
#include <sys/tree.h>
@@ -131,7 +155,10 @@ struct pool {
const struct kmem_pa_mode *pr_crange;
};
+#endif /* _KERNEL || _LIBKVM */
+
#ifdef _KERNEL
+
extern struct pool_allocator pool_allocator_nointr;
/* these functions are not locked */