subr_param.c revision 81986
1/*
2 * Copyright (c) 1980, 1986, 1989, 1993
3 *	The Regents of the University of California.  All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 *    notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 *    notice, this list of conditions and the following disclaimer in the
17 *    documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 *    must display the following acknowledgement:
20 *	This product includes software developed by the University of
21 *	California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 *    may be used to endorse or promote products derived from this software
24 *    without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 *	@(#)param.c	8.3 (Berkeley) 8/20/94
39 * $FreeBSD: head/sys/kern/subr_param.c 81986 2001-08-20 16:29:13Z dillon $
40 */
41
42#include "opt_param.h"
43#include "opt_maxusers.h"
44
45#include <sys/param.h>
46#include <sys/systm.h>
47#include <sys/kernel.h>
48
49/*
50 * System parameter formulae.
51 */
52
53#ifndef HZ
54#define	HZ 100
55#endif
56#define	NPROC (20 + 16 * maxusers)
57#ifndef NBUF
58#define NBUF 0
59#endif
60#ifndef MAXFILES
61#define	MAXFILES (maxproc * 2)
62#endif
63
64int	hz;
65int	tick;
66int	tickadj;			 /* can adjust 30ms in 60s */
67int	maxusers;			/* base tunable */
68int	maxproc;			/* maximum # of processes */
69int	maxprocperuid;			/* max # of procs per user */
70int	maxfiles;			/* sys. wide open files limit */
71int	maxfilesperproc;		/* per-proc open files limit */
72int	ncallout;			/* maximum # of timer events */
73int	nbuf;
74int	nswbuf;
75int	maxswzone;			/* max swmeta KVA storage */
76int	maxbcache;			/* max buffer cache KVA storage */
77
78/*
79 * These have to be allocated somewhere; allocating
80 * them here forces loader errors if this file is omitted
81 * (if they've been externed everywhere else; hah!).
82 */
83struct	buf *swbuf;
84
85/*
86 * Total number of shared mutexes to protect all lockmgr locks.
87 */
88#ifndef	LOCKMUTEX
89#define LOCKMUTEX	10
90#endif
91int	lock_nmtx = LOCKMUTEX;
92
93/*
94 * Boot time overrides
95 */
96void
97init_param(void)
98{
99
100	/* Base parameters */
101	maxusers = MAXUSERS;
102	TUNABLE_INT_FETCH("kern.maxusers", &maxusers);
103	hz = HZ;
104	TUNABLE_INT_FETCH("kern.hz", &hz);
105	tick = 1000000 / hz;
106	tickadj = howmany(30000, 60 * hz);	/* can adjust 30ms in 60s */
107
108	/* The following can be overridden after boot via sysctl */
109	maxproc = NPROC;
110	TUNABLE_INT_FETCH("kern.maxproc", &maxproc);
111	maxfiles = MAXFILES;
112	TUNABLE_INT_FETCH("kern.maxfiles", &maxfiles);
113	maxprocperuid = maxproc - 1;
114	maxfilesperproc = maxfiles;
115
116	/* Cannot be changed after boot */
117	nbuf = NBUF;
118	TUNABLE_INT_FETCH("kern.nbuf", &nbuf);
119#ifdef VM_SWZONE_SIZE_MAX
120	maxswzone = VM_SWZONE_SIZE_MAX;
121#endif
122	TUNABLE_INT_FETCH("kern.maxswzone", &maxswzone);
123#ifdef VM_BCACHE_SIZE_MAX
124	maxbcache = VM_BCACHE_SIZE_MAX;
125#endif
126	TUNABLE_INT_FETCH("kern.maxbcache", &maxbcache);
127	ncallout = 16 + maxproc + maxfiles;
128	TUNABLE_INT_FETCH("kern.ncallout", &ncallout);
129}
130