kern_mbuf.c patch

Randall Stewart rrs at cisco.com
Fri Jan 19 14:18:09 UTC 2007


All:

George and I have been discussing making the attached change
to limit kernel large cluster growth.

Note I also have added a fix so that if the limit
is 0 (unlimited), then you cannot change the limit
(back downward)... This is in response to Li Xin's comments
about the code I posted earlier..

I have no idea if the "default numbers" for these are
correct... it was a wild swag guess.

Maybe someone might have a better idea of what
the default limits for 4k/9k and 16k clusters should
be :)

Comments would be appreciated :-)

R
-- 
Randall Stewart
NSSTG - Cisco Systems Inc.
803-345-0369 <or> 803-317-4952 (cell)
-------------- next part --------------
Index: kern_mbuf.c
===================================================================
RCS file: /usr/FreeBSD/src/sys/kern/kern_mbuf.c,v
retrieving revision 1.27
diff -u -r1.27 kern_mbuf.c
--- kern_mbuf.c	22 Oct 2006 11:52:13 -0000	1.27
+++ kern_mbuf.c	19 Jan 2007 14:06:35 -0000
@@ -107,6 +107,9 @@
 
 	/* This has to be done before VM init. */
 	nmbclusters = 1024 + maxusers * 64;
+        nmbjumbop   = 100 + (maxusers * 4);
+        nmbjumbo9   = 100 + (maxusers * 2);
+        nmbjumbo16  = 100 + (maxusers * 2);
 	TUNABLE_INT_FETCH("kern.ipc.nmbclusters", &nmbclusters);
 }
 SYSINIT(tunable_mbinit, SI_SUB_TUNABLES, SI_ORDER_ANY, tunable_mbinit, NULL);
@@ -120,7 +123,7 @@
 	newnmbclusters = nmbclusters;
 	error = sysctl_handle_int(oidp, &newnmbclusters, sizeof(int), req); 
 	if (error == 0 && req->newptr) {
-		if (newnmbclusters > nmbclusters) {
+		if (nmbclusters && (newnmbclusters > nmbclusters)) {
 			nmbclusters = newnmbclusters;
 			uma_zone_set_max(zone_clust, nmbclusters);
 			EVENTHANDLER_INVOKE(nmbclusters_change);
@@ -129,15 +132,75 @@
 	}
 	return (error);
 }
+
+static int
+sysctl_nmbjclusters(SYSCTL_HANDLER_ARGS)
+{
+	int error, newnmbjclusters;
+
+	newnmbjclusters = nmbjumbop;
+	error = sysctl_handle_int(oidp, &newnmbjclusters, sizeof(int), req); 
+	if (error == 0 && req->newptr) {
+		if (nmbjumbop && (newnmbjclusters > nmbjumbop)) {
+			nmbjumbop = newnmbjclusters;
+			uma_zone_set_max(zone_jumbop, nmbjumbop);
+		} else
+			error = EINVAL;
+	}
+	return (error);
+}
+
+
+static int
+sysctl_nmbj9clusters(SYSCTL_HANDLER_ARGS)
+{
+	int error, newnmbj9clusters;
+
+	newnmbj9clusters = nmbjumbo9;
+	error = sysctl_handle_int(oidp, &newnmbj9clusters, sizeof(int), req); 
+	if (error == 0 && req->newptr) {
+		if (nmbjumbo9 && (newnmbj9clusters > nmbjumbo9)) {
+			nmbjumbo9 = newnmbj9clusters;
+			uma_zone_set_max(zone_jumbo9, nmbjumbo9);
+		} else
+			error = EINVAL;
+	}
+	return (error);
+}
+
+static int
+sysctl_nmbj16clusters(SYSCTL_HANDLER_ARGS)
+{
+	int error, newnmbj16clusters;
+
+	newnmbj16clusters = nmbjumbo16;
+	error = sysctl_handle_int(oidp, &newnmbj16clusters, sizeof(int), req); 
+	if (error == 0 && req->newptr) {
+		if (nmbjumbo16 && (newnmbj16clusters > nmbjumbo16)) {
+			nmbjumbo16 = newnmbj16clusters;
+			uma_zone_set_max(zone_jumbo16, nmbjumbo16);
+		} else
+			error = EINVAL;
+	}
+	return (error);
+}
+
 SYSCTL_PROC(_kern_ipc, OID_AUTO, nmbclusters, CTLTYPE_INT|CTLFLAG_RW,
 &nmbclusters, 0, sysctl_nmbclusters, "IU",
     "Maximum number of mbuf clusters allowed");
-SYSCTL_INT(_kern_ipc, OID_AUTO, nmbjumbop, CTLFLAG_RW, &nmbjumbop, 0,
+
+SYSCTL_PROC(_kern_ipc, OID_AUTO, nmbjumbop, CTLTYPE_INT|CTLFLAG_RW, 
+&nmbjumbop, 0, sysctl_nmbjclusters, "IU",
     "Maximum number of mbuf page size jumbo clusters allowed");
-SYSCTL_INT(_kern_ipc, OID_AUTO, nmbjumbo9, CTLFLAG_RW, &nmbjumbo9, 0,
+
+SYSCTL_PROC(_kern_ipc, OID_AUTO, nmbjumbo9, CTLTYPE_INT|CTLFLAG_RW, 
+&nmbjumbo9, 0, sysctl_nmbj9clusters, "IU",
     "Maximum number of mbuf 9k jumbo clusters allowed");
-SYSCTL_INT(_kern_ipc, OID_AUTO, nmbjumbo16, CTLFLAG_RW, &nmbjumbo16, 0,
+
+SYSCTL_PROC(_kern_ipc, OID_AUTO, nmbjumbo16, CTLTYPE_INT|CTLFLAG_RW, 
+&nmbjumbo16, 0, sysctl_nmbj16clusters, "IU",
     "Maximum number of mbuf 16k jumbo clusters allowed");
+
 SYSCTL_STRUCT(_kern_ipc, OID_AUTO, mbstat, CTLFLAG_RD, &mbstat, mbstat,
     "Mbuf general information and statistics");
 


More information about the freebsd-net mailing list