[PATCH 1/2] res_counter : check limit change

Previous thread: [GIT PULL] SLUB fixes for 2.6.26 by Pekka J Enberg on Friday, July 4, 2008 - 2:50 am. (1 message)

Next thread: linux-next: Tree for July 4 by Stephen Rothwell on Friday, July 4, 2008 - 5:55 am. (8 messages)
To: LKML <linux-kernel@...>
Cc: linux-mm@kvack.org <linux-mm@...>, Andrew Morton <akpm@...>, balbir@linux.vnet.ibm.com <balbir@...>, xemul@openvz.org <xemul@...>, menage@google.com <menage@...>, nishimura@mxp.nes.nec.co.jp <nishimura@...>, yamamoto@valinux.co.jp <yamamoto@...>
Date: Friday, July 4, 2008 - 5:12 am

Add an interface to set limit. This is necessary to memory resource controller
because it shrinks usage at set limit.

(*) Other controller may not need this interface to shrink usage because
shrinking is not necessary or impossible in it.

Changelog:
- fixed white space bug.

Acked-by: Balbir Singh <balbir@linux.vnet.ibm.com>
Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>

include/linux/res_counter.h | 15 +++++++++++++++
1 file changed, 15 insertions(+)

Index: test-2.6.26-rc8-mm1/include/linux/res_counter.h
===================================================================
--- test-2.6.26-rc8-mm1.orig/include/linux/res_counter.h
+++ test-2.6.26-rc8-mm1/include/linux/res_counter.h
@@ -176,4 +176,19 @@ static inline bool res_counter_can_add(s
return ret;
}

+static inline int res_counter_set_limit(struct res_counter *cnt,
+ unsigned long long limit)
+{
+ unsigned long flags;
+ int ret = -EBUSY;
+
+ spin_lock_irqsave(&cnt->lock, flags);
+ if (cnt->usage < limit) {
+ cnt->limit = limit;
+ ret = 0;
+ }
+ spin_unlock_irqrestore(&cnt->lock, flags);
+ return ret;
+}
+
#endif

--

To: KAMEZAWA Hiroyuki <kamezawa.hiroyu@...>
Cc: LKML <linux-kernel@...>, linux-mm@kvack.org <linux-mm@...>, Andrew Morton <akpm@...>, balbir@linux.vnet.ibm.com <balbir@...>, menage@google.com <menage@...>, nishimura@mxp.nes.nec.co.jp <nishimura@...>, yamamoto@valinux.co.jp <yamamoto@...>
Date: Friday, July 4, 2008 - 6:34 am

--

To: KAMEZAWA Hiroyuki <kamezawa.hiroyu@...>
Cc: LKML <linux-kernel@...>, linux-mm@kvack.org <linux-mm@...>, Andrew Morton <akpm@...>, balbir@linux.vnet.ibm.com <balbir@...>, xemul@openvz.org <xemul@...>, menage@google.com <menage@...>, nishimura@mxp.nes.nec.co.jp <nishimura@...>, yamamoto@valinux.co.jp <yamamoto@...>
Date: Friday, July 4, 2008 - 5:16 am

Shrinking memory usage at limit change.

Changelog: v1 -> v2
- adjusted to be based on write_string() patch set
fixed pointed out styles (below)
- removed backword goto.
- removed unneccesary cond_resched().

Acked-by: Balbir Singh <balbir@linux.vnet.ibm.com>
Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>

Documentation/controllers/memory.txt | 3 --
mm/memcontrol.c | 43 +++++++++++++++++++++++++++++++----
2 files changed, 40 insertions(+), 6 deletions(-)

Index: test-2.6.26-rc8-mm1/mm/memcontrol.c
===================================================================
--- test-2.6.26-rc8-mm1.orig/mm/memcontrol.c
+++ test-2.6.26-rc8-mm1/mm/memcontrol.c
@@ -836,6 +836,26 @@ int mem_cgroup_shrink_usage(struct mm_st
return 0;
}

+int mem_cgroup_resize_limit(struct mem_cgroup *memcg, unsigned long long val)
+{
+
+ int retry_count = MEM_CGROUP_RECLAIM_RETRIES;
+ int progress;
+ int ret = 0;
+
+ while (res_counter_set_limit(&memcg->res, val)) {
+ if (!retry_count) {
+ ret = -EBUSY;
+ break;
+ }
+ progress = try_to_free_mem_cgroup_pages(memcg, GFP_KERNEL);
+ if (!progress)
+ retry_count--;
+ }
+ return ret;
+}
+
+
/*
* This routine traverse page_cgroup in given list and drop them all.
* *And* this routine doesn't reclaim page itself, just removes page_cgroup.
@@ -916,13 +936,29 @@ static u64 mem_cgroup_read(struct cgroup
return res_counter_read_u64(&mem_cgroup_from_cont(cont)->res,
cft->private);
}
-
+/*
+ * The user of this function is...
+ * RES_LIMIT.
+ */
static int mem_cgroup_write(struct cgroup *cont, struct cftype *cft,
const char *buffer)
{
- return res_counter_write(&mem_cgroup_from_cont(cont)->res,
- cft->private, buffer,
- res_counter_memparse_write_strategy);
+ struct mem_cgroup *memcg = mem_cgroup_from_cont(cont);
+ unsigned long long val;
+ int ret;
+
+ switch (cft->private) {
+ case RES_LIMI...

To: KAMEZAWA Hiroyuki <kamezawa.hiroyu@...>
Cc: LKML <linux-kernel@...>, linux-mm@kvack.org <linux-mm@...>, Andrew Morton <akpm@...>, balbir@linux.vnet.ibm.com <balbir@...>, menage@google.com <menage@...>, nishimura@mxp.nes.nec.co.jp <nishimura@...>, yamamoto@valinux.co.jp <yamamoto@...>
Date: Friday, July 4, 2008 - 6:35 am

--

Previous thread: [GIT PULL] SLUB fixes for 2.6.26 by Pekka J Enberg on Friday, July 4, 2008 - 2:50 am. (1 message)

Next thread: linux-next: Tree for July 4 by Stephen Rothwell on Friday, July 4, 2008 - 5:55 am. (8 messages)