kern/159281: [PATCH] Linux-like /proc/swaps for linprocfs

Robert Millan rmh at debian.org
Thu Jul 28 23:40:08 UTC 2011


>Number:         159281
>Category:       kern
>Synopsis:       [PATCH] Linux-like /proc/swaps for linprocfs
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu Jul 28 23:40:07 UTC 2011
>Closed-Date:
>Last-Modified:
>Originator:     Robert Millan
>Release:        Debian GNU/kFreeBSD "sid"
>Organization:
>Environment:
>Description:
Please consider this patch, it implements Linux-like /proc/swaps for linprocfs.

E.g.

$ cat /proc/swaps
Filename                                Type            Size    Used    Priority
/dev/zvol/dimoni/swap                   unknown         2097152 0       -1

>How-To-Repeat:

>Fix:


Patch attached with submission follows:

--- a/sys/compat/linprocfs/linprocfs.c
+++ b/sys/compat/linprocfs/linprocfs.c
@@ -498,6 +498,44 @@
 	return (0);
 }
 
+static int
+linprocfs_doswaps(PFS_FILL_ARGS)
+{
+	struct xswdev xsw;
+	int mib[3], mibsize;
+	size_t size;
+	int n;
+	long long total, used;
+	char devname[SPECNAMELEN + 1];
+
+	sbuf_printf(sb, "Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
+
+	mibsize = sizeof mib / sizeof mib[0];
+
+	mib[0] = CTL_VM;
+	mib[1] = VM_SWAP_INFO;
+
+	for (n = 0; ; n++) {
+		mib[2] = n;
+		size = sizeof(xsw);
+		if (kernel_sysctl(td, mib, mibsize, &xsw, &size, NULL, 0,
+			NULL, 0) != 0)
+			break;
+
+		size = sizeof(devname);
+		if (kernel_sysctlbyname(td, "kern.devname", devname, &size,
+			&xsw.xsw_dev, sizeof (xsw.xsw_dev), NULL, 0) != 0)
+			break;
+
+		total = (long long)xsw.xsw_nblks * PAGE_SIZE / 1024;
+		used  = (long long)xsw.xsw_used * PAGE_SIZE / 1024;
+
+		sbuf_printf(sb, "/dev/%-34s unknown\t\t%u\t%u\t-1\n", devname, total, used);
+	}
+
+	return (0);
+}
+
 /*
  * Filler function for proc/uptime
  */
@@ -1486,6 +1524,8 @@
 	    NULL, NULL, NULL, 0);
 	pfs_create_file(root, "stat", &linprocfs_dostat,
 	    NULL, NULL, NULL, PFS_RD);
+	pfs_create_file(root, "swaps", &linprocfs_doswaps,
+	    NULL, NULL, NULL, PFS_RD);
 	pfs_create_file(root, "uptime", &linprocfs_douptime,
 	    NULL, NULL, NULL, PFS_RD);
 	pfs_create_file(root, "version", &linprocfs_doversion,
--- a/sys/vm/swap_pager.c
+++ b/sys/vm/swap_pager.c
@@ -2398,7 +2398,7 @@
 
 SYSCTL_INT(_vm, OID_AUTO, nswapdev, CTLFLAG_RD, &nswapdev, 0,
     "Number of swap devices");
-SYSCTL_NODE(_vm, OID_AUTO, swap_info, CTLFLAG_RD, sysctl_vm_swap_info,
+SYSCTL_NODE(_vm, VM_SWAP_INFO, swap_info, CTLFLAG_RD, sysctl_vm_swap_info,
     "Swap statistics by device");
 
 /*
--- a/sys/vm/vm_param.h
+++ b/sys/vm/vm_param.h
@@ -84,7 +84,8 @@
 #define VM_V_PAGEOUT_FREE_MIN	9	/* cnt.v_pageout_free_min */
 #define	VM_PAGEOUT_ALGORITHM	10	/* pageout algorithm */
 #define VM_SWAPPING_ENABLED	11	/* swapping enabled */
-#define	VM_MAXID		12	/* number of valid vm ids */
+#define	VM_SWAP_INFO		12	/* swap_info */
+#define	VM_MAXID		13	/* number of valid vm ids */
 
 #define CTL_VM_NAMES { \
 	{ 0, 0 }, \
@@ -99,6 +100,7 @@
 	{ "v_pageout_free_min", CTLTYPE_UINT}, \
 	{ "pageout_algorithm", CTLTYPE_INT}, \
 	{ "swap_enabled", CTLTYPE_INT},\
+	{ "swap_info", CTLTYPE_STRUCT},\
 }
 
 /*


>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list