From owner-svn-soc-all@FreeBSD.ORG Fri Jul 20 14:57:20 2012 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id AD457106566B for ; Fri, 20 Jul 2012 14:57:18 +0000 (UTC) (envelope-from rudot@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Fri, 20 Jul 2012 14:57:18 +0000 Date: Fri, 20 Jul 2012 14:57:18 +0000 From: rudot@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20120720145718.AD457106566B@hub.freebsd.org> Cc: Subject: socsvn commit: r239622 - in soc2012/rudot/sys: kern sys X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 Jul 2012 14:57:20 -0000 Author: rudot Date: Fri Jul 20 14:57:18 2012 New Revision: 239622 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=239622 Log: roll back a small change in rctl_enforce and create instead a new function that does exactly what I need Modified: soc2012/rudot/sys/kern/kern_racct.c soc2012/rudot/sys/kern/kern_rctl.c soc2012/rudot/sys/sys/rctl.h Modified: soc2012/rudot/sys/kern/kern_racct.c ============================================================================== --- soc2012/rudot/sys/kern/kern_racct.c Fri Jul 20 09:49:50 2012 (r239621) +++ soc2012/rudot/sys/kern/kern_racct.c Fri Jul 20 14:57:18 2012 (r239622) @@ -562,10 +562,9 @@ ("racct_set: usage of non-reclaimable resource %d dropping", resource)); #endif -#ifdef RCTL - over_limit = rctl_enforce(p, resource, diff); -#else over_limit = 0; +#ifdef RCTL + over_limit = rctl_over_limit(p, resource, diff); #endif racct_alloc_resource(p->p_racct, resource, diff); if (diff > 0) Modified: soc2012/rudot/sys/kern/kern_rctl.c ============================================================================== --- soc2012/rudot/sys/kern/kern_rctl.c Fri Jul 20 09:49:50 2012 (r239621) +++ soc2012/rudot/sys/kern/kern_rctl.c Fri Jul 20 14:57:18 2012 (r239622) @@ -272,12 +272,40 @@ } /* + * Return non-zero if allocating 'amount' by proc 'p' would exceed + * 'resource' limit specified by any rule applicable to the process 'p'. + * The 'amount' can be negative. + */ +int +rctl_over_limit(const struct proc *p, int resource, int64_t amount) { + struct rctl_rule *rule; + struct rctl_rule_link *link; + int over_limit; + + over_limit = 0; + rw_rlock(&rctl_lock); + + LIST_FOREACH(link, &p->p_racct->r_rule_links, rrl_next) { + rule = link->rrl_rule; + if (rule->rr_resource != resource) + continue; + if (rctl_would_exceed(p, rule, amount)) { + over_limit = 1; + break; + } + } + + rw_runlock(&rctl_lock); + return (over_limit); +} + +/* * Check whether the proc 'p' can allocate 'amount' of 'resource' in addition * to what it keeps allocated now. Returns non-zero if the allocation should * be denied, 0 otherwise. */ int -rctl_enforce(struct proc *p, int resource, int64_t amount) +rctl_enforce(struct proc *p, int resource, uint64_t amount) { struct rctl_rule *rule; struct rctl_rule_link *link; Modified: soc2012/rudot/sys/sys/rctl.h ============================================================================== --- soc2012/rudot/sys/sys/rctl.h Fri Jul 20 09:49:50 2012 (r239621) +++ soc2012/rudot/sys/sys/rctl.h Fri Jul 20 14:57:18 2012 (r239622) @@ -139,7 +139,8 @@ void rctl_rule_release(struct rctl_rule *rule); int rctl_rule_add(struct rctl_rule *rule); int rctl_rule_remove(struct rctl_rule *filter); -int rctl_enforce(struct proc *p, int resource, int64_t amount); +int rctl_enforce(struct proc *p, int resource, uint64_t amount); +int rctl_over_limit(const struct proc *p, int resource, int64_t amount); uint64_t rctl_get_limit(struct proc *p, int resource); uint64_t rctl_get_available(struct proc *p, int resource); const char *rctl_resource_name(int resource);