diff options
author | Frederic Weisbecker <fweisbec@gmail.com> | 2009-12-07 01:28:35 -0500 |
---|---|---|
committer | Frederic Weisbecker <fweisbec@gmail.com> | 2009-12-07 01:29:22 -0500 |
commit | 6548698f929814375fa5d62ae1db96959b0418c1 (patch) | |
tree | 340924ae82cb0946aa15045b2b72186de52a8146 /include/linux/res_counter.h | |
parent | 1d2c6cfd40b2dece3bb958cbbc405a2c1536ab75 (diff) | |
parent | 22763c5cf3690a681551162c15d34d935308c8d7 (diff) |
Merge commit 'v2.6.32' into reiserfs/kill-bkl
Merge-reason: The tree was based 2.6.31. It's better to be up to date
with 2.6.32. Although no conflicting changes were made in between,
it gives benchmarking results closer to the lastest kernel behaviour.
Diffstat (limited to 'include/linux/res_counter.h')
-rw-r--r-- | include/linux/res_counter.h | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/include/linux/res_counter.h b/include/linux/res_counter.h index 511f42fc6816..fcb9884df618 100644 --- a/include/linux/res_counter.h +++ b/include/linux/res_counter.h | |||
@@ -35,6 +35,10 @@ struct res_counter { | |||
35 | */ | 35 | */ |
36 | unsigned long long limit; | 36 | unsigned long long limit; |
37 | /* | 37 | /* |
38 | * the limit that usage can be exceed | ||
39 | */ | ||
40 | unsigned long long soft_limit; | ||
41 | /* | ||
38 | * the number of unsuccessful attempts to consume the resource | 42 | * the number of unsuccessful attempts to consume the resource |
39 | */ | 43 | */ |
40 | unsigned long long failcnt; | 44 | unsigned long long failcnt; |
@@ -87,6 +91,7 @@ enum { | |||
87 | RES_MAX_USAGE, | 91 | RES_MAX_USAGE, |
88 | RES_LIMIT, | 92 | RES_LIMIT, |
89 | RES_FAILCNT, | 93 | RES_FAILCNT, |
94 | RES_SOFT_LIMIT, | ||
90 | }; | 95 | }; |
91 | 96 | ||
92 | /* | 97 | /* |
@@ -132,6 +137,36 @@ static inline bool res_counter_limit_check_locked(struct res_counter *cnt) | |||
132 | return false; | 137 | return false; |
133 | } | 138 | } |
134 | 139 | ||
140 | static inline bool res_counter_soft_limit_check_locked(struct res_counter *cnt) | ||
141 | { | ||
142 | if (cnt->usage < cnt->soft_limit) | ||
143 | return true; | ||
144 | |||
145 | return false; | ||
146 | } | ||
147 | |||
148 | /** | ||
149 | * Get the difference between the usage and the soft limit | ||
150 | * @cnt: The counter | ||
151 | * | ||
152 | * Returns 0 if usage is less than or equal to soft limit | ||
153 | * The difference between usage and soft limit, otherwise. | ||
154 | */ | ||
155 | static inline unsigned long long | ||
156 | res_counter_soft_limit_excess(struct res_counter *cnt) | ||
157 | { | ||
158 | unsigned long long excess; | ||
159 | unsigned long flags; | ||
160 | |||
161 | spin_lock_irqsave(&cnt->lock, flags); | ||
162 | if (cnt->usage <= cnt->soft_limit) | ||
163 | excess = 0; | ||
164 | else | ||
165 | excess = cnt->usage - cnt->soft_limit; | ||
166 | spin_unlock_irqrestore(&cnt->lock, flags); | ||
167 | return excess; | ||
168 | } | ||
169 | |||
135 | /* | 170 | /* |
136 | * Helper function to detect if the cgroup is within it's limit or | 171 | * Helper function to detect if the cgroup is within it's limit or |
137 | * not. It's currently called from cgroup_rss_prepare() | 172 | * not. It's currently called from cgroup_rss_prepare() |
@@ -147,6 +182,17 @@ static inline bool res_counter_check_under_limit(struct res_counter *cnt) | |||
147 | return ret; | 182 | return ret; |
148 | } | 183 | } |
149 | 184 | ||
185 | static inline bool res_counter_check_under_soft_limit(struct res_counter *cnt) | ||
186 | { | ||
187 | bool ret; | ||
188 | unsigned long flags; | ||
189 | |||
190 | spin_lock_irqsave(&cnt->lock, flags); | ||
191 | ret = res_counter_soft_limit_check_locked(cnt); | ||
192 | spin_unlock_irqrestore(&cnt->lock, flags); | ||
193 | return ret; | ||
194 | } | ||
195 | |||
150 | static inline void res_counter_reset_max(struct res_counter *cnt) | 196 | static inline void res_counter_reset_max(struct res_counter *cnt) |
151 | { | 197 | { |
152 | unsigned long flags; | 198 | unsigned long flags; |
@@ -180,4 +226,16 @@ static inline int res_counter_set_limit(struct res_counter *cnt, | |||
180 | return ret; | 226 | return ret; |
181 | } | 227 | } |
182 | 228 | ||
229 | static inline int | ||
230 | res_counter_set_soft_limit(struct res_counter *cnt, | ||
231 | unsigned long long soft_limit) | ||
232 | { | ||
233 | unsigned long flags; | ||
234 | |||
235 | spin_lock_irqsave(&cnt->lock, flags); | ||
236 | cnt->soft_limit = soft_limit; | ||
237 | spin_unlock_irqrestore(&cnt->lock, flags); | ||
238 | return 0; | ||
239 | } | ||
240 | |||
183 | #endif | 241 | #endif |