diff options
author | Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp> | 2009-01-07 21:08:12 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-01-08 11:31:07 -0500 |
commit | b85a96c0b6cb79c67e7b01b66368f2e31579d7c5 (patch) | |
tree | 178005176284faef0f8a47293eaddd2885062f53 /mm/memcontrol.c | |
parent | f9717d28d673468883df8ac34b47268719ac5a3d (diff) |
memcg: memory swap controller: fix limit check
There are scatterd calls of res_counter_check_under_limit(), and most of
them don't take mem+swap accounting into account.
define mem_cgroup_check_under_limit() and avoid direct use of
res_counter_check_limit().
Reported-by: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>
Signed-off-by: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>
Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Balbir Singh <balbir@in.ibm.com>
Cc: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>
Cc: Hugh Dickins <hugh@veritas.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/memcontrol.c')
-rw-r--r-- | mm/memcontrol.c | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/mm/memcontrol.c b/mm/memcontrol.c index b83790083087..6ad309e9825f 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c | |||
@@ -571,6 +571,18 @@ done: | |||
571 | return ret; | 571 | return ret; |
572 | } | 572 | } |
573 | 573 | ||
574 | static bool mem_cgroup_check_under_limit(struct mem_cgroup *mem) | ||
575 | { | ||
576 | if (do_swap_account) { | ||
577 | if (res_counter_check_under_limit(&mem->res) && | ||
578 | res_counter_check_under_limit(&mem->memsw)) | ||
579 | return true; | ||
580 | } else | ||
581 | if (res_counter_check_under_limit(&mem->res)) | ||
582 | return true; | ||
583 | return false; | ||
584 | } | ||
585 | |||
574 | /* | 586 | /* |
575 | * Dance down the hierarchy if needed to reclaim memory. We remember the | 587 | * Dance down the hierarchy if needed to reclaim memory. We remember the |
576 | * last child we reclaimed from, so that we don't end up penalizing | 588 | * last child we reclaimed from, so that we don't end up penalizing |
@@ -592,7 +604,7 @@ static int mem_cgroup_hierarchical_reclaim(struct mem_cgroup *root_mem, | |||
592 | * have left. | 604 | * have left. |
593 | */ | 605 | */ |
594 | ret = try_to_free_mem_cgroup_pages(root_mem, gfp_mask, noswap); | 606 | ret = try_to_free_mem_cgroup_pages(root_mem, gfp_mask, noswap); |
595 | if (res_counter_check_under_limit(&root_mem->res)) | 607 | if (mem_cgroup_check_under_limit(root_mem)) |
596 | return 0; | 608 | return 0; |
597 | 609 | ||
598 | next_mem = mem_cgroup_get_first_node(root_mem); | 610 | next_mem = mem_cgroup_get_first_node(root_mem); |
@@ -606,7 +618,7 @@ static int mem_cgroup_hierarchical_reclaim(struct mem_cgroup *root_mem, | |||
606 | continue; | 618 | continue; |
607 | } | 619 | } |
608 | ret = try_to_free_mem_cgroup_pages(next_mem, gfp_mask, noswap); | 620 | ret = try_to_free_mem_cgroup_pages(next_mem, gfp_mask, noswap); |
609 | if (res_counter_check_under_limit(&root_mem->res)) | 621 | if (mem_cgroup_check_under_limit(root_mem)) |
610 | return 0; | 622 | return 0; |
611 | cgroup_lock(); | 623 | cgroup_lock(); |
612 | next_mem = mem_cgroup_get_next_node(next_mem, root_mem); | 624 | next_mem = mem_cgroup_get_next_node(next_mem, root_mem); |
@@ -709,12 +721,8 @@ static int __mem_cgroup_try_charge(struct mm_struct *mm, | |||
709 | * current usage of the cgroup before giving up | 721 | * current usage of the cgroup before giving up |
710 | * | 722 | * |
711 | */ | 723 | */ |
712 | if (do_swap_account) { | 724 | if (mem_cgroup_check_under_limit(mem_over_limit)) |
713 | if (res_counter_check_under_limit(&mem_over_limit->res) && | 725 | continue; |
714 | res_counter_check_under_limit(&mem_over_limit->memsw)) | ||
715 | continue; | ||
716 | } else if (res_counter_check_under_limit(&mem_over_limit->res)) | ||
717 | continue; | ||
718 | 726 | ||
719 | if (!nr_retries--) { | 727 | if (!nr_retries--) { |
720 | if (oom) { | 728 | if (oom) { |
@@ -1334,7 +1342,7 @@ int mem_cgroup_shrink_usage(struct mm_struct *mm, gfp_t gfp_mask) | |||
1334 | 1342 | ||
1335 | do { | 1343 | do { |
1336 | progress = try_to_free_mem_cgroup_pages(mem, gfp_mask, true); | 1344 | progress = try_to_free_mem_cgroup_pages(mem, gfp_mask, true); |
1337 | progress += res_counter_check_under_limit(&mem->res); | 1345 | progress += mem_cgroup_check_under_limit(mem); |
1338 | } while (!progress && --retry); | 1346 | } while (!progress && --retry); |
1339 | 1347 | ||
1340 | css_put(&mem->css); | 1348 | css_put(&mem->css); |