diff options
author | andre <andre@FreeBSD.org> | 2013-01-17 21:28:31 +0000 |
---|---|---|
committer | andre <andre@FreeBSD.org> | 2013-01-17 21:28:31 +0000 |
commit | d8067c27f54c1f0d1bc952da140a4f0b469b19ea (patch) | |
tree | 4ea33b1ea256eb1cad9fb08de3e6343f9199b000 /sys | |
parent | b7ec793bc800e8ebcc73c3f5371a4bf478262d8f (diff) | |
download | FreeBSD-src-d8067c27f54c1f0d1bc952da140a4f0b469b19ea.zip FreeBSD-src-d8067c27f54c1f0d1bc952da140a4f0b469b19ea.tar.gz |
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().
Diffstat (limited to 'sys')
-rw-r--r-- | sys/kern/kern_mbuf.c | 27 | ||||
-rw-r--r-- | sys/kern/subr_param.c | 14 | ||||
-rw-r--r-- | sys/sys/mbuf.h | 1 |
3 files changed, 18 insertions, 24 deletions
diff --git a/sys/kern/kern_mbuf.c b/sys/kern/kern_mbuf.c index 3bdfd88..2259aa2 100644 --- a/sys/kern/kern_mbuf.c +++ b/sys/kern/kern_mbuf.c @@ -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 16k jumbo clusters */ 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, int); 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. diff --git a/sys/kern/subr_param.c b/sys/kern/subr_param.c index 7671615..f36c769 100644 --- a/sys/kern/subr_param.c +++ b/sys/kern/subr_param.c @@ -93,7 +93,6 @@ int ncallout; /* maximum # of timer events */ 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. */ diff --git a/sys/sys/mbuf.h b/sys/sys/mbuf.h index 22742c9..2e778f7 100644 --- a/sys/sys/mbuf.h +++ b/sys/sys/mbuf.h @@ -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; |