From edc99bcd885f4004d6cffdbe82f15aa2eb27ee9c Mon Sep 17 00:00:00 2001 From: visa Date: Fri, 21 Jun 2019 09:39:48 +0000 Subject: Make resource limit access MP-safe. So far, the copy-on-write sharing of resource limit structs has been done between processes. By applying copy-on-write also between threads, threads can read rlimits in a nearly lock-free manner. Inspired by code in DragonFly BSD and FreeBSD. OK mpi@, agreement from jmatthew@ and anton@ --- sys/kern/kern_exit.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'sys/kern/kern_exit.c') diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c index 74ac47d02f8..ab2f0de086d 100644 --- a/sys/kern/kern_exit.c +++ b/sys/kern/kern_exit.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_exit.c,v 1.177 2019/06/13 21:19:28 mpi Exp $ */ +/* $OpenBSD: kern_exit.c,v 1.178 2019/06/21 09:39:48 visa Exp $ */ /* $NetBSD: kern_exit.c,v 1.39 1996/04/22 01:38:25 christos Exp $ */ /* @@ -328,6 +328,15 @@ exit1(struct proc *p, int rv, int flags) KASSERT(pr->ps_refcnt > 0); } + /* Release the thread's read reference of resource limit structure. */ + if (p->p_limit != NULL) { + struct plimit *limit; + + limit = p->p_limit; + p->p_limit = NULL; + lim_free(limit); + } + /* * Other substructures are freed from reaper and wait(). */ @@ -636,7 +645,7 @@ process_zap(struct process *pr) free(pr->ps_ptstat, M_SUBPROC, sizeof(*pr->ps_ptstat)); pool_put(&rusage_pool, pr->ps_ru); KASSERT(TAILQ_EMPTY(&pr->ps_threads)); - limfree(pr->ps_limit); + lim_free(pr->ps_limit); crfree(pr->ps_ucred); pool_put(&process_pool, pr); nprocesses--; -- cgit v1.2.3-59-g8ed1b