The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/kern/subr_param.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    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: releng/8.0/sys/kern/subr_param.c 195430 2009-07-08 01:09:12Z silby $");
   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 #include <sys/sysctl.h>
   47 
   48 #include <vm/vm_param.h>
   49 
   50 /*
   51  * System parameter formulae.
   52  */
   53 
   54 #ifndef HZ
   55 #  if defined(__amd64__) || defined(__i386__) || defined(__ia64__) || defined(__sparc64__)
   56 #    define     HZ 1000
   57 #  else
   58 #    define     HZ 100
   59 #  endif
   60 #  ifndef HZ_VM
   61 #    define     HZ_VM 100
   62 #  endif
   63 #else
   64 #  ifndef HZ_VM
   65 #    define     HZ_VM HZ
   66 #  endif
   67 #endif
   68 #define NPROC (20 + 16 * maxusers)
   69 #ifndef NBUF
   70 #define NBUF 0
   71 #endif
   72 #ifndef MAXFILES
   73 #define MAXFILES (maxproc * 2)
   74 #endif
   75 
   76 /* Values of enum VM_GUEST members are used as indices in 
   77  * vm_guest_sysctl_names */
   78 enum VM_GUEST { VM_GUEST_NO = 0, VM_GUEST_VM, VM_GUEST_XEN };
   79 
   80 static int sysctl_kern_vm_guest(SYSCTL_HANDLER_ARGS);
   81 
   82 int     hz;
   83 int     tick;
   84 int     maxusers;                       /* base tunable */
   85 int     maxproc;                        /* maximum # of processes */
   86 int     maxprocperuid;                  /* max # of procs per user */
   87 int     maxfiles;                       /* sys. wide open files limit */
   88 int     maxfilesperproc;                /* per-proc open files limit */
   89 int     ncallout;                       /* maximum # of timer events */
   90 int     nbuf;
   91 int     nswbuf;
   92 long    maxswzone;                      /* max swmeta KVA storage */
   93 long    maxbcache;                      /* max buffer cache KVA storage */
   94 long    maxpipekva;                     /* Limit on pipe KVA */
   95 int     vm_guest;                       /* Running as virtual machine guest? */
   96 u_long  maxtsiz;                        /* max text size */
   97 u_long  dfldsiz;                        /* initial data size limit */
   98 u_long  maxdsiz;                        /* max data size */
   99 u_long  dflssiz;                        /* initial stack size limit */
  100 u_long  maxssiz;                        /* max stack size */
  101 u_long  sgrowsiz;                       /* amount to grow stack */
  102 
  103 SYSCTL_INT(_kern, OID_AUTO, hz, CTLFLAG_RDTUN, &hz, 0,
  104     "Number of clock ticks per second");
  105 SYSCTL_INT(_kern, OID_AUTO, ncallout, CTLFLAG_RDTUN, &ncallout, 0,
  106     "Number of pre-allocated timer events");
  107 SYSCTL_INT(_kern, OID_AUTO, nbuf, CTLFLAG_RDTUN, &nbuf, 0,
  108     "Number of buffers in the buffer cache");
  109 SYSCTL_INT(_kern, OID_AUTO, nswbuf, CTLFLAG_RDTUN, &nswbuf, 0,
  110     "Number of swap buffers");
  111 SYSCTL_LONG(_kern, OID_AUTO, maxswzone, CTLFLAG_RDTUN, &maxswzone, 0,
  112     "Maximum memory for swap metadata");
  113 SYSCTL_LONG(_kern, OID_AUTO, maxbcache, CTLFLAG_RDTUN, &maxbcache, 0,
  114     "Maximum value of vfs.maxbufspace");
  115 SYSCTL_ULONG(_kern, OID_AUTO, maxtsiz, CTLFLAG_RDTUN, &maxtsiz, 0,
  116     "Maximum text size");
  117 SYSCTL_ULONG(_kern, OID_AUTO, dfldsiz, CTLFLAG_RDTUN, &dfldsiz, 0,
  118     "Initial data size limit");
  119 SYSCTL_ULONG(_kern, OID_AUTO, maxdsiz, CTLFLAG_RDTUN, &maxdsiz, 0,
  120     "Maximum data size");
  121 SYSCTL_ULONG(_kern, OID_AUTO, dflssiz, CTLFLAG_RDTUN, &dflssiz, 0,
  122     "Initial stack size limit");
  123 SYSCTL_ULONG(_kern, OID_AUTO, maxssiz, CTLFLAG_RDTUN, &maxssiz, 0,
  124     "Maximum stack size");
  125 SYSCTL_ULONG(_kern, OID_AUTO, sgrowsiz, CTLFLAG_RDTUN, &sgrowsiz, 0,
  126     "Amount to grow stack on a stack fault");
  127 SYSCTL_PROC(_kern, OID_AUTO, vm_guest, CTLFLAG_RD | CTLTYPE_STRING,
  128     NULL, 0, sysctl_kern_vm_guest, "A",
  129     "Virtual machine detected? (none|generic|xen)");
  130 
  131 /*
  132  * These have to be allocated somewhere; allocating
  133  * them here forces loader errors if this file is omitted
  134  * (if they've been externed everywhere else; hah!).
  135  */
  136 struct  buf *swbuf;
  137 
  138 static const char *const vm_guest_sysctl_names[] = {
  139         "none",
  140         "generic",
  141         "xen",
  142         NULL
  143 };
  144 
  145 #ifndef XEN
  146 static const char *const vm_bnames[] = {
  147         "QEMU",                         /* QEMU */
  148         "Plex86",                       /* Plex86 */
  149         "Bochs",                        /* Bochs */
  150         NULL
  151 };
  152 
  153 static const char *const vm_pnames[] = {
  154         "VMware Virtual Platform",      /* VMWare VM */
  155         "Virtual Machine",              /* Microsoft VirtualPC */
  156         "VirtualBox",                   /* Sun xVM VirtualBox */
  157         "Parallels Virtual Platform",   /* Parallels VM */
  158         NULL
  159 };
  160 
  161 
  162 /*
  163  * Detect known Virtual Machine hosts by inspecting the emulated BIOS.
  164  */
  165 static enum VM_GUEST
  166 detect_virtual(void)
  167 {
  168         char *sysenv;
  169         int i;
  170 
  171         sysenv = getenv("smbios.bios.vendor");
  172         if (sysenv != NULL) {
  173                 for (i = 0; vm_bnames[i] != NULL; i++)
  174                         if (strcmp(sysenv, vm_bnames[i]) == 0) {
  175                                 freeenv(sysenv);
  176                                 return (VM_GUEST_VM);
  177                         }
  178                 freeenv(sysenv);
  179         }
  180         sysenv = getenv("smbios.system.product");
  181         if (sysenv != NULL) {
  182                 for (i = 0; vm_pnames[i] != NULL; i++)
  183                         if (strcmp(sysenv, vm_pnames[i]) == 0) {
  184                                 freeenv(sysenv);
  185                                 return (VM_GUEST_VM);
  186                         }
  187                 freeenv(sysenv);
  188         }
  189         return (VM_GUEST_NO);
  190 }
  191 #endif
  192 
  193 /*
  194  * Boot time overrides that are not scaled against main memory
  195  */
  196 void
  197 init_param1(void)
  198 {
  199 #ifndef XEN
  200         vm_guest = detect_virtual();
  201 #else
  202         vm_guest = VM_GUEST_XEN;
  203 #endif
  204         hz = -1;
  205         TUNABLE_INT_FETCH("kern.hz", &hz);
  206         if (hz == -1)
  207                 hz = vm_guest > VM_GUEST_NO ? HZ_VM : HZ;
  208         tick = 1000000 / hz;
  209 
  210 #ifdef VM_SWZONE_SIZE_MAX
  211         maxswzone = VM_SWZONE_SIZE_MAX;
  212 #endif
  213         TUNABLE_LONG_FETCH("kern.maxswzone", &maxswzone);
  214 #ifdef VM_BCACHE_SIZE_MAX
  215         maxbcache = VM_BCACHE_SIZE_MAX;
  216 #endif
  217         TUNABLE_LONG_FETCH("kern.maxbcache", &maxbcache);
  218 
  219         maxtsiz = MAXTSIZ;
  220         TUNABLE_ULONG_FETCH("kern.maxtsiz", &maxtsiz);
  221         dfldsiz = DFLDSIZ;
  222         TUNABLE_ULONG_FETCH("kern.dfldsiz", &dfldsiz);
  223         maxdsiz = MAXDSIZ;
  224         TUNABLE_ULONG_FETCH("kern.maxdsiz", &maxdsiz);
  225         dflssiz = DFLSSIZ;
  226         TUNABLE_ULONG_FETCH("kern.dflssiz", &dflssiz);
  227         maxssiz = MAXSSIZ;
  228         TUNABLE_ULONG_FETCH("kern.maxssiz", &maxssiz);
  229         sgrowsiz = SGROWSIZ;
  230         TUNABLE_ULONG_FETCH("kern.sgrowsiz", &sgrowsiz);
  231 }
  232 
  233 /*
  234  * Boot time overrides that are scaled against main memory
  235  */
  236 void
  237 init_param2(long physpages)
  238 {
  239 
  240         /* Base parameters */
  241         maxusers = MAXUSERS;
  242         TUNABLE_INT_FETCH("kern.maxusers", &maxusers);
  243         if (maxusers == 0) {
  244                 maxusers = physpages / (2 * 1024 * 1024 / PAGE_SIZE);
  245                 if (maxusers < 32)
  246                         maxusers = 32;
  247                 if (maxusers > 384)
  248                         maxusers = 384;
  249         }
  250 
  251         /*
  252          * The following can be overridden after boot via sysctl.  Note:
  253          * unless overriden, these macros are ultimately based on maxusers.
  254          */
  255         maxproc = NPROC;
  256         TUNABLE_INT_FETCH("kern.maxproc", &maxproc);
  257         /*
  258          * Limit maxproc so that kmap entries cannot be exhausted by
  259          * processes.
  260          */
  261         if (maxproc > (physpages / 12))
  262                 maxproc = physpages / 12;
  263         maxfiles = MAXFILES;
  264         TUNABLE_INT_FETCH("kern.maxfiles", &maxfiles);
  265         maxprocperuid = (maxproc * 9) / 10;
  266         maxfilesperproc = (maxfiles * 9) / 10;
  267         
  268         /*
  269          * Cannot be changed after boot.
  270          */
  271         nbuf = NBUF;
  272         TUNABLE_INT_FETCH("kern.nbuf", &nbuf);
  273 
  274         ncallout = 16 + maxproc + maxfiles;
  275         TUNABLE_INT_FETCH("kern.ncallout", &ncallout);
  276 }
  277 
  278 /*
  279  * Boot time overrides that are scaled against the kmem map
  280  */
  281 void
  282 init_param3(long kmempages)
  283 {
  284 
  285         /*
  286          * The default for maxpipekva is max(5% of the kmem map, 512KB).
  287          * See sys_pipe.c for more details.
  288          */
  289         maxpipekva = (kmempages / 20) * PAGE_SIZE;
  290         if (maxpipekva < 512 * 1024)
  291                 maxpipekva = 512 * 1024;
  292         TUNABLE_LONG_FETCH("kern.ipc.maxpipekva", &maxpipekva);
  293 }
  294 
  295 /*
  296  * Sysctl stringiying handler for kern.vm_guest.
  297  */
  298 static int
  299 sysctl_kern_vm_guest(SYSCTL_HANDLER_ARGS)
  300 {
  301         return (SYSCTL_OUT(req, vm_guest_sysctl_names[vm_guest], 
  302             strlen(vm_guest_sysctl_names[vm_guest])));
  303 }

Cache object: a1197deba3ffa2b7699d1d55f2a86f53


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.