Add kern.forkfsleep sysctl - set/get time (in miliseconds) for which

process would be forced to sleep in fork() if it hits either global
or user maxproc limit. Default is zero (no forced sleep).
Maximum is 20 seconds.
This commit is contained in:
jdolecek 2002-12-11 19:14:34 +00:00
parent aa0e549885
commit 5fd22809a5
4 changed files with 42 additions and 6 deletions

View File

@ -1,4 +1,4 @@
.\" $NetBSD: sysctl.3,v 1.102 2002/12/11 12:59:33 scw Exp $
.\" $NetBSD: sysctl.3,v 1.103 2002/12/11 19:14:34 jdolecek Exp $
.\"
.\" Copyright (c) 1993
.\" The Regents of the University of California. All rights reserved.
@ -283,6 +283,7 @@ information.
.It KERN\_DEFCORENAME string yes
.It KERN\_DOMAINNAME string yes
.It KERN\_FILE struct file no
.It KERN\_FORKFSLEEP integer yes
.It KERN\_FSCALE integer no
.It KERN\_FSYNC integer no
.It KERN\_HOSTID integer yes
@ -384,6 +385,15 @@ followed by an array of
whose size depends on the current number of such objects in the system.
.It Li KERN_FSCALE
The kernel fixed-point scale factor.
.It Li KERN_FORKFSLEEP
If
.Xr fork 2
system call fails due to limit on number of processes (either
the global maxproc limit or user's one), wait for this many
miliseconds before returning
.Er EAGAIN
error to process. Useful to keep heavily forking runaway
processes in bay. Default zero (no sleep). Maximum is 20 seconds.
.It Li KERN_FSYNC
Return 1 if the POSIX 1003.1b File Synchronization Option is available
on this system,

View File

@ -1,4 +1,4 @@
.\" $NetBSD: sysctl.8,v 1.83 2002/12/11 12:59:29 scw Exp $
.\" $NetBSD: sysctl.8,v 1.84 2002/12/11 19:14:34 jdolecek Exp $
.\"
.\" Copyright (c) 1993
.\" The Regents of the University of California. All rights reserved.
@ -180,6 +180,7 @@ privilege can change the value.
.It kern.chown_restricted integer no
.It kern.clockrate struct no
.It kern.defcorename string yes
.It kern.forkfsleep integer yes
.It kern.fsync integer no
.It kern.hostid integer yes
.It kern.hostname string yes

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_sysctl.c,v 1.119 2002/12/11 12:59:31 scw Exp $ */
/* $NetBSD: kern_sysctl.c,v 1.120 2002/12/11 19:14:35 jdolecek Exp $ */
/*-
* Copyright (c) 1982, 1986, 1989, 1993
@ -43,7 +43,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: kern_sysctl.c,v 1.119 2002/12/11 12:59:31 scw Exp $");
__KERNEL_RCSID(0, "$NetBSD: kern_sysctl.c,v 1.120 2002/12/11 19:14:35 jdolecek Exp $");
#include "opt_ddb.h"
#include "opt_insecure.h"
@ -276,6 +276,7 @@ int defcorenamelen = sizeof(DEFCORENAME);
extern int kern_logsigexit;
extern fixpt_t ccpu;
extern int forkfsleep;
#ifndef MULTIPROCESSOR
#define sysctl_ncpus() 1
@ -590,6 +591,28 @@ kern_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp,
return (sysctl_rdint(oldp, oldlenp, newp, LABELSECTOR));
case KERN_LABELOFFSET:
return (sysctl_rdint(oldp, oldlenp, newp, LABELOFFSET));
case KERN_FORKFSLEEP:
{
/* userland sees value in ms, internally is in ticks */
int timo, lsleep = forkfsleep * 1000 / hz;
error = (sysctl_int(oldp, oldlenp, newp, newlen, &lsleep));
if (newp && !error) {
/* refuse negative values, and overly 'long time' */
if (lsleep < 0 || lsleep > MAXSLP * 1000)
return (EINVAL);
timo = mstohz(lsleep);
/* if the interval is >0 ms && <1 tick, use 1 tick */
if (lsleep != 0 && timo == 0)
forkfsleep = 1;
else
forkfsleep = timo;
}
return (error);
}
default:
return (EOPNOTSUPP);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: sysctl.h,v 1.84 2002/12/11 17:32:53 jdolecek Exp $ */
/* $NetBSD: sysctl.h,v 1.85 2002/12/11 19:14:35 jdolecek Exp $ */
/*
* Copyright (c) 1989, 1993
@ -187,7 +187,8 @@ struct ctlname {
#define KERN_LABELSECTOR 62 /* int: disklabel sector */
#define KERN_LABELOFFSET 63 /* int: offset of label within sector */
#define KERN_LWP 64 /* struct: lwp entries */
#define KERN_MAXID 65 /* number of valid kern ids */
#define KERN_FORKFSLEEP 65 /* int: sleep length on failed fork */
#define KERN_MAXID 66 /* number of valid kern ids */
#define CTL_KERN_NAMES { \
{ 0, 0 }, \
@ -255,6 +256,7 @@ struct ctlname {
{ "labelsector", CTLTYPE_INT }, \
{ "labeloffset", CTLTYPE_INT }, \
{ "lwp", CTLTYPE_STRUCT }, \
{ "forkfsleep", CTLTYPE_INT }, \
}
/*