Skip to content

Commit 4d1c627

Browse files
Daisuke Nishimuratorvalds
authored andcommitted
memcg: make oom less frequently
In previous implementation, mem_cgroup_try_charge checked the return value of mem_cgroup_try_to_free_pages, and just retried if some pages had been reclaimed. But now, try_charge(and mem_cgroup_hierarchical_reclaim called from it) only checks whether the usage is less than the limit. This patch tries to change the behavior as before to cause oom less frequently. Signed-off-by: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp> Acked-by: Balbir Singh <balbir@linux.vnet.ibm.com> Acked-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Cc: Pavel Emelyanov <xemul@openvz.org> Cc: Li Zefan <lizf@cn.fujitsu.com> Cc: Paul Menage <menage@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent c268e99 commit 4d1c627

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

‎mm/memcontrol.c‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -773,10 +773,10 @@ static int mem_cgroup_hierarchical_reclaim(struct mem_cgroup *root_mem,
773773
* but there might be left over accounting, even after children
774774
* have left.
775775
*/
776-
ret = try_to_free_mem_cgroup_pages(root_mem, gfp_mask, noswap,
776+
ret += try_to_free_mem_cgroup_pages(root_mem, gfp_mask, noswap,
777777
get_swappiness(root_mem));
778778
if (mem_cgroup_check_under_limit(root_mem))
779-
return 0;
779+
return 1; /* indicate reclaim has succeeded */
780780
if (!root_mem->use_hierarchy)
781781
return ret;
782782

@@ -787,10 +787,10 @@ static int mem_cgroup_hierarchical_reclaim(struct mem_cgroup *root_mem,
787787
next_mem = mem_cgroup_get_next_node(root_mem);
788788
continue;
789789
}
790-
ret = try_to_free_mem_cgroup_pages(next_mem, gfp_mask, noswap,
790+
ret += try_to_free_mem_cgroup_pages(next_mem, gfp_mask, noswap,
791791
get_swappiness(next_mem));
792792
if (mem_cgroup_check_under_limit(root_mem))
793-
return 0;
793+
return 1; /* indicate reclaim has succeeded */
794794
next_mem = mem_cgroup_get_next_node(root_mem);
795795
}
796796
return ret;
@@ -875,6 +875,8 @@ static int __mem_cgroup_try_charge(struct mm_struct *mm,
875875

876876
ret = mem_cgroup_hierarchical_reclaim(mem_over_limit, gfp_mask,
877877
noswap);
878+
if (ret)
879+
continue;
878880

879881
/*
880882
* try_to_free_mem_cgroup_pages() might not give us a full

0 commit comments

Comments
 (0)