xref: /freebsd/sys/kern/subr_param.c (revision 4fbd563eb89914311d738ed728728d069ff2415b)
1df8bae1dSRodney W. Grimes /*
2df8bae1dSRodney W. Grimes  * Copyright (c) 1980, 1986, 1989, 1993
3df8bae1dSRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
4df8bae1dSRodney W. Grimes  * (c) UNIX System Laboratories, Inc.
5df8bae1dSRodney W. Grimes  * All or some portions of this file are derived from material licensed
6df8bae1dSRodney W. Grimes  * to the University of California by American Telephone and Telegraph
7df8bae1dSRodney W. Grimes  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8df8bae1dSRodney W. Grimes  * the permission of UNIX System Laboratories, Inc.
9df8bae1dSRodney W. Grimes  *
10df8bae1dSRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
11df8bae1dSRodney W. Grimes  * modification, are permitted provided that the following conditions
12df8bae1dSRodney W. Grimes  * are met:
13df8bae1dSRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
14df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
15df8bae1dSRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
16df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
17df8bae1dSRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
18df8bae1dSRodney W. Grimes  * 3. All advertising materials mentioning features or use of this software
19df8bae1dSRodney W. Grimes  *    must display the following acknowledgement:
20df8bae1dSRodney W. Grimes  *	This product includes software developed by the University of
21df8bae1dSRodney W. Grimes  *	California, Berkeley and its contributors.
22df8bae1dSRodney W. Grimes  * 4. Neither the name of the University nor the names of its contributors
23df8bae1dSRodney W. Grimes  *    may be used to endorse or promote products derived from this software
24df8bae1dSRodney W. Grimes  *    without specific prior written permission.
25df8bae1dSRodney W. Grimes  *
26df8bae1dSRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27df8bae1dSRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28df8bae1dSRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29df8bae1dSRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30df8bae1dSRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31df8bae1dSRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32df8bae1dSRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33df8bae1dSRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34df8bae1dSRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35df8bae1dSRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36df8bae1dSRodney W. Grimes  * SUCH DAMAGE.
37df8bae1dSRodney W. Grimes  *
3870b012caSJeffrey Hsu  *	@(#)param.c	8.3 (Berkeley) 8/20/94
39c3aac50fSPeter Wemm  * $FreeBSD$
40df8bae1dSRodney W. Grimes  */
41df8bae1dSRodney W. Grimes 
424bd49128SPeter Wemm #include "opt_param.h"
43ee342e1bSPeter Wemm #include "opt_maxusers.h"
4450c73f36SGarrett Wollman 
45df8bae1dSRodney W. Grimes #include <sys/param.h>
46ee342e1bSPeter Wemm #include <sys/systm.h>
47ee342e1bSPeter Wemm #include <sys/kernel.h>
48df8bae1dSRodney W. Grimes 
49cbc89bfbSPaul Saab #include <machine/vmparam.h>
50cbc89bfbSPaul Saab 
51df8bae1dSRodney W. Grimes /*
52df8bae1dSRodney W. Grimes  * System parameter formulae.
53df8bae1dSRodney W. Grimes  */
54df8bae1dSRodney W. Grimes 
55df8bae1dSRodney W. Grimes #ifndef HZ
56df8bae1dSRodney W. Grimes #define	HZ 100
57df8bae1dSRodney W. Grimes #endif
58ee342e1bSPeter Wemm #define	NPROC (20 + 16 * maxusers)
59ee342e1bSPeter Wemm #ifndef NBUF
60ee342e1bSPeter Wemm #define NBUF 0
61ee342e1bSPeter Wemm #endif
625a00f364SDag-Erling Smørgrav #ifndef MAXFILES
63ee342e1bSPeter Wemm #define	MAXFILES (maxproc * 2)
645a00f364SDag-Erling Smørgrav #endif
65dd0b2081SDavid Greenman 
66ee342e1bSPeter Wemm int	hz;
67ee342e1bSPeter Wemm int	tick;
68ee342e1bSPeter Wemm int	tickadj;			 /* can adjust 30ms in 60s */
69ee342e1bSPeter Wemm int	maxusers;			/* base tunable */
70ee342e1bSPeter Wemm int	maxproc;			/* maximum # of processes */
71ee342e1bSPeter Wemm int	maxprocperuid;			/* max # of procs per user */
72ee342e1bSPeter Wemm int	maxfiles;			/* sys. wide open files limit */
73ee342e1bSPeter Wemm int	maxfilesperproc;		/* per-proc open files limit */
74ee342e1bSPeter Wemm int	ncallout;			/* maximum # of timer events */
75ee342e1bSPeter Wemm int	nbuf;
76ee342e1bSPeter Wemm int	nswbuf;
772f9e4e80SMatthew Dillon int	maxswzone;			/* max swmeta KVA storage */
782f9e4e80SMatthew Dillon int	maxbcache;			/* max buffer cache KVA storage */
79cbc89bfbSPaul Saab u_quad_t	maxtsiz;			/* max text size */
80cbc89bfbSPaul Saab u_quad_t	dfldsiz;			/* initial data size limit */
81cbc89bfbSPaul Saab u_quad_t	maxdsiz;			/* max data size */
82cbc89bfbSPaul Saab u_quad_t	dflssiz;			/* initial stack size limit */
83cbc89bfbSPaul Saab u_quad_t	maxssiz;			/* max stack size */
84cbc89bfbSPaul Saab u_quad_t	sgrowsiz;			/* amount to grow stack */
85df8bae1dSRodney W. Grimes 
86df8bae1dSRodney W. Grimes /*
87df8bae1dSRodney W. Grimes  * These have to be allocated somewhere; allocating
88df8bae1dSRodney W. Grimes  * them here forces loader errors if this file is omitted
89df8bae1dSRodney W. Grimes  * (if they've been externed everywhere else; hah!).
90df8bae1dSRodney W. Grimes  */
9128f8db14SBruce Evans struct	buf *swbuf;
929722d88fSJason Evans 
939722d88fSJason Evans /*
9466a11b9fSMatthew Dillon  * Boot time overrides that are not scaled against main memory
95ee342e1bSPeter Wemm  */
96ee342e1bSPeter Wemm void
9766a11b9fSMatthew Dillon init_param1(void)
98ee342e1bSPeter Wemm {
99ee342e1bSPeter Wemm 
100ee342e1bSPeter Wemm 	hz = HZ;
101ee342e1bSPeter Wemm 	TUNABLE_INT_FETCH("kern.hz", &hz);
102ee342e1bSPeter Wemm 	tick = 1000000 / hz;
103ee342e1bSPeter Wemm 	tickadj = howmany(30000, 60 * hz);	/* can adjust 30ms in 60s */
104ee342e1bSPeter Wemm 
105e1616f3aSMatthew Dillon #ifdef VM_SWZONE_SIZE_MAX
1062f9e4e80SMatthew Dillon 	maxswzone = VM_SWZONE_SIZE_MAX;
107e1616f3aSMatthew Dillon #endif
1082f9e4e80SMatthew Dillon 	TUNABLE_INT_FETCH("kern.maxswzone", &maxswzone);
109e1616f3aSMatthew Dillon #ifdef VM_BCACHE_SIZE_MAX
1102f9e4e80SMatthew Dillon 	maxbcache = VM_BCACHE_SIZE_MAX;
111e1616f3aSMatthew Dillon #endif
1122f9e4e80SMatthew Dillon 	TUNABLE_INT_FETCH("kern.maxbcache", &maxbcache);
113cbc89bfbSPaul Saab 
114cbc89bfbSPaul Saab 	maxtsiz = MAXTSIZ;
115cbc89bfbSPaul Saab 	TUNABLE_QUAD_FETCH("kern.maxtsiz", &maxtsiz);
116cbc89bfbSPaul Saab 	dfldsiz = DFLDSIZ;
117cbc89bfbSPaul Saab 	TUNABLE_QUAD_FETCH("kern.dfldsiz", &dfldsiz);
118cbc89bfbSPaul Saab 	maxdsiz = MAXDSIZ;
119cbc89bfbSPaul Saab 	TUNABLE_QUAD_FETCH("kern.maxdsiz", &maxdsiz);
120cbc89bfbSPaul Saab 	dflssiz = DFLSSIZ;
121cbc89bfbSPaul Saab 	TUNABLE_QUAD_FETCH("kern.dflssiz", &dflssiz);
122cbc89bfbSPaul Saab 	maxssiz = MAXSSIZ;
123cbc89bfbSPaul Saab 	TUNABLE_QUAD_FETCH("kern.maxssiz", &maxssiz);
124cbc89bfbSPaul Saab 	sgrowsiz = SGROWSIZ;
125cbc89bfbSPaul Saab 	TUNABLE_QUAD_FETCH("kern.sgrowsiz", &sgrowsiz);
126ee342e1bSPeter Wemm }
12766a11b9fSMatthew Dillon 
12866a11b9fSMatthew Dillon /*
12966a11b9fSMatthew Dillon  * Boot time overrides that are scaled against main memory
13066a11b9fSMatthew Dillon  */
13166a11b9fSMatthew Dillon void
13266a11b9fSMatthew Dillon init_param2(int physpages)
13366a11b9fSMatthew Dillon {
13466a11b9fSMatthew Dillon 
13566a11b9fSMatthew Dillon 	/* Base parameters */
136f6916f66SPeter Wemm 	if ((maxusers = MAXUSERS) == 0) {
1374fbd563eSMatthew Dillon 		maxusers = physpages / (2 * 1024 * 1024 / PAGE_SIZE);
13866a11b9fSMatthew Dillon 		if (maxusers < 32)
13966a11b9fSMatthew Dillon 			maxusers = 32;
1404fbd563eSMatthew Dillon 		if (maxusers > 384)
1414fbd563eSMatthew Dillon 			maxusers = 384;
14266a11b9fSMatthew Dillon 	}
14366a11b9fSMatthew Dillon 	TUNABLE_INT_FETCH("kern.maxusers", &maxusers);
14466a11b9fSMatthew Dillon 
14566a11b9fSMatthew Dillon 	/*
14666a11b9fSMatthew Dillon 	 * The following can be overridden after boot via sysctl.  Note:
14766a11b9fSMatthew Dillon 	 * unless overriden, these macros are ultimately based on maxusers.
14866a11b9fSMatthew Dillon 	 */
14966a11b9fSMatthew Dillon 	maxproc = NPROC;
15066a11b9fSMatthew Dillon 	TUNABLE_INT_FETCH("kern.maxproc", &maxproc);
15166a11b9fSMatthew Dillon 	maxfiles = MAXFILES;
15266a11b9fSMatthew Dillon 	TUNABLE_INT_FETCH("kern.maxfiles", &maxfiles);
153ebacce5eSMike Silbersack 	maxprocperuid = (maxproc * 9) / 10;
154ebacce5eSMike Silbersack 	maxfilesperproc = (maxfiles * 9) / 10;
15566a11b9fSMatthew Dillon 
15666a11b9fSMatthew Dillon 	/*
15766a11b9fSMatthew Dillon 	 * Cannot be changed after boot.
15866a11b9fSMatthew Dillon 	 */
15966a11b9fSMatthew Dillon 	nbuf = NBUF;
16066a11b9fSMatthew Dillon 	TUNABLE_INT_FETCH("kern.nbuf", &nbuf);
16166a11b9fSMatthew Dillon 
16266a11b9fSMatthew Dillon 	ncallout = 16 + maxproc + maxfiles;
16366a11b9fSMatthew Dillon 	TUNABLE_INT_FETCH("kern.ncallout", &ncallout);
16466a11b9fSMatthew Dillon }
165