subr_param.c revision 102600
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
3950477Speter * $FreeBSD: head/sys/kern/subr_param.c 102600 2002-08-30 04:04:37Z peter $
401541Srgrimes */
411541Srgrimes
4214328Speter#include "opt_param.h"
4380418Speter#include "opt_maxusers.h"
4413226Swollman
451541Srgrimes#include <sys/param.h>
4680418Speter#include <sys/systm.h>
4780418Speter#include <sys/kernel.h>
481541Srgrimes
4984783Sps#include <machine/vmparam.h>
5084783Sps
511541Srgrimes/*
521541Srgrimes * System parameter formulae.
531541Srgrimes */
541541Srgrimes
551541Srgrimes#ifndef HZ
561541Srgrimes#define	HZ 100
571541Srgrimes#endif
5880418Speter#define	NPROC (20 + 16 * maxusers)
5980418Speter#ifndef NBUF
6080418Speter#define NBUF 0
6180418Speter#endif
6245515Sdes#ifndef MAXFILES
6380418Speter#define	MAXFILES (maxproc * 2)
6445515Sdes#endif
658747Sdg
6680418Speterint	hz;
6780418Speterint	tick;
6880418Speterint	maxusers;			/* base tunable */
6980418Speterint	maxproc;			/* maximum # of processes */
7080418Speterint	maxprocperuid;			/* max # of procs per user */
7180418Speterint	maxfiles;			/* sys. wide open files limit */
7280418Speterint	maxfilesperproc;		/* per-proc open files limit */
7380418Speterint	ncallout;			/* maximum # of timer events */
7480418Speterint	nbuf;
7580418Speterint	nswbuf;
7681933Sdillonint	maxswzone;			/* max swmeta KVA storage */
7781933Sdillonint	maxbcache;			/* max buffer cache KVA storage */
7884783Spsu_quad_t	maxtsiz;			/* max text size */
7984783Spsu_quad_t	dfldsiz;			/* initial data size limit */
8084783Spsu_quad_t	maxdsiz;			/* max data size */
8184783Spsu_quad_t	dflssiz;			/* initial stack size limit */
8284783Spsu_quad_t	maxssiz;			/* max stack size */
8384783Spsu_quad_t	sgrowsiz;			/* amount to grow stack */
841541Srgrimes
851541Srgrimes/*
861541Srgrimes * These have to be allocated somewhere; allocating
871541Srgrimes * them here forces loader errors if this file is omitted
881541Srgrimes * (if they've been externed everywhere else; hah!).
891541Srgrimes */
909759Sbdestruct	buf *swbuf;
9167046Sjasone
9267046Sjasone/*
9387546Sdillon * Boot time overrides that are not scaled against main memory
9480418Speter */
9580418Spetervoid
9687546Sdilloninit_param1(void)
9780418Speter{
9880418Speter
9980418Speter	hz = HZ;
10080418Speter	TUNABLE_INT_FETCH("kern.hz", &hz);
10180418Speter	tick = 1000000 / hz;
10280418Speter
10381986Sdillon#ifdef VM_SWZONE_SIZE_MAX
10481933Sdillon	maxswzone = VM_SWZONE_SIZE_MAX;
10581986Sdillon#endif
10681933Sdillon	TUNABLE_INT_FETCH("kern.maxswzone", &maxswzone);
10781986Sdillon#ifdef VM_BCACHE_SIZE_MAX
10881933Sdillon	maxbcache = VM_BCACHE_SIZE_MAX;
10981986Sdillon#endif
11081933Sdillon	TUNABLE_INT_FETCH("kern.maxbcache", &maxbcache);
11184783Sps
11284783Sps	maxtsiz = MAXTSIZ;
11384783Sps	TUNABLE_QUAD_FETCH("kern.maxtsiz", &maxtsiz);
11484783Sps	dfldsiz = DFLDSIZ;
11584783Sps	TUNABLE_QUAD_FETCH("kern.dfldsiz", &dfldsiz);
11684783Sps	maxdsiz = MAXDSIZ;
11784783Sps	TUNABLE_QUAD_FETCH("kern.maxdsiz", &maxdsiz);
11884783Sps	dflssiz = DFLSSIZ;
11984783Sps	TUNABLE_QUAD_FETCH("kern.dflssiz", &dflssiz);
12084783Sps	maxssiz = MAXSSIZ;
12184783Sps	TUNABLE_QUAD_FETCH("kern.maxssiz", &maxssiz);
12284783Sps	sgrowsiz = SGROWSIZ;
12384783Sps	TUNABLE_QUAD_FETCH("kern.sgrowsiz", &sgrowsiz);
12480418Speter}
12587546Sdillon
12687546Sdillon/*
12787546Sdillon * Boot time overrides that are scaled against main memory
12887546Sdillon */
12987546Sdillonvoid
130102600Speterinit_param2(long physpages)
13187546Sdillon{
13287546Sdillon
13387546Sdillon	/* Base parameters */
13490274Sdillon	maxusers = MAXUSERS;
13590274Sdillon	TUNABLE_INT_FETCH("kern.maxusers", &maxusers);
13690274Sdillon	if (maxusers == 0) {
13789769Sdillon		maxusers = physpages / (2 * 1024 * 1024 / PAGE_SIZE);
13887546Sdillon		if (maxusers < 32)
13987546Sdillon			maxusers = 32;
14089769Sdillon		if (maxusers > 384)
14189769Sdillon			maxusers = 384;
14287546Sdillon	}
14387546Sdillon
14487546Sdillon	/*
14587546Sdillon	 * The following can be overridden after boot via sysctl.  Note:
14687546Sdillon	 * unless overriden, these macros are ultimately based on maxusers.
14787546Sdillon	 */
14887546Sdillon	maxproc = NPROC;
14987546Sdillon	TUNABLE_INT_FETCH("kern.maxproc", &maxproc);
15091780Ssilby	/*
15191780Ssilby	 * Limit maxproc so that kmap entries cannot be exhausted by
15291780Ssilby	 * processes.
15391780Ssilby	 */
15491780Ssilby	if (maxproc > (physpages / 12))
15591780Ssilby		maxproc = physpages / 12;
15687546Sdillon	maxfiles = MAXFILES;
15787546Sdillon	TUNABLE_INT_FETCH("kern.maxfiles", &maxfiles);
15887817Ssilby	maxprocperuid = (maxproc * 9) / 10;
15987817Ssilby	maxfilesperproc = (maxfiles * 9) / 10;
16087546Sdillon
16187546Sdillon	/*
16287546Sdillon	 * Cannot be changed after boot.
16387546Sdillon	 */
16487546Sdillon	nbuf = NBUF;
16587546Sdillon	TUNABLE_INT_FETCH("kern.nbuf", &nbuf);
16687546Sdillon
16787546Sdillon	ncallout = 16 + maxproc + maxfiles;
16887546Sdillon	TUNABLE_INT_FETCH("kern.ncallout", &ncallout);
16987546Sdillon}
170