19454b2d8SWarner Losh /*- 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 * 4. Neither the name of the University nor the names of its contributors 19df8bae1dSRodney W. Grimes * may be used to endorse or promote products derived from this software 20df8bae1dSRodney W. Grimes * without specific prior written permission. 21df8bae1dSRodney W. Grimes * 22df8bae1dSRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23df8bae1dSRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24df8bae1dSRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25df8bae1dSRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26df8bae1dSRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27df8bae1dSRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28df8bae1dSRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29df8bae1dSRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30df8bae1dSRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31df8bae1dSRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32df8bae1dSRodney W. Grimes * SUCH DAMAGE. 33df8bae1dSRodney W. Grimes * 3470b012caSJeffrey Hsu * @(#)param.c 8.3 (Berkeley) 8/20/94 35df8bae1dSRodney W. Grimes */ 36df8bae1dSRodney W. Grimes 37677b542eSDavid E. O'Brien #include <sys/cdefs.h> 38677b542eSDavid E. O'Brien __FBSDID("$FreeBSD$"); 39677b542eSDavid E. O'Brien 404bd49128SPeter Wemm #include "opt_param.h" 41ee342e1bSPeter Wemm #include "opt_maxusers.h" 4250c73f36SGarrett Wollman 43df8bae1dSRodney W. Grimes #include <sys/param.h> 44ee342e1bSPeter Wemm #include <sys/systm.h> 45ee342e1bSPeter Wemm #include <sys/kernel.h> 467c45a9c4SAlfred Perlstein #include <sys/sysctl.h> 47df8bae1dSRodney W. Grimes 487419d1e2SDag-Erling Smørgrav #include <vm/vm_param.h> 49cbc89bfbSPaul Saab 50df8bae1dSRodney W. Grimes /* 51df8bae1dSRodney W. Grimes * System parameter formulae. 52df8bae1dSRodney W. Grimes */ 53df8bae1dSRodney W. Grimes 54df8bae1dSRodney W. Grimes #ifndef HZ 55ea35b592SMarius Strobl # if defined(__amd64__) || defined(__i386__) || defined(__ia64__) || defined(__sparc64__) 560c7d0f96SPoul-Henning Kamp # define HZ 1000 578f650450SPeter Wemm # else 58df8bae1dSRodney W. Grimes # define HZ 100 59df8bae1dSRodney W. Grimes # endif 608f650450SPeter Wemm #endif 61ee342e1bSPeter Wemm #define NPROC (20 + 16 * maxusers) 62ee342e1bSPeter Wemm #ifndef NBUF 63ee342e1bSPeter Wemm #define NBUF 0 64ee342e1bSPeter Wemm #endif 655a00f364SDag-Erling Smørgrav #ifndef MAXFILES 66ee342e1bSPeter Wemm #define MAXFILES (maxproc * 2) 675a00f364SDag-Erling Smørgrav #endif 68dd0b2081SDavid Greenman 69ee342e1bSPeter Wemm int hz; 70ee342e1bSPeter Wemm int tick; 71ee342e1bSPeter Wemm int maxusers; /* base tunable */ 72ee342e1bSPeter Wemm int maxproc; /* maximum # of processes */ 73ee342e1bSPeter Wemm int maxprocperuid; /* max # of procs per user */ 74ee342e1bSPeter Wemm int maxfiles; /* sys. wide open files limit */ 75ee342e1bSPeter Wemm int maxfilesperproc; /* per-proc open files limit */ 76ee342e1bSPeter Wemm int ncallout; /* maximum # of timer events */ 77ee342e1bSPeter Wemm int nbuf; 78ee342e1bSPeter Wemm int nswbuf; 79f098dcdeSKris Kennaway int maxswzone; /* max swmeta KVA storage */ 80f098dcdeSKris Kennaway int maxbcache; /* max buffer cache KVA storage */ 81289016f2SMike Silbersack int maxpipekva; /* Limit on pipe KVA */ 827419d1e2SDag-Erling Smørgrav u_long maxtsiz; /* max text size */ 837419d1e2SDag-Erling Smørgrav u_long dfldsiz; /* initial data size limit */ 847419d1e2SDag-Erling Smørgrav u_long maxdsiz; /* max data size */ 857419d1e2SDag-Erling Smørgrav u_long dflssiz; /* initial stack size limit */ 867419d1e2SDag-Erling Smørgrav u_long maxssiz; /* max stack size */ 877419d1e2SDag-Erling Smørgrav u_long sgrowsiz; /* amount to grow stack */ 88df8bae1dSRodney W. Grimes 897c45a9c4SAlfred Perlstein SYSCTL_INT(_kern, OID_AUTO, maxswzone, CTLFLAG_RD, &maxswzone, 0, ""); 907c45a9c4SAlfred Perlstein SYSCTL_INT(_kern, OID_AUTO, maxbcache, CTLFLAG_RD, &maxbcache, 0, ""); 917c45a9c4SAlfred Perlstein SYSCTL_ULONG(_kern, OID_AUTO, maxtsiz, CTLFLAG_RD, &maxtsiz, 0, ""); 927c45a9c4SAlfred Perlstein SYSCTL_ULONG(_kern, OID_AUTO, dfldsiz, CTLFLAG_RD, &dfldsiz, 0, ""); 937c45a9c4SAlfred Perlstein SYSCTL_ULONG(_kern, OID_AUTO, maxdsiz, CTLFLAG_RD, &maxdsiz, 0, ""); 947c45a9c4SAlfred Perlstein SYSCTL_ULONG(_kern, OID_AUTO, dflssiz, CTLFLAG_RD, &dflssiz, 0, ""); 957c45a9c4SAlfred Perlstein SYSCTL_ULONG(_kern, OID_AUTO, maxssiz, CTLFLAG_RD, &maxssiz, 0, ""); 967c45a9c4SAlfred Perlstein SYSCTL_ULONG(_kern, OID_AUTO, sgrowsiz, CTLFLAG_RD, &sgrowsiz, 0, ""); 977c45a9c4SAlfred Perlstein 98df8bae1dSRodney W. Grimes /* 99df8bae1dSRodney W. Grimes * These have to be allocated somewhere; allocating 100df8bae1dSRodney W. Grimes * them here forces loader errors if this file is omitted 101df8bae1dSRodney W. Grimes * (if they've been externed everywhere else; hah!). 102df8bae1dSRodney W. Grimes */ 10328f8db14SBruce Evans struct buf *swbuf; 1049722d88fSJason Evans 1059722d88fSJason Evans /* 10666a11b9fSMatthew Dillon * Boot time overrides that are not scaled against main memory 107ee342e1bSPeter Wemm */ 108ee342e1bSPeter Wemm void 10966a11b9fSMatthew Dillon init_param1(void) 110ee342e1bSPeter Wemm { 111ee342e1bSPeter Wemm 112ee342e1bSPeter Wemm hz = HZ; 113ee342e1bSPeter Wemm TUNABLE_INT_FETCH("kern.hz", &hz); 114ee342e1bSPeter Wemm tick = 1000000 / hz; 115ee342e1bSPeter Wemm 116e1616f3aSMatthew Dillon #ifdef VM_SWZONE_SIZE_MAX 1172f9e4e80SMatthew Dillon maxswzone = VM_SWZONE_SIZE_MAX; 118e1616f3aSMatthew Dillon #endif 119f098dcdeSKris Kennaway TUNABLE_INT_FETCH("kern.maxswzone", &maxswzone); 120e1616f3aSMatthew Dillon #ifdef VM_BCACHE_SIZE_MAX 1212f9e4e80SMatthew Dillon maxbcache = VM_BCACHE_SIZE_MAX; 122e1616f3aSMatthew Dillon #endif 123f098dcdeSKris Kennaway TUNABLE_INT_FETCH("kern.maxbcache", &maxbcache); 124cbc89bfbSPaul Saab 125cbc89bfbSPaul Saab maxtsiz = MAXTSIZ; 1267419d1e2SDag-Erling Smørgrav TUNABLE_ULONG_FETCH("kern.maxtsiz", &maxtsiz); 127cbc89bfbSPaul Saab dfldsiz = DFLDSIZ; 1287419d1e2SDag-Erling Smørgrav TUNABLE_ULONG_FETCH("kern.dfldsiz", &dfldsiz); 129cbc89bfbSPaul Saab maxdsiz = MAXDSIZ; 1307419d1e2SDag-Erling Smørgrav TUNABLE_ULONG_FETCH("kern.maxdsiz", &maxdsiz); 131cbc89bfbSPaul Saab dflssiz = DFLSSIZ; 1327419d1e2SDag-Erling Smørgrav TUNABLE_ULONG_FETCH("kern.dflssiz", &dflssiz); 133cbc89bfbSPaul Saab maxssiz = MAXSSIZ; 1347419d1e2SDag-Erling Smørgrav TUNABLE_ULONG_FETCH("kern.maxssiz", &maxssiz); 135cbc89bfbSPaul Saab sgrowsiz = SGROWSIZ; 1367419d1e2SDag-Erling Smørgrav TUNABLE_ULONG_FETCH("kern.sgrowsiz", &sgrowsiz); 137ee342e1bSPeter Wemm } 13866a11b9fSMatthew Dillon 13966a11b9fSMatthew Dillon /* 14066a11b9fSMatthew Dillon * Boot time overrides that are scaled against main memory 14166a11b9fSMatthew Dillon */ 14266a11b9fSMatthew Dillon void 143447b3772SPeter Wemm init_param2(long physpages) 14466a11b9fSMatthew Dillon { 14566a11b9fSMatthew Dillon 14666a11b9fSMatthew Dillon /* Base parameters */ 1470b94a0e9SMatthew Dillon maxusers = MAXUSERS; 1480b94a0e9SMatthew Dillon TUNABLE_INT_FETCH("kern.maxusers", &maxusers); 1490b94a0e9SMatthew Dillon if (maxusers == 0) { 1504fbd563eSMatthew Dillon maxusers = physpages / (2 * 1024 * 1024 / PAGE_SIZE); 15166a11b9fSMatthew Dillon if (maxusers < 32) 15266a11b9fSMatthew Dillon maxusers = 32; 1534fbd563eSMatthew Dillon if (maxusers > 384) 1544fbd563eSMatthew Dillon maxusers = 384; 15566a11b9fSMatthew Dillon } 15666a11b9fSMatthew Dillon 15766a11b9fSMatthew Dillon /* 15866a11b9fSMatthew Dillon * The following can be overridden after boot via sysctl. Note: 15966a11b9fSMatthew Dillon * unless overriden, these macros are ultimately based on maxusers. 16066a11b9fSMatthew Dillon */ 16166a11b9fSMatthew Dillon maxproc = NPROC; 16266a11b9fSMatthew Dillon TUNABLE_INT_FETCH("kern.maxproc", &maxproc); 16377a7d074SMike Silbersack /* 16477a7d074SMike Silbersack * Limit maxproc so that kmap entries cannot be exhausted by 16577a7d074SMike Silbersack * processes. 16677a7d074SMike Silbersack */ 16777a7d074SMike Silbersack if (maxproc > (physpages / 12)) 16877a7d074SMike Silbersack maxproc = physpages / 12; 16966a11b9fSMatthew Dillon maxfiles = MAXFILES; 17066a11b9fSMatthew Dillon TUNABLE_INT_FETCH("kern.maxfiles", &maxfiles); 171ebacce5eSMike Silbersack maxprocperuid = (maxproc * 9) / 10; 172ebacce5eSMike Silbersack maxfilesperproc = (maxfiles * 9) / 10; 17366a11b9fSMatthew Dillon 17466a11b9fSMatthew Dillon /* 175347194c1SMike Silbersack * Cannot be changed after boot. 176347194c1SMike Silbersack */ 177347194c1SMike Silbersack nbuf = NBUF; 178347194c1SMike Silbersack TUNABLE_INT_FETCH("kern.nbuf", &nbuf); 179347194c1SMike Silbersack 180347194c1SMike Silbersack ncallout = 16 + maxproc + maxfiles; 181347194c1SMike Silbersack TUNABLE_INT_FETCH("kern.ncallout", &ncallout); 182347194c1SMike Silbersack } 183347194c1SMike Silbersack 184347194c1SMike Silbersack /* 185347194c1SMike Silbersack * Boot time overrides that are scaled against the kernel map 186347194c1SMike Silbersack */ 187347194c1SMike Silbersack void 188347194c1SMike Silbersack init_param3(long kmempages) 189347194c1SMike Silbersack { 1901dc10fceSAlan Cox 191347194c1SMike Silbersack /* 1921dc10fceSAlan Cox * The default for maxpipekva is max(5% of the kernel map, 512KB). 1931dc10fceSAlan Cox * See sys_pipe.c for more details. 194289016f2SMike Silbersack */ 195cebde069SMike Silbersack maxpipekva = (kmempages / 20) * PAGE_SIZE; 196289016f2SMike Silbersack if (maxpipekva < 512 * 1024) 197289016f2SMike Silbersack maxpipekva = 512 * 1024; 198cebde069SMike Silbersack TUNABLE_INT_FETCH("kern.ipc.maxpipekva", &maxpipekva); 19966a11b9fSMatthew Dillon } 200