1df8bae1dSRodney W. Grimes /* 2df8bae1dSRodney W. Grimes * Copyright (c) 1980, 1986, 1989, 1993 3df8bae1dSRodney W. Grimes * The Regents of the University of California. All rights reserved. 4df8bae1dSRodney W. Grimes * (c) UNIX System Laboratories, Inc. 5df8bae1dSRodney W. Grimes * All or some portions of this file are derived from material licensed 6df8bae1dSRodney W. Grimes * to the University of California by American Telephone and Telegraph 7df8bae1dSRodney W. Grimes * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8df8bae1dSRodney W. Grimes * the permission of UNIX System Laboratories, Inc. 9df8bae1dSRodney W. Grimes * 10df8bae1dSRodney W. Grimes * Redistribution and use in source and binary forms, with or without 11df8bae1dSRodney W. Grimes * modification, are permitted provided that the following conditions 12df8bae1dSRodney W. Grimes * are met: 13df8bae1dSRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 14df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer. 15df8bae1dSRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 16df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 17df8bae1dSRodney W. Grimes * documentation and/or other materials provided with the distribution. 18df8bae1dSRodney W. Grimes * 3. All advertising materials mentioning features or use of this software 19df8bae1dSRodney W. Grimes * must display the following acknowledgement: 20df8bae1dSRodney W. Grimes * This product includes software developed by the University of 21df8bae1dSRodney W. Grimes * California, Berkeley and its contributors. 22df8bae1dSRodney W. Grimes * 4. Neither the name of the University nor the names of its contributors 23df8bae1dSRodney W. Grimes * may be used to endorse or promote products derived from this software 24df8bae1dSRodney W. Grimes * without specific prior written permission. 25df8bae1dSRodney W. Grimes * 26df8bae1dSRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27df8bae1dSRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28df8bae1dSRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29df8bae1dSRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30df8bae1dSRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31df8bae1dSRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32df8bae1dSRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33df8bae1dSRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34df8bae1dSRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35df8bae1dSRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36df8bae1dSRodney W. Grimes * SUCH DAMAGE. 37df8bae1dSRodney W. Grimes * 3870b012caSJeffrey Hsu * @(#)param.c 8.3 (Berkeley) 8/20/94 39df8bae1dSRodney W. Grimes */ 40df8bae1dSRodney W. Grimes 41677b542eSDavid E. O'Brien #include <sys/cdefs.h> 42677b542eSDavid E. O'Brien __FBSDID("$FreeBSD$"); 43677b542eSDavid E. O'Brien 444bd49128SPeter Wemm #include "opt_param.h" 45ee342e1bSPeter Wemm #include "opt_maxusers.h" 4650c73f36SGarrett Wollman 47df8bae1dSRodney W. Grimes #include <sys/param.h> 48ee342e1bSPeter Wemm #include <sys/systm.h> 49ee342e1bSPeter Wemm #include <sys/kernel.h> 50df8bae1dSRodney W. Grimes 51cbc89bfbSPaul Saab #include <machine/vmparam.h> 52cbc89bfbSPaul Saab 53df8bae1dSRodney W. Grimes /* 54df8bae1dSRodney W. Grimes * System parameter formulae. 55df8bae1dSRodney W. Grimes */ 56df8bae1dSRodney W. Grimes 57df8bae1dSRodney W. Grimes #ifndef HZ 58df8bae1dSRodney W. Grimes #define HZ 100 59df8bae1dSRodney W. Grimes #endif 60ee342e1bSPeter Wemm #define NPROC (20 + 16 * maxusers) 61ee342e1bSPeter Wemm #ifndef NBUF 62ee342e1bSPeter Wemm #define NBUF 0 63ee342e1bSPeter Wemm #endif 645a00f364SDag-Erling Smørgrav #ifndef MAXFILES 65ee342e1bSPeter Wemm #define MAXFILES (maxproc * 2) 665a00f364SDag-Erling Smørgrav #endif 67dd0b2081SDavid Greenman 68ee342e1bSPeter Wemm int hz; 69ee342e1bSPeter Wemm int tick; 70ee342e1bSPeter Wemm int maxusers; /* base tunable */ 71ee342e1bSPeter Wemm int maxproc; /* maximum # of processes */ 72ee342e1bSPeter Wemm int maxprocperuid; /* max # of procs per user */ 73ee342e1bSPeter Wemm int maxfiles; /* sys. wide open files limit */ 74ee342e1bSPeter Wemm int maxfilesperproc; /* per-proc open files limit */ 75ee342e1bSPeter Wemm int ncallout; /* maximum # of timer events */ 76ee342e1bSPeter Wemm int nbuf; 77ee342e1bSPeter Wemm int nswbuf; 782f9e4e80SMatthew Dillon int maxswzone; /* max swmeta KVA storage */ 792f9e4e80SMatthew Dillon int maxbcache; /* max buffer cache KVA storage */ 80289016f2SMike Silbersack int maxpipes; /* Limit on # of pipes */ 81289016f2SMike Silbersack int maxpipekva; /* Limit on pipe KVA */ 82289016f2SMike Silbersack int maxpipekvawired; /* Limit on wired pipe KVA */ 83cbc89bfbSPaul Saab u_quad_t maxtsiz; /* max text size */ 84cbc89bfbSPaul Saab u_quad_t dfldsiz; /* initial data size limit */ 85cbc89bfbSPaul Saab u_quad_t maxdsiz; /* max data size */ 86cbc89bfbSPaul Saab u_quad_t dflssiz; /* initial stack size limit */ 87cbc89bfbSPaul Saab u_quad_t maxssiz; /* max stack size */ 88cbc89bfbSPaul Saab u_quad_t sgrowsiz; /* amount to grow stack */ 89df8bae1dSRodney W. Grimes 90df8bae1dSRodney W. Grimes /* 91df8bae1dSRodney W. Grimes * These have to be allocated somewhere; allocating 92df8bae1dSRodney W. Grimes * them here forces loader errors if this file is omitted 93df8bae1dSRodney W. Grimes * (if they've been externed everywhere else; hah!). 94df8bae1dSRodney W. Grimes */ 9528f8db14SBruce Evans struct buf *swbuf; 969722d88fSJason Evans 979722d88fSJason Evans /* 9866a11b9fSMatthew Dillon * Boot time overrides that are not scaled against main memory 99ee342e1bSPeter Wemm */ 100ee342e1bSPeter Wemm void 10166a11b9fSMatthew Dillon init_param1(void) 102ee342e1bSPeter Wemm { 103ee342e1bSPeter Wemm 104ee342e1bSPeter Wemm hz = HZ; 105ee342e1bSPeter Wemm TUNABLE_INT_FETCH("kern.hz", &hz); 106ee342e1bSPeter Wemm tick = 1000000 / hz; 107ee342e1bSPeter Wemm 108e1616f3aSMatthew Dillon #ifdef VM_SWZONE_SIZE_MAX 1092f9e4e80SMatthew Dillon maxswzone = VM_SWZONE_SIZE_MAX; 110e1616f3aSMatthew Dillon #endif 1112f9e4e80SMatthew Dillon TUNABLE_INT_FETCH("kern.maxswzone", &maxswzone); 112e1616f3aSMatthew Dillon #ifdef VM_BCACHE_SIZE_MAX 1132f9e4e80SMatthew Dillon maxbcache = VM_BCACHE_SIZE_MAX; 114e1616f3aSMatthew Dillon #endif 1152f9e4e80SMatthew Dillon TUNABLE_INT_FETCH("kern.maxbcache", &maxbcache); 116cbc89bfbSPaul Saab 117cbc89bfbSPaul Saab maxtsiz = MAXTSIZ; 118cbc89bfbSPaul Saab TUNABLE_QUAD_FETCH("kern.maxtsiz", &maxtsiz); 119cbc89bfbSPaul Saab dfldsiz = DFLDSIZ; 120cbc89bfbSPaul Saab TUNABLE_QUAD_FETCH("kern.dfldsiz", &dfldsiz); 121cbc89bfbSPaul Saab maxdsiz = MAXDSIZ; 122cbc89bfbSPaul Saab TUNABLE_QUAD_FETCH("kern.maxdsiz", &maxdsiz); 123cbc89bfbSPaul Saab dflssiz = DFLSSIZ; 124cbc89bfbSPaul Saab TUNABLE_QUAD_FETCH("kern.dflssiz", &dflssiz); 125cbc89bfbSPaul Saab maxssiz = MAXSSIZ; 126cbc89bfbSPaul Saab TUNABLE_QUAD_FETCH("kern.maxssiz", &maxssiz); 127cbc89bfbSPaul Saab sgrowsiz = SGROWSIZ; 128cbc89bfbSPaul Saab TUNABLE_QUAD_FETCH("kern.sgrowsiz", &sgrowsiz); 129ee342e1bSPeter Wemm } 13066a11b9fSMatthew Dillon 13166a11b9fSMatthew Dillon /* 13266a11b9fSMatthew Dillon * Boot time overrides that are scaled against main memory 13366a11b9fSMatthew Dillon */ 13466a11b9fSMatthew Dillon void 135447b3772SPeter Wemm init_param2(long physpages) 13666a11b9fSMatthew Dillon { 13766a11b9fSMatthew Dillon 138289016f2SMike Silbersack /* Kernel map size */ 139289016f2SMike Silbersack int kmempages, kmemtunable; 140289016f2SMike Silbersack kmemtunable = 0; 141289016f2SMike Silbersack TUNABLE_INT_FETCH("kern.vm.kmem.size", &kmemtunable); 142289016f2SMike Silbersack if (kmemtunable != 0) 143289016f2SMike Silbersack kmempages = kmemtunable / PAGE_SIZE; 144289016f2SMike Silbersack else 145289016f2SMike Silbersack kmempages = VM_KMEM_SIZE_MAX / PAGE_SIZE; 146289016f2SMike Silbersack kmempages = min(physpages, kmempages); 14766a11b9fSMatthew Dillon /* Base parameters */ 1480b94a0e9SMatthew Dillon maxusers = MAXUSERS; 1490b94a0e9SMatthew Dillon TUNABLE_INT_FETCH("kern.maxusers", &maxusers); 1500b94a0e9SMatthew Dillon if (maxusers == 0) { 1514fbd563eSMatthew Dillon maxusers = physpages / (2 * 1024 * 1024 / PAGE_SIZE); 15266a11b9fSMatthew Dillon if (maxusers < 32) 15366a11b9fSMatthew Dillon maxusers = 32; 1544fbd563eSMatthew Dillon if (maxusers > 384) 1554fbd563eSMatthew Dillon maxusers = 384; 15666a11b9fSMatthew Dillon } 15766a11b9fSMatthew Dillon 15866a11b9fSMatthew Dillon /* 15966a11b9fSMatthew Dillon * The following can be overridden after boot via sysctl. Note: 16066a11b9fSMatthew Dillon * unless overriden, these macros are ultimately based on maxusers. 16166a11b9fSMatthew Dillon */ 16266a11b9fSMatthew Dillon maxproc = NPROC; 16366a11b9fSMatthew Dillon TUNABLE_INT_FETCH("kern.maxproc", &maxproc); 16477a7d074SMike Silbersack /* 16577a7d074SMike Silbersack * Limit maxproc so that kmap entries cannot be exhausted by 16677a7d074SMike Silbersack * processes. 16777a7d074SMike Silbersack */ 16877a7d074SMike Silbersack if (maxproc > (physpages / 12)) 16977a7d074SMike Silbersack maxproc = physpages / 12; 17066a11b9fSMatthew Dillon maxfiles = MAXFILES; 17166a11b9fSMatthew Dillon TUNABLE_INT_FETCH("kern.maxfiles", &maxfiles); 172ebacce5eSMike Silbersack maxprocperuid = (maxproc * 9) / 10; 173ebacce5eSMike Silbersack maxfilesperproc = (maxfiles * 9) / 10; 17466a11b9fSMatthew Dillon 17566a11b9fSMatthew Dillon /* 176289016f2SMike Silbersack * Limit number of pipes to a reasonable fraction of kmap entries, 177289016f2SMike Silbersack * pageable pipe memory usage to 2.5% of the kernel map, and wired 178289016f2SMike Silbersack * pipe memory usage to 1% of the same. Ensure that all have 179289016f2SMike Silbersack * reasonable floors. (See sys_pipe.c for more info.) 180289016f2SMike Silbersack */ 181289016f2SMike Silbersack maxpipes = kmempages / 20; 182289016f2SMike Silbersack maxpipekva = (kmempages / 40) * PAGE_SIZE; 183289016f2SMike Silbersack maxpipekvawired = (kmempages / 100) * PAGE_SIZE; 184289016f2SMike Silbersack 185289016f2SMike Silbersack if (maxpipes < 128) 186289016f2SMike Silbersack maxpipes = 128; 187289016f2SMike Silbersack if (maxpipekva < 512 * 1024) 188289016f2SMike Silbersack maxpipekva = 512 * 1024; 189289016f2SMike Silbersack if (maxpipekvawired < 512 * 1024) 190289016f2SMike Silbersack maxpipekvawired = 512 * 1024; 191289016f2SMike Silbersack 192289016f2SMike Silbersack /* 19366a11b9fSMatthew Dillon * Cannot be changed after boot. 19466a11b9fSMatthew Dillon */ 19566a11b9fSMatthew Dillon nbuf = NBUF; 19666a11b9fSMatthew Dillon TUNABLE_INT_FETCH("kern.nbuf", &nbuf); 19766a11b9fSMatthew Dillon 19866a11b9fSMatthew Dillon ncallout = 16 + maxproc + maxfiles; 19966a11b9fSMatthew Dillon TUNABLE_INT_FETCH("kern.ncallout", &ncallout); 20066a11b9fSMatthew Dillon } 201