19454b2d8SWarner Losh /*- 251369649SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause 351369649SPedro F. Giffuni * 4df8bae1dSRodney W. Grimes * Copyright (c) 1980, 1986, 1989, 1993 5df8bae1dSRodney W. Grimes * The Regents of the University of California. All rights reserved. 6df8bae1dSRodney W. Grimes * (c) UNIX System Laboratories, Inc. 7df8bae1dSRodney W. Grimes * All or some portions of this file are derived from material licensed 8df8bae1dSRodney W. Grimes * to the University of California by American Telephone and Telegraph 9df8bae1dSRodney W. Grimes * Co. or Unix System Laboratories, Inc. and are reproduced herein with 10df8bae1dSRodney W. Grimes * the permission of UNIX System Laboratories, Inc. 11df8bae1dSRodney W. Grimes * 12df8bae1dSRodney W. Grimes * Redistribution and use in source and binary forms, with or without 13df8bae1dSRodney W. Grimes * modification, are permitted provided that the following conditions 14df8bae1dSRodney W. Grimes * are met: 15df8bae1dSRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 16df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer. 17df8bae1dSRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 18df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 19df8bae1dSRodney W. Grimes * documentation and/or other materials provided with the distribution. 2069a28758SEd Maste * 3. Neither the name of the University nor the names of its contributors 21df8bae1dSRodney W. Grimes * may be used to endorse or promote products derived from this software 22df8bae1dSRodney W. Grimes * without specific prior written permission. 23df8bae1dSRodney W. Grimes * 24df8bae1dSRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25df8bae1dSRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26df8bae1dSRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27df8bae1dSRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28df8bae1dSRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29df8bae1dSRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30df8bae1dSRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31df8bae1dSRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32df8bae1dSRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33df8bae1dSRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34df8bae1dSRodney W. Grimes * SUCH DAMAGE. 35df8bae1dSRodney W. Grimes */ 36df8bae1dSRodney W. Grimes 37677b542eSDavid E. O'Brien #include <sys/cdefs.h> 384bd49128SPeter Wemm #include "opt_param.h" 394053b05bSSergey Kandaurov #include "opt_msgbuf.h" 40cd853791SKonstantin Belousov #include "opt_maxphys.h" 41ee342e1bSPeter Wemm #include "opt_maxusers.h" 4250c73f36SGarrett Wollman 43df8bae1dSRodney W. Grimes #include <sys/param.h> 4413a5a46cSAndrew Gallatin #include <sys/_maxphys.h> 45ee342e1bSPeter Wemm #include <sys/systm.h> 46756a5412SGleb Smirnoff #include <sys/buf.h> 47ee342e1bSPeter Wemm #include <sys/kernel.h> 4802c6fc21SKonstantin Belousov #include <sys/limits.h> 494053b05bSSergey Kandaurov #include <sys/msgbuf.h> 5002c6fc21SKonstantin Belousov #include <sys/sysctl.h> 5102c6fc21SKonstantin Belousov #include <sys/proc.h> 523b1f974bSKonstantin Belousov #include <sys/vnode.h> 53df8bae1dSRodney W. Grimes 54e9a3f785SAlan Cox #include <vm/vm.h> 557419d1e2SDag-Erling Smørgrav #include <vm/vm_param.h> 56e9a3f785SAlan Cox #include <vm/pmap.h> 57cbc89bfbSPaul Saab 58df8bae1dSRodney W. Grimes /* 59df8bae1dSRodney W. Grimes * System parameter formulae. 60df8bae1dSRodney W. Grimes */ 61df8bae1dSRodney W. Grimes 62df8bae1dSRodney W. Grimes #ifndef HZ 63bcebf6a1SNathan Whitehorn # define HZ 1000 647f03c419SMaxim Sobolev # ifndef HZ_VM 65347e22a6SMike Silbersack # define HZ_VM 100 667f03c419SMaxim Sobolev # endif 677f03c419SMaxim Sobolev #else 687f03c419SMaxim Sobolev # ifndef HZ_VM 697f03c419SMaxim Sobolev # define HZ_VM HZ 707f03c419SMaxim Sobolev # endif 718f650450SPeter Wemm #endif 72ee342e1bSPeter Wemm #define NPROC (20 + 16 * maxusers) 73ee342e1bSPeter Wemm #ifndef NBUF 74ee342e1bSPeter Wemm #define NBUF 0 75ee342e1bSPeter Wemm #endif 765a00f364SDag-Erling Smørgrav #ifndef MAXFILES 771f57d8c6SKonstantin Belousov #define MAXFILES (40 + 32 * maxusers) 785a00f364SDag-Erling Smørgrav #endif 79dd0b2081SDavid Greenman 803610a226SIvan Voras static int sysctl_kern_vm_guest(SYSCTL_HANDLER_ARGS); 813610a226SIvan Voras 825b999a6bSDavide Italiano int hz; /* system clock's frequency */ 835b999a6bSDavide Italiano int tick; /* usec per tick (1000000 / hz) */ 8435a33d14SHans Petter Selasky time_t tick_seconds_max; /* max hz * seconds an integer can hold */ 855b999a6bSDavide Italiano struct bintime tick_bt; /* bintime per tick (1s / hz) */ 865b999a6bSDavide Italiano sbintime_t tick_sbt; 87ee342e1bSPeter Wemm int maxusers; /* base tunable */ 88ee342e1bSPeter Wemm int maxproc; /* maximum # of processes */ 89ee342e1bSPeter Wemm int maxprocperuid; /* max # of procs per user */ 90ee342e1bSPeter Wemm int maxfiles; /* sys. wide open files limit */ 91ee342e1bSPeter Wemm int maxfilesperproc; /* per-proc open files limit */ 924053b05bSSergey Kandaurov int msgbufsize; /* size of kernel message buffer */ 93cd853791SKonstantin Belousov int nbuf; /* number of bcache bufs */ 94ee75e7deSKonstantin Belousov int bio_transient_maxcnt; 95412f9500SBrooks Davis int ngroups_max; /* max # groups per process */ 96ee342e1bSPeter Wemm int nswbuf; 9702c6fc21SKonstantin Belousov pid_t pid_max = PID_MAX; 98cd853791SKonstantin Belousov u_long maxswzone; /* max swmeta KVA storage */ 99cd853791SKonstantin Belousov u_long maxbcache; /* max buffer cache KVA storage */ 100cd853791SKonstantin Belousov u_long maxpipekva; /* Limit on pipe KVA */ 101cd853791SKonstantin Belousov u_long maxphys; /* max raw I/O transfer size */ 10201e1933dSJohn Baldwin int vm_guest = VM_GUEST_NO; /* Running as virtual machine guest? */ 1037419d1e2SDag-Erling Smørgrav u_long maxtsiz; /* max text size */ 1047419d1e2SDag-Erling Smørgrav u_long dfldsiz; /* initial data size limit */ 1057419d1e2SDag-Erling Smørgrav u_long maxdsiz; /* max data size */ 1067419d1e2SDag-Erling Smørgrav u_long dflssiz; /* initial stack size limit */ 1077419d1e2SDag-Erling Smørgrav u_long maxssiz; /* max stack size */ 1087419d1e2SDag-Erling Smørgrav u_long sgrowsiz; /* amount to grow stack */ 109df8bae1dSRodney W. Grimes 110af3b2549SHans Petter Selasky SYSCTL_INT(_kern, OID_AUTO, hz, CTLFLAG_RDTUN | CTLFLAG_NOFETCH, &hz, 0, 1119b84ba1cSJohn Baldwin "Number of clock ticks per second"); 112ee29897fSHans Petter Selasky SYSCTL_INT(_kern, OID_AUTO, hz_max, CTLFLAG_RD, SYSCTL_NULL_INT_PTR, HZ_MAXIMUM, 113ee29897fSHans Petter Selasky "Maximum hz value supported"); 114ee29897fSHans Petter Selasky SYSCTL_INT(_kern, OID_AUTO, hz_min, CTLFLAG_RD, SYSCTL_NULL_INT_PTR, HZ_MINIMUM, 115ee29897fSHans Petter Selasky "Minimum hz value supported"); 116af3b2549SHans Petter Selasky SYSCTL_INT(_kern, OID_AUTO, nbuf, CTLFLAG_RDTUN | CTLFLAG_NOFETCH, &nbuf, 0, 1179b84ba1cSJohn Baldwin "Number of buffers in the buffer cache"); 118af3b2549SHans Petter Selasky SYSCTL_INT(_kern, OID_AUTO, nswbuf, CTLFLAG_RDTUN | CTLFLAG_NOFETCH, &nswbuf, 0, 119b9f2a7daSJohn Baldwin "Number of swap buffers"); 120af3b2549SHans Petter Selasky SYSCTL_INT(_kern, OID_AUTO, msgbufsize, CTLFLAG_RDTUN | CTLFLAG_NOFETCH, &msgbufsize, 0, 1214053b05bSSergey Kandaurov "Size of the kernel message buffer"); 122af3b2549SHans Petter Selasky SYSCTL_LONG(_kern, OID_AUTO, maxswzone, CTLFLAG_RDTUN | CTLFLAG_NOFETCH, &maxswzone, 0, 1239b84ba1cSJohn Baldwin "Maximum memory for swap metadata"); 124af3b2549SHans Petter Selasky SYSCTL_LONG(_kern, OID_AUTO, maxbcache, CTLFLAG_RDTUN | CTLFLAG_NOFETCH, &maxbcache, 0, 1259b84ba1cSJohn Baldwin "Maximum value of vfs.maxbufspace"); 126af3b2549SHans Petter Selasky SYSCTL_INT(_kern, OID_AUTO, bio_transient_maxcnt, CTLFLAG_RDTUN | CTLFLAG_NOFETCH, 127ee75e7deSKonstantin Belousov &bio_transient_maxcnt, 0, 128ee75e7deSKonstantin Belousov "Maximum number of transient BIOs mappings"); 129af3b2549SHans Petter Selasky SYSCTL_ULONG(_kern, OID_AUTO, maxtsiz, CTLFLAG_RWTUN | CTLFLAG_NOFETCH, &maxtsiz, 0, 1309b84ba1cSJohn Baldwin "Maximum text size"); 131af3b2549SHans Petter Selasky SYSCTL_ULONG(_kern, OID_AUTO, dfldsiz, CTLFLAG_RWTUN | CTLFLAG_NOFETCH, &dfldsiz, 0, 1329b84ba1cSJohn Baldwin "Initial data size limit"); 133af3b2549SHans Petter Selasky SYSCTL_ULONG(_kern, OID_AUTO, maxdsiz, CTLFLAG_RWTUN | CTLFLAG_NOFETCH, &maxdsiz, 0, 1349b84ba1cSJohn Baldwin "Maximum data size"); 135af3b2549SHans Petter Selasky SYSCTL_ULONG(_kern, OID_AUTO, dflssiz, CTLFLAG_RWTUN | CTLFLAG_NOFETCH, &dflssiz, 0, 1369b84ba1cSJohn Baldwin "Initial stack size limit"); 137af3b2549SHans Petter Selasky SYSCTL_ULONG(_kern, OID_AUTO, maxssiz, CTLFLAG_RWTUN | CTLFLAG_NOFETCH, &maxssiz, 0, 1389b84ba1cSJohn Baldwin "Maximum stack size"); 139af3b2549SHans Petter Selasky SYSCTL_ULONG(_kern, OID_AUTO, sgrowsiz, CTLFLAG_RWTUN | CTLFLAG_NOFETCH, &sgrowsiz, 0, 140ceb0f715SAndrey Zonov "Amount to grow stack on a stack fault"); 1417029da5cSPawel Biernacki SYSCTL_PROC(_kern, OID_AUTO, vm_guest, 1427029da5cSPawel Biernacki CTLFLAG_RD | CTLTYPE_STRING | CTLFLAG_MPSAFE, NULL, 0, 1437029da5cSPawel Biernacki sysctl_kern_vm_guest, "A", 14401e1933dSJohn Baldwin "Virtual machine guest detected?"); 1457c45a9c4SAlfred Perlstein 146df8bae1dSRodney W. Grimes /* 1470b993ee5SAlan Cox * The elements of this array are ordered based upon the values of the 1480b993ee5SAlan Cox * corresponding enum VM_GUEST members. 1490b993ee5SAlan Cox */ 15034820bbfSBjoern A. Zeeb static const char *const vm_guest_sysctl_names[] = { 1511177d38cSStephen J. Kiernan [VM_GUEST_NO] = "none", 1521177d38cSStephen J. Kiernan [VM_GUEST_VM] = "generic", 1531177d38cSStephen J. Kiernan [VM_GUEST_XEN] = "xen", 1541177d38cSStephen J. Kiernan [VM_GUEST_HV] = "hv", 1551177d38cSStephen J. Kiernan [VM_GUEST_VMWARE] = "vmware", 1561177d38cSStephen J. Kiernan [VM_GUEST_KVM] = "kvm", 1571177d38cSStephen J. Kiernan [VM_GUEST_BHYVE] = "bhyve", 1581177d38cSStephen J. Kiernan [VM_GUEST_VBOX] = "vbox", 1591177d38cSStephen J. Kiernan [VM_GUEST_PARALLELS] = "parallels", 160*f622dc5dSKevin Bowling [VM_GUEST_NVMM] = "nvmm", 16134820bbfSBjoern A. Zeeb }; 162b0aaf8beSMateusz Guzik _Static_assert(nitems(vm_guest_sysctl_names) == VM_GUEST_LAST, 163733a6684SMateusz Guzik "new vm guest type not added to vm_guest_sysctl_names"); 16434820bbfSBjoern A. Zeeb 1659722d88fSJason Evans /* 16666a11b9fSMatthew Dillon * Boot time overrides that are not scaled against main memory 167ee342e1bSPeter Wemm */ 168ee342e1bSPeter Wemm void 16966a11b9fSMatthew Dillon init_param1(void) 170ee342e1bSPeter Wemm { 17101e1933dSJohn Baldwin 1729d6ae1e3SColin Percival TSENTER(); 17339cddbd7SKonstantin Belousov 17439cddbd7SKonstantin Belousov /* 17539cddbd7SKonstantin Belousov * arm64 and riscv currently hard-code the thread0 kstack size 17639cddbd7SKonstantin Belousov * to KSTACK_PAGES, ignoring the tunable. 17739cddbd7SKonstantin Belousov */ 178edc82223SKonstantin Belousov TUNABLE_INT_FETCH("kern.kstack_pages", &kstack_pages); 17939cddbd7SKonstantin Belousov 1807f03c419SMaxim Sobolev hz = -1; 181ee342e1bSPeter Wemm TUNABLE_INT_FETCH("kern.hz", &hz); 1829bd2cbe4SJung-uk Kim if (hz == -1) 1833dc30911SIvan Voras hz = vm_guest > VM_GUEST_NO ? HZ_VM : HZ; 184ee29897fSHans Petter Selasky 185ee29897fSHans Petter Selasky /* range check the "hz" value */ 186ee29897fSHans Petter Selasky if (__predict_false(hz < HZ_MINIMUM)) 187ee29897fSHans Petter Selasky hz = HZ_MINIMUM; 188ee29897fSHans Petter Selasky else if (__predict_false(hz > HZ_MAXIMUM)) 189ee29897fSHans Petter Selasky hz = HZ_MAXIMUM; 190ee29897fSHans Petter Selasky 191ee342e1bSPeter Wemm tick = 1000000 / hz; 1925b999a6bSDavide Italiano tick_sbt = SBT_1S / hz; 1935b999a6bSDavide Italiano tick_bt = sbttobt(tick_sbt); 19435a33d14SHans Petter Selasky tick_seconds_max = INT_MAX / hz; 195ee342e1bSPeter Wemm 1965d8cce17SJohn Baldwin /* 1975d8cce17SJohn Baldwin * Arrange for ticks to wrap 10 minutes after boot to help catch 1985d8cce17SJohn Baldwin * sign problems sooner. 1995d8cce17SJohn Baldwin */ 2005d8cce17SJohn Baldwin ticks = INT_MAX - (hz * 10 * 60); 2015d8cce17SJohn Baldwin 2023b1f974bSKonstantin Belousov vn_lock_pair_pause_max = hz / 100; 2033b1f974bSKonstantin Belousov if (vn_lock_pair_pause_max == 0) 2043b1f974bSKonstantin Belousov vn_lock_pair_pause_max = 1; 2053b1f974bSKonstantin Belousov 206e1616f3aSMatthew Dillon #ifdef VM_SWZONE_SIZE_MAX 2072f9e4e80SMatthew Dillon maxswzone = VM_SWZONE_SIZE_MAX; 208e1616f3aSMatthew Dillon #endif 2095bd65606SJohn Baldwin TUNABLE_LONG_FETCH("kern.maxswzone", &maxswzone); 210e1616f3aSMatthew Dillon #ifdef VM_BCACHE_SIZE_MAX 2112f9e4e80SMatthew Dillon maxbcache = VM_BCACHE_SIZE_MAX; 212e1616f3aSMatthew Dillon #endif 2135bd65606SJohn Baldwin TUNABLE_LONG_FETCH("kern.maxbcache", &maxbcache); 2144053b05bSSergey Kandaurov msgbufsize = MSGBUF_SIZE; 2154053b05bSSergey Kandaurov TUNABLE_INT_FETCH("kern.msgbufsize", &msgbufsize); 216cbc89bfbSPaul Saab 217cbc89bfbSPaul Saab maxtsiz = MAXTSIZ; 2187419d1e2SDag-Erling Smørgrav TUNABLE_ULONG_FETCH("kern.maxtsiz", &maxtsiz); 219cbc89bfbSPaul Saab dfldsiz = DFLDSIZ; 2207419d1e2SDag-Erling Smørgrav TUNABLE_ULONG_FETCH("kern.dfldsiz", &dfldsiz); 221cbc89bfbSPaul Saab maxdsiz = MAXDSIZ; 2227419d1e2SDag-Erling Smørgrav TUNABLE_ULONG_FETCH("kern.maxdsiz", &maxdsiz); 223cbc89bfbSPaul Saab dflssiz = DFLSSIZ; 2247419d1e2SDag-Erling Smørgrav TUNABLE_ULONG_FETCH("kern.dflssiz", &dflssiz); 225cbc89bfbSPaul Saab maxssiz = MAXSSIZ; 2267419d1e2SDag-Erling Smørgrav TUNABLE_ULONG_FETCH("kern.maxssiz", &maxssiz); 227cbc89bfbSPaul Saab sgrowsiz = SGROWSIZ; 2287419d1e2SDag-Erling Smørgrav TUNABLE_ULONG_FETCH("kern.sgrowsiz", &sgrowsiz); 229412f9500SBrooks Davis 230412f9500SBrooks Davis /* 231412f9500SBrooks Davis * Let the administrator set {NGROUPS_MAX}, but disallow values 232412f9500SBrooks Davis * less than NGROUPS_MAX which would violate POSIX.1-2008 or 233412f9500SBrooks Davis * greater than INT_MAX-1 which would result in overflow. 234412f9500SBrooks Davis */ 235412f9500SBrooks Davis ngroups_max = NGROUPS_MAX; 236412f9500SBrooks Davis TUNABLE_INT_FETCH("kern.ngroups", &ngroups_max); 237412f9500SBrooks Davis if (ngroups_max < NGROUPS_MAX) 238412f9500SBrooks Davis ngroups_max = NGROUPS_MAX; 23902c6fc21SKonstantin Belousov 24002c6fc21SKonstantin Belousov /* 24102c6fc21SKonstantin Belousov * Only allow to lower the maximal pid. 2423fa615bcSKonstantin Belousov * Prevent setting up a non-bootable system if pid_max is too low. 24302c6fc21SKonstantin Belousov */ 24402c6fc21SKonstantin Belousov TUNABLE_INT_FETCH("kern.pid_max", &pid_max); 24502c6fc21SKonstantin Belousov if (pid_max > PID_MAX) 24602c6fc21SKonstantin Belousov pid_max = PID_MAX; 2473fa615bcSKonstantin Belousov else if (pid_max < 300) 2483fa615bcSKonstantin Belousov pid_max = 300; 249ee75e7deSKonstantin Belousov 250ee75e7deSKonstantin Belousov TUNABLE_INT_FETCH("vfs.unmapped_buf_allowed", &unmapped_buf_allowed); 2519d6ae1e3SColin Percival TSEXIT(); 252ee342e1bSPeter Wemm } 25366a11b9fSMatthew Dillon 25466a11b9fSMatthew Dillon /* 25566a11b9fSMatthew Dillon * Boot time overrides that are scaled against main memory 25666a11b9fSMatthew Dillon */ 25766a11b9fSMatthew Dillon void 258447b3772SPeter Wemm init_param2(long physpages) 25966a11b9fSMatthew Dillon { 26066a11b9fSMatthew Dillon 2619d6ae1e3SColin Percival TSENTER(); 26266a11b9fSMatthew Dillon /* Base parameters */ 2630b94a0e9SMatthew Dillon maxusers = MAXUSERS; 2640b94a0e9SMatthew Dillon TUNABLE_INT_FETCH("kern.maxusers", &maxusers); 2650b94a0e9SMatthew Dillon if (maxusers == 0) { 2664fbd563eSMatthew Dillon maxusers = physpages / (2 * 1024 * 1024 / PAGE_SIZE); 26766a11b9fSMatthew Dillon if (maxusers < 32) 26866a11b9fSMatthew Dillon maxusers = 32; 26979f62ed6SAlfred Perlstein #ifdef VM_MAX_AUTOTUNE_MAXUSERS 27079f62ed6SAlfred Perlstein if (maxusers > VM_MAX_AUTOTUNE_MAXUSERS) 27179f62ed6SAlfred Perlstein maxusers = VM_MAX_AUTOTUNE_MAXUSERS; 27279f62ed6SAlfred Perlstein #endif 2737b6d92c0SAlfred Perlstein /* 27479f62ed6SAlfred Perlstein * Scales down the function in which maxusers grows once 27579f62ed6SAlfred Perlstein * we hit 384. 2767b6d92c0SAlfred Perlstein */ 27779f62ed6SAlfred Perlstein if (maxusers > 384) 27879f62ed6SAlfred Perlstein maxusers = 384 + ((maxusers - 384) / 8); 27966a11b9fSMatthew Dillon } 28066a11b9fSMatthew Dillon 28166a11b9fSMatthew Dillon /* 28266a11b9fSMatthew Dillon * The following can be overridden after boot via sysctl. Note: 2832b7d656fSGordon Bergling * unless overridden, these macros are ultimately based on maxusers. 28477a7d074SMike Silbersack * Limit maxproc so that kmap entries cannot be exhausted by 28577a7d074SMike Silbersack * processes. 28677a7d074SMike Silbersack */ 287ead46972SAndre Oppermann maxproc = NPROC; 288ead46972SAndre Oppermann TUNABLE_INT_FETCH("kern.maxproc", &maxproc); 28977a7d074SMike Silbersack if (maxproc > (physpages / 12)) 29077a7d074SMike Silbersack maxproc = physpages / 12; 2911f57d8c6SKonstantin Belousov if (maxproc > pid_max) 2921f57d8c6SKonstantin Belousov maxproc = pid_max; 293ebacce5eSMike Silbersack maxprocperuid = (maxproc * 9) / 10; 294ead46972SAndre Oppermann 295ead46972SAndre Oppermann /* 296ead46972SAndre Oppermann * The default limit for maxfiles is 1/12 of the number of 297ead46972SAndre Oppermann * physical page but not less than 16 times maxusers. 298ead46972SAndre Oppermann * At most it can be 1/6 the number of physical pages. 299ead46972SAndre Oppermann */ 300ead46972SAndre Oppermann maxfiles = imax(MAXFILES, physpages / 8); 301ead46972SAndre Oppermann TUNABLE_INT_FETCH("kern.maxfiles", &maxfiles); 302ead46972SAndre Oppermann if (maxfiles > (physpages / 4)) 303ead46972SAndre Oppermann maxfiles = physpages / 4; 304ead46972SAndre Oppermann maxfilesperproc = (maxfiles / 10) * 9; 30532766cd2SAdrian Chadd TUNABLE_INT_FETCH("kern.maxfilesperproc", &maxfilesperproc); 30666a11b9fSMatthew Dillon 30766a11b9fSMatthew Dillon /* 308347194c1SMike Silbersack * Cannot be changed after boot. 309347194c1SMike Silbersack */ 310347194c1SMike Silbersack nbuf = NBUF; 311347194c1SMike Silbersack TUNABLE_INT_FETCH("kern.nbuf", &nbuf); 312ee75e7deSKonstantin Belousov TUNABLE_INT_FETCH("kern.bio_transient_maxcnt", &bio_transient_maxcnt); 313cd853791SKonstantin Belousov maxphys = MAXPHYS; 314cd853791SKonstantin Belousov TUNABLE_ULONG_FETCH("kern.maxphys", &maxphys); 315cd853791SKonstantin Belousov if (maxphys == 0) { 316cd853791SKonstantin Belousov maxphys = MAXPHYS; 317cd853791SKonstantin Belousov } else if (__bitcountl(maxphys) != 1) { /* power of two */ 318cd853791SKonstantin Belousov if (flsl(maxphys) == NBBY * sizeof(maxphys)) 319cd853791SKonstantin Belousov maxphys = MAXPHYS; 320cd853791SKonstantin Belousov else 321cd853791SKonstantin Belousov maxphys = 1UL << flsl(maxphys); 322cd853791SKonstantin Belousov } 323cd853791SKonstantin Belousov if (maxphys < PAGE_SIZE) 324cd853791SKonstantin Belousov maxphys = MAXPHYS; 325347194c1SMike Silbersack 326ead46972SAndre Oppermann /* 327756a5412SGleb Smirnoff * Physical buffers are pre-allocated buffers (struct buf) that 328756a5412SGleb Smirnoff * are used as temporary holders for I/O, such as paging I/O. 329756a5412SGleb Smirnoff */ 330756a5412SGleb Smirnoff TUNABLE_INT_FETCH("kern.nswbuf", &nswbuf); 331756a5412SGleb Smirnoff 332756a5412SGleb Smirnoff /* 333e9a3f785SAlan Cox * The default for maxpipekva is min(1/64 of the kernel address space, 334e9a3f785SAlan Cox * max(1/64 of main memory, 512KB)). See sys_pipe.c for more details. 335347194c1SMike Silbersack */ 336cd853791SKonstantin Belousov maxpipekva = ptoa(physpages / 64); 337ead46972SAndre Oppermann TUNABLE_LONG_FETCH("kern.ipc.maxpipekva", &maxpipekva); 338289016f2SMike Silbersack if (maxpipekva < 512 * 1024) 339289016f2SMike Silbersack maxpipekva = 512 * 1024; 340e9a3f785SAlan Cox if (maxpipekva > (VM_MAX_KERNEL_ADDRESS - VM_MIN_KERNEL_ADDRESS) / 64) 341e9a3f785SAlan Cox maxpipekva = (VM_MAX_KERNEL_ADDRESS - VM_MIN_KERNEL_ADDRESS) / 342e9a3f785SAlan Cox 64; 3439d6ae1e3SColin Percival TSEXIT(); 34466a11b9fSMatthew Dillon } 3453610a226SIvan Voras 3463610a226SIvan Voras /* 34746038d7fSKonstantin Belousov * Sysctl stringifying handler for kern.vm_guest. 3483610a226SIvan Voras */ 3493610a226SIvan Voras static int 3503610a226SIvan Voras sysctl_kern_vm_guest(SYSCTL_HANDLER_ARGS) 3513610a226SIvan Voras { 352acfc962fSIan Lepore return (SYSCTL_OUT_STR(req, vm_guest_sysctl_names[vm_guest])); 3533610a226SIvan Voras } 354