subr_param.c revision 117391
1168404Spjd/* 2168404Spjd * Copyright (c) 1980, 1986, 1989, 1993 3168404Spjd * The Regents of the University of California. All rights reserved. 4168404Spjd * (c) UNIX System Laboratories, Inc. 5185029Spjd * All or some portions of this file are derived from material licensed 6185029Spjd * to the University of California by American Telephone and Telegraph 7168404Spjd * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8168404Spjd * the permission of UNIX System Laboratories, Inc. 9168404Spjd * 10168404Spjd * Redistribution and use in source and binary forms, with or without 11168404Spjd * modification, are permitted provided that the following conditions 12168404Spjd * are met: 13168404Spjd * 1. Redistributions of source code must retain the above copyright 14168404Spjd * notice, this list of conditions and the following disclaimer. 15168404Spjd * 2. Redistributions in binary form must reproduce the above copyright 16168404Spjd * notice, this list of conditions and the following disclaimer in the 17168404Spjd * documentation and/or other materials provided with the distribution. 18168404Spjd * 3. All advertising materials mentioning features or use of this software 19168404Spjd * must display the following acknowledgement: 20168404Spjd * This product includes software developed by the University of 21168404Spjd * California, Berkeley and its contributors. 22185029Spjd * 4. Neither the name of the University nor the names of its contributors 23168404Spjd * may be used to endorse or promote products derived from this software 24168404Spjd * without specific prior written permission. 25168404Spjd * 26168404Spjd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27168404Spjd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28168404Spjd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29168404Spjd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30168404Spjd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31168404Spjd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32168404Spjd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33168404Spjd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34168404Spjd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35168404Spjd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36168404Spjd * SUCH DAMAGE. 37168404Spjd * 38168404Spjd * @(#)param.c 8.3 (Berkeley) 8/20/94 39168404Spjd */ 40168404Spjd 41168404Spjd#include <sys/cdefs.h> 42168404Spjd__FBSDID("$FreeBSD: head/sys/kern/subr_param.c 117391 2003-07-11 00:01:03Z silby $"); 43168404Spjd 44168404Spjd#include "opt_param.h" 45168404Spjd#include "opt_maxusers.h" 46168404Spjd 47168404Spjd#include <sys/param.h> 48168404Spjd#include <sys/systm.h> 49168404Spjd#include <sys/kernel.h> 50168404Spjd 51168404Spjd#include <machine/vmparam.h> 52168404Spjd 53168404Spjd/* 54168404Spjd * System parameter formulae. 55168404Spjd */ 56168404Spjd 57168404Spjd#ifndef HZ 58168404Spjd#define HZ 100 59168404Spjd#endif 60168404Spjd#define NPROC (20 + 16 * maxusers) 61168404Spjd#ifndef NBUF 62168404Spjd#define NBUF 0 63168404Spjd#endif 64168404Spjd#ifndef MAXFILES 65168404Spjd#define MAXFILES (maxproc * 2) 66168404Spjd#endif 67168404Spjd 68168404Spjdint hz; 69168404Spjdint tick; 70168404Spjdint maxusers; /* base tunable */ 71168404Spjdint maxproc; /* maximum # of processes */ 72168404Spjdint maxprocperuid; /* max # of procs per user */ 73168404Spjdint maxfiles; /* sys. wide open files limit */ 74168404Spjdint maxfilesperproc; /* per-proc open files limit */ 75168404Spjdint ncallout; /* maximum # of timer events */ 76168404Spjdint nbuf; 77168404Spjdint nswbuf; 78168404Spjdint maxswzone; /* max swmeta KVA storage */ 79168404Spjdint maxbcache; /* max buffer cache KVA storage */ 80168404Spjdint maxpipes; /* Limit on # of pipes */ 81168404Spjdint maxpipekva; /* Limit on pipe KVA */ 82168404Spjdint maxpipekvawired; /* Limit on wired pipe KVA */ 83168404Spjdu_quad_t maxtsiz; /* max text size */ 84168404Spjdu_quad_t dfldsiz; /* initial data size limit */ 85168404Spjdu_quad_t maxdsiz; /* max data size */ 86168404Spjdu_quad_t dflssiz; /* initial stack size limit */ 87168404Spjdu_quad_t maxssiz; /* max stack size */ 88168404Spjdu_quad_t sgrowsiz; /* amount to grow stack */ 89168404Spjd 90168404Spjd/* 91168404Spjd * These have to be allocated somewhere; allocating 92168404Spjd * them here forces loader errors if this file is omitted 93168404Spjd * (if they've been externed everywhere else; hah!). 94168404Spjd */ 95168404Spjdstruct buf *swbuf; 96168404Spjd 97168404Spjd/* 98168404Spjd * Boot time overrides that are not scaled against main memory 99168404Spjd */ 100168404Spjdvoid 101168404Spjdinit_param1(void) 102168404Spjd{ 103168404Spjd 104168404Spjd hz = HZ; 105168404Spjd TUNABLE_INT_FETCH("kern.hz", &hz); 106168404Spjd tick = 1000000 / hz; 107168404Spjd 108168404Spjd#ifdef VM_SWZONE_SIZE_MAX 109168404Spjd maxswzone = VM_SWZONE_SIZE_MAX; 110168404Spjd#endif 111168404Spjd TUNABLE_INT_FETCH("kern.maxswzone", &maxswzone); 112168404Spjd#ifdef VM_BCACHE_SIZE_MAX 113168404Spjd maxbcache = VM_BCACHE_SIZE_MAX; 114168404Spjd#endif 115168404Spjd TUNABLE_INT_FETCH("kern.maxbcache", &maxbcache); 116168404Spjd 117168404Spjd maxtsiz = MAXTSIZ; 118168404Spjd TUNABLE_QUAD_FETCH("kern.maxtsiz", &maxtsiz); 119185029Spjd dfldsiz = DFLDSIZ; 120185029Spjd TUNABLE_QUAD_FETCH("kern.dfldsiz", &dfldsiz); 121168404Spjd maxdsiz = MAXDSIZ; 122168404Spjd TUNABLE_QUAD_FETCH("kern.maxdsiz", &maxdsiz); 123168404Spjd dflssiz = DFLSSIZ; 124168404Spjd TUNABLE_QUAD_FETCH("kern.dflssiz", &dflssiz); 125168404Spjd maxssiz = MAXSSIZ; 126168404Spjd TUNABLE_QUAD_FETCH("kern.maxssiz", &maxssiz); 127168404Spjd sgrowsiz = SGROWSIZ; 128168404Spjd TUNABLE_QUAD_FETCH("kern.sgrowsiz", &sgrowsiz); 129168404Spjd} 130168404Spjd 131168404Spjd/* 132168404Spjd * Boot time overrides that are scaled against main memory 133168404Spjd */ 134168404Spjdvoid 135168404Spjdinit_param2(long physpages) 136168404Spjd{ 137168404Spjd 138168404Spjd /* Base parameters */ 139168404Spjd maxusers = MAXUSERS; 140168404Spjd TUNABLE_INT_FETCH("kern.maxusers", &maxusers); 141168404Spjd if (maxusers == 0) { 142185029Spjd maxusers = physpages / (2 * 1024 * 1024 / PAGE_SIZE); 143185029Spjd if (maxusers < 32) 144168404Spjd maxusers = 32; 145168404Spjd if (maxusers > 384) 146168404Spjd maxusers = 384; 147168404Spjd } 148185029Spjd 149185029Spjd /* 150168404Spjd * The following can be overridden after boot via sysctl. Note: 151168404Spjd * unless overriden, these macros are ultimately based on maxusers. 152168404Spjd */ 153168404Spjd maxproc = NPROC; 154168404Spjd TUNABLE_INT_FETCH("kern.maxproc", &maxproc); 155168404Spjd /* 156168404Spjd * Limit maxproc so that kmap entries cannot be exhausted by 157168404Spjd * processes. 158168404Spjd */ 159168404Spjd if (maxproc > (physpages / 12)) 160168404Spjd maxproc = physpages / 12; 161168404Spjd maxfiles = MAXFILES; 162168404Spjd TUNABLE_INT_FETCH("kern.maxfiles", &maxfiles); 163168404Spjd maxprocperuid = (maxproc * 9) / 10; 164168404Spjd maxfilesperproc = (maxfiles * 9) / 10; 165168404Spjd 166185029Spjd /* 167168404Spjd * Cannot be changed after boot. 168168404Spjd */ 169168404Spjd nbuf = NBUF; 170168404Spjd TUNABLE_INT_FETCH("kern.nbuf", &nbuf); 171168404Spjd 172185029Spjd ncallout = 16 + maxproc + maxfiles; 173168404Spjd TUNABLE_INT_FETCH("kern.ncallout", &ncallout); 174168404Spjd} 175168404Spjd 176168404Spjd/* 177168404Spjd * Boot time overrides that are scaled against the kernel map 178168404Spjd */ 179168404Spjdvoid 180168404Spjdinit_param3(long kmempages) 181168404Spjd{ 182168404Spjd /* 183168404Spjd * Limit number of pipes to a reasonable fraction of kmap entries, 184168404Spjd * pageable pipe memory usage to 2.5% of the kernel map, and wired 185168404Spjd * pipe memory usage to 1% of the same. Ensure that all have 186168404Spjd * reasonable floors. (See sys_pipe.c for more info.) 187168404Spjd */ 188168404Spjd maxpipes = kmempages / 5; 189168404Spjd maxpipekva = (kmempages / 40) * PAGE_SIZE; 190168404Spjd maxpipekvawired = (kmempages / 100) * PAGE_SIZE; 191168404Spjd 192168404Spjd if (maxpipes < 128) 193185029Spjd maxpipes = 128; 194168404Spjd if (maxpipekva < 512 * 1024) 195168404Spjd maxpipekva = 512 * 1024; 196168404Spjd if (maxpipekvawired < 512 * 1024) 197168404Spjd maxpipekvawired = 512 * 1024; 198168404Spjd} 199168404Spjd