summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authortmm <tmm@FreeBSD.org>2001-06-01 22:53:10 +0000
committertmm <tmm@FreeBSD.org>2001-06-01 22:53:10 +0000
commit87a858d545f37c808cc22343f075241e15fee343 (patch)
tree330c4e3ba5cf61d0a358f97401039aa45d6e15d7 /sys
parentbf437699a2710e571265ed8b49504026dae2d36b (diff)
downloadFreeBSD-src-87a858d545f37c808cc22343f075241e15fee343.zip
FreeBSD-src-87a858d545f37c808cc22343f075241e15fee343.tar.gz
Change the way information about swap devices is exported to be more
canonical: define a versioned struct xswdev, and add a sysctl node handler that allows the user to get this structure for a certain device index by specifying this index as last element of the MIB. This new node handler, vm.swap_info, replaces the old vm.nswapdev and vm.swapdevX.* (where X was the index) sysctls.
Diffstat (limited to 'sys')
-rw-r--r--sys/vm/vm_param.h12
-rw-r--r--sys/vm/vm_swap.c62
2 files changed, 46 insertions, 28 deletions
diff --git a/sys/vm/vm_param.h b/sys/vm/vm_param.h
index a0809fe..7237638 100644
--- a/sys/vm/vm_param.h
+++ b/sys/vm/vm_param.h
@@ -105,6 +105,18 @@
}
/*
+ * Structure for swap device statistics
+ */
+#define XSWDEV_VERSION 1
+struct xswdev {
+ u_int xsw_version;
+ udev_t xsw_dev;
+ int xsw_flags;
+ int xsw_nblks;
+ int xsw_used;
+};
+
+/*
* Return values from the VM routines.
*/
#define KERN_SUCCESS 0
diff --git a/sys/vm/vm_swap.c b/sys/vm/vm_swap.c
index 5904395..168f5cf 100644
--- a/sys/vm/vm_swap.c
+++ b/sys/vm/vm_swap.c
@@ -55,6 +55,7 @@
#include <vm/vm.h>
#include <vm/vm_extern.h>
#include <vm/vm_zone.h>
+#include <vm/vm_param.h>
#include <vm/swap_pager.h>
/*
@@ -69,9 +70,6 @@ struct swdevt *swdevt = should_be_malloced;
static int nswap; /* first block after the interleaved devs */
int nswdev = NSWAPDEV;
int vm_swap_size;
-static int ncswdev = 0; /* # of configured swap devs */
-SYSCTL_INT(_vm, OID_AUTO, nswapdev, CTLFLAG_RD,
- &ncswdev, 0, "Number of swap devices");
static int swapdev_strategy __P((struct vop_strategy_args *ap));
struct vnode *swapdev_vp;
@@ -250,8 +248,6 @@ swaponvp(p, vp, dev, nblks)
swblk_t dvbase;
int error;
u_long aligned_nblks;
- struct sysctl_oid *oid;
- char name[11];
if (!swapdev_vp) {
error = getnewvnode(VT_NON, NULL, swapdev_vnodeop_p,
@@ -334,29 +330,39 @@ swaponvp(p, vp, dev, nblks)
blist_free(swapblist, vsbase, blk);
vm_swap_size += blk;
}
- /*
- * Add sysctl entries for new swap area. XXX: if some day swap devices
- * can be removed, add an oid member to swdevt.
- */
- if (snprintf(name, sizeof(name), "swapdev%d", ncswdev) < sizeof(name)) {
- oid = SYSCTL_ADD_NODE(NULL, SYSCTL_STATIC_CHILDREN(_vm),
- OID_AUTO, name, CTLFLAG_RD, NULL, "Swap device stats");
- if (oid != NULL) {
- SYSCTL_ADD_INT(NULL, SYSCTL_CHILDREN(oid), OID_AUTO,
- "flags", CTLFLAG_RD, &sp->sw_flags, 0, "Flags");
- SYSCTL_ADD_INT(NULL, SYSCTL_CHILDREN(oid), OID_AUTO,
- "nblks", CTLFLAG_RD, &sp->sw_nblks, 0,
- "Number of blocks");
- SYSCTL_ADD_INT(NULL, SYSCTL_CHILDREN(oid), OID_AUTO,
- "used", CTLFLAG_RD, &sp->sw_used, 0,
- "Number of blocks in use");
- SYSCTL_ADD_OPAQUE(NULL, SYSCTL_CHILDREN(oid), OID_AUTO,
- "dev", CTLFLAG_RD, &sp->sw_dev, sizeof(sp->sw_dev),
- "T,dev_t", "Device");
- }
- } else
- printf("XXX: swaponvp() name buffer too small!\n");
- ncswdev++;
return (0);
}
+
+static int
+sysctl_vm_swap_info(SYSCTL_HANDLER_ARGS)
+{
+ int *name = (int *)arg1;
+ int error, i, n;
+ struct xswdev xs;
+ struct swdevt *sp;
+
+ if (arg2 != 1) /* name length */
+ return (EINVAL);
+
+ for (sp = swdevt, i = 0, n = 0 ; i < nswdev; i++, sp++) {
+ if (sp->sw_vp) {
+ if (n == *name) {
+ xs.xsw_version = XSWDEV_VERSION;
+ xs.xsw_dev = sp->sw_dev;
+ xs.xsw_flags = sp->sw_flags;
+ xs.xsw_nblks = sp->sw_nblks;
+ xs.xsw_used = sp->sw_used;
+
+ error = SYSCTL_OUT(req, &xs, sizeof(xs));
+ return (error);
+ }
+ n++;
+ }
+
+ }
+ return (ENOENT);
+}
+
+SYSCTL_NODE(_vm, OID_AUTO, swap_info, CTLFLAG_RD, sysctl_vm_swap_info,
+ "Swap statistics by device");
OpenPOWER on IntegriCloud