[PATCH 5/7] Fix not good check of mem_cgroup_local_usage()

From: KAMEZAWA Hiroyuki
Date: Wed Jun 15 2011 - 20:23:54 EST


Now, mem_cgroup_local_usage(memcg) is used as hint for scanning memory
cgroup hierarchy. If it returns true, the memcg has some reclaimable memory.

But this function doesn't take care of
- unevictable pages
- anon pages on swapless system.

This patch fixes the function to use LRU information.
For NUMA, for avoid scanning, numa scan bitmap is used. If it's
empty, some more precise check will be done.

Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@xxxxxxxxxxxxxx>
---
mm/memcontrol.c | 43 +++++++++++++++++++++++++++++++++----------
1 files changed, 33 insertions(+), 10 deletions(-)

Index: mmotm-0615/mm/memcontrol.c
===================================================================
--- mmotm-0615.orig/mm/memcontrol.c
+++ mmotm-0615/mm/memcontrol.c
@@ -632,15 +632,6 @@ static long mem_cgroup_read_stat(struct
return val;
}

-static long mem_cgroup_local_usage(struct mem_cgroup *mem)
-{
- long ret;
-
- ret = mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_RSS);
- ret += mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_CACHE);
- return ret;
-}
-
static void mem_cgroup_swap_statistics(struct mem_cgroup *mem,
bool charge)
{
@@ -1713,6 +1704,23 @@ static void mem_cgroup_numascan_init(str
mutex_init(&mem->numascan_mutex);
}

+static bool mem_cgroup_reclaimable(struct mem_cgroup *mem, bool noswap)
+{
+ if (!nodes_empty(mem->scan_nodes))
+ return true;
+ /* slow path */
+ if (mem_cgroup_get_local_zonestat(mem, LRU_INACTIVE_FILE))
+ return true;
+ if (mem_cgroup_get_local_zonestat(mem, LRU_ACTIVE_FILE))
+ return true;
+ if (noswap || !total_swap_pages)
+ return false;
+ if (mem_cgroup_get_local_zonestat(mem, LRU_INACTIVE_ANON))
+ return true;
+ if (mem_cgroup_get_local_zonestat(mem, LRU_ACTIVE_ANON))
+ return true;
+ return false;
+}
#else
int mem_cgroup_select_victim_node(struct mem_cgroup *mem)
{
@@ -1722,6 +1730,21 @@ static void mem_cgroup_numascan_init(str
{
return 0;
}
+
+static bool mem_cgroup_reclaimable(struct mem_cgroup *mem, bool noswap)
+{
+ if (mem_cgroup_get_zonestat_node(mem, 0, LRU_INACTIVE_FILE))
+ return true;
+ if (mem_cgroup_get_zonestat_node(mem, 0, LRU_ACTIVE_FILE))
+ return true;
+ if (noswap || !total_swap_pages)
+ return false;
+ if (mem_cgroup_get_zonestat_node(mem, 0, LRU_INACTIVE_ANON))
+ return true;
+ if (mem_cgroup_get_zonestat_node(mem, 0, LRU_ACTIVE_ANON))
+ return true;
+ return false;
+}
#endif


@@ -1811,7 +1834,7 @@ again:

while (visit--) {
victim = mem_cgroup_select_victim(root_mem);
- if (!mem_cgroup_local_usage(victim)) {
+ if (!mem_cgroup_reclaimable(victim, noswap)) {
/* this cgroup's local usage == 0 */
css_put(&victim->css);
continue;

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/