summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrwatson <rwatson@FreeBSD.org>2001-02-23 18:46:21 +0000
committerrwatson <rwatson@FreeBSD.org>2001-02-23 18:46:21 +0000
commit9a2d215a5f08b9bb59d6d213ebe2bdff2ee4aa87 (patch)
tree6b4232b4922baff01f3d46559d27e345af6a2614
parent77373f9493f436fa85a07471b20c91698090819c (diff)
downloadFreeBSD-src-9a2d215a5f08b9bb59d6d213ebe2bdff2ee4aa87.zip
FreeBSD-src-9a2d215a5f08b9bb59d6d213ebe2bdff2ee4aa87.tar.gz
Introduce per-swap area accounting in the VM system, and export
this information via the vm.nswapdev sysctl (number of swap areas) and vm.swapdevX nodes (where X is the device), which contain the MIBs dev, blocks, used, and flags. These changes are required to allow top and other userland swap-monitoring utilities to run without setgid kmem. Submitted by: Thomas Moestl <tmoestl@gmx.net> Reviewed by: freebsd-audit
-rw-r--r--sys/sys/conf.h1
-rw-r--r--sys/sys/linedisc.h1
-rw-r--r--sys/vm/swap_pager.c11
-rw-r--r--sys/vm/vm_swap.c34
4 files changed, 44 insertions, 3 deletions
diff --git a/sys/sys/conf.h b/sys/sys/conf.h
index 81ea6af..81b94bc 100644
--- a/sys/sys/conf.h
+++ b/sys/sys/conf.h
@@ -232,6 +232,7 @@ struct swdevt {
udev_t sw_dev; /* For quasibogus swapdev reporting */
int sw_flags;
int sw_nblks;
+ int sw_used;
struct vnode *sw_vp;
dev_t sw_device;
};
diff --git a/sys/sys/linedisc.h b/sys/sys/linedisc.h
index 81ea6af..81b94bc 100644
--- a/sys/sys/linedisc.h
+++ b/sys/sys/linedisc.h
@@ -232,6 +232,7 @@ struct swdevt {
udev_t sw_dev; /* For quasibogus swapdev reporting */
int sw_flags;
int sw_nblks;
+ int sw_used;
struct vnode *sw_vp;
dev_t sw_device;
};
diff --git a/sys/vm/swap_pager.c b/sys/vm/swap_pager.c
index 9a0ca56..d62ada2 100644
--- a/sys/vm/swap_pager.c
+++ b/sys/vm/swap_pager.c
@@ -125,11 +125,16 @@ static struct swblock **swhash;
static int swhash_mask;
static int swap_async_max = 4; /* maximum in-progress async I/O's */
-extern struct vnode *swapdev_vp; /* from vm_swap.c */
+/* from vm_swap.c */
+extern struct vnode *swapdev_vp;
+extern struct swdevt *swdevt;
+extern int nswdev;
SYSCTL_INT(_vm, OID_AUTO, swap_async_max,
CTLFLAG_RW, &swap_async_max, 0, "Maximum running async swap ops");
+#define BLK2DEVIDX(blk) (nswdev > 1 ? blk / dmmax % nswdev : 0)
+
/*
* "named" and "unnamed" anon region objects. Try to reduce the overhead
* of searching a named list by hashing it just a little.
@@ -490,6 +495,8 @@ swp_pager_getswapspace(npages)
}
} else {
vm_swap_size -= npages;
+ /* per-swap area stats */
+ swdevt[BLK2DEVIDX(blk)].sw_used += npages;
swp_sizecheck();
}
return(blk);
@@ -517,6 +524,8 @@ swp_pager_freeswapspace(blk, npages)
{
blist_free(swapblist, blk, npages);
vm_swap_size += npages;
+ /* per-swap area stats */
+ swdevt[BLK2DEVIDX(blk)].sw_used -= npages;
swp_sizecheck();
}
diff --git a/sys/vm/vm_swap.c b/sys/vm/vm_swap.c
index fada384..5904395 100644
--- a/sys/vm/vm_swap.c
+++ b/sys/vm/vm_swap.c
@@ -51,6 +51,7 @@
#include <sys/lock.h>
#include <sys/conf.h>
#include <sys/stat.h>
+#include <sys/sysctl.h>
#include <vm/vm.h>
#include <vm/vm_extern.h>
#include <vm/vm_zone.h>
@@ -64,10 +65,13 @@
#define NSWAPDEV 4
#endif
static struct swdevt should_be_malloced[NSWAPDEV];
-static struct swdevt *swdevt = should_be_malloced;
+struct swdevt *swdevt = should_be_malloced;
static int nswap; /* first block after the interleaved devs */
-static int nswdev = NSWAPDEV;
+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;
@@ -246,6 +250,8 @@ 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,
@@ -305,6 +311,7 @@ swaponvp(p, vp, dev, nblks)
sp->sw_device = dev;
sp->sw_flags |= SW_FREED;
sp->sw_nblks = nblks;
+ sp->sw_used = 0;
/*
* nblks, nswap, and dmmax are PAGE_SIZE'd parameters now, not
@@ -327,6 +334,29 @@ 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);
}
OpenPOWER on IntegriCloud