aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/res_counter.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/res_counter.h')
-rw-r--r--include/linux/res_counter.h58
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
140static 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 */
155static inline unsigned long long
156res_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
185static 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
150static inline void res_counter_reset_max(struct res_counter *cnt) 196static 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
229static inline int
230res_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