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$"); 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 47 #include <vm/vm_param.h> 48 49 /* 50 * System parameter formulae. 51 */ 52 53 #ifndef HZ 54 # if defined(__amd64__) 55 # define HZ 1024 56 # elif defined(__i386__) || defined(__ia64__) 57 # define HZ 1000 58 # else 59 # define HZ 100 60 #endif 61 #endif 62 #define NPROC (20 + 16 * maxusers) 63 #ifndef NBUF 64 #define NBUF 0 65 #endif 66 #ifndef MAXFILES 67 #define MAXFILES (maxproc * 2) 68 #endif 69 70 int hz; 71 int tick; 72 int maxusers; /* base tunable */ 73 int maxproc; /* maximum # of processes */ 74 int maxprocperuid; /* max # of procs per user */ 75 int maxfiles; /* sys. wide open files limit */ 76 int maxfilesperproc; /* per-proc open files limit */ 77 int ncallout; /* maximum # of timer events */ 78 int nbuf; 79 int nswbuf; 80 long maxswzone; /* max swmeta KVA storage */ 81 long maxbcache; /* max buffer cache KVA storage */ 82 int maxpipekva; /* Limit on pipe KVA */ 83 u_long maxtsiz; /* max text size */ 84 u_long dfldsiz; /* initial data size limit */ 85 u_long maxdsiz; /* max data size */ 86 u_long dflssiz; /* initial stack size limit */ 87 u_long maxssiz; /* max stack size */ 88 u_long sgrowsiz; /* amount to grow stack */ 89 90 /* 91 * These have to be allocated somewhere; allocating 92 * them here forces loader errors if this file is omitted 93 * (if they've been externed everywhere else; hah!). 94 */ 95 struct buf *swbuf; 96 97 /* 98 * Boot time overrides that are not scaled against main memory 99 */ 100 void 101 init_param1(void) 102 { 103 104 hz = HZ; 105 TUNABLE_INT_FETCH("kern.hz", &hz); 106 tick = 1000000 / hz; 107 108 #ifdef VM_SWZONE_SIZE_MAX 109 maxswzone = VM_SWZONE_SIZE_MAX; 110 #endif 111 TUNABLE_LONG_FETCH("kern.maxswzone", &maxswzone); 112 #ifdef VM_BCACHE_SIZE_MAX 113 maxbcache = VM_BCACHE_SIZE_MAX; 114 #endif 115 TUNABLE_LONG_FETCH("kern.maxbcache", &maxbcache); 116 117 maxtsiz = MAXTSIZ; 118 TUNABLE_ULONG_FETCH("kern.maxtsiz", &maxtsiz); 119 dfldsiz = DFLDSIZ; 120 TUNABLE_ULONG_FETCH("kern.dfldsiz", &dfldsiz); 121 maxdsiz = MAXDSIZ; 122 TUNABLE_ULONG_FETCH("kern.maxdsiz", &maxdsiz); 123 dflssiz = DFLSSIZ; 124 TUNABLE_ULONG_FETCH("kern.dflssiz", &dflssiz); 125 maxssiz = MAXSSIZ; 126 TUNABLE_ULONG_FETCH("kern.maxssiz", &maxssiz); 127 sgrowsiz = SGROWSIZ; 128 TUNABLE_ULONG_FETCH("kern.sgrowsiz", &sgrowsiz); 129 } 130 131 /* 132 * Boot time overrides that are scaled against main memory 133 */ 134 void 135 init_param2(long physpages) 136 { 137 138 /* Base parameters */ 139 maxusers = MAXUSERS; 140 TUNABLE_INT_FETCH("kern.maxusers", &maxusers); 141 if (maxusers == 0) { 142 maxusers = physpages / (2 * 1024 * 1024 / PAGE_SIZE); 143 if (maxusers < 32) 144 maxusers = 32; 145 if (maxusers > 384) 146 maxusers = 384; 147 } 148 149 /* 150 * The following can be overridden after boot via sysctl. Note: 151 * unless overriden, these macros are ultimately based on maxusers. 152 */ 153 maxproc = NPROC; 154 TUNABLE_INT_FETCH("kern.maxproc", &maxproc); 155 /* 156 * Limit maxproc so that kmap entries cannot be exhausted by 157 * processes. 158 */ 159 if (maxproc > (physpages / 12)) 160 maxproc = physpages / 12; 161 maxfiles = MAXFILES; 162 TUNABLE_INT_FETCH("kern.maxfiles", &maxfiles); 163 maxprocperuid = (maxproc * 9) / 10; 164 maxfilesperproc = (maxfiles * 9) / 10; 165 166 /* 167 * Cannot be changed after boot. 168 */ 169 nbuf = NBUF; 170 TUNABLE_INT_FETCH("kern.nbuf", &nbuf); 171 172 ncallout = 16 + maxproc + maxfiles; 173 TUNABLE_INT_FETCH("kern.ncallout", &ncallout); 174 } 175 176 /* 177 * Boot time overrides that are scaled against the kernel map 178 */ 179 void 180 init_param3(long kmempages) 181 { 182 183 /* 184 * The default for maxpipekva is max(5% of the kernel map, 512KB). 185 * See sys_pipe.c for more details. 186 */ 187 maxpipekva = (kmempages / 20) * PAGE_SIZE; 188 if (maxpipekva < 512 * 1024) 189 maxpipekva = 512 * 1024; 190 TUNABLE_INT_FETCH("kern.ipc.maxpipekva", &maxpipekva); 191 } 192