aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/linux/res_counter.h58
-rw-r--r--kernel/res_counter.c3
-rw-r--r--mm/memcontrol.c20
3 files changed, 81 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
diff --git a/kernel/res_counter.c b/kernel/res_counter.c
index e1338f074314..bcdabf37c40b 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
@@ -101,6 +102,8 @@ res_counter_member(struct res_counter *counter, int member)
101 return &counter->limit; 102 return &counter->limit;
102 case RES_FAILCNT: 103 case RES_FAILCNT:
103 return &counter->failcnt; 104 return &counter->failcnt;
105 case RES_SOFT_LIMIT:
106 return &counter->soft_limit;
104 }; 107 };
105 108
106 BUG(); 109 BUG();
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index eb9571815f0c..4ad3e6be045d 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -2123,6 +2123,20 @@ static int mem_cgroup_write(struct cgroup *cont, struct cftype *cft,
2123 else 2123 else
2124 ret = mem_cgroup_resize_memsw_limit(memcg, val); 2124 ret = mem_cgroup_resize_memsw_limit(memcg, val);
2125 break; 2125 break;
2126 case RES_SOFT_LIMIT:
2127 ret = res_counter_memparse_write_strategy(buffer, &val);
2128 if (ret)
2129 break;
2130 /*
2131 * For memsw, soft limits are hard to implement in terms
2132 * of semantics, for now, we support soft limits for
2133 * control without swap
2134 */
2135 if (type == _MEM)
2136 ret = res_counter_set_soft_limit(&memcg->res, val);
2137 else
2138 ret = -EINVAL;
2139 break;
2126 default: 2140 default:
2127 ret = -EINVAL; /* should be BUG() ? */ 2141 ret = -EINVAL; /* should be BUG() ? */
2128 break; 2142 break;
@@ -2376,6 +2390,12 @@ static struct cftype mem_cgroup_files[] = {
2376 .read_u64 = mem_cgroup_read, 2390 .read_u64 = mem_cgroup_read,
2377 }, 2391 },
2378 { 2392 {
2393 .name = "soft_limit_in_bytes",
2394 .private = MEMFILE_PRIVATE(_MEM, RES_SOFT_LIMIT),
2395 .write_string = mem_cgroup_write,
2396 .read_u64 = mem_cgroup_read,
2397 },
2398 {
2379 .name = "failcnt", 2399 .name = "failcnt",
2380 .private = MEMFILE_PRIVATE(_MEM, RES_FAILCNT), 2400 .private = MEMFILE_PRIVATE(_MEM, RES_FAILCNT),
2381 .trigger = mem_cgroup_reset, 2401 .trigger = mem_cgroup_reset,