summaryrefslogtreecommitdiff
path: root/sys/kern
diff options
context:
space:
mode:
authorVitaliy Makkoveev <mvs@cvs.openbsd.org>2024-08-20 07:48:24 +0000
committerVitaliy Makkoveev <mvs@cvs.openbsd.org>2024-08-20 07:48:24 +0000
commit9c7be1b42d3b35ddc5ee216a93833960252a4b8c (patch)
treec264f7b31beb1a601ff1e91dadfe33bfa02741eb /sys/kern
parent497ccfca54af4795787cf8295f790a6d414fedf6 (diff)
Unlock KERN_MAXPROC and KERN_MAXTHREAD from `kern_vars'. Both
`maxprocess' and `maxthread' are atomically accessed integers. ok mpi
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/kern_fork.c15
-rw-r--r--sys/kern/kern_resource.c4
-rw-r--r--sys/kern/kern_sysctl.c4
3 files changed, 14 insertions, 9 deletions
diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c
index d0d465babb6..2f97fabaf89 100644
--- a/sys/kern/kern_fork.c
+++ b/sys/kern/kern_fork.c
@@ -1,4 +1,4 @@
-/* $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 $ */
/*
@@ -307,7 +307,7 @@ struct timeval fork_tfmrate = { 10, 0 };
int
fork_check_maxthread(uid_t uid)
{
- int val;
+ int maxthread_local, val;
/*
* Although process entries are dynamically created, we still keep
@@ -318,8 +318,10 @@ fork_check_maxthread(uid_t uid)
* 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))
@@ -353,7 +355,7 @@ fork1(struct proc *curp, int flags, void (*func)(void *), void *arg,
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;
@@ -366,8 +368,9 @@ fork1(struct proc *curp, int flags, void (*func)(void *), void *arg,
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))
diff --git a/sys/kern/kern_resource.c b/sys/kern/kern_resource.c
index c4fec1b4b6b..2afc6287f21 100644
--- a/sys/kern/kern_resource.c
+++ b/sys/kern/kern_resource.c
@@ -1,4 +1,4 @@
-/* $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 $ */
/*-
@@ -278,7 +278,7 @@ dosetrlimit(struct proc *p, u_int which, struct rlimit *limp)
maxlim = maxfiles;
break;
case RLIMIT_NPROC:
- maxlim = maxprocess;
+ maxlim = atomic_load_int(&maxprocess);
break;
default:
maxlim = RLIM_INFINITY;
diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c
index 8b10fd14208..698548fbcf8 100644
--- a/sys/kern/kern_sysctl.c
+++ b/sys/kern/kern_sysctl.c
@@ -1,4 +1,4 @@
-/* $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 $ */
/*-
@@ -554,6 +554,7 @@ kern_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,
return (sysctl_rdint(oldp, oldlenp, newp, mp->msg_bufs));
}
case KERN_OSREV:
+ case KERN_MAXPROC:
case KERN_NFILES:
case KERN_TTYCOUNT:
case KERN_ARGMAX:
@@ -563,6 +564,7 @@ kern_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,
case KERN_SAVED_IDS:
case KERN_MAXPARTITIONS:
case KERN_RAWPARTITION:
+ case KERN_MAXTHREAD:
case KERN_NTHREADS:
case KERN_SOMAXCONN:
case KERN_SOMINCONN: