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: src/sys/kern/subr_param.c,v 1.42.2.10 2002/03/09 21:05:47 silby Exp $ 40 * $DragonFly: src/sys/kern/subr_param.c,v 1.3 2004/01/30 05:42:17 dillon Exp $ 41 */ 42 43 #include "opt_param.h" 44 #include "opt_maxusers.h" 45 46 #include <sys/param.h> 47 #include <sys/systm.h> 48 #include <sys/kernel.h> 49 50 #include <machine/vmparam.h> 51 52 /* 53 * System parameter formulae. 54 */ 55 56 #ifndef HZ 57 #define HZ 100 58 #endif 59 #define NPROC (20 + 16 * maxusers) 60 #ifndef NBUF 61 #define NBUF 0 62 #endif 63 #ifndef MAXFILES 64 #define MAXFILES (maxproc * 2) 65 #endif 66 #ifndef NSFBUFS 67 #define NSFBUFS (512 + maxusers * 16) 68 #endif 69 70 int hz; 71 int stathz; 72 int profhz; 73 int tick; 74 int tickadj; /* can adjust 30ms in 60s */ 75 int maxusers; /* base tunable */ 76 int maxproc; /* maximum # of processes */ 77 int maxprocperuid; /* max # of procs per user */ 78 int maxfiles; /* sys. wide open files limit */ 79 int maxfilesperproc; /* per-proc open files limit */ 80 int ncallout; /* maximum # of timer events */ 81 int mbuf_wait = 32; /* mbuf sleep time in ticks */ 82 int nbuf; 83 int nswbuf; 84 int maxswzone; /* max swmeta KVA storage */ 85 int maxbcache; /* max buffer cache KVA storage */ 86 u_quad_t maxtsiz; /* max text size */ 87 u_quad_t dfldsiz; /* initial data size limit */ 88 u_quad_t maxdsiz; /* max data size */ 89 u_quad_t dflssiz; /* initial stack size limit */ 90 u_quad_t maxssiz; /* max stack size */ 91 u_quad_t sgrowsiz; /* amount to grow stack */ 92 93 /* maximum # of sf_bufs (sendfile(2) zero-copy virtual buffers) */ 94 int nsfbufs; 95 96 /* 97 * These have to be allocated somewhere; allocating 98 * them here forces loader errors if this file is omitted 99 * (if they've been externed everywhere else; hah!). 100 */ 101 struct buf *swbuf; 102 103 /* 104 * Boot time overrides that are not scaled against main memory 105 */ 106 void 107 init_param1(void) 108 { 109 hz = HZ; 110 TUNABLE_INT_FETCH("kern.hz", &hz); 111 stathz = hz * 128 / 100; 112 profhz = stathz; 113 tick = 1000000 / hz; 114 tickadj = howmany(30000, 60 * hz); /* can adjust 30ms in 60s */ 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_QUAD_FETCH("kern.maxtsiz", &maxtsiz); 127 dfldsiz = DFLDSIZ; 128 TUNABLE_QUAD_FETCH("kern.dfldsiz", &dfldsiz); 129 maxdsiz = MAXDSIZ; 130 TUNABLE_QUAD_FETCH("kern.maxdsiz", &maxdsiz); 131 dflssiz = DFLSSIZ; 132 TUNABLE_QUAD_FETCH("kern.dflssiz", &dflssiz); 133 maxssiz = MAXSSIZ; 134 TUNABLE_QUAD_FETCH("kern.maxssiz", &maxssiz); 135 sgrowsiz = SGROWSIZ; 136 TUNABLE_QUAD_FETCH("kern.sgrowsiz", &sgrowsiz); 137 } 138 139 /* 140 * Boot time overrides that are scaled against main memory 141 */ 142 void 143 init_param2(int 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. Unless overriden, NSFBUFS is based 176 * on maxusers and NBUF is typically 0 (auto-sized later). 177 */ 178 nsfbufs = NSFBUFS; 179 TUNABLE_INT_FETCH("kern.ipc.nsfbufs", &nsfbufs); 180 nbuf = NBUF; 181 TUNABLE_INT_FETCH("kern.nbuf", &nbuf); 182 183 ncallout = 16 + maxproc + maxfiles; 184 TUNABLE_INT_FETCH("kern.ncallout", &ncallout); 185 } 186 187