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  * 3. All advertising materials mentioning features or use of this software
   19  *    must display the following acknowledgement:
   20  *      This product includes software developed by the University of
   21  *      California, Berkeley and its contributors.
   22  * 4. Neither the name of the University nor the names of its contributors
   23  *    may be used to endorse or promote products derived from this software
   24  *    without specific prior written permission.
   25  *
   26  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   29  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   30  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   32  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   36  * SUCH DAMAGE.
   37  *
   38  *      @(#)param.c     8.3 (Berkeley) 8/20/94
   39  * $FreeBSD$
   40  */
   41 
   42 #include "opt_param.h"
   43 #include "opt_maxusers.h"
   44 
   45 #include <sys/param.h>
   46 #include <sys/systm.h>
   47 #include <sys/kernel.h>
   48 
   49 #include <machine/vmparam.h>
   50 
   51 /*
   52  * System parameter formulae.
   53  */
   54 
   55 #ifndef HZ
   56 #define HZ 100
   57 #endif
   58 #define NPROC (20 + 16 * maxusers)
   59 #ifndef NBUF
   60 #define NBUF 0
   61 #endif
   62 #ifndef MAXFILES
   63 #define MAXFILES (maxproc * 2)
   64 #endif
   65 #ifndef NSFBUFS
   66 #define NSFBUFS (512 + maxusers * 16)
   67 #endif
   68 
   69 int     hz;
   70 int     tick;
   71 int     tickadj;                         /* can adjust 30ms in 60s */
   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     mbuf_wait = 32;                 /* mbuf sleep time in ticks */
   79 int     nbuf;
   80 int     nswbuf;
   81 int     maxswzone;                      /* max swmeta KVA storage */
   82 int     maxbcache;                      /* max buffer cache KVA storage */
   83 u_quad_t        maxtsiz;                        /* max text size */
   84 u_quad_t        dfldsiz;                        /* initial data size limit */
   85 u_quad_t        maxdsiz;                        /* max data size */
   86 u_quad_t        dflssiz;                        /* initial stack size limit */
   87 u_quad_t        maxssiz;                        /* max stack size */
   88 u_quad_t        sgrowsiz;                       /* amount to grow stack */
   89 
   90 /* maximum # of sf_bufs (sendfile(2) zero-copy virtual buffers) */
   91 int     nsfbufs;
   92 
   93 /*
   94  * These have to be allocated somewhere; allocating
   95  * them here forces loader errors if this file is omitted
   96  * (if they've been externed everywhere else; hah!).
   97  */
   98 struct  buf *swbuf;
   99 
  100 /*
  101  * Boot time overrides that are not scaled against main memory
  102  */
  103 void
  104 init_param1(void)
  105 {
  106         hz = HZ;
  107         TUNABLE_INT_FETCH("kern.hz", &hz);
  108         tick = 1000000 / hz;
  109         tickadj = howmany(30000, 60 * hz);      /* can adjust 30ms in 60s */
  110 
  111 #ifdef VM_SWZONE_SIZE_MAX
  112         maxswzone = VM_SWZONE_SIZE_MAX;
  113 #endif
  114         TUNABLE_INT_FETCH("kern.maxswzone", &maxswzone);
  115 #ifdef VM_BCACHE_SIZE_MAX
  116         maxbcache = VM_BCACHE_SIZE_MAX;
  117 #endif
  118         TUNABLE_INT_FETCH("kern.maxbcache", &maxbcache);
  119 
  120         maxtsiz = MAXTSIZ;
  121         TUNABLE_QUAD_FETCH("kern.maxtsiz", &maxtsiz);
  122         dfldsiz = DFLDSIZ;
  123         TUNABLE_QUAD_FETCH("kern.dfldsiz", &dfldsiz);
  124         maxdsiz = MAXDSIZ;
  125         TUNABLE_QUAD_FETCH("kern.maxdsiz", &maxdsiz);
  126         dflssiz = DFLSSIZ;
  127         TUNABLE_QUAD_FETCH("kern.dflssiz", &dflssiz);
  128         maxssiz = MAXSSIZ;
  129         TUNABLE_QUAD_FETCH("kern.maxssiz", &maxssiz);
  130         sgrowsiz = SGROWSIZ;
  131         TUNABLE_QUAD_FETCH("kern.sgrowsiz", &sgrowsiz);
  132 }
  133 
  134 /*
  135  * Boot time overrides that are scaled against main memory
  136  */
  137 void
  138 init_param2(int physpages)
  139 {
  140 
  141         /* Base parameters */
  142         maxusers = MAXUSERS;
  143         TUNABLE_INT_FETCH("kern.maxusers", &maxusers);
  144         if (maxusers == 0) {
  145                 maxusers = physpages / (2 * 1024 * 1024 / PAGE_SIZE);
  146                 if (maxusers < 32)
  147                     maxusers = 32;
  148                 if (maxusers > 384)
  149                     maxusers = 384;
  150         }
  151 
  152         /*
  153          * The following can be overridden after boot via sysctl.  Note:
  154          * unless overriden, these macros are ultimately based on maxusers.
  155          */
  156         maxproc = NPROC;
  157         TUNABLE_INT_FETCH("kern.maxproc", &maxproc);
  158         /*
  159          * Limit maxproc so that kmap entries cannot be exhausted by
  160          * processes.
  161          */
  162         if (maxproc > (physpages / 12))
  163                 maxproc = physpages / 12;
  164         maxfiles = MAXFILES;
  165         TUNABLE_INT_FETCH("kern.maxfiles", &maxfiles);
  166         maxprocperuid = (maxproc * 9) / 10;
  167         maxfilesperproc = (maxfiles * 9) / 10;
  168 
  169         /*
  170          * Cannot be changed after boot.  Unless overriden, NSFBUFS is based
  171          * on maxusers and NBUF is typically 0 (auto-sized later).
  172          */
  173         nsfbufs = NSFBUFS;
  174         TUNABLE_INT_FETCH("kern.ipc.nsfbufs", &nsfbufs);
  175         nbuf = NBUF;
  176         TUNABLE_INT_FETCH("kern.nbuf", &nbuf);
  177 
  178         ncallout = 16 + maxproc + maxfiles;
  179         TUNABLE_INT_FETCH("kern.ncallout", &ncallout);
  180 }
  181 

Cache object: d6d716af96819eff145223c6606d13a1


[ 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.