diff options
Diffstat (limited to 'kernel/res_counter.c')
-rw-r--r-- | kernel/res_counter.c | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/kernel/res_counter.c b/kernel/res_counter.c index e1338f07431..88faec23e83 100644 --- a/kernel/res_counter.c +++ b/kernel/res_counter.c | |||
@@ -19,6 +19,7 @@ void res_counter_init(struct res_counter *counter, struct res_counter *parent) | |||
19 | { | 19 | { |
20 | spin_lock_init(&counter->lock); | 20 | spin_lock_init(&counter->lock); |
21 | counter->limit = RESOURCE_MAX; | 21 | counter->limit = RESOURCE_MAX; |
22 | counter->soft_limit = RESOURCE_MAX; | ||
22 | counter->parent = parent; | 23 | counter->parent = parent; |
23 | } | 24 | } |
24 | 25 | ||
@@ -36,17 +37,27 @@ int res_counter_charge_locked(struct res_counter *counter, unsigned long val) | |||
36 | } | 37 | } |
37 | 38 | ||
38 | int res_counter_charge(struct res_counter *counter, unsigned long val, | 39 | int res_counter_charge(struct res_counter *counter, unsigned long val, |
39 | struct res_counter **limit_fail_at) | 40 | struct res_counter **limit_fail_at, |
41 | struct res_counter **soft_limit_fail_at) | ||
40 | { | 42 | { |
41 | int ret; | 43 | int ret; |
42 | unsigned long flags; | 44 | unsigned long flags; |
43 | struct res_counter *c, *u; | 45 | struct res_counter *c, *u; |
44 | 46 | ||
45 | *limit_fail_at = NULL; | 47 | *limit_fail_at = NULL; |
48 | if (soft_limit_fail_at) | ||
49 | *soft_limit_fail_at = NULL; | ||
46 | local_irq_save(flags); | 50 | local_irq_save(flags); |
47 | for (c = counter; c != NULL; c = c->parent) { | 51 | for (c = counter; c != NULL; c = c->parent) { |
48 | spin_lock(&c->lock); | 52 | spin_lock(&c->lock); |
49 | ret = res_counter_charge_locked(c, val); | 53 | ret = res_counter_charge_locked(c, val); |
54 | /* | ||
55 | * With soft limits, we return the highest ancestor | ||
56 | * that exceeds its soft limit | ||
57 | */ | ||
58 | if (soft_limit_fail_at && | ||
59 | !res_counter_soft_limit_check_locked(c)) | ||
60 | *soft_limit_fail_at = c; | ||
50 | spin_unlock(&c->lock); | 61 | spin_unlock(&c->lock); |
51 | if (ret < 0) { | 62 | if (ret < 0) { |
52 | *limit_fail_at = c; | 63 | *limit_fail_at = c; |
@@ -74,7 +85,8 @@ void res_counter_uncharge_locked(struct res_counter *counter, unsigned long val) | |||
74 | counter->usage -= val; | 85 | counter->usage -= val; |
75 | } | 86 | } |
76 | 87 | ||
77 | void res_counter_uncharge(struct res_counter *counter, unsigned long val) | 88 | void res_counter_uncharge(struct res_counter *counter, unsigned long val, |
89 | bool *was_soft_limit_excess) | ||
78 | { | 90 | { |
79 | unsigned long flags; | 91 | unsigned long flags; |
80 | struct res_counter *c; | 92 | struct res_counter *c; |
@@ -82,6 +94,9 @@ void res_counter_uncharge(struct res_counter *counter, unsigned long val) | |||
82 | local_irq_save(flags); | 94 | local_irq_save(flags); |
83 | for (c = counter; c != NULL; c = c->parent) { | 95 | for (c = counter; c != NULL; c = c->parent) { |
84 | spin_lock(&c->lock); | 96 | spin_lock(&c->lock); |
97 | if (was_soft_limit_excess) | ||
98 | *was_soft_limit_excess = | ||
99 | !res_counter_soft_limit_check_locked(c); | ||
85 | res_counter_uncharge_locked(c, val); | 100 | res_counter_uncharge_locked(c, val); |
86 | spin_unlock(&c->lock); | 101 | spin_unlock(&c->lock); |
87 | } | 102 | } |
@@ -101,6 +116,8 @@ res_counter_member(struct res_counter *counter, int member) | |||
101 | return &counter->limit; | 116 | return &counter->limit; |
102 | case RES_FAILCNT: | 117 | case RES_FAILCNT: |
103 | return &counter->failcnt; | 118 | return &counter->failcnt; |
119 | case RES_SOFT_LIMIT: | ||
120 | return &counter->soft_limit; | ||
104 | }; | 121 | }; |
105 | 122 | ||
106 | BUG(); | 123 | BUG(); |