subr_param.c revision 9759
11541Srgrimes/*
21541Srgrimes * Copyright (c) 1980, 1986, 1989, 1993
31541Srgrimes *	The Regents of the University of California.  All rights reserved.
41541Srgrimes * (c) UNIX System Laboratories, Inc.
51541Srgrimes * All or some portions of this file are derived from material licensed
61541Srgrimes * to the University of California by American Telephone and Telegraph
71541Srgrimes * Co. or Unix System Laboratories, Inc. and are reproduced herein with
81541Srgrimes * the permission of UNIX System Laboratories, Inc.
91541Srgrimes *
101541Srgrimes * Redistribution and use in source and binary forms, with or without
111541Srgrimes * modification, are permitted provided that the following conditions
121541Srgrimes * are met:
131541Srgrimes * 1. Redistributions of source code must retain the above copyright
141541Srgrimes *    notice, this list of conditions and the following disclaimer.
151541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
161541Srgrimes *    notice, this list of conditions and the following disclaimer in the
171541Srgrimes *    documentation and/or other materials provided with the distribution.
181541Srgrimes * 3. All advertising materials mentioning features or use of this software
191541Srgrimes *    must display the following acknowledgement:
201541Srgrimes *	This product includes software developed by the University of
211541Srgrimes *	California, Berkeley and its contributors.
221541Srgrimes * 4. Neither the name of the University nor the names of its contributors
231541Srgrimes *    may be used to endorse or promote products derived from this software
241541Srgrimes *    without specific prior written permission.
251541Srgrimes *
261541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
271541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
281541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
291541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
301541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
311541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
321541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
331541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
341541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
351541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
361541Srgrimes * SUCH DAMAGE.
371541Srgrimes *
381541Srgrimes *	@(#)param.c	8.2 (Berkeley) 1/21/94
399759Sbde * $Id: param.c,v 1.11 1995/06/29 08:21:32 davidg Exp $
401541Srgrimes */
411541Srgrimes
421541Srgrimes#include <sys/param.h>
431541Srgrimes#include <sys/systm.h>
441541Srgrimes#include <sys/socket.h>
451541Srgrimes#include <sys/proc.h>
461541Srgrimes#include <sys/vnode.h>
471541Srgrimes#include <sys/file.h>
481541Srgrimes#include <sys/callout.h>
491541Srgrimes#include <sys/clist.h>
501541Srgrimes#include <sys/mbuf.h>
511541Srgrimes#include <sys/kernel.h>
521541Srgrimes
531541Srgrimes#include <ufs/ufs/quota.h>
541541Srgrimes
551541Srgrimes#ifdef SYSVSHM
561541Srgrimes#include <machine/vmparam.h>
571541Srgrimes#include <sys/shm.h>
581541Srgrimes#endif
592729Sdfr#ifdef SYSVSEM
602729Sdfr#include "sys/sem.h"
612729Sdfr#endif
622729Sdfr#ifdef SYSVMSG
632729Sdfr#include "sys/msg.h"
642729Sdfr#endif
651541Srgrimes
661541Srgrimes/*
671541Srgrimes * System parameter formulae.
681541Srgrimes *
691541Srgrimes * This file is copied into each directory where we compile
701541Srgrimes * the kernel; it should be modified there to suit local taste
711541Srgrimes * if necessary.
721541Srgrimes *
739369Sdg * Compiled with -DMAXUSERS=xx
741541Srgrimes */
751541Srgrimes
761541Srgrimes#ifndef HZ
771541Srgrimes#define	HZ 100
781541Srgrimes#endif
791541Srgrimesint	hz = HZ;
801541Srgrimesint	tick = 1000000 / HZ;
811541Srgrimesint	tickadj = 30000 / (60 * HZ);		/* can adjust 30ms in 60s */
821541Srgrimes#define	NPROC (20 + 16 * MAXUSERS)
835455Sdgint	maxproc = NPROC;			/* maximum # of processes */
846577Sguidoint	maxprocperuid = NPROC-1;		/* maximum # of processes per user */
855530Sdgint	maxfiles = NPROC*2;			/* system wide open files limit */
868747Sdgint	maxfilesperproc = NPROC*2;		/* per-process open files limit */
875455Sdgint	ncallout = 16 + NPROC;			/* maximum # of timer events */
888747Sdg
898747Sdg/* maximum # of mbuf clusters */
908747Sdg#ifndef NMBCLUSTERS
918747Sdgint	nmbclusters = 512 + MAXUSERS * 16;
928747Sdg#else
931541Srgrimesint	nmbclusters = NMBCLUSTERS;
948747Sdg#endif
958747Sdg
961541Srgrimesint	fscale = FSCALE;	/* kernel uses `FSCALE', user uses `fscale' */
971541Srgrimes
981541Srgrimes/*
991541Srgrimes * Values in support of System V compatible shared memory.	XXX
1001541Srgrimes */
1011541Srgrimes#ifdef SYSVSHM
1026492Sjoerg#ifndef SHMMAX
1031541Srgrimes#define	SHMMAX	(SHMMAXPGS*NBPG)
1046492Sjoerg#endif
1056492Sjoerg#ifndef SHMMIN
1061541Srgrimes#define	SHMMIN	1
1076492Sjoerg#endif
1086492Sjoerg#ifndef SHMMNI
1091541Srgrimes#define	SHMMNI	32			/* <= SHMMMNI in shm.h */
1106492Sjoerg#endif
1116492Sjoerg#ifndef SHMSEG
1121541Srgrimes#define	SHMSEG	8
1136492Sjoerg#endif
1146492Sjoerg#ifndef SHMALL
1151541Srgrimes#define	SHMALL	(SHMMAXPGS/CLSIZE)
1166492Sjoerg#endif
1171541Srgrimes
1181541Srgrimesstruct	shminfo shminfo = {
1191541Srgrimes	SHMMAX,
1201541Srgrimes	SHMMIN,
1211541Srgrimes	SHMMNI,
1221541Srgrimes	SHMSEG,
1231541Srgrimes	SHMALL
1241541Srgrimes};
1251541Srgrimes#endif
1261541Srgrimes
1271541Srgrimes/*
1282729Sdfr * Values in support of System V compatible semaphores.
1292729Sdfr */
1302729Sdfr
1312729Sdfr#ifdef SYSVSEM
1322729Sdfr
1332729Sdfrstruct seminfo seminfo = {
1342729Sdfr                SEMMAP,         /* # of entries in semaphore map */
1352729Sdfr                SEMMNI,         /* # of semaphore identifiers */
1362729Sdfr                SEMMNS,         /* # of semaphores in system */
1372729Sdfr                SEMMNU,         /* # of undo structures in system */
1382729Sdfr                SEMMSL,         /* max # of semaphores per id */
1392729Sdfr                SEMOPM,         /* max # of operations per semop call */
1402729Sdfr                SEMUME,         /* max # of undo entries per process */
1412729Sdfr                SEMUSZ,         /* size in bytes of undo structure */
1422729Sdfr                SEMVMX,         /* semaphore maximum value */
1432729Sdfr                SEMAEM          /* adjust on exit max value */
1442729Sdfr};
1452729Sdfr#endif
1462729Sdfr
1472729Sdfr/*
1482729Sdfr * Values in support of System V compatible messages.
1492729Sdfr */
1502729Sdfr
1512729Sdfr#ifdef SYSVMSG
1522729Sdfr
1532729Sdfrstruct msginfo msginfo = {
1542729Sdfr                MSGMAX,         /* max chars in a message */
1552729Sdfr                MSGMNI,         /* # of message queue identifiers */
1562729Sdfr                MSGMNB,         /* max chars in a queue */
1572729Sdfr                MSGTQL,         /* max messages in system */
1582729Sdfr                MSGSSZ,         /* size of a message segment */
1592729Sdfr                		/* (must be small power of 2 greater than 4) */
1602729Sdfr                MSGSEG          /* number of message segments */
1612729Sdfr};
1622729Sdfr#endif
1632729Sdfr
1642729Sdfr/*
1659759Sbde * These may be set to nonzero here or by patching.
1669759Sbde * If they are nonzero at bootstrap time then they are
1679759Sbde * initialized to values dependent on the memory size.
1681541Srgrimes */
1699759Sbde#ifdef	NBUF
1709759Sbdeint	nbuf = NBUF;
1719759Sbde#else
1729759Sbdeint	nbuf = 0;
1739759Sbde#endif
1749759Sbdeint	nswbuf = 0;
1751541Srgrimes
1761541Srgrimes/*
1771541Srgrimes * These have to be allocated somewhere; allocating
1781541Srgrimes * them here forces loader errors if this file is omitted
1791541Srgrimes * (if they've been externed everywhere else; hah!).
1801541Srgrimes */
1811541Srgrimesstruct	cblock *cfree;
1829759Sbdestruct	buf *swbuf;
1831541Srgrimeschar	*buffers;
1841541Srgrimes
1851541Srgrimes/*
1861541Srgrimes * Proc/pgrp hashing.
1871541Srgrimes * Here so that hash table sizes can depend on MAXUSERS/NPROC.
1881541Srgrimes * Hash size must be a power of two.
1891541Srgrimes * NOW omission of this file will cause loader errors!
1901541Srgrimes */
1911541Srgrimes
1921541Srgrimes#if NPROC > 1024
1931541Srgrimes#define	PIDHSZ		512
1941541Srgrimes#else
1951541Srgrimes#if NPROC > 512
1961541Srgrimes#define	PIDHSZ		256
1971541Srgrimes#else
1981541Srgrimes#if NPROC > 256
1991541Srgrimes#define	PIDHSZ		128
2001541Srgrimes#else
2011541Srgrimes#define	PIDHSZ		64
2021541Srgrimes#endif
2031541Srgrimes#endif
2041541Srgrimes#endif
2051541Srgrimes
2061541Srgrimesstruct	proc *pidhash[PIDHSZ];
2071541Srgrimesstruct	pgrp *pgrphash[PIDHSZ];
2081541Srgrimesint	pidhashmask = PIDHSZ - 1;
209