subr_param.c revision 116182
11541Srgrimes/*
21541Srgrimes * Copyright (c) 1980, 1986, 1989, 1993
31541Srgrimes *	The Regents of the University of California.  All rights reserved.
41541Srgrimes * (c) UNIX System Laboratories, Inc.
51541Srgrimes * All or some portions of this file are derived from material licensed
61541Srgrimes * to the University of California by American Telephone and Telegraph
71541Srgrimes * Co. or Unix System Laboratories, Inc. and are reproduced herein with
81541Srgrimes * the permission of UNIX System Laboratories, Inc.
91541Srgrimes *
101541Srgrimes * Redistribution and use in source and binary forms, with or without
111541Srgrimes * modification, are permitted provided that the following conditions
121541Srgrimes * are met:
131541Srgrimes * 1. Redistributions of source code must retain the above copyright
141541Srgrimes *    notice, this list of conditions and the following disclaimer.
151541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
161541Srgrimes *    notice, this list of conditions and the following disclaimer in the
171541Srgrimes *    documentation and/or other materials provided with the distribution.
181541Srgrimes * 3. All advertising materials mentioning features or use of this software
191541Srgrimes *    must display the following acknowledgement:
201541Srgrimes *	This product includes software developed by the University of
211541Srgrimes *	California, Berkeley and its contributors.
221541Srgrimes * 4. Neither the name of the University nor the names of its contributors
231541Srgrimes *    may be used to endorse or promote products derived from this software
241541Srgrimes *    without specific prior written permission.
251541Srgrimes *
261541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
271541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
281541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
291541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
301541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
311541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
321541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
331541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
341541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
351541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
361541Srgrimes * SUCH DAMAGE.
371541Srgrimes *
3814526Shsu *	@(#)param.c	8.3 (Berkeley) 8/20/94
391541Srgrimes */
401541Srgrimes
41116182Sobrien#include <sys/cdefs.h>
42116182Sobrien__FBSDID("$FreeBSD: head/sys/kern/subr_param.c 116182 2003-06-11 00:56:59Z obrien $");
43116182Sobrien
4414328Speter#include "opt_param.h"
4580418Speter#include "opt_maxusers.h"
4613226Swollman
471541Srgrimes#include <sys/param.h>
4880418Speter#include <sys/systm.h>
4980418Speter#include <sys/kernel.h>
501541Srgrimes
5184783Sps#include <machine/vmparam.h>
5284783Sps
531541Srgrimes/*
541541Srgrimes * System parameter formulae.
551541Srgrimes */
561541Srgrimes
571541Srgrimes#ifndef HZ
581541Srgrimes#define	HZ 100
591541Srgrimes#endif
6080418Speter#define	NPROC (20 + 16 * maxusers)
6180418Speter#ifndef NBUF
6280418Speter#define NBUF 0
6380418Speter#endif
6445515Sdes#ifndef MAXFILES
6580418Speter#define	MAXFILES (maxproc * 2)
6645515Sdes#endif
678747Sdg
6880418Speterint	hz;
6980418Speterint	tick;
7080418Speterint	maxusers;			/* base tunable */
7180418Speterint	maxproc;			/* maximum # of processes */
7280418Speterint	maxprocperuid;			/* max # of procs per user */
7380418Speterint	maxfiles;			/* sys. wide open files limit */
7480418Speterint	maxfilesperproc;		/* per-proc open files limit */
7580418Speterint	ncallout;			/* maximum # of timer events */
7680418Speterint	nbuf;
7780418Speterint	nswbuf;
7881933Sdillonint	maxswzone;			/* max swmeta KVA storage */
7981933Sdillonint	maxbcache;			/* max buffer cache KVA storage */
8084783Spsu_quad_t	maxtsiz;			/* max text size */
8184783Spsu_quad_t	dfldsiz;			/* initial data size limit */
8284783Spsu_quad_t	maxdsiz;			/* max data size */
8384783Spsu_quad_t	dflssiz;			/* initial stack size limit */
8484783Spsu_quad_t	maxssiz;			/* max stack size */
8584783Spsu_quad_t	sgrowsiz;			/* amount to grow stack */
861541Srgrimes
871541Srgrimes/*
881541Srgrimes * These have to be allocated somewhere; allocating
891541Srgrimes * them here forces loader errors if this file is omitted
901541Srgrimes * (if they've been externed everywhere else; hah!).
911541Srgrimes */
929759Sbdestruct	buf *swbuf;
9367046Sjasone
9467046Sjasone/*
9587546Sdillon * Boot time overrides that are not scaled against main memory
9680418Speter */
9780418Spetervoid
9887546Sdilloninit_param1(void)
9980418Speter{
10080418Speter
10180418Speter	hz = HZ;
10280418Speter	TUNABLE_INT_FETCH("kern.hz", &hz);
10380418Speter	tick = 1000000 / hz;
10480418Speter
10581986Sdillon#ifdef VM_SWZONE_SIZE_MAX
10681933Sdillon	maxswzone = VM_SWZONE_SIZE_MAX;
10781986Sdillon#endif
10881933Sdillon	TUNABLE_INT_FETCH("kern.maxswzone", &maxswzone);
10981986Sdillon#ifdef VM_BCACHE_SIZE_MAX
11081933Sdillon	maxbcache = VM_BCACHE_SIZE_MAX;
11181986Sdillon#endif
11281933Sdillon	TUNABLE_INT_FETCH("kern.maxbcache", &maxbcache);
11384783Sps
11484783Sps	maxtsiz = MAXTSIZ;
11584783Sps	TUNABLE_QUAD_FETCH("kern.maxtsiz", &maxtsiz);
11684783Sps	dfldsiz = DFLDSIZ;
11784783Sps	TUNABLE_QUAD_FETCH("kern.dfldsiz", &dfldsiz);
11884783Sps	maxdsiz = MAXDSIZ;
11984783Sps	TUNABLE_QUAD_FETCH("kern.maxdsiz", &maxdsiz);
12084783Sps	dflssiz = DFLSSIZ;
12184783Sps	TUNABLE_QUAD_FETCH("kern.dflssiz", &dflssiz);
12284783Sps	maxssiz = MAXSSIZ;
12384783Sps	TUNABLE_QUAD_FETCH("kern.maxssiz", &maxssiz);
12484783Sps	sgrowsiz = SGROWSIZ;
12584783Sps	TUNABLE_QUAD_FETCH("kern.sgrowsiz", &sgrowsiz);
12680418Speter}
12787546Sdillon
12887546Sdillon/*
12987546Sdillon * Boot time overrides that are scaled against main memory
13087546Sdillon */
13187546Sdillonvoid
132102600Speterinit_param2(long physpages)
13387546Sdillon{
13487546Sdillon
13587546Sdillon	/* Base parameters */
13690274Sdillon	maxusers = MAXUSERS;
13790274Sdillon	TUNABLE_INT_FETCH("kern.maxusers", &maxusers);
13890274Sdillon	if (maxusers == 0) {
13989769Sdillon		maxusers = physpages / (2 * 1024 * 1024 / PAGE_SIZE);
14087546Sdillon		if (maxusers < 32)
14187546Sdillon			maxusers = 32;
14289769Sdillon		if (maxusers > 384)
14389769Sdillon			maxusers = 384;
14487546Sdillon	}
14587546Sdillon
14687546Sdillon	/*
14787546Sdillon	 * The following can be overridden after boot via sysctl.  Note:
14887546Sdillon	 * unless overriden, these macros are ultimately based on maxusers.
14987546Sdillon	 */
15087546Sdillon	maxproc = NPROC;
15187546Sdillon	TUNABLE_INT_FETCH("kern.maxproc", &maxproc);
15291780Ssilby	/*
15391780Ssilby	 * Limit maxproc so that kmap entries cannot be exhausted by
15491780Ssilby	 * processes.
15591780Ssilby	 */
15691780Ssilby	if (maxproc > (physpages / 12))
15791780Ssilby		maxproc = physpages / 12;
15887546Sdillon	maxfiles = MAXFILES;
15987546Sdillon	TUNABLE_INT_FETCH("kern.maxfiles", &maxfiles);
16087817Ssilby	maxprocperuid = (maxproc * 9) / 10;
16187817Ssilby	maxfilesperproc = (maxfiles * 9) / 10;
16287546Sdillon
16387546Sdillon	/*
16487546Sdillon	 * Cannot be changed after boot.
16587546Sdillon	 */
16687546Sdillon	nbuf = NBUF;
16787546Sdillon	TUNABLE_INT_FETCH("kern.nbuf", &nbuf);
16887546Sdillon
16987546Sdillon	ncallout = 16 + maxproc + maxfiles;
17087546Sdillon	TUNABLE_INT_FETCH("kern.ncallout", &ncallout);
17187546Sdillon}
172