Date: Tue, 23 Jan 2007 16:11:15 -0500 From: Randall Stewart <rrs@cisco.com> To: freebsd-net <freebsd-net@freebsd.org> Subject: mbuf patch with sysctl suggestions too Message-ID: <45B679F3.3080407@cisco.com>
next in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format. --------------080208020809070508020709 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hi all: Here is iteration 2 of the mbuf patch with limits I proposed. Also note the changes for sysctl stuff that Lugi suggested. Please let me know what you think :-) R -- Randall Stewart NSSTG - Cisco Systems Inc. 803-345-0369 <or> 803-317-4952 (cell) --------------080208020809070508020709 Content-Type: text/plain; name="patch.mbuf.2" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="patch.mbuf.2" Index: kern/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/kern_mbuf.c 22 Oct 2006 11:52:13 -0000 1.27 +++ kern/kern_mbuf.c 23 Jan 2007 17:55:21 -0000 @@ -106,8 +106,19 @@ { /* This has to be done before VM init. */ - nmbclusters = 1024 + maxusers * 64; + nmbclusters = 1024 + (maxusers * 64); + nmbjumbop = 512 + (maxusers * 32); + /* 9k pages take 3 pages, so you get + * 1/3 of the limit of nmbjumbop. 16k + * pages take 4 pages, so you get + * 1/4 of the limit of nmbjumbop. + */ + nmbjumbo9 = nmbjumbop/3; + nmbjumbo16 = nmbjumbop/4; TUNABLE_INT_FETCH("kern.ipc.nmbclusters", &nmbclusters); + TUNABLE_INT_FETCH("kern.ipc.nmbjumbop", &nmbjumbop); + TUNABLE_INT_FETCH("kern.ipc.nmbjumbo9", &nmbjumbo9); + TUNABLE_INT_FETCH("kern.ipc.nmbjumbo16", &nmbjumbo16); } SYSINIT(tunable_mbinit, SI_SUB_TUNABLES, SI_ORDER_ANY, tunable_mbinit, NULL); @@ -118,26 +129,78 @@ int error, newnmbclusters; newnmbclusters = nmbclusters; - error = sysctl_handle_int(oidp, &newnmbclusters, sizeof(int), req); + error = sysctl_int_checked(oidp, &newnmbclusters, nmbclusters, + SYSCTL_NO_LIMIT, req); + if (error == 0 && req->newptr) { + nmbclusters = newnmbclusters; + uma_zone_set_max(zone_clust, nmbclusters); + EVENTHANDLER_INVOKE(nmbclusters_change); + } + return (error); +} + +static int +sysctl_nmbjclusters(SYSCTL_HANDLER_ARGS) +{ + int error, newnmbjclusters; + + newnmbjclusters = nmbjumbop; + error = sysctl_int_checked(oidp, &newnmbjclusters, nmbjumbop, + SYSCTL_NO_LIMIT, req); if (error == 0 && req->newptr) { - if (newnmbclusters > nmbclusters) { - nmbclusters = newnmbclusters; - uma_zone_set_max(zone_clust, nmbclusters); - EVENTHANDLER_INVOKE(nmbclusters_change); - } else - error = EINVAL; + nmbjumbop = newnmbjclusters; + uma_zone_set_max(zone_jumbop, nmbjumbop); } return (error); } + + +static int +sysctl_nmbj9clusters(SYSCTL_HANDLER_ARGS) +{ + int error, newnmbj9clusters; + + newnmbj9clusters = nmbjumbo9; + error = sysctl_int_checked(oidp, &newnmbj9clusters, nmbjumbo9, + SYSCTL_NO_LIMIT, req); + if (error == 0 && req->newptr) { + nmbjumbo9 = newnmbj9clusters; + uma_zone_set_max(zone_jumbo9, nmbjumbo9); + } + return (error); +} + +static int +sysctl_nmbj16clusters(SYSCTL_HANDLER_ARGS) +{ + int error, newnmbj16clusters; + + newnmbj16clusters = nmbjumbo16; + error = sysctl_int_checked(oidp, &newnmbj16clusters, nmbjumbo16, + SYSCTL_NO_LIMIT, req); + if (error == 0 && req->newptr) { + nmbjumbo16 = newnmbj16clusters; + uma_zone_set_max(zone_jumbo16, nmbjumbo16); + } + 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"); Index: kern/kern_sysctl.c =================================================================== RCS file: /usr/FreeBSD/src/sys/kern/kern_sysctl.c,v retrieving revision 1.172 diff -u -r1.172 kern_sysctl.c --- kern/kern_sysctl.c 6 Nov 2006 13:42:01 -0000 1.172 +++ kern/kern_sysctl.c 23 Jan 2007 17:44:39 -0000 @@ -826,6 +826,43 @@ } + +/* + * Handle an int, unsigned, but limited + * between min and max (unsigned) + * Two cases: + * a variable: point arg1 at it. + * a constant: pass it in arg2. + * + */ + +extern int nmbjumbo9; + +int +sysctl_int_checked(struct sysctl_oid *oidp, void *val, uint32_t min, uint32_t max, struct sysctl_req *req) +{ + uint32_t tmpout=0; + int error = 0; + + if(val == NULL) + return (EINVAL); + + tmpout = *(int *)val; + error = SYSCTL_OUT(req, &tmpout, sizeof(int)); + + if (error || !req->newptr) { + return (error); + } + error = SYSCTL_IN(req, (void *)&tmpout, sizeof(uint32_t)); + if ((tmpout < min) || (tmpout > max)) { + error = EINVAL; + return(error); + } + *((uint32_t *)val) = tmpout; + return (error); +} + + /* * Based on on sysctl_handle_int() convert milliseconds into ticks. */ Index: sys/sysctl.h =================================================================== RCS file: /usr/FreeBSD/src/sys/sys/sysctl.h,v retrieving revision 1.145 diff -u -r1.145 sysctl.h --- sys/sysctl.h 17 Sep 2006 20:00:35 -0000 1.145 +++ sys/sysctl.h 22 Jan 2007 18:04:42 -0000 @@ -167,6 +167,11 @@ #define SYSCTL_IN(r, p, l) (r->newfunc)(r, p, l) #define SYSCTL_OUT(r, p, l) (r->oldfunc)(r, p, l) +#define SYSCTL_NO_LIMIT 0xffffffff +int +sysctl_int_checked(struct sysctl_oid *, void *, uint32_t min, + uint32_t max, struct sysctl_req *); + int sysctl_handle_int(SYSCTL_HANDLER_ARGS); int sysctl_msec_to_ticks(SYSCTL_HANDLER_ARGS); int sysctl_handle_long(SYSCTL_HANDLER_ARGS); --------------080208020809070508020709--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?45B679F3.3080407>