summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorVisa Hankala <visa@cvs.openbsd.org>2019-06-10 03:15:54 +0000
committerVisa Hankala <visa@cvs.openbsd.org>2019-06-10 03:15:54 +0000
commit8b7de691cc69919ba3a5f0cc6aaff826d89fa81c (patch)
treec955a91afc04c768d58c40b74db5314fa4a83853 /sys
parentafd92dc63c35ae5a5ba67363ac99dba05d4ebe3e (diff)
Avoid changing resource limits in rucheck() by introducing a new state
variable that tracks when to send next SIGXCPU. This eases MP work and prevents accidental alteration of shared resource limit structs. OK mpi@ semarie@
Diffstat (limited to 'sys')
-rw-r--r--sys/kern/kern_resource.c17
-rw-r--r--sys/sys/proc.h4
2 files changed, 12 insertions, 9 deletions
diff --git a/sys/kern/kern_resource.c b/sys/kern/kern_resource.c
index 24559ecda99..3bc9425020a 100644
--- a/sys/kern/kern_resource.c
+++ b/sys/kern/kern_resource.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_resource.c,v 1.63 2019/06/02 03:58:28 visa Exp $ */
+/* $OpenBSD: kern_resource.c,v 1.64 2019/06/10 03:15:53 visa Exp $ */
/* $NetBSD: kern_resource.c,v 1.38 1996/10/23 07:19:38 matthias Exp $ */
/*-
@@ -53,6 +53,9 @@
#include <uvm/uvm_extern.h>
+/* SIGXCPU interval in seconds of process runtime */
+#define SIGXCPU_INTERVAL 5
+
void tuagg_sub(struct tusage *, struct proc *);
/*
@@ -506,7 +509,7 @@ rucheck(void *arg)
{
struct process *pr = arg;
struct rlimit *rlim;
- rlim_t runtime;
+ time_t runtime;
int s;
KERNEL_ASSERT_LOCKED();
@@ -516,14 +519,12 @@ rucheck(void *arg)
SCHED_UNLOCK(s);
rlim = &pr->ps_limit->pl_rlimit[RLIMIT_CPU];
- if (runtime >= rlim->rlim_cur) {
- if (runtime >= rlim->rlim_max) {
+ if ((rlim_t)runtime >= rlim->rlim_cur) {
+ if ((rlim_t)runtime >= rlim->rlim_max) {
prsignal(pr, SIGKILL);
- } else {
+ } else if (runtime >= pr->ps_nextxcpu) {
prsignal(pr, SIGXCPU);
- if (rlim->rlim_cur < rlim->rlim_max)
- rlim->rlim_cur = MIN(rlim->rlim_cur + 5,
- rlim->rlim_max);
+ pr->ps_nextxcpu = runtime + SIGXCPU_INTERVAL;
}
}
diff --git a/sys/sys/proc.h b/sys/sys/proc.h
index f63b4301309..76aac28ddef 100644
--- a/sys/sys/proc.h
+++ b/sys/sys/proc.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: proc.h,v 1.268 2019/06/01 22:42:18 deraadt Exp $ */
+/* $OpenBSD: proc.h,v 1.269 2019/06/10 03:15:53 visa Exp $ */
/* $NetBSD: proc.h,v 1.44 1996/04/22 01:23:21 christos Exp $ */
/*-
@@ -204,6 +204,8 @@ struct process {
struct rusage ps_cru; /* sum of stats for reaped children */
struct itimerval ps_timer[3]; /* timers, indexed by ITIMER_* */
struct timeout ps_rucheck_to; /* resource limit check timer */
+ time_t ps_nextxcpu; /* when to send next SIGXCPU, */
+ /* in seconds of process runtime */
u_int64_t ps_wxcounter;