subr_param.c revision 172696
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 * 4. Neither the name of the University nor the names of its contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * @(#)param.c 8.3 (Berkeley) 8/20/94 35 */ 36 37#include <sys/cdefs.h> 38__FBSDID("$FreeBSD: head/sys/kern/subr_param.c 172696 2007-10-16 10:40:53Z alfred $"); 39 40#include "opt_param.h" 41#include "opt_maxusers.h" 42 43#include <sys/param.h> 44#include <sys/systm.h> 45#include <sys/kernel.h> 46#include <sys/sysctl.h> 47 48#include <vm/vm_param.h> 49 50/* 51 * System parameter formulae. 52 */ 53 54#ifndef HZ 55# if defined(__amd64__) || defined(__i386__) || defined(__ia64__) || defined(__sparc64__) 56# define HZ 1000 57# else 58# define HZ 100 59# endif 60#endif 61#define NPROC (20 + 16 * maxusers) 62#ifndef NBUF 63#define NBUF 0 64#endif 65#ifndef MAXFILES 66#define MAXFILES (maxproc * 2) 67#endif 68 69int hz; 70int tick; 71int maxusers; /* base tunable */ 72int maxproc; /* maximum # of processes */ 73int maxprocperuid; /* max # of procs per user */ 74int maxfiles; /* sys. wide open files limit */ 75int maxfilesperproc; /* per-proc open files limit */ 76int ncallout; /* maximum # of timer events */ 77int nbuf; 78int nswbuf; 79int maxswzone; /* max swmeta KVA storage */ 80int maxbcache; /* max buffer cache KVA storage */ 81int maxpipekva; /* Limit on pipe KVA */ 82u_long maxtsiz; /* max text size */ 83u_long dfldsiz; /* initial data size limit */ 84u_long maxdsiz; /* max data size */ 85u_long dflssiz; /* initial stack size limit */ 86u_long maxssiz; /* max stack size */ 87u_long sgrowsiz; /* amount to grow stack */ 88 89SYSCTL_INT(_kern, OID_AUTO, maxswzone, CTLFLAG_RD, &maxswzone, 0, ""); 90SYSCTL_INT(_kern, OID_AUTO, maxbcache, CTLFLAG_RD, &maxbcache, 0, ""); 91SYSCTL_ULONG(_kern, OID_AUTO, maxtsiz, CTLFLAG_RD, &maxtsiz, 0, ""); 92SYSCTL_ULONG(_kern, OID_AUTO, dfldsiz, CTLFLAG_RD, &dfldsiz, 0, ""); 93SYSCTL_ULONG(_kern, OID_AUTO, maxdsiz, CTLFLAG_RD, &maxdsiz, 0, ""); 94SYSCTL_ULONG(_kern, OID_AUTO, dflssiz, CTLFLAG_RD, &dflssiz, 0, ""); 95SYSCTL_ULONG(_kern, OID_AUTO, maxssiz, CTLFLAG_RD, &maxssiz, 0, ""); 96SYSCTL_ULONG(_kern, OID_AUTO, sgrowsiz, CTLFLAG_RD, &sgrowsiz, 0, ""); 97 98/* 99 * These have to be allocated somewhere; allocating 100 * them here forces loader errors if this file is omitted 101 * (if they've been externed everywhere else; hah!). 102 */ 103struct buf *swbuf; 104 105/* 106 * Boot time overrides that are not scaled against main memory 107 */ 108void 109init_param1(void) 110{ 111 112 hz = HZ; 113 TUNABLE_INT_FETCH("kern.hz", &hz); 114 tick = 1000000 / hz; 115 116#ifdef VM_SWZONE_SIZE_MAX 117 maxswzone = VM_SWZONE_SIZE_MAX; 118#endif 119 TUNABLE_INT_FETCH("kern.maxswzone", &maxswzone); 120#ifdef VM_BCACHE_SIZE_MAX 121 maxbcache = VM_BCACHE_SIZE_MAX; 122#endif 123 TUNABLE_INT_FETCH("kern.maxbcache", &maxbcache); 124 125 maxtsiz = MAXTSIZ; 126 TUNABLE_ULONG_FETCH("kern.maxtsiz", &maxtsiz); 127 dfldsiz = DFLDSIZ; 128 TUNABLE_ULONG_FETCH("kern.dfldsiz", &dfldsiz); 129 maxdsiz = MAXDSIZ; 130 TUNABLE_ULONG_FETCH("kern.maxdsiz", &maxdsiz); 131 dflssiz = DFLSSIZ; 132 TUNABLE_ULONG_FETCH("kern.dflssiz", &dflssiz); 133 maxssiz = MAXSSIZ; 134 TUNABLE_ULONG_FETCH("kern.maxssiz", &maxssiz); 135 sgrowsiz = SGROWSIZ; 136 TUNABLE_ULONG_FETCH("kern.sgrowsiz", &sgrowsiz); 137} 138 139/* 140 * Boot time overrides that are scaled against main memory 141 */ 142void 143init_param2(long physpages) 144{ 145 146 /* Base parameters */ 147 maxusers = MAXUSERS; 148 TUNABLE_INT_FETCH("kern.maxusers", &maxusers); 149 if (maxusers == 0) { 150 maxusers = physpages / (2 * 1024 * 1024 / PAGE_SIZE); 151 if (maxusers < 32) 152 maxusers = 32; 153 if (maxusers > 384) 154 maxusers = 384; 155 } 156 157 /* 158 * The following can be overridden after boot via sysctl. Note: 159 * unless overriden, these macros are ultimately based on maxusers. 160 */ 161 maxproc = NPROC; 162 TUNABLE_INT_FETCH("kern.maxproc", &maxproc); 163 /* 164 * Limit maxproc so that kmap entries cannot be exhausted by 165 * processes. 166 */ 167 if (maxproc > (physpages / 12)) 168 maxproc = physpages / 12; 169 maxfiles = MAXFILES; 170 TUNABLE_INT_FETCH("kern.maxfiles", &maxfiles); 171 maxprocperuid = (maxproc * 9) / 10; 172 maxfilesperproc = (maxfiles * 9) / 10; 173 174 /* 175 * Cannot be changed after boot. 176 */ 177 nbuf = NBUF; 178 TUNABLE_INT_FETCH("kern.nbuf", &nbuf); 179 180 ncallout = 16 + maxproc + maxfiles; 181 TUNABLE_INT_FETCH("kern.ncallout", &ncallout); 182} 183 184/* 185 * Boot time overrides that are scaled against the kernel map 186 */ 187void 188init_param3(long kmempages) 189{ 190 191 /* 192 * The default for maxpipekva is max(5% of the kernel map, 512KB). 193 * See sys_pipe.c for more details. 194 */ 195 maxpipekva = (kmempages / 20) * PAGE_SIZE; 196 if (maxpipekva < 512 * 1024) 197 maxpipekva = 512 * 1024; 198 TUNABLE_INT_FETCH("kern.ipc.maxpipekva", &maxpipekva); 199} 200