subr_param.c revision 139804
1139804Simp/*-
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 * 4. Neither the name of the University nor the names of its contributors
191541Srgrimes *    may be used to endorse or promote products derived from this software
201541Srgrimes *    without specific prior written permission.
211541Srgrimes *
221541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
231541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
241541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
251541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
261541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
271541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
281541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
291541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
301541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
311541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
321541Srgrimes * SUCH DAMAGE.
331541Srgrimes *
3414526Shsu *	@(#)param.c	8.3 (Berkeley) 8/20/94
351541Srgrimes */
361541Srgrimes
37116182Sobrien#include <sys/cdefs.h>
38116182Sobrien__FBSDID("$FreeBSD: head/sys/kern/subr_param.c 139804 2005-01-06 23:35:40Z imp $");
39116182Sobrien
4014328Speter#include "opt_param.h"
4180418Speter#include "opt_maxusers.h"
4213226Swollman
431541Srgrimes#include <sys/param.h>
4480418Speter#include <sys/systm.h>
4580418Speter#include <sys/kernel.h>
461541Srgrimes
47137393Sdes#include <vm/vm_param.h>
4884783Sps
491541Srgrimes/*
501541Srgrimes * System parameter formulae.
511541Srgrimes */
521541Srgrimes
531541Srgrimes#ifndef HZ
54138214Sbms#  if defined(__amd64__) || defined(__i386__) || defined(__ia64__)
55137307Sphk#    define	HZ 1000
56137307Sphk#  else
57137307Sphk#    define	HZ 100
58138214Sbms#  endif
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;
78137393Sdeslong	maxswzone;			/* max swmeta KVA storage */
79137393Sdeslong	maxbcache;			/* max buffer cache KVA storage */
80117325Ssilbyint	maxpipekva;			/* Limit on pipe KVA */
81137393Sdesu_long	maxtsiz;			/* max text size */
82137393Sdesu_long	dfldsiz;			/* initial data size limit */
83137393Sdesu_long	maxdsiz;			/* max data size */
84137393Sdesu_long	dflssiz;			/* initial stack size limit */
85137393Sdesu_long	maxssiz;			/* max stack size */
86137393Sdesu_long	sgrowsiz;			/* amount to grow stack */
871541Srgrimes
881541Srgrimes/*
891541Srgrimes * These have to be allocated somewhere; allocating
901541Srgrimes * them here forces loader errors if this file is omitted
911541Srgrimes * (if they've been externed everywhere else; hah!).
921541Srgrimes */
939759Sbdestruct	buf *swbuf;
9467046Sjasone
9567046Sjasone/*
9687546Sdillon * Boot time overrides that are not scaled against main memory
9780418Speter */
9880418Spetervoid
9987546Sdilloninit_param1(void)
10080418Speter{
10180418Speter
10280418Speter	hz = HZ;
10380418Speter	TUNABLE_INT_FETCH("kern.hz", &hz);
10480418Speter	tick = 1000000 / hz;
10580418Speter
10681986Sdillon#ifdef VM_SWZONE_SIZE_MAX
10781933Sdillon	maxswzone = VM_SWZONE_SIZE_MAX;
10881986Sdillon#endif
109137393Sdes	TUNABLE_LONG_FETCH("kern.maxswzone", &maxswzone);
11081986Sdillon#ifdef VM_BCACHE_SIZE_MAX
11181933Sdillon	maxbcache = VM_BCACHE_SIZE_MAX;
11281986Sdillon#endif
113137393Sdes	TUNABLE_LONG_FETCH("kern.maxbcache", &maxbcache);
11484783Sps
11584783Sps	maxtsiz = MAXTSIZ;
116137393Sdes	TUNABLE_ULONG_FETCH("kern.maxtsiz", &maxtsiz);
11784783Sps	dfldsiz = DFLDSIZ;
118137393Sdes	TUNABLE_ULONG_FETCH("kern.dfldsiz", &dfldsiz);
11984783Sps	maxdsiz = MAXDSIZ;
120137393Sdes	TUNABLE_ULONG_FETCH("kern.maxdsiz", &maxdsiz);
12184783Sps	dflssiz = DFLSSIZ;
122137393Sdes	TUNABLE_ULONG_FETCH("kern.dflssiz", &dflssiz);
12384783Sps	maxssiz = MAXSSIZ;
124137393Sdes	TUNABLE_ULONG_FETCH("kern.maxssiz", &maxssiz);
12584783Sps	sgrowsiz = SGROWSIZ;
126137393Sdes	TUNABLE_ULONG_FETCH("kern.sgrowsiz", &sgrowsiz);
12780418Speter}
12887546Sdillon
12987546Sdillon/*
13087546Sdillon * Boot time overrides that are scaled against main memory
13187546Sdillon */
13287546Sdillonvoid
133102600Speterinit_param2(long physpages)
13487546Sdillon{
13587546Sdillon
13687546Sdillon	/* Base parameters */
13790274Sdillon	maxusers = MAXUSERS;
13890274Sdillon	TUNABLE_INT_FETCH("kern.maxusers", &maxusers);
13990274Sdillon	if (maxusers == 0) {
14089769Sdillon		maxusers = physpages / (2 * 1024 * 1024 / PAGE_SIZE);
14187546Sdillon		if (maxusers < 32)
14287546Sdillon			maxusers = 32;
14389769Sdillon		if (maxusers > 384)
14489769Sdillon			maxusers = 384;
14587546Sdillon	}
14687546Sdillon
14787546Sdillon	/*
14887546Sdillon	 * The following can be overridden after boot via sysctl.  Note:
14987546Sdillon	 * unless overriden, these macros are ultimately based on maxusers.
15087546Sdillon	 */
15187546Sdillon	maxproc = NPROC;
15287546Sdillon	TUNABLE_INT_FETCH("kern.maxproc", &maxproc);
15391780Ssilby	/*
15491780Ssilby	 * Limit maxproc so that kmap entries cannot be exhausted by
15591780Ssilby	 * processes.
15691780Ssilby	 */
15791780Ssilby	if (maxproc > (physpages / 12))
15891780Ssilby		maxproc = physpages / 12;
15987546Sdillon	maxfiles = MAXFILES;
16087546Sdillon	TUNABLE_INT_FETCH("kern.maxfiles", &maxfiles);
16187817Ssilby	maxprocperuid = (maxproc * 9) / 10;
16287817Ssilby	maxfilesperproc = (maxfiles * 9) / 10;
163117391Ssilby
164117391Ssilby	/*
165117391Ssilby	 * Cannot be changed after boot.
166117391Ssilby	 */
167117391Ssilby	nbuf = NBUF;
168117391Ssilby	TUNABLE_INT_FETCH("kern.nbuf", &nbuf);
16987546Sdillon
170117391Ssilby	ncallout = 16 + maxproc + maxfiles;
171117391Ssilby	TUNABLE_INT_FETCH("kern.ncallout", &ncallout);
172117391Ssilby}
173117391Ssilby
174117391Ssilby/*
175117391Ssilby * Boot time overrides that are scaled against the kernel map
176117391Ssilby */
177117391Ssilbyvoid
178117391Ssilbyinit_param3(long kmempages)
179117391Ssilby{
180127612Salc
18187546Sdillon	/*
182127612Salc	 * The default for maxpipekva is max(5% of the kernel map, 512KB).
183127612Salc	 * See sys_pipe.c for more details.
184117325Ssilby	 */
185118764Ssilby	maxpipekva = (kmempages / 20) * PAGE_SIZE;
186117325Ssilby	if (maxpipekva < 512 * 1024)
187117325Ssilby		maxpipekva = 512 * 1024;
188118764Ssilby	TUNABLE_INT_FETCH("kern.ipc.maxpipekva", &maxpipekva);
18987546Sdillon}
190