Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 13 Dec 2013 20:54:45 +0000 (UTC)
From:      Mateusz Guzik <mjg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r259331 - head/sys/kern
Message-ID:  <201312132054.rBDKsjBN018150@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mjg
Date: Fri Dec 13 20:54:45 2013
New Revision: 259331
URL: http://svnweb.freebsd.org/changeset/base/259331

Log:
  rlimit: avoid unnecessary copying of rlimits
  
  If refcount is 1 just modify rlimits in place.
  
  MFC after:	2 weeks

Modified:
  head/sys/kern/kern_resource.c

Modified: head/sys/kern/kern_resource.c
==============================================================================
--- head/sys/kern/kern_resource.c	Fri Dec 13 20:53:31 2013	(r259330)
+++ head/sys/kern/kern_resource.c	Fri Dec 13 20:54:45 2013	(r259331)
@@ -679,21 +679,29 @@ kern_proc_setrlimit(struct thread *td, s
 		limp->rlim_max = RLIM_INFINITY;
 
 	oldssiz.rlim_cur = 0;
-	newlim = lim_alloc();
+	newlim = NULL;
 	PROC_LOCK(p);
+	if (lim_shared(p->p_limit)) {
+		PROC_UNLOCK(p);
+		newlim = lim_alloc();
+		PROC_LOCK(p);
+	}
 	oldlim = p->p_limit;
 	alimp = &oldlim->pl_rlimit[which];
 	if (limp->rlim_cur > alimp->rlim_max ||
 	    limp->rlim_max > alimp->rlim_max)
 		if ((error = priv_check(td, PRIV_PROC_SETRLIMIT))) {
 			PROC_UNLOCK(p);
-			lim_free(newlim);
+			if (newlim != NULL)
+				lim_free(newlim);
 			return (error);
 		}
 	if (limp->rlim_cur > limp->rlim_max)
 		limp->rlim_cur = limp->rlim_max;
-	lim_copy(newlim, oldlim);
-	alimp = &newlim->pl_rlimit[which];
+	if (newlim != NULL) {
+		lim_copy(newlim, oldlim);
+		alimp = &newlim->pl_rlimit[which];
+	}
 
 	switch (which) {
 
@@ -743,9 +751,11 @@ kern_proc_setrlimit(struct thread *td, s
 	if (p->p_sysent->sv_fixlimit != NULL)
 		p->p_sysent->sv_fixlimit(limp, which);
 	*alimp = *limp;
-	p->p_limit = newlim;
+	if (newlim != NULL)
+		p->p_limit = newlim;
 	PROC_UNLOCK(p);
-	lim_free(oldlim);
+	if (newlim != NULL)
+		lim_free(oldlim);
 
 	if (which == RLIMIT_STACK) {
 		/*



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201312132054.rBDKsjBN018150>