diff options
Diffstat (limited to 'include/linux/res_counter.h')
-rw-r--r-- | include/linux/res_counter.h | 52 |
1 files changed, 14 insertions, 38 deletions
diff --git a/include/linux/res_counter.h b/include/linux/res_counter.h index fcb9884df618..c9d625ca659e 100644 --- a/include/linux/res_counter.h +++ b/include/linux/res_counter.h | |||
@@ -129,20 +129,22 @@ int __must_check res_counter_charge(struct res_counter *counter, | |||
129 | void res_counter_uncharge_locked(struct res_counter *counter, unsigned long val); | 129 | void res_counter_uncharge_locked(struct res_counter *counter, unsigned long val); |
130 | void res_counter_uncharge(struct res_counter *counter, unsigned long val); | 130 | void res_counter_uncharge(struct res_counter *counter, unsigned long val); |
131 | 131 | ||
132 | static inline bool res_counter_limit_check_locked(struct res_counter *cnt) | 132 | /** |
133 | { | 133 | * res_counter_margin - calculate chargeable space of a counter |
134 | if (cnt->usage < cnt->limit) | 134 | * @cnt: the counter |
135 | return true; | 135 | * |
136 | 136 | * Returns the difference between the hard limit and the current usage | |
137 | return false; | 137 | * of resource counter @cnt. |
138 | } | 138 | */ |
139 | 139 | static inline unsigned long long res_counter_margin(struct res_counter *cnt) | |
140 | static inline bool res_counter_soft_limit_check_locked(struct res_counter *cnt) | ||
141 | { | 140 | { |
142 | if (cnt->usage < cnt->soft_limit) | 141 | unsigned long long margin; |
143 | return true; | 142 | unsigned long flags; |
144 | 143 | ||
145 | return false; | 144 | spin_lock_irqsave(&cnt->lock, flags); |
145 | margin = cnt->limit - cnt->usage; | ||
146 | spin_unlock_irqrestore(&cnt->lock, flags); | ||
147 | return margin; | ||
146 | } | 148 | } |
147 | 149 | ||
148 | /** | 150 | /** |
@@ -167,32 +169,6 @@ res_counter_soft_limit_excess(struct res_counter *cnt) | |||
167 | return excess; | 169 | return excess; |
168 | } | 170 | } |
169 | 171 | ||
170 | /* | ||
171 | * Helper function to detect if the cgroup is within it's limit or | ||
172 | * not. It's currently called from cgroup_rss_prepare() | ||
173 | */ | ||
174 | static inline bool res_counter_check_under_limit(struct res_counter *cnt) | ||
175 | { | ||
176 | bool ret; | ||
177 | unsigned long flags; | ||
178 | |||
179 | spin_lock_irqsave(&cnt->lock, flags); | ||
180 | ret = res_counter_limit_check_locked(cnt); | ||
181 | spin_unlock_irqrestore(&cnt->lock, flags); | ||
182 | return ret; | ||
183 | } | ||
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 | |||
196 | static inline void res_counter_reset_max(struct res_counter *cnt) | 172 | static inline void res_counter_reset_max(struct res_counter *cnt) |
197 | { | 173 | { |
198 | unsigned long flags; | 174 | unsigned long flags; |