Use atomics to maintain nprocs.
This commit is contained in:
parent
f078e05288
commit
deb8b3146e
|
@ -1,14 +1,12 @@
|
|||
/* $NetBSD: kern_fork.c,v 1.150 2007/12/03 22:37:34 elad Exp $ */
|
||||
/* $NetBSD: kern_fork.c,v 1.151 2007/12/04 16:56:17 ad Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1999, 2001, 2004 The NetBSD Foundation, Inc.
|
||||
* Copyright (c) 1999, 2001, 2004, 2006, 2007 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
|
||||
* NASA Ames Research Center.
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Charles M. Hannum.
|
||||
* NASA Ames Research Center, by Charles M. Hannum, and by Andrew Doran.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
@ -76,7 +74,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: kern_fork.c,v 1.150 2007/12/03 22:37:34 elad Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: kern_fork.c,v 1.151 2007/12/04 16:56:17 ad Exp $");
|
||||
|
||||
#include "opt_ktrace.h"
|
||||
#include "opt_systrace.h"
|
||||
|
@ -101,13 +99,12 @@ __KERNEL_RCSID(0, "$NetBSD: kern_fork.c,v 1.150 2007/12/03 22:37:34 elad Exp $")
|
|||
#include <sys/signalvar.h>
|
||||
#include <sys/systrace.h>
|
||||
#include <sys/kauth.h>
|
||||
|
||||
#include <sys/atomic.h>
|
||||
#include <sys/syscallargs.h>
|
||||
|
||||
#include <uvm/uvm_extern.h>
|
||||
|
||||
|
||||
int nprocs = 1; /* process 0 */
|
||||
u_int nprocs = 1; /* process 0 */
|
||||
|
||||
/*
|
||||
* Number of ticks to sleep if fork() would fail due to process hitting
|
||||
|
@ -222,6 +219,7 @@ fork1(struct lwp *l1, int flags, int exitsig, void *stack, size_t stacksize,
|
|||
vaddr_t uaddr;
|
||||
bool inmem;
|
||||
int tmp;
|
||||
int tnprocs;
|
||||
|
||||
/*
|
||||
* Although process entries are dynamically created, we still keep
|
||||
|
@ -234,17 +232,17 @@ fork1(struct lwp *l1, int flags, int exitsig, void *stack, size_t stacksize,
|
|||
mutex_enter(&p1->p_mutex);
|
||||
uid = kauth_cred_getuid(p1->p_cred);
|
||||
mutex_exit(&p1->p_mutex);
|
||||
if (__predict_false((nprocs >= maxproc - 5 && uid != 0) ||
|
||||
nprocs >= maxproc)) {
|
||||
tnprocs = atomic_inc_uint_nv(&nprocs);
|
||||
if (__predict_false((tnprocs >= maxproc - 5 && uid != 0) ||
|
||||
tnprocs >= maxproc)) {
|
||||
static struct timeval lasttfm;
|
||||
|
||||
atomic_dec_uint(&nprocs);
|
||||
if (ratecheck(&lasttfm, &fork_tfmrate))
|
||||
tablefull("proc", "increase kern.maxproc or NPROC");
|
||||
if (forkfsleep)
|
||||
(void)tsleep(&nprocs, PUSER, "forkmx", forkfsleep);
|
||||
return (EAGAIN);
|
||||
}
|
||||
nprocs++;
|
||||
|
||||
/*
|
||||
* Enforce limits.
|
||||
|
@ -252,7 +250,7 @@ fork1(struct lwp *l1, int flags, int exitsig, void *stack, size_t stacksize,
|
|||
count = chgproccnt(uid, 1);
|
||||
if (__predict_false(count > p1->p_rlimit[RLIMIT_NPROC].rlim_cur)) {
|
||||
(void)chgproccnt(uid, -1);
|
||||
nprocs--;
|
||||
atomic_dec_uint(&nprocs);
|
||||
if (forkfsleep)
|
||||
(void)tsleep(&nprocs, PUSER, "forkulim", forkfsleep);
|
||||
return (EAGAIN);
|
||||
|
@ -268,7 +266,7 @@ fork1(struct lwp *l1, int flags, int exitsig, void *stack, size_t stacksize,
|
|||
inmem = uvm_uarea_alloc(&uaddr);
|
||||
if (__predict_false(uaddr == 0)) {
|
||||
(void)chgproccnt(uid, -1);
|
||||
nprocs--;
|
||||
atomic_dec_uint(&nprocs);
|
||||
return (ENOMEM);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: kern_proc.c,v 1.125 2007/12/03 20:26:25 ad Exp $ */
|
||||
/* $NetBSD: kern_proc.c,v 1.126 2007/12/04 16:56:17 ad Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1999, 2006, 2007 The NetBSD Foundation, Inc.
|
||||
|
@ -69,7 +69,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: kern_proc.c,v 1.125 2007/12/03 20:26:25 ad Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: kern_proc.c,v 1.126 2007/12/04 16:56:17 ad Exp $");
|
||||
|
||||
#include "opt_kstack.h"
|
||||
#include "opt_maxuprc.h"
|
||||
|
@ -98,6 +98,7 @@ __KERNEL_RCSID(0, "$NetBSD: kern_proc.c,v 1.125 2007/12/03 20:26:25 ad Exp $");
|
|||
#include "sys/syscall_stats.h"
|
||||
#include <sys/kauth.h>
|
||||
#include <sys/sleepq.h>
|
||||
#include <sys/atomic.h>
|
||||
|
||||
#include <uvm/uvm.h>
|
||||
#include <uvm/uvm_extern.h>
|
||||
|
@ -706,7 +707,7 @@ proc_free_pid(struct proc *p)
|
|||
}
|
||||
mutex_exit(&proclist_mutex);
|
||||
|
||||
nprocs--;
|
||||
atomic_dec_uint(&nprocs);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: proc.h,v 1.261 2007/11/12 23:12:00 ad Exp $ */
|
||||
/* $NetBSD: proc.h,v 1.262 2007/12/04 16:56:16 ad Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2006, 2007 The NetBSD Foundation, Inc.
|
||||
|
@ -476,7 +476,8 @@ CURCPU_IDLE_P(void)
|
|||
#define curproc (curlwp->l_proc)
|
||||
|
||||
extern struct proc proc0; /* Process slot for swapper */
|
||||
extern int nprocs, maxproc; /* Current and max number of procs */
|
||||
extern u_int nprocs; /* Current number of procs */
|
||||
extern int maxproc; /* Max number of procs */
|
||||
#define vmspace_kernel() (proc0.p_vmspace)
|
||||
|
||||
/* Process list locks; see kern_proc.c for locking protocol details */
|
||||
|
|
Loading…
Reference in New Issue