Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 29 Apr 2015 10:23:02 +0000 (UTC)
From:      Edward Tomasz Napierala <trasz@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r282213 - in head/sys: conf kern sys vm
Message-ID:  <201504291023.t3TAN22I014763@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: trasz
Date: Wed Apr 29 10:23:02 2015
New Revision: 282213
URL: https://svnweb.freebsd.org/changeset/base/282213

Log:
  Add kern.racct.enable tunable and RACCT_DISABLED config option.
  The point of this is to be able to add RACCT (with RACCT_DISABLED)
  to GENERIC, to avoid having to rebuild the kernel to use rctl(8).
  
  Differential Revision:	https://reviews.freebsd.org/D2369
  Reviewed by:	kib@
  MFC after:	1 month
  Relnotes:	yes
  Sponsored by:	The FreeBSD Foundation

Modified:
  head/sys/conf/options
  head/sys/kern/imgact_elf.c
  head/sys/kern/kern_descrip.c
  head/sys/kern/kern_exit.c
  head/sys/kern/kern_jail.c
  head/sys/kern/kern_racct.c
  head/sys/kern/kern_rctl.c
  head/sys/kern/kern_thr.c
  head/sys/kern/sched_4bsd.c
  head/sys/kern/subr_trap.c
  head/sys/kern/sysv_msg.c
  head/sys/kern/sysv_sem.c
  head/sys/kern/sysv_shm.c
  head/sys/sys/racct.h
  head/sys/vm/swap_pager.c
  head/sys/vm/vm_map.c
  head/sys/vm/vm_mmap.c
  head/sys/vm/vm_pageout.c
  head/sys/vm/vm_unix.c

Modified: head/sys/conf/options
==============================================================================
--- head/sys/conf/options	Wed Apr 29 10:12:34 2015	(r282212)
+++ head/sys/conf/options	Wed Apr 29 10:23:02 2015	(r282213)
@@ -928,6 +928,7 @@ IPOIB_CM	opt_ofed.h
 
 # Resource Accounting
 RACCT		opt_global.h
+RACCT_DISABLED	opt_global.h
 
 # Resource Limits
 RCTL		opt_global.h

Modified: head/sys/kern/imgact_elf.c
==============================================================================
--- head/sys/kern/imgact_elf.c	Wed Apr 29 10:12:34 2015	(r282212)
+++ head/sys/kern/imgact_elf.c	Wed Apr 29 10:23:02 2015	(r282213)
@@ -1238,12 +1238,14 @@ __elfN(coredump)(struct thread *td, stru
 	coresize = round_page(hdrsize + notesz) + seginfo.size;
 
 #ifdef RACCT
-	PROC_LOCK(td->td_proc);
-	error = racct_add(td->td_proc, RACCT_CORE, coresize);
-	PROC_UNLOCK(td->td_proc);
-	if (error != 0) {
-		error = EFAULT;
-		goto done;
+	if (racct_enable) {
+		PROC_LOCK(td->td_proc);
+		error = racct_add(td->td_proc, RACCT_CORE, coresize);
+		PROC_UNLOCK(td->td_proc);
+		if (error != 0) {
+			error = EFAULT;
+			goto done;
+		}
 	}
 #endif
 	if (coresize >= limit) {

Modified: head/sys/kern/kern_descrip.c
==============================================================================
--- head/sys/kern/kern_descrip.c	Wed Apr 29 10:12:34 2015	(r282212)
+++ head/sys/kern/kern_descrip.c	Wed Apr 29 10:23:02 2015	(r282213)
@@ -857,13 +857,15 @@ do_dup(struct thread *td, int flags, int
 			 * the limit on the size of the file descriptor table.
 			 */
 #ifdef RACCT
-			PROC_LOCK(p);
-			error = racct_set(p, RACCT_NOFILE, new + 1);
-			PROC_UNLOCK(p);
-			if (error != 0) {
-				FILEDESC_XUNLOCK(fdp);
-				fdrop(fp, td);
-				return (EMFILE);
+			if (racct_enable) {
+				PROC_LOCK(p);
+				error = racct_set(p, RACCT_NOFILE, new + 1);
+				PROC_UNLOCK(p);
+				if (error != 0) {
+					FILEDESC_XUNLOCK(fdp);
+					fdrop(fp, td);
+					return (EMFILE);
+				}
 			}
 #endif
 			fdgrowtable_exp(fdp, new + 1);
@@ -1631,11 +1633,13 @@ fdalloc(struct thread *td, int minfd, in
 	if (fd >= fdp->fd_nfiles) {
 		allocfd = min(fd * 2, maxfd);
 #ifdef RACCT
-		PROC_LOCK(p);
-		error = racct_set(p, RACCT_NOFILE, allocfd);
-		PROC_UNLOCK(p);
-		if (error != 0)
-			return (EMFILE);
+		if (racct_enable) {
+			PROC_LOCK(p);
+			error = racct_set(p, RACCT_NOFILE, allocfd);
+			PROC_UNLOCK(p);
+			if (error != 0)
+				return (EMFILE);
+		}
 #endif
 		/*
 		 * fd is already equal to first free descriptor >= minfd, so
@@ -2042,9 +2046,11 @@ fdescfree(struct thread *td)
 	MPASS(fdp != NULL);
 
 #ifdef RACCT
-	PROC_LOCK(td->td_proc);
-	racct_set(td->td_proc, RACCT_NOFILE, 0);
-	PROC_UNLOCK(td->td_proc);
+	if (racct_enable) {
+		PROC_LOCK(td->td_proc);
+		racct_set(td->td_proc, RACCT_NOFILE, 0);
+		PROC_UNLOCK(td->td_proc);
+	}
 #endif
 
 	if (td->td_proc->p_fdtol != NULL)

Modified: head/sys/kern/kern_exit.c
==============================================================================
--- head/sys/kern/kern_exit.c	Wed Apr 29 10:12:34 2015	(r282212)
+++ head/sys/kern/kern_exit.c	Wed Apr 29 10:23:02 2015	(r282213)
@@ -907,9 +907,11 @@ proc_reap(struct thread *td, struct proc
 	 * Destroy resource accounting information associated with the process.
 	 */
 #ifdef RACCT
-	PROC_LOCK(p);
-	racct_sub(p, RACCT_NPROC, 1);
-	PROC_UNLOCK(p);
+	if (racct_enable) {
+		PROC_LOCK(p);
+		racct_sub(p, RACCT_NPROC, 1);
+		PROC_UNLOCK(p);
+	}
 #endif
 	racct_proc_exit(p);
 

Modified: head/sys/kern/kern_jail.c
==============================================================================
--- head/sys/kern/kern_jail.c	Wed Apr 29 10:12:34 2015	(r282212)
+++ head/sys/kern/kern_jail.c	Wed Apr 29 10:23:02 2015	(r282213)
@@ -1778,7 +1778,7 @@ kern_jail_set(struct thread *td, struct 
 	mtx_unlock(&pr->pr_mtx);
 
 #ifdef RACCT
-	if (created)
+	if (racct_enable && created)
 		prison_racct_attach(pr);
 #endif
 
@@ -1862,7 +1862,7 @@ kern_jail_set(struct thread *td, struct 
 	}
 
 #ifdef RACCT
-	if (!created) {
+	if (racct_enable && !created) {
 		if (!(flags & JAIL_ATTACH))
 			sx_sunlock(&allprison_lock);
 		prison_racct_modify(pr);
@@ -2652,7 +2652,8 @@ prison_deref(struct prison *pr, int flag
 			cpuset_rel(pr->pr_cpuset);
 		osd_jail_exit(pr);
 #ifdef RACCT
-		prison_racct_detach(pr);
+		if (racct_enable)
+			prison_racct_detach(pr);
 #endif
 		free(pr, M_PRISON);
 
@@ -4460,12 +4461,15 @@ SYSCTL_JAIL_PARAM(_allow_mount, tmpfs, C
 SYSCTL_JAIL_PARAM(_allow_mount, zfs, CTLTYPE_INT | CTLFLAG_RW,
     "B", "Jail may mount the zfs file system");
 
+#ifdef RACCT
 void
 prison_racct_foreach(void (*callback)(struct racct *racct,
     void *arg2, void *arg3), void *arg2, void *arg3)
 {
 	struct prison_racct *prr;
 
+	ASSERT_RACCT_ENABLED();
+
 	sx_slock(&allprison_lock);
 	LIST_FOREACH(prr, &allprison_racct, prr_next)
 		(callback)(prr->prr_racct, arg2, arg3);
@@ -4477,6 +4481,7 @@ prison_racct_find_locked(const char *nam
 {
 	struct prison_racct *prr;
 
+	ASSERT_RACCT_ENABLED();
 	sx_assert(&allprison_lock, SA_XLOCKED);
 
 	if (name[0] == '\0' || strlen(name) >= MAXHOSTNAMELEN)
@@ -4507,6 +4512,8 @@ prison_racct_find(const char *name)
 {
 	struct prison_racct *prr;
 
+	ASSERT_RACCT_ENABLED();
+
 	sx_xlock(&allprison_lock);
 	prr = prison_racct_find_locked(name);
 	sx_xunlock(&allprison_lock);
@@ -4517,6 +4524,8 @@ void
 prison_racct_hold(struct prison_racct *prr)
 {
 
+	ASSERT_RACCT_ENABLED();
+
 	refcount_acquire(&prr->prr_refcount);
 }
 
@@ -4524,6 +4533,7 @@ static void
 prison_racct_free_locked(struct prison_racct *prr)
 {
 
+	ASSERT_RACCT_ENABLED();
 	sx_assert(&allprison_lock, SA_XLOCKED);
 
 	if (refcount_release(&prr->prr_refcount)) {
@@ -4538,6 +4548,7 @@ prison_racct_free(struct prison_racct *p
 {
 	int old;
 
+	ASSERT_RACCT_ENABLED();
 	sx_assert(&allprison_lock, SA_UNLOCKED);
 
 	old = prr->prr_refcount;
@@ -4549,12 +4560,12 @@ prison_racct_free(struct prison_racct *p
 	sx_xunlock(&allprison_lock);
 }
 
-#ifdef RACCT
 static void
 prison_racct_attach(struct prison *pr)
 {
 	struct prison_racct *prr;
 
+	ASSERT_RACCT_ENABLED();
 	sx_assert(&allprison_lock, SA_XLOCKED);
 
 	prr = prison_racct_find_locked(pr->pr_name);
@@ -4574,6 +4585,8 @@ prison_racct_modify(struct prison *pr)
 	struct ucred *cred;
 	struct prison_racct *oldprr;
 
+	ASSERT_RACCT_ENABLED();
+
 	sx_slock(&allproc_lock);
 	sx_xlock(&allprison_lock);
 
@@ -4613,6 +4626,7 @@ static void
 prison_racct_detach(struct prison *pr)
 {
 
+	ASSERT_RACCT_ENABLED();
 	sx_assert(&allprison_lock, SA_UNLOCKED);
 
 	if (pr->pr_prison_racct == NULL)

Modified: head/sys/kern/kern_racct.c
==============================================================================
--- head/sys/kern/kern_racct.c	Wed Apr 29 10:12:34 2015	(r282212)
+++ head/sys/kern/kern_racct.c	Wed Apr 29 10:23:02 2015	(r282213)
@@ -70,8 +70,15 @@ FEATURE(racct, "Resource Accounting");
  * Do not block processes that have their %cpu usage <= pcpu_threshold.
  */
 static int pcpu_threshold = 1;
+#ifdef RACCT_DISABLED
+int racct_enable = 0;
+#else
+int racct_enable = 1;
+#endif
 
 SYSCTL_NODE(_kern, OID_AUTO, racct, CTLFLAG_RW, 0, "Resource Accounting");
+SYSCTL_UINT(_kern_racct, OID_AUTO, enable, CTLFLAG_RDTUN, &racct_enable,
+    0, "Enable RACCT/RCTL");
 SYSCTL_UINT(_kern_racct, OID_AUTO, pcpu_threshold, CTLFLAG_RW, &pcpu_threshold,
     0, "Processes with higher %cpu usage than this value can be throttled.");
 
@@ -313,6 +320,8 @@ racct_getpcpu(struct proc *p, u_int pcpu
 	fixpt_t p_pctcpu;
 	struct thread *td;
 
+	ASSERT_RACCT_ENABLED();
+
 	/*
 	 * If the process is swapped out, we count its %cpu usage as zero.
 	 * This behaviour is consistent with the userland ps(1) tool.
@@ -377,6 +386,7 @@ racct_add_racct(struct racct *dest, cons
 {
 	int i;
 
+	ASSERT_RACCT_ENABLED();
 	mtx_assert(&racct_lock, MA_OWNED);
 
 	/*
@@ -398,6 +408,7 @@ racct_sub_racct(struct racct *dest, cons
 {
 	int i;
 
+	ASSERT_RACCT_ENABLED();
 	mtx_assert(&racct_lock, MA_OWNED);
 
 	/*
@@ -431,6 +442,9 @@ void
 racct_create(struct racct **racctp)
 {
 
+	if (!racct_enable)
+		return;
+
 	SDT_PROBE(racct, kernel, racct, create, racctp, 0, 0, 0, 0);
 
 	KASSERT(*racctp == NULL, ("racct already allocated"));
@@ -444,6 +458,8 @@ racct_destroy_locked(struct racct **racc
 	int i;
 	struct racct *racct;
 
+	ASSERT_RACCT_ENABLED();
+
 	SDT_PROBE(racct, kernel, racct, destroy, racctp, 0, 0, 0, 0);
 
 	mtx_assert(&racct_lock, MA_OWNED);
@@ -470,6 +486,9 @@ void
 racct_destroy(struct racct **racct)
 {
 
+	if (!racct_enable)
+		return;
+
 	mtx_lock(&racct_lock);
 	racct_destroy_locked(racct);
 	mtx_unlock(&racct_lock);
@@ -485,6 +504,7 @@ racct_alloc_resource(struct racct *racct
     uint64_t amount)
 {
 
+	ASSERT_RACCT_ENABLED();
 	mtx_assert(&racct_lock, MA_OWNED);
 	KASSERT(racct != NULL, ("NULL racct"));
 
@@ -516,6 +536,8 @@ racct_add_locked(struct proc *p, int res
 	int error;
 #endif
 
+	ASSERT_RACCT_ENABLED();
+
 	SDT_PROBE(racct, kernel, rusage, add, p, resource, amount, 0, 0);
 
 	/*
@@ -546,6 +568,9 @@ racct_add(struct proc *p, int resource, 
 {
 	int error;
 
+	if (!racct_enable)
+		return (0);
+
 	mtx_lock(&racct_lock);
 	error = racct_add_locked(p, resource, amount);
 	mtx_unlock(&racct_lock);
@@ -557,6 +582,8 @@ racct_add_cred_locked(struct ucred *cred
 {
 	struct prison *pr;
 
+	ASSERT_RACCT_ENABLED();
+
 	SDT_PROBE(racct, kernel, rusage, add__cred, cred, resource, amount,
 	    0, 0);
 
@@ -577,6 +604,9 @@ void
 racct_add_cred(struct ucred *cred, int resource, uint64_t amount)
 {
 
+	if (!racct_enable)
+		return;
+
 	mtx_lock(&racct_lock);
 	racct_add_cred_locked(cred, resource, amount);
 	mtx_unlock(&racct_lock);
@@ -590,6 +620,9 @@ void
 racct_add_force(struct proc *p, int resource, uint64_t amount)
 {
 
+	if (!racct_enable)
+		return;
+
 	SDT_PROBE(racct, kernel, rusage, add__force, p, resource, amount, 0, 0);
 
 	/*
@@ -612,6 +645,8 @@ racct_set_locked(struct proc *p, int res
 	int error;
 #endif
 
+	ASSERT_RACCT_ENABLED();
+
 	SDT_PROBE(racct, kernel, rusage, set, p, resource, amount, 0, 0);
 
 	/*
@@ -671,6 +706,9 @@ racct_set(struct proc *p, int resource, 
 {
 	int error;
 
+	if (!racct_enable)
+		return (0);
+
 	mtx_lock(&racct_lock);
 	error = racct_set_locked(p, resource, amount);
 	mtx_unlock(&racct_lock);
@@ -683,6 +721,8 @@ racct_set_force_locked(struct proc *p, i
 	int64_t old_amount, decayed_amount;
 	int64_t diff_proc, diff_cred;
 
+	ASSERT_RACCT_ENABLED();
+
 	SDT_PROBE(racct, kernel, rusage, set, p, resource, amount, 0, 0);
 
 	/*
@@ -717,6 +757,10 @@ racct_set_force_locked(struct proc *p, i
 void
 racct_set_force(struct proc *p, int resource, uint64_t amount)
 {
+
+	if (!racct_enable)
+		return;
+
 	mtx_lock(&racct_lock);
 	racct_set_force_locked(p, resource, amount);
 	mtx_unlock(&racct_lock);
@@ -732,6 +776,9 @@ uint64_t
 racct_get_limit(struct proc *p, int resource)
 {
 
+	if (!racct_enable)
+		return (UINT64_MAX);
+
 #ifdef RCTL
 	return (rctl_get_limit(p, resource));
 #else
@@ -749,6 +796,9 @@ uint64_t
 racct_get_available(struct proc *p, int resource)
 {
 
+	if (!racct_enable)
+		return (UINT64_MAX);
+
 #ifdef RCTL
 	return (rctl_get_available(p, resource));
 #else
@@ -765,6 +815,8 @@ static int64_t
 racct_pcpu_available(struct proc *p)
 {
 
+	ASSERT_RACCT_ENABLED();
+
 #ifdef RCTL
 	return (rctl_pcpu_available(p));
 #else
@@ -779,6 +831,9 @@ void
 racct_sub(struct proc *p, int resource, uint64_t amount)
 {
 
+	if (!racct_enable)
+		return;
+
 	SDT_PROBE(racct, kernel, rusage, sub, p, resource, amount, 0, 0);
 
 	/*
@@ -804,6 +859,8 @@ racct_sub_cred_locked(struct ucred *cred
 {
 	struct prison *pr;
 
+	ASSERT_RACCT_ENABLED();
+
 	SDT_PROBE(racct, kernel, rusage, sub__cred, cred, resource, amount,
 	    0, 0);
 
@@ -827,6 +884,9 @@ void
 racct_sub_cred(struct ucred *cred, int resource, uint64_t amount)
 {
 
+	if (!racct_enable)
+		return;
+
 	mtx_lock(&racct_lock);
 	racct_sub_cred_locked(cred, resource, amount);
 	mtx_unlock(&racct_lock);
@@ -840,6 +900,9 @@ racct_proc_fork(struct proc *parent, str
 {
 	int i, error = 0;
 
+	if (!racct_enable)
+		return (0);
+
 	/*
 	 * Create racct for the child process.
 	 */
@@ -896,6 +959,9 @@ racct_proc_fork_done(struct proc *child)
 {
 
 #ifdef RCTL
+	if (!racct_enable)
+		return;
+
 	PROC_LOCK(child);
 	mtx_lock(&racct_lock);
 	rctl_enforce(child, RACCT_NPROC, 0);
@@ -913,6 +979,9 @@ racct_proc_exit(struct proc *p)
 	struct timeval wallclock;
 	uint64_t pct_estimate, pct;
 
+	if (!racct_enable)
+		return;
+
 	PROC_LOCK(p);
 	/*
 	 * We don't need to calculate rux, proc_reap() has already done this.
@@ -967,6 +1036,9 @@ racct_proc_ucred_changed(struct proc *p,
 	struct loginclass *oldlc, *newlc;
 	struct prison *oldpr, *newpr, *pr;
 
+	if (!racct_enable)
+		return;
+
 	PROC_LOCK_ASSERT(p, MA_NOTOWNED);
 
 	newuip = newcred->cr_ruidinfo;
@@ -1004,6 +1076,8 @@ void
 racct_move(struct racct *dest, struct racct *src)
 {
 
+	ASSERT_RACCT_ENABLED();
+
 	mtx_lock(&racct_lock);
 
 	racct_add_racct(dest, src);
@@ -1020,6 +1094,7 @@ racct_proc_throttle(struct proc *p)
 	int cpuid;
 #endif
 
+	ASSERT_RACCT_ENABLED();
 	PROC_LOCK_ASSERT(p, MA_OWNED);
 
 	/*
@@ -1065,6 +1140,9 @@ racct_proc_throttle(struct proc *p)
 static void
 racct_proc_wakeup(struct proc *p)
 {
+
+	ASSERT_RACCT_ENABLED();
+
 	PROC_LOCK_ASSERT(p, MA_OWNED);
 
 	if (p->p_throttled) {
@@ -1079,6 +1157,8 @@ racct_decay_resource(struct racct *racct
 	int resource;
 	int64_t r_old, r_new;
 
+	ASSERT_RACCT_ENABLED();
+
 	resource = *(int *)res;
 	r_old = racct->r_resources[resource];
 
@@ -1095,6 +1175,9 @@ racct_decay_resource(struct racct *racct
 static void
 racct_decay(int resource)
 {
+
+	ASSERT_RACCT_ENABLED();
+
 	ui_racct_foreach(racct_decay_resource, &resource, NULL);
 	loginclass_racct_foreach(racct_decay_resource, &resource, NULL);
 	prison_racct_foreach(racct_decay_resource, &resource, NULL);
@@ -1109,6 +1192,8 @@ racctd(void)
 	uint64_t runtime;
 	uint64_t pct, pct_estimate;
 
+	ASSERT_RACCT_ENABLED();
+
 	for (;;) {
 		racct_decay(RACCT_PCTCPU);
 
@@ -1188,11 +1273,22 @@ static struct kproc_desc racctd_kp = {
 	racctd,
 	NULL
 };
-SYSINIT(racctd, SI_SUB_RACCTD, SI_ORDER_FIRST, kproc_start, &racctd_kp);
+
+static void
+racctd_init(void)
+{
+	if (!racct_enable)
+		return;
+
+	kproc_start(&racctd_kp);
+}
+SYSINIT(racctd, SI_SUB_RACCTD, SI_ORDER_FIRST, racctd_init, NULL);
 
 static void
 racct_init(void)
 {
+	if (!racct_enable)
+		return;
 
 	racct_zone = uma_zcreate("racct", sizeof(struct racct),
 	    NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_NOFREE);

Modified: head/sys/kern/kern_rctl.c
==============================================================================
--- head/sys/kern/kern_rctl.c	Wed Apr 29 10:12:34 2015	(r282212)
+++ head/sys/kern/kern_rctl.c	Wed Apr 29 10:23:02 2015	(r282213)
@@ -225,6 +225,7 @@ rctl_available_resource(const struct pro
 	int64_t available = INT64_MAX;
 	struct ucred *cred = p->p_ucred;
 
+	ASSERT_RACCT_ENABLED();
 	rw_assert(&rctl_lock, RA_LOCKED);
 
 	resource = rule->rr_resource;
@@ -264,6 +265,8 @@ rctl_would_exceed(const struct proc *p, 
 {
 	int64_t available;
 
+	ASSERT_RACCT_ENABLED();
+
 	rw_assert(&rctl_lock, RA_LOCKED);
 
 	available = rctl_available_resource(p, rule);
@@ -283,6 +286,8 @@ rctl_pcpu_available(const struct proc *p
 	struct rctl_rule_link *link;
 	int64_t available, minavailable, limit;
 
+	ASSERT_RACCT_ENABLED();
+
 	minavailable = INT64_MAX;
 	limit = 0;
 
@@ -334,6 +339,8 @@ rctl_enforce(struct proc *p, int resourc
 	static int curtime = 0;
 	static struct timeval lasttime;
 
+	ASSERT_RACCT_ENABLED();
+
 	rw_rlock(&rctl_lock);
 
 	/*
@@ -457,6 +464,8 @@ rctl_get_limit(struct proc *p, int resou
 	struct rctl_rule_link *link;
 	uint64_t amount = UINT64_MAX;
 
+	ASSERT_RACCT_ENABLED();
+
 	rw_rlock(&rctl_lock);
 
 	/*
@@ -487,6 +496,8 @@ rctl_get_available(struct proc *p, int r
 
 	minavailable = INT64_MAX;
 
+	ASSERT_RACCT_ENABLED();
+
 	rw_rlock(&rctl_lock);
 
 	/*
@@ -521,6 +532,8 @@ static int
 rctl_rule_matches(const struct rctl_rule *rule, const struct rctl_rule *filter)
 {
 
+	ASSERT_RACCT_ENABLED();
+
 	if (filter->rr_subject_type != RCTL_SUBJECT_TYPE_UNDEFINED) {
 		if (rule->rr_subject_type != filter->rr_subject_type)
 			return (0);
@@ -635,6 +648,7 @@ rctl_racct_add_rule(struct racct *racct,
 {
 	struct rctl_rule_link *link;
 
+	ASSERT_RACCT_ENABLED();
 	KASSERT(rctl_rule_fully_specified(rule), ("rule not fully specified"));
 
 	rctl_rule_acquire(rule);
@@ -652,6 +666,7 @@ rctl_racct_add_rule_locked(struct racct 
 {
 	struct rctl_rule_link *link;
 
+	ASSERT_RACCT_ENABLED();
 	KASSERT(rctl_rule_fully_specified(rule), ("rule not fully specified"));
 	rw_assert(&rctl_lock, RA_WLOCKED);
 
@@ -678,6 +693,7 @@ rctl_racct_remove_rules(struct racct *ra
 	int removed = 0;
 	struct rctl_rule_link *link, *linktmp;
 
+	ASSERT_RACCT_ENABLED();
 	rw_assert(&rctl_lock, RA_WLOCKED);
 
 	LIST_FOREACH_SAFE(link, &racct->r_rule_links, rrl_next, linktmp) {
@@ -696,6 +712,8 @@ static void
 rctl_rule_acquire_subject(struct rctl_rule *rule)
 {
 
+	ASSERT_RACCT_ENABLED();
+
 	switch (rule->rr_subject_type) {
 	case RCTL_SUBJECT_TYPE_UNDEFINED:
 	case RCTL_SUBJECT_TYPE_PROCESS:
@@ -722,6 +740,8 @@ static void
 rctl_rule_release_subject(struct rctl_rule *rule)
 {
 
+	ASSERT_RACCT_ENABLED();
+
 	switch (rule->rr_subject_type) {
 	case RCTL_SUBJECT_TYPE_UNDEFINED:
 	case RCTL_SUBJECT_TYPE_PROCESS:
@@ -749,6 +769,8 @@ rctl_rule_alloc(int flags)
 {
 	struct rctl_rule *rule;
 
+	ASSERT_RACCT_ENABLED();
+
 	rule = uma_zalloc(rctl_rule_zone, flags);
 	if (rule == NULL)
 		return (NULL);
@@ -771,6 +793,8 @@ rctl_rule_duplicate(const struct rctl_ru
 {
 	struct rctl_rule *copy;
 
+	ASSERT_RACCT_ENABLED();
+
 	copy = uma_zalloc(rctl_rule_zone, flags);
 	if (copy == NULL)
 		return (NULL);
@@ -793,6 +817,7 @@ void
 rctl_rule_acquire(struct rctl_rule *rule)
 {
 
+	ASSERT_RACCT_ENABLED();
 	KASSERT(rule->rr_refcount > 0, ("rule->rr_refcount <= 0"));
 
 	refcount_acquire(&rule->rr_refcount);
@@ -805,6 +830,7 @@ rctl_rule_free(void *context, int pendin
 	
 	rule = (struct rctl_rule *)context;
 
+	ASSERT_RACCT_ENABLED();
 	KASSERT(rule->rr_refcount == 0, ("rule->rr_refcount != 0"));
 	
 	/*
@@ -819,6 +845,7 @@ void
 rctl_rule_release(struct rctl_rule *rule)
 {
 
+	ASSERT_RACCT_ENABLED();
 	KASSERT(rule->rr_refcount > 0, ("rule->rr_refcount <= 0"));
 
 	if (refcount_release(&rule->rr_refcount)) {
@@ -838,6 +865,8 @@ static int
 rctl_rule_fully_specified(const struct rctl_rule *rule)
 {
 
+	ASSERT_RACCT_ENABLED();
+
 	switch (rule->rr_subject_type) {
 	case RCTL_SUBJECT_TYPE_UNDEFINED:
 		return (0);
@@ -882,6 +911,8 @@ rctl_string_to_rule(char *rulestr, struc
 	struct rctl_rule *rule;
 	id_t id;
 
+	ASSERT_RACCT_ENABLED();
+
 	rule = rctl_rule_alloc(M_WAITOK);
 
 	subjectstr = strsep(&rulestr, ":");
@@ -1008,6 +1039,7 @@ rctl_rule_add(struct rctl_rule *rule)
 	struct rctl_rule *rule2;
 	int match;
 
+	ASSERT_RACCT_ENABLED();
 	KASSERT(rctl_rule_fully_specified(rule), ("rule not fully specified"));
 
 	/*
@@ -1118,6 +1150,8 @@ rctl_rule_remove_callback(struct racct *
 	struct rctl_rule *filter = (struct rctl_rule *)arg2;
 	int found = 0;
 
+	ASSERT_RACCT_ENABLED();
+
 	rw_wlock(&rctl_lock);
 	found += rctl_racct_remove_rules(racct, filter);
 	rw_wunlock(&rctl_lock);
@@ -1134,6 +1168,8 @@ rctl_rule_remove(struct rctl_rule *filte
 	int found = 0;
 	struct proc *p;
 
+	ASSERT_RACCT_ENABLED();
+
 	if (filter->rr_subject_type == RCTL_SUBJECT_TYPE_PROCESS &&
 	    filter->rr_subject.rs_proc != NULL) {
 		p = filter->rr_subject.rs_proc;
@@ -1172,6 +1208,8 @@ rctl_rule_to_sbuf(struct sbuf *sb, const
 {
 	int64_t amount;
 
+	ASSERT_RACCT_ENABLED();
+
 	sbuf_printf(sb, "%s:", rctl_subject_type_name(rule->rr_subject_type));
 
 	switch (rule->rr_subject_type) {
@@ -1231,6 +1269,8 @@ rctl_read_inbuf(char **inputstr, const c
 	int error;
 	char *str;
 
+	ASSERT_RACCT_ENABLED();
+
 	if (inbuflen <= 0)
 		return (EINVAL);
 	if (inbuflen > RCTL_MAX_INBUFLEN)
@@ -1256,6 +1296,8 @@ rctl_write_outbuf(struct sbuf *outputsbu
 {
 	int error;
 
+	ASSERT_RACCT_ENABLED();
+
 	if (outputsbuf == NULL)
 		return (0);
 
@@ -1277,6 +1319,8 @@ rctl_racct_to_sbuf(struct racct *racct, 
 	int64_t amount;
 	struct sbuf *sb;
 
+	ASSERT_RACCT_ENABLED();
+
 	sb = sbuf_new_auto();
 	for (i = 0; i <= RACCT_MAX; i++) {
 		if (sloppy == 0 && RACCT_IS_SLOPPY(i))
@@ -1302,6 +1346,9 @@ sys_rctl_get_racct(struct thread *td, st
 	struct loginclass *lc;
 	struct prison_racct *prr;
 
+	if (!racct_enable)
+		return (ENOSYS);
+
 	error = priv_check(td, PRIV_RCTL_GET_RACCT);
 	if (error != 0)
 		return (error);
@@ -1372,6 +1419,8 @@ rctl_get_rules_callback(struct racct *ra
 	struct rctl_rule_link *link;
 	struct sbuf *sb = (struct sbuf *)arg3;
 
+	ASSERT_RACCT_ENABLED();
+
 	rw_rlock(&rctl_lock);
 	LIST_FOREACH(link, &racct->r_rule_links, rrl_next) {
 		if (!rctl_rule_matches(link->rrl_rule, filter))
@@ -1393,6 +1442,9 @@ sys_rctl_get_rules(struct thread *td, st
 	struct rctl_rule_link *link;
 	struct proc *p;
 
+	if (!racct_enable)
+		return (ENOSYS);
+
 	error = priv_check(td, PRIV_RCTL_GET_RULES);
 	if (error != 0)
 		return (error);
@@ -1467,6 +1519,9 @@ sys_rctl_get_limits(struct thread *td, s
 	struct rctl_rule *filter;
 	struct rctl_rule_link *link;
 
+	if (!racct_enable)
+		return (ENOSYS);
+
 	error = priv_check(td, PRIV_RCTL_GET_LIMITS);
 	if (error != 0)
 		return (error);
@@ -1538,6 +1593,9 @@ sys_rctl_add_rule(struct thread *td, str
 	struct rctl_rule *rule;
 	char *inputstr;
 
+	if (!racct_enable)
+		return (ENOSYS);
+
 	error = priv_check(td, PRIV_RCTL_ADD_RULE);
 	if (error != 0)
 		return (error);
@@ -1580,6 +1638,9 @@ sys_rctl_remove_rule(struct thread *td, 
 	struct rctl_rule *filter;
 	char *inputstr;
 
+	if (!racct_enable)
+		return (ENOSYS);
+
 	error = priv_check(td, PRIV_RCTL_REMOVE_RULE);
 	if (error != 0)
 		return (error);
@@ -1616,6 +1677,8 @@ rctl_proc_ucred_changed(struct proc *p, 
 	struct prison_racct *newprr;
 	LIST_HEAD(, rctl_rule_link) newrules;
 
+	ASSERT_RACCT_ENABLED();
+
 	newuip = newcred->cr_ruidinfo;
 	newlc = newcred->cr_loginclass;
 	newprr = newcred->cr_prison->pr_prison_racct;
@@ -1756,6 +1819,7 @@ rctl_proc_fork(struct proc *parent, stru
 
 	LIST_INIT(&child->p_racct->r_rule_links);
 
+	ASSERT_RACCT_ENABLED();
 	KASSERT(parent->p_racct != NULL, ("process without racct; p = %p", parent));
 
 	rw_wlock(&rctl_lock);
@@ -1809,6 +1873,8 @@ rctl_racct_release(struct racct *racct)
 {
 	struct rctl_rule_link *link;
 
+	ASSERT_RACCT_ENABLED();
+
 	rw_wlock(&rctl_lock);
 	while (!LIST_EMPTY(&racct->r_rule_links)) {
 		link = LIST_FIRST(&racct->r_rule_links);
@@ -1823,6 +1889,9 @@ static void
 rctl_init(void)
 {
 
+	if (!racct_enable)
+		return;
+
 	rctl_rule_link_zone = uma_zcreate("rctl_rule_link",
 	    sizeof(struct rctl_rule_link), NULL, NULL, NULL, NULL,
 	    UMA_ALIGN_PTR, UMA_ZONE_NOFREE);

Modified: head/sys/kern/kern_thr.c
==============================================================================
--- head/sys/kern/kern_thr.c	Wed Apr 29 10:12:34 2015	(r282212)
+++ head/sys/kern/kern_thr.c	Wed Apr 29 10:23:02 2015	(r282213)
@@ -187,11 +187,13 @@ create_thread(struct thread *td, mcontex
 	}
 
 #ifdef RACCT
-	PROC_LOCK(p);
-	error = racct_add(p, RACCT_NTHR, 1);
-	PROC_UNLOCK(p);
-	if (error != 0)
-		return (EPROCLIM);
+	if (racct_enable) {
+		PROC_LOCK(p);
+		error = racct_add(p, RACCT_NTHR, 1);
+		PROC_UNLOCK(p);
+		if (error != 0)
+			return (EPROCLIM);
+	}
 #endif
 
 	/* Initialize our td */
@@ -280,9 +282,11 @@ create_thread(struct thread *td, mcontex
 
 fail:
 #ifdef RACCT
-	PROC_LOCK(p);
-	racct_sub(p, RACCT_NTHR, 1);
-	PROC_UNLOCK(p);
+	if (racct_enable) {
+		PROC_LOCK(p);
+		racct_sub(p, RACCT_NTHR, 1);
+		PROC_UNLOCK(p);
+	}
 #endif
 	return (error);
 }

Modified: head/sys/kern/sched_4bsd.c
==============================================================================
--- head/sys/kern/sched_4bsd.c	Wed Apr 29 10:12:34 2015	(r282212)
+++ head/sys/kern/sched_4bsd.c	Wed Apr 29 10:23:02 2015	(r282213)
@@ -1585,7 +1585,7 @@ sched_pctcpu(struct thread *td)
 	return (ts->ts_pctcpu);
 }
 
-#ifdef	RACCT
+#ifdef RACCT
 /*
  * Calculates the contribution to the thread cpu usage for the latest
  * (unfinished) second.

Modified: head/sys/kern/subr_trap.c
==============================================================================
--- head/sys/kern/subr_trap.c	Wed Apr 29 10:12:34 2015	(r282212)
+++ head/sys/kern/subr_trap.c	Wed Apr 29 10:23:02 2015	(r282213)
@@ -59,6 +59,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/ktr.h>
 #include <sys/pioctl.h>
 #include <sys/ptrace.h>
+#include <sys/racct.h>
 #include <sys/resourcevar.h>
 #include <sys/sched.h>
 #include <sys/signalvar.h>
@@ -172,11 +173,13 @@ userret(struct thread *td, struct trapfr
 	    __func__, td, p->p_pid, td->td_name, curvnet,
 	    (td->td_vnet_lpush != NULL) ? td->td_vnet_lpush : "N/A"));
 #endif
-#ifdef	RACCT
-	PROC_LOCK(p);
-	while (p->p_throttled == 1)
-		msleep(p->p_racct, &p->p_mtx, 0, "racct", 0);
-	PROC_UNLOCK(p);
+#ifdef RACCT
+	if (racct_enable) {
+		PROC_LOCK(p);
+		while (p->p_throttled == 1)
+			msleep(p->p_racct, &p->p_mtx, 0, "racct", 0);
+		PROC_UNLOCK(p);
+	}
 #endif
 }
 

Modified: head/sys/kern/sysv_msg.c
==============================================================================
--- head/sys/kern/sysv_msg.c	Wed Apr 29 10:12:34 2015	(r282212)
+++ head/sys/kern/sysv_msg.c	Wed Apr 29 10:23:02 2015	(r282213)
@@ -617,12 +617,14 @@ sys_msgget(td, uap)
 			goto done2;
 		}
 #ifdef RACCT
-		PROC_LOCK(td->td_proc);
-		error = racct_add(td->td_proc, RACCT_NMSGQ, 1);
-		PROC_UNLOCK(td->td_proc);
-		if (error != 0) {
-			error = ENOSPC;
-			goto done2;
+		if (racct_enable) {
+			PROC_LOCK(td->td_proc);
+			error = racct_add(td->td_proc, RACCT_NMSGQ, 1);
+			PROC_UNLOCK(td->td_proc);
+			if (error != 0) {
+				error = ENOSPC;
+				goto done2;
+			}
 		}
 #endif
 		DPRINTF(("msqid %d is available\n", msqid));
@@ -724,20 +726,22 @@ kern_msgsnd(td, msqid, msgp, msgsz, msgf
 #endif
 
 #ifdef RACCT
-	PROC_LOCK(td->td_proc);
-	if (racct_add(td->td_proc, RACCT_MSGQQUEUED, 1)) {

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***



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