-/* $OpenBSD: param.c,v 1.50 2024/05/05 06:14:37 jsg Exp $ */
+/* $OpenBSD: param.c,v 1.51 2024/08/20 07:48:23 mvs Exp $ */
/* $NetBSD: param.c,v 1.16 1996/03/12 03:08:40 mrg Exp $ */
/*
#include <sys/sem.h>
#endif
+/*
+ * Locks used to protect data:
+ * a atomic
+ */
+
/*
* System parameter formulae.
*
#define NTEXT (80 + NPROCESS / 8) /* actually the object cache */
#define NVNODE (NPROCESS * 2 + NTEXT + 100)
int initialvnodes = NVNODE;
-int maxprocess = NPROCESS;
-int maxthread = 2 * NPROCESS;
+int maxprocess = NPROCESS; /* [a] */
+int maxthread = 2 * NPROCESS; /* [a] */
int maxfiles = 5 * (NPROCESS + MAXUSERS) + 80;
long nmbclust = NMBCLUSTERS;
-/* $OpenBSD: kern_fork.c,v 1.263 2024/08/16 16:19:03 mpi Exp $ */
+/* $OpenBSD: kern_fork.c,v 1.264 2024/08/20 07:48:23 mvs Exp $ */
/* $NetBSD: kern_fork.c,v 1.29 1996/02/09 18:59:34 christos Exp $ */
/*
int
fork_check_maxthread(uid_t uid)
{
- int val;
+ int maxthread_local, val;
/*
* Although process entries are dynamically created, we still keep
* the variable nthreads is the current number of procs, maxthread is
* the limit.
*/
+ maxthread_local = atomic_load_int(&maxthread);
val = atomic_inc_int_nv(&nthreads);
- if ((val > maxthread - 5 && uid != 0) || val > maxthread) {
+ if ((val > maxthread_local - 5 && uid != 0) ||
+ val > maxthread_local) {
static struct timeval lasttfm;
if (ratecheck(&lasttfm, &fork_tfmrate))
struct proc *p;
uid_t uid = curp->p_ucred->cr_ruid;
struct vmspace *vm;
- int count;
+ int count, maxprocess_local;
vaddr_t uaddr;
int error;
struct ptrace_state *newptstat = NULL;
if ((error = fork_check_maxthread(uid)))
return error;
- if ((nprocesses >= maxprocess - 5 && uid != 0) ||
- nprocesses >= maxprocess) {
+ maxprocess_local = atomic_load_int(&maxprocess);
+ if ((nprocesses >= maxprocess_local - 5 && uid != 0) ||
+ nprocesses >= maxprocess_local) {
static struct timeval lasttfm;
if (ratecheck(&lasttfm, &fork_tfmrate))
-/* $OpenBSD: kern_resource.c,v 1.86 2024/07/09 15:20:15 claudio Exp $ */
+/* $OpenBSD: kern_resource.c,v 1.87 2024/08/20 07:48:23 mvs Exp $ */
/* $NetBSD: kern_resource.c,v 1.38 1996/10/23 07:19:38 matthias Exp $ */
/*-
maxlim = maxfiles;
break;
case RLIMIT_NPROC:
- maxlim = maxprocess;
+ maxlim = atomic_load_int(&maxprocess);
break;
default:
maxlim = RLIM_INFINITY;
-/* $OpenBSD: kern_sysctl.c,v 1.440 2024/08/20 07:44:36 mvs Exp $ */
+/* $OpenBSD: kern_sysctl.c,v 1.441 2024/08/20 07:48:23 mvs Exp $ */
/* $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $ */
/*-
return (sysctl_rdint(oldp, oldlenp, newp, mp->msg_bufs));
}
case KERN_OSREV:
+ case KERN_MAXPROC:
case KERN_NFILES:
case KERN_TTYCOUNT:
case KERN_ARGMAX:
case KERN_SAVED_IDS:
case KERN_MAXPARTITIONS:
case KERN_RAWPARTITION:
+ case KERN_MAXTHREAD:
case KERN_NTHREADS:
case KERN_SOMAXCONN:
case KERN_SOMINCONN: