subr_param.c revision 137307
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 * 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 137307 2004-11-06 11:33:43Z phk $");
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
4784783Sps#include <machine/vmparam.h>
4884783Sps
491541Srgrimes/*
501541Srgrimes * System parameter formulae.
511541Srgrimes */
521541Srgrimes
531541Srgrimes#ifndef HZ
54137307Sphk#  if defined(__amd64__)
55137307Sphk#    define	HZ 1024
56137307Sphk#  elif defined(__i386__)
57137307Sphk#    define	HZ 1000
58137307Sphk#  else
59137307Sphk#    define	HZ 100
601541Srgrimes#endif
61126959Speter#endif
6280418Speter#define	NPROC (20 + 16 * maxusers)
6380418Speter#ifndef NBUF
6480418Speter#define NBUF 0
6580418Speter#endif
6645515Sdes#ifndef MAXFILES
6780418Speter#define	MAXFILES (maxproc * 2)
6845515Sdes#endif
698747Sdg
7080418Speterint	hz;
7180418Speterint	tick;
7280418Speterint	maxusers;			/* base tunable */
7380418Speterint	maxproc;			/* maximum # of processes */
7480418Speterint	maxprocperuid;			/* max # of procs per user */
7580418Speterint	maxfiles;			/* sys. wide open files limit */
7680418Speterint	maxfilesperproc;		/* per-proc open files limit */
7780418Speterint	ncallout;			/* maximum # of timer events */
7880418Speterint	nbuf;
7980418Speterint	nswbuf;
8081933Sdillonint	maxswzone;			/* max swmeta KVA storage */
8181933Sdillonint	maxbcache;			/* max buffer cache KVA storage */
82117325Ssilbyint	maxpipekva;			/* Limit on pipe KVA */
8384783Spsu_quad_t	maxtsiz;			/* max text size */
8484783Spsu_quad_t	dfldsiz;			/* initial data size limit */
8584783Spsu_quad_t	maxdsiz;			/* max data size */
8684783Spsu_quad_t	dflssiz;			/* initial stack size limit */
8784783Spsu_quad_t	maxssiz;			/* max stack size */
8884783Spsu_quad_t	sgrowsiz;			/* amount to grow stack */
891541Srgrimes
901541Srgrimes/*
911541Srgrimes * These have to be allocated somewhere; allocating
921541Srgrimes * them here forces loader errors if this file is omitted
931541Srgrimes * (if they've been externed everywhere else; hah!).
941541Srgrimes */
959759Sbdestruct	buf *swbuf;
9667046Sjasone
9767046Sjasone/*
9887546Sdillon * Boot time overrides that are not scaled against main memory
9980418Speter */
10080418Spetervoid
10187546Sdilloninit_param1(void)
10280418Speter{
10380418Speter
10480418Speter	hz = HZ;
10580418Speter	TUNABLE_INT_FETCH("kern.hz", &hz);
10680418Speter	tick = 1000000 / hz;
10780418Speter
10881986Sdillon#ifdef VM_SWZONE_SIZE_MAX
10981933Sdillon	maxswzone = VM_SWZONE_SIZE_MAX;
11081986Sdillon#endif
11181933Sdillon	TUNABLE_INT_FETCH("kern.maxswzone", &maxswzone);
11281986Sdillon#ifdef VM_BCACHE_SIZE_MAX
11381933Sdillon	maxbcache = VM_BCACHE_SIZE_MAX;
11481986Sdillon#endif
11581933Sdillon	TUNABLE_INT_FETCH("kern.maxbcache", &maxbcache);
11684783Sps
11784783Sps	maxtsiz = MAXTSIZ;
11884783Sps	TUNABLE_QUAD_FETCH("kern.maxtsiz", &maxtsiz);
11984783Sps	dfldsiz = DFLDSIZ;
12084783Sps	TUNABLE_QUAD_FETCH("kern.dfldsiz", &dfldsiz);
12184783Sps	maxdsiz = MAXDSIZ;
12284783Sps	TUNABLE_QUAD_FETCH("kern.maxdsiz", &maxdsiz);
12384783Sps	dflssiz = DFLSSIZ;
12484783Sps	TUNABLE_QUAD_FETCH("kern.dflssiz", &dflssiz);
12584783Sps	maxssiz = MAXSSIZ;
12684783Sps	TUNABLE_QUAD_FETCH("kern.maxssiz", &maxssiz);
12784783Sps	sgrowsiz = SGROWSIZ;
12884783Sps	TUNABLE_QUAD_FETCH("kern.sgrowsiz", &sgrowsiz);
12980418Speter}
13087546Sdillon
13187546Sdillon/*
13287546Sdillon * Boot time overrides that are scaled against main memory
13387546Sdillon */
13487546Sdillonvoid
135102600Speterinit_param2(long physpages)
13687546Sdillon{
13787546Sdillon
13887546Sdillon	/* Base parameters */
13990274Sdillon	maxusers = MAXUSERS;
14090274Sdillon	TUNABLE_INT_FETCH("kern.maxusers", &maxusers);
14190274Sdillon	if (maxusers == 0) {
14289769Sdillon		maxusers = physpages / (2 * 1024 * 1024 / PAGE_SIZE);
14387546Sdillon		if (maxusers < 32)
14487546Sdillon			maxusers = 32;
14589769Sdillon		if (maxusers > 384)
14689769Sdillon			maxusers = 384;
14787546Sdillon	}
14887546Sdillon
14987546Sdillon	/*
15087546Sdillon	 * The following can be overridden after boot via sysctl.  Note:
15187546Sdillon	 * unless overriden, these macros are ultimately based on maxusers.
15287546Sdillon	 */
15387546Sdillon	maxproc = NPROC;
15487546Sdillon	TUNABLE_INT_FETCH("kern.maxproc", &maxproc);
15591780Ssilby	/*
15691780Ssilby	 * Limit maxproc so that kmap entries cannot be exhausted by
15791780Ssilby	 * processes.
15891780Ssilby	 */
15991780Ssilby	if (maxproc > (physpages / 12))
16091780Ssilby		maxproc = physpages / 12;
16187546Sdillon	maxfiles = MAXFILES;
16287546Sdillon	TUNABLE_INT_FETCH("kern.maxfiles", &maxfiles);
16387817Ssilby	maxprocperuid = (maxproc * 9) / 10;
16487817Ssilby	maxfilesperproc = (maxfiles * 9) / 10;
165117391Ssilby
166117391Ssilby	/*
167117391Ssilby	 * Cannot be changed after boot.
168117391Ssilby	 */
169117391Ssilby	nbuf = NBUF;
170117391Ssilby	TUNABLE_INT_FETCH("kern.nbuf", &nbuf);
17187546Sdillon
172117391Ssilby	ncallout = 16 + maxproc + maxfiles;
173117391Ssilby	TUNABLE_INT_FETCH("kern.ncallout", &ncallout);
174117391Ssilby}
175117391Ssilby
176117391Ssilby/*
177117391Ssilby * Boot time overrides that are scaled against the kernel map
178117391Ssilby */
179117391Ssilbyvoid
180117391Ssilbyinit_param3(long kmempages)
181117391Ssilby{
182127612Salc
18387546Sdillon	/*
184127612Salc	 * The default for maxpipekva is max(5% of the kernel map, 512KB).
185127612Salc	 * See sys_pipe.c for more details.
186117325Ssilby	 */
187118764Ssilby	maxpipekva = (kmempages / 20) * PAGE_SIZE;
188117325Ssilby	if (maxpipekva < 512 * 1024)
189117325Ssilby		maxpipekva = 512 * 1024;
190118764Ssilby	TUNABLE_INT_FETCH("kern.ipc.maxpipekva", &maxpipekva);
19187546Sdillon}
192