svn commit: r245575 - in head/sys: kern sys

Andre Oppermann andre at FreeBSD.org
Thu Jan 17 21:28:33 UTC 2013


Author: andre
Date: Thu Jan 17 21:28:31 2013
New Revision: 245575
URL: http://svnweb.freebsd.org/changeset/base/245575

Log:
  Move the mbuf memory limit calculations from init_param2() to
  tunable_mbinit() where it is next to where it is used later.
  
  Change the sysinit level of tunable_mbinit() from SI_SUB_TUNABLES
  to SI_SUB_KMEM after the VM is running.  This allows to use better
  methods to determine the effectively available physical and virtual
  memory available to the kernel.
  
  Update comments.
  
  In a second step it can be merged into mbuf_init().

Modified:
  head/sys/kern/kern_mbuf.c
  head/sys/kern/subr_param.c
  head/sys/sys/mbuf.h

Modified: head/sys/kern/kern_mbuf.c
==============================================================================
--- head/sys/kern/kern_mbuf.c	Thu Jan 17 21:20:15 2013	(r245574)
+++ head/sys/kern/kern_mbuf.c	Thu Jan 17 21:28:31 2013	(r245575)
@@ -47,6 +47,7 @@ __FBSDID("$FreeBSD$");
 #include <vm/vm_extern.h>
 #include <vm/vm_kern.h>
 #include <vm/vm_page.h>
+#include <vm/vm_map.h>
 #include <vm/uma.h>
 #include <vm/uma_int.h>
 #include <vm/uma_dbg.h>
@@ -104,15 +105,24 @@ int nmbjumbo16;			/* limits number of 16
 struct mbstat mbstat;
 
 /*
- * tunable_mbinit() has to be run before init_maxsockets() thus
- * the SYSINIT order below is SI_ORDER_MIDDLE while init_maxsockets()
- * runs at SI_ORDER_ANY.
- *
- * NB: This has to be done before VM init.
+ * tunable_mbinit() has to be run before any mbuf allocations are done.
  */
 static void
 tunable_mbinit(void *dummy)
 {
+	quad_t realmem, maxmbufmem;
+
+	/*
+	 * The default limit for all mbuf related memory is 1/2 of all
+	 * available kernel memory (physical or kmem).
+	 * At most it can be 3/4 of available kernel memory.
+	 */
+	realmem = qmin((quad_t)physmem * PAGE_SIZE,
+	    vm_map_max(kernel_map) - vm_map_min(kernel_map));
+	maxmbufmem = realmem / 2;
+	TUNABLE_QUAD_FETCH("kern.maxmbufmem", &maxmbufmem);
+	if (maxmbufmem > realmem / 4 * 3)
+		maxmbufmem = realmem / 4 * 3;
 
 	TUNABLE_INT_FETCH("kern.ipc.nmbclusters", &nmbclusters);
 	if (nmbclusters == 0)
@@ -139,7 +149,7 @@ tunable_mbinit(void *dummy)
 		nmbufs = lmax(maxmbufmem / MSIZE / 5,
 		    nmbclusters + nmbjumbop + nmbjumbo9 + nmbjumbo16);
 }
-SYSINIT(tunable_mbinit, SI_SUB_TUNABLES, SI_ORDER_MIDDLE, tunable_mbinit, NULL);
+SYSINIT(tunable_mbinit, SI_SUB_KMEM, SI_ORDER_MIDDLE, tunable_mbinit, NULL);
 
 static int
 sysctl_nmbclusters(SYSCTL_HANDLER_ARGS)
@@ -279,16 +289,14 @@ static int	mb_zinit_pack(void *, int, in
 static void	mb_zfini_pack(void *, int);
 
 static void	mb_reclaim(void *);
-static void	mbuf_init(void *);
 static void    *mbuf_jumbo_alloc(uma_zone_t, int, uint8_t *, int);
 
-/* Ensure that MSIZE must be a power of 2. */
+/* Ensure that MSIZE is a power of 2. */
 CTASSERT((((MSIZE - 1) ^ MSIZE) + 1) >> 1 == MSIZE);
 
 /*
  * Initialize FreeBSD Network buffer allocation.
  */
-SYSINIT(mbuf, SI_SUB_MBUF, SI_ORDER_FIRST, mbuf_init, NULL);
 static void
 mbuf_init(void *dummy)
 {
@@ -396,6 +404,7 @@ mbuf_init(void *dummy)
 	mbstat.sf_iocnt = 0;
 	mbstat.sf_allocwait = mbstat.sf_allocfail = 0;
 }
+SYSINIT(mbuf, SI_SUB_MBUF, SI_ORDER_FIRST, mbuf_init, NULL);
 
 /*
  * UMA backend page allocator for the jumbo frame zones.

Modified: head/sys/kern/subr_param.c
==============================================================================
--- head/sys/kern/subr_param.c	Thu Jan 17 21:20:15 2013	(r245574)
+++ head/sys/kern/subr_param.c	Thu Jan 17 21:28:31 2013	(r245575)
@@ -93,7 +93,6 @@ int	ncallout;			/* maximum # of timer ev
 int	nbuf;
 int	ngroups_max;			/* max # groups per process */
 int	nswbuf;
-quad_t	maxmbufmem;			/* max mbuf memory */
 pid_t	pid_max = PID_MAX;
 long	maxswzone;			/* max swmeta KVA storage */
 long	maxbcache;			/* max buffer cache KVA storage */
@@ -274,7 +273,6 @@ init_param1(void)
 void
 init_param2(long physpages)
 {
-	quad_t realmem;
 
 	/* Base parameters */
 	maxusers = MAXUSERS;
@@ -334,18 +332,6 @@ init_param2(long physpages)
 	TUNABLE_INT_FETCH("kern.ncallout", &ncallout);
 
 	/*
-	 * The default limit for all mbuf related memory is 1/2 of all
-	 * available kernel memory (physical or kmem).
-	 * At most it can be 3/4 of available kernel memory.
-	 */
-	realmem = qmin((quad_t)physpages * PAGE_SIZE,
-	    VM_MAX_KERNEL_ADDRESS - VM_MIN_KERNEL_ADDRESS);
-	maxmbufmem = realmem / 2;
-	TUNABLE_QUAD_FETCH("kern.maxmbufmem", &maxmbufmem);
-	if (maxmbufmem > (realmem / 4) * 3)
-		maxmbufmem = (realmem / 4) * 3;
-
-	/*
 	 * The default for maxpipekva is min(1/64 of the kernel address space,
 	 * max(1/64 of main memory, 512KB)).  See sys_pipe.c for more details.
 	 */

Modified: head/sys/sys/mbuf.h
==============================================================================
--- head/sys/sys/mbuf.h	Thu Jan 17 21:20:15 2013	(r245574)
+++ head/sys/sys/mbuf.h	Thu Jan 17 21:28:31 2013	(r245575)
@@ -384,7 +384,6 @@ struct mbstat {
  *
  * The rest of it is defined in kern/kern_mbuf.c
  */
-extern quad_t		maxmbufmem;
 extern uma_zone_t	zone_mbuf;
 extern uma_zone_t	zone_clust;
 extern uma_zone_t	zone_pack;


More information about the svn-src-all mailing list