subr_param.c revision 89769
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 89769 2002-01-25 01:54:16Z dillon $
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	tickadj;			 /* can adjust 30ms in 60s */
6980418Speterint	maxusers;			/* base tunable */
7080418Speterint	maxproc;			/* maximum # of processes */
7180418Speterint	maxprocperuid;			/* max # of procs per user */
7280418Speterint	maxfiles;			/* sys. wide open files limit */
7380418Speterint	maxfilesperproc;		/* per-proc open files limit */
7480418Speterint	ncallout;			/* maximum # of timer events */
7580418Speterint	nbuf;
7680418Speterint	nswbuf;
7781933Sdillonint	maxswzone;			/* max swmeta KVA storage */
7881933Sdillonint	maxbcache;			/* max buffer cache KVA storage */
7984783Spsu_quad_t	maxtsiz;			/* max text size */
8084783Spsu_quad_t	dfldsiz;			/* initial data size limit */
8184783Spsu_quad_t	maxdsiz;			/* max data size */
8284783Spsu_quad_t	dflssiz;			/* initial stack size limit */
8384783Spsu_quad_t	maxssiz;			/* max stack size */
8484783Spsu_quad_t	sgrowsiz;			/* amount to grow stack */
851541Srgrimes
861541Srgrimes/*
871541Srgrimes * These have to be allocated somewhere; allocating
881541Srgrimes * them here forces loader errors if this file is omitted
891541Srgrimes * (if they've been externed everywhere else; hah!).
901541Srgrimes */
919759Sbdestruct	buf *swbuf;
9267046Sjasone
9367046Sjasone/*
9487546Sdillon * Boot time overrides that are not scaled against main memory
9580418Speter */
9680418Spetervoid
9787546Sdilloninit_param1(void)
9880418Speter{
9980418Speter
10080418Speter	hz = HZ;
10180418Speter	TUNABLE_INT_FETCH("kern.hz", &hz);
10280418Speter	tick = 1000000 / hz;
10380418Speter	tickadj = howmany(30000, 60 * hz);	/* can adjust 30ms in 60s */
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
13287546Sdilloninit_param2(int physpages)
13387546Sdillon{
13487546Sdillon
13587546Sdillon	/* Base parameters */
13687860Speter	if ((maxusers = 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	TUNABLE_INT_FETCH("kern.maxusers", &maxusers);
14487546Sdillon
14587546Sdillon	/*
14687546Sdillon	 * The following can be overridden after boot via sysctl.  Note:
14787546Sdillon	 * unless overriden, these macros are ultimately based on maxusers.
14887546Sdillon	 */
14987546Sdillon	maxproc = NPROC;
15087546Sdillon	TUNABLE_INT_FETCH("kern.maxproc", &maxproc);
15187546Sdillon	maxfiles = MAXFILES;
15287546Sdillon	TUNABLE_INT_FETCH("kern.maxfiles", &maxfiles);
15387817Ssilby	maxprocperuid = (maxproc * 9) / 10;
15487817Ssilby	maxfilesperproc = (maxfiles * 9) / 10;
15587546Sdillon
15687546Sdillon	/*
15787546Sdillon	 * Cannot be changed after boot.
15887546Sdillon	 */
15987546Sdillon	nbuf = NBUF;
16087546Sdillon	TUNABLE_INT_FETCH("kern.nbuf", &nbuf);
16187546Sdillon
16287546Sdillon	ncallout = 16 + maxproc + maxfiles;
16387546Sdillon	TUNABLE_INT_FETCH("kern.ncallout", &ncallout);
16487546Sdillon}
165