subr_param.c revision 81933
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 81933 2001-08-20 00:41:12Z 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
491541Srgrimes/*
501541Srgrimes * System parameter formulae.
511541Srgrimes */
521541Srgrimes
531541Srgrimes#ifndef HZ
541541Srgrimes#define	HZ 100
551541Srgrimes#endif
5680418Speter#define	NPROC (20 + 16 * maxusers)
5780418Speter#ifndef NBUF
5880418Speter#define NBUF 0
5980418Speter#endif
6045515Sdes#ifndef MAXFILES
6180418Speter#define	MAXFILES (maxproc * 2)
6245515Sdes#endif
638747Sdg
6480418Speterint	hz;
6580418Speterint	tick;
6680418Speterint	tickadj;			 /* can adjust 30ms in 60s */
6780418Speterint	maxusers;			/* base tunable */
6880418Speterint	maxproc;			/* maximum # of processes */
6980418Speterint	maxprocperuid;			/* max # of procs per user */
7080418Speterint	maxfiles;			/* sys. wide open files limit */
7180418Speterint	maxfilesperproc;		/* per-proc open files limit */
7280418Speterint	ncallout;			/* maximum # of timer events */
7380418Speterint	nbuf;
7480418Speterint	nswbuf;
7581933Sdillonint	maxswzone;			/* max swmeta KVA storage */
7681933Sdillonint	maxbcache;			/* max buffer cache KVA storage */
771541Srgrimes
781541Srgrimes/*
791541Srgrimes * These have to be allocated somewhere; allocating
801541Srgrimes * them here forces loader errors if this file is omitted
811541Srgrimes * (if they've been externed everywhere else; hah!).
821541Srgrimes */
839759Sbdestruct	buf *swbuf;
8467046Sjasone
8567046Sjasone/*
8667046Sjasone * Total number of shared mutexes to protect all lockmgr locks.
8767046Sjasone */
8867046Sjasone#ifndef	LOCKMUTEX
8967046Sjasone#define LOCKMUTEX	10
9067046Sjasone#endif
9167046Sjasoneint	lock_nmtx = LOCKMUTEX;
9280418Speter
9380418Speter/*
9480418Speter * Boot time overrides
9580418Speter */
9680418Spetervoid
9780418Speterinit_param(void)
9880418Speter{
9980418Speter
10080418Speter	/* Base parameters */
10180418Speter	maxusers = MAXUSERS;
10280418Speter	TUNABLE_INT_FETCH("kern.maxusers", &maxusers);
10380418Speter	hz = HZ;
10480418Speter	TUNABLE_INT_FETCH("kern.hz", &hz);
10580418Speter	tick = 1000000 / hz;
10680418Speter	tickadj = howmany(30000, 60 * hz);	/* can adjust 30ms in 60s */
10780418Speter
10880418Speter	/* The following can be overridden after boot via sysctl */
10980418Speter	maxproc = NPROC;
11080418Speter	TUNABLE_INT_FETCH("kern.maxproc", &maxproc);
11180418Speter	maxfiles = MAXFILES;
11280418Speter	TUNABLE_INT_FETCH("kern.maxfiles", &maxfiles);
11380418Speter	maxprocperuid = maxproc - 1;
11480418Speter	maxfilesperproc = maxfiles;
11580418Speter
11680418Speter	/* Cannot be changed after boot */
11780418Speter	nbuf = NBUF;
11880418Speter	TUNABLE_INT_FETCH("kern.nbuf", &nbuf);
11981933Sdillon	maxswzone = VM_SWZONE_SIZE_MAX;
12081933Sdillon	TUNABLE_INT_FETCH("kern.maxswzone", &maxswzone);
12181933Sdillon	maxbcache = VM_BCACHE_SIZE_MAX;
12281933Sdillon	TUNABLE_INT_FETCH("kern.maxbcache", &maxbcache);
12380418Speter	ncallout = 16 + maxproc + maxfiles;
12480418Speter	TUNABLE_INT_FETCH("kern.ncallout", &ncallout);
12580418Speter}
126