[PATCH 1/2] res_counter: provide res_counter_write_u64
From: Michal Hocko
Date: Thu Jun 19 2014 - 13:14:31 EST
to allow setting member based value setting. This will reduce code
duplication for the new limits added by this patch series.
Use the new helper to replace one-off res_counter_set_soft_limit.
Signed-off-by: Michal Hocko <mhocko@xxxxxxx>
---
include/linux/res_counter.h | 14 ++------------
kernel/res_counter.c | 14 ++++++++++++++
mm/memcontrol.c | 2 +-
3 files changed, 17 insertions(+), 13 deletions(-)
diff --git a/include/linux/res_counter.h b/include/linux/res_counter.h
index 56b7bc32db4f..bea7f9f45f7a 100644
--- a/include/linux/res_counter.h
+++ b/include/linux/res_counter.h
@@ -71,6 +71,8 @@ struct res_counter {
u64 res_counter_read_u64(struct res_counter *counter, int member);
+void res_counter_write_u64(struct res_counter *counter, int member, u64 val);
+
ssize_t res_counter_read(struct res_counter *counter, int member,
const char __user *buf, size_t nbytes, loff_t *pos,
int (*read_strategy)(unsigned long long val, char *s));
@@ -208,16 +210,4 @@ static inline int res_counter_set_limit(struct res_counter *cnt,
return ret;
}
-static inline int
-res_counter_set_soft_limit(struct res_counter *cnt,
- unsigned long long soft_limit)
-{
- unsigned long flags;
-
- spin_lock_irqsave(&cnt->lock, flags);
- cnt->soft_limit = soft_limit;
- spin_unlock_irqrestore(&cnt->lock, flags);
- return 0;
-}
-
#endif
diff --git a/kernel/res_counter.c b/kernel/res_counter.c
index e791130f85a7..4789c2323a94 100644
--- a/kernel/res_counter.c
+++ b/kernel/res_counter.c
@@ -171,11 +171,25 @@ u64 res_counter_read_u64(struct res_counter *counter, int member)
return ret;
}
+
+void res_counter_write_u64(struct res_counter *counter, int member, u64 val)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&counter->lock, flags);
+ *res_counter_member(counter, member) = val;
+ spin_unlock_irqrestore(&counter->lock, flags);
+}
#else
u64 res_counter_read_u64(struct res_counter *counter, int member)
{
return *res_counter_member(counter, member);
}
+
+void res_counter_write_u64(struct res_counter *counter, int member, u64 val)
+{
+ *res_counter_member(counter, member) = val;
+}
#endif
int res_counter_memparse_write_strategy(const char *buf,
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index d1b311687769..1ad5d4a2bc4e 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -4378,7 +4378,7 @@ static ssize_t mem_cgroup_write(struct kernfs_open_file *of,
* control without swap
*/
if (type == _MEM)
- ret = res_counter_set_soft_limit(&memcg->res, val);
+ res_counter_write_u64(&memcg->res, name, val);
else
ret = -EINVAL;
break;
--
2.1.0.rc1
---