Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys - Only increment nprocs when we're creating a new proces...
details: https://anonhg.NetBSD.org/src/rev/46848191ca77
branches: trunk
changeset: 971262:46848191ca77
user: thorpej <thorpej%NetBSD.org@localhost>
date: Sun Apr 19 20:31:59 2020 +0000
description:
- Only increment nprocs when we're creating a new process, not just
when allocating a PID.
- Per above, proc_free_pid() no longer decrements nprocs. It's now done
in proc_free() right after proc_free_pid().
- Ensure nprocs is accessed using atomics everywhere.
diffstat:
sys/compat/linux/common/linux_misc.c | 6 +++---
sys/compat/linux/common/linux_sched.c | 16 +++-------------
sys/compat/linux32/common/linux32_sysinfo.c | 6 +++---
sys/compat/netbsd32/netbsd32_execve.c | 5 +++--
sys/kern/kern_exec.c | 9 +++++++--
sys/kern/kern_exit.c | 5 +++--
sys/kern/kern_proc.c | 6 ++----
sys/miscfs/procfs/procfs_linux.c | 6 +++---
sys/miscfs/procfs/procfs_vfsops.c | 10 +++++-----
sys/rump/librump/rumpkern/lwproc.c | 7 ++++---
10 files changed, 36 insertions(+), 40 deletions(-)
diffs (truncated from 309 to 300 lines):
diff -r 5529b706a7d2 -r 46848191ca77 sys/compat/linux/common/linux_misc.c
--- a/sys/compat/linux/common/linux_misc.c Sun Apr 19 20:07:53 2020 +0000
+++ b/sys/compat/linux/common/linux_misc.c Sun Apr 19 20:31:59 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: linux_misc.c,v 1.247 2019/12/31 13:07:13 ad Exp $ */
+/* $NetBSD: linux_misc.c,v 1.248 2020/04/19 20:31:59 thorpej Exp $ */
/*-
* Copyright (c) 1995, 1998, 1999, 2008 The NetBSD Foundation, Inc.
@@ -57,7 +57,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux_misc.c,v 1.247 2019/12/31 13:07:13 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_misc.c,v 1.248 2020/04/19 20:31:59 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -1360,7 +1360,7 @@
si.totalswap = (u_long)uvmexp.swpages * uvmexp.pagesize;
si.freeswap =
(u_long)(uvmexp.swpages - uvmexp.swpginuse) * uvmexp.pagesize;
- si.procs = nprocs;
+ si.procs = atomic_load_relaxed(&nprocs);
/* The following are only present in newer Linux kernels. */
si.totalbig = 0;
diff -r 5529b706a7d2 -r 46848191ca77 sys/compat/linux/common/linux_sched.c
--- a/sys/compat/linux/common/linux_sched.c Sun Apr 19 20:07:53 2020 +0000
+++ b/sys/compat/linux/common/linux_sched.c Sun Apr 19 20:31:59 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: linux_sched.c,v 1.73 2019/11/23 19:42:52 ad Exp $ */
+/* $NetBSD: linux_sched.c,v 1.74 2020/04/19 20:31:59 thorpej Exp $ */
/*-
* Copyright (c) 1999, 2019 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux_sched.c,v 1.73 2019/11/23 19:42:52 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_sched.c,v 1.74 2020/04/19 20:31:59 thorpej Exp $");
#include <sys/param.h>
#include <sys/mount.h>
@@ -182,7 +182,7 @@
void *parent_tidptr, *tls, *child_tidptr;
vaddr_t uaddr;
lwpid_t lid;
- int flags, tnprocs, error;
+ int flags, error;
p = l->l_proc;
flags = SCARG(uap, flags);
@@ -190,17 +190,8 @@
tls = SCARG(uap, tls);
child_tidptr = SCARG(uap, child_tidptr);
- tnprocs = atomic_inc_uint_nv(&nprocs);
- if (__predict_false(tnprocs >= maxproc) ||
- kauth_authorize_process(l->l_cred, KAUTH_PROCESS_FORK, p,
- KAUTH_ARG(tnprocs), NULL, NULL) != 0) {
- atomic_dec_uint(&nprocs);
- return EAGAIN;
- }
-
uaddr = uvm_uarea_alloc();
if (__predict_false(uaddr == 0)) {
- atomic_dec_uint(&nprocs);
return ENOMEM;
}
@@ -209,7 +200,6 @@
&l->l_sigmask, &l->l_sigstk);
if (__predict_false(error)) {
DPRINTF(("%s: lwp_create error=%d\n", __func__, error));
- atomic_dec_uint(&nprocs);
uvm_uarea_free(uaddr);
return error;
}
diff -r 5529b706a7d2 -r 46848191ca77 sys/compat/linux32/common/linux32_sysinfo.c
--- a/sys/compat/linux32/common/linux32_sysinfo.c Sun Apr 19 20:07:53 2020 +0000
+++ b/sys/compat/linux32/common/linux32_sysinfo.c Sun Apr 19 20:31:59 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: linux32_sysinfo.c,v 1.10 2019/12/31 13:07:13 ad Exp $ */
+/* $NetBSD: linux32_sysinfo.c,v 1.11 2020/04/19 20:31:59 thorpej Exp $ */
/*-
* Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved.
@@ -33,7 +33,7 @@
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux32_sysinfo.c,v 1.10 2019/12/31 13:07:13 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux32_sysinfo.c,v 1.11 2020/04/19 20:31:59 thorpej Exp $");
#include <sys/types.h>
#include <sys/param.h>
@@ -83,7 +83,7 @@
si.totalswap = (u_long)uvmexp.swpages * uvmexp.pagesize;
si.freeswap =
(u_long)(uvmexp.swpages - uvmexp.swpginuse) * uvmexp.pagesize;
- si.procs = nprocs;
+ si.procs = atomic_load_relaxed(&nprocs);
/* The following are only present in newer Linux kernels. */
si.totalbig = 0;
diff -r 5529b706a7d2 -r 46848191ca77 sys/compat/netbsd32/netbsd32_execve.c
--- a/sys/compat/netbsd32/netbsd32_execve.c Sun Apr 19 20:07:53 2020 +0000
+++ b/sys/compat/netbsd32/netbsd32_execve.c Sun Apr 19 20:31:59 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: netbsd32_execve.c,v 1.41 2019/09/17 15:19:27 christos Exp $ */
+/* $NetBSD: netbsd32_execve.c,v 1.42 2020/04/19 20:31:59 thorpej Exp $ */
/*
* Copyright (c) 1998, 2001 Matthew R. Green
@@ -28,7 +28,7 @@
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_execve.c,v 1.41 2019/09/17 15:19:27 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_execve.c,v 1.42 2020/04/19 20:31:59 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -182,6 +182,7 @@
rlim_t max_fileactions;
proc_t *p = l->l_proc;
+ /* check_posix_spawn() increments nprocs for us. */
error = check_posix_spawn(l);
if (error) {
*retval = error;
diff -r 5529b706a7d2 -r 46848191ca77 sys/kern/kern_exec.c
--- a/sys/kern/kern_exec.c Sun Apr 19 20:07:53 2020 +0000
+++ b/sys/kern/kern_exec.c Sun Apr 19 20:31:59 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_exec.c,v 1.496 2020/04/14 22:42:18 kamil Exp $ */
+/* $NetBSD: kern_exec.c,v 1.497 2020/04/19 20:31:59 thorpej Exp $ */
/*-
* Copyright (c) 2008, 2019, 2020 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.496 2020/04/14 22:42:18 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.497 2020/04/19 20:31:59 thorpej Exp $");
#include "opt_exec.h"
#include "opt_execfmt.h"
@@ -2397,6 +2397,10 @@
return error;
}
+/*
+ * N.B. increments nprocs upon success. Callers need to drop nprocs if
+ * they fail for some other reason.
+ */
int
check_posix_spawn(struct lwp *l1)
{
@@ -2751,6 +2755,7 @@
rlim_t max_fileactions;
proc_t *p = l1->l_proc;
+ /* check_posix_spawn() increments nprocs for us. */
error = check_posix_spawn(l1);
if (error) {
*retval = error;
diff -r 5529b706a7d2 -r 46848191ca77 sys/kern/kern_exit.c
--- a/sys/kern/kern_exit.c Sun Apr 19 20:07:53 2020 +0000
+++ b/sys/kern/kern_exit.c Sun Apr 19 20:31:59 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_exit.c,v 1.287 2020/04/04 20:20:12 thorpej Exp $ */
+/* $NetBSD: kern_exit.c,v 1.288 2020/04/19 20:31:59 thorpej Exp $ */
/*-
* Copyright (c) 1998, 1999, 2006, 2007, 2008, 2020 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.287 2020/04/04 20:20:12 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.288 2020/04/19 20:31:59 thorpej Exp $");
#include "opt_ktrace.h"
#include "opt_dtrace.h"
@@ -1216,6 +1216,7 @@
* Let pid be reallocated.
*/
proc_free_pid(p->p_pid);
+ atomic_dec_uint(&nprocs);
/*
* Unlink process from its process group.
diff -r 5529b706a7d2 -r 46848191ca77 sys/kern/kern_proc.c
--- a/sys/kern/kern_proc.c Sun Apr 19 20:07:53 2020 +0000
+++ b/sys/kern/kern_proc.c Sun Apr 19 20:31:59 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_proc.c,v 1.243 2020/04/06 08:20:05 kamil Exp $ */
+/* $NetBSD: kern_proc.c,v 1.244 2020/04/19 20:31:59 thorpej Exp $ */
/*-
* Copyright (c) 1999, 2006, 2007, 2008, 2020 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_proc.c,v 1.243 2020/04/06 08:20:05 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_proc.c,v 1.244 2020/04/19 20:31:59 thorpej Exp $");
#ifdef _KERNEL_OPT
#include "opt_kstack.h"
@@ -866,8 +866,6 @@
last_free_pt = pid;
pid_alloc_cnt--;
}
-
- atomic_dec_uint(&nprocs);
}
void
diff -r 5529b706a7d2 -r 46848191ca77 sys/miscfs/procfs/procfs_linux.c
--- a/sys/miscfs/procfs/procfs_linux.c Sun Apr 19 20:07:53 2020 +0000
+++ b/sys/miscfs/procfs/procfs_linux.c Sun Apr 19 20:31:59 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: procfs_linux.c,v 1.80 2020/01/02 15:42:27 thorpej Exp $ */
+/* $NetBSD: procfs_linux.c,v 1.81 2020/04/19 20:31:59 thorpej Exp $ */
/*
* Copyright (c) 2001 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: procfs_linux.c,v 1.80 2020/01/02 15:42:27 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: procfs_linux.c,v 1.81 2020/04/19 20:31:59 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -346,7 +346,7 @@
(int)(averunnable.ldavg[2] / averunnable.fscale),
(int)(averunnable.ldavg[2] * 100 / averunnable.fscale % 100),
1, /* number of ONPROC processes */
- nprocs,
+ atomic_load_relaxed(&nprocs),
30000); /* last pid */
if (len == 0)
goto out;
diff -r 5529b706a7d2 -r 46848191ca77 sys/miscfs/procfs/procfs_vfsops.c
--- a/sys/miscfs/procfs/procfs_vfsops.c Sun Apr 19 20:07:53 2020 +0000
+++ b/sys/miscfs/procfs/procfs_vfsops.c Sun Apr 19 20:31:59 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: procfs_vfsops.c,v 1.104 2020/04/04 20:49:30 ad Exp $ */
+/* $NetBSD: procfs_vfsops.c,v 1.105 2020/04/19 20:31:59 thorpej Exp $ */
/*
* Copyright (c) 1993
@@ -76,7 +76,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: procfs_vfsops.c,v 1.104 2020/04/04 20:49:30 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: procfs_vfsops.c,v 1.105 2020/04/19 20:31:59 thorpej Exp $");
#if defined(_KERNEL_OPT)
#include "opt_compat_netbsd.h"
@@ -236,9 +236,9 @@
sbp->f_frsize = PAGE_SIZE;
sbp->f_iosize = PAGE_SIZE;
sbp->f_blocks = 1;
- sbp->f_files = maxproc; /* approx */
- sbp->f_ffree = maxproc - nprocs; /* approx */
- sbp->f_favail = maxproc - nprocs; /* approx */
+ sbp->f_files = maxproc; /* approx */
+ sbp->f_ffree = maxproc - atomic_load_relaxed(&nprocs); /* approx */
+ sbp->f_favail = maxproc - atomic_load_relaxed(&nprocs); /* approx */
return (0);
}
diff -r 5529b706a7d2 -r 46848191ca77 sys/rump/librump/rumpkern/lwproc.c
--- a/sys/rump/librump/rumpkern/lwproc.c Sun Apr 19 20:07:53 2020 +0000
+++ b/sys/rump/librump/rumpkern/lwproc.c Sun Apr 19 20:31:59 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lwproc.c,v 1.44 2020/02/15 18:12:15 ad Exp $ */
+/* $NetBSD: lwproc.c,v 1.45 2020/04/19 20:32:00 thorpej Exp $ */
/*
* Copyright (c) 2010, 2011 Antti Kantee. All Rights Reserved.
@@ -28,7 +28,7 @@
#define RUMP__CURLWP_PRIVATE
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lwproc.c,v 1.44 2020/02/15 18:12:15 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lwproc.c,v 1.45 2020/04/19 20:32:00 thorpej Exp $");
#include <sys/param.h>
#include <sys/atomic.h>
@@ -178,7 +178,8 @@
Home |
Main Index |
Thread Index |
Old Index