socsvn commit: r239622 - in soc2012/rudot/sys: kern sys
rudot at FreeBSD.org
rudot at FreeBSD.org
Fri Jul 20 14:57:20 UTC 2012
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);
More information about the svn-soc-all
mailing list