Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

memcg: fix a race when setting memory.swappiness

(suppose: memcg->use_hierarchy == 0 and memcg->swappiness == 60)

echo 10 > /memcg/0/swappiness |
mem_cgroup_swappiness_write() |
... | echo 1 > /memcg/0/use_hierarchy
| mkdir /mnt/0/1
| sub_memcg->swappiness = 60;
memcg->swappiness = 10; |

In the above scenario, we end up having 2 different swappiness
values in a single hierarchy.

We should hold cgroup_lock() when cheking cgrp->children list.

Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Acked-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Balbir Singh <balbir@in.ibm.com>
Cc: Paul Menage <menage@google.com>
Cc: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Li Zefan and committed by
Linus Torvalds
068b38c1 0eb253e2

+9 -1
+9 -1
mm/memcontrol.c
··· 1992 1992 { 1993 1993 struct mem_cgroup *memcg = mem_cgroup_from_cont(cgrp); 1994 1994 struct mem_cgroup *parent; 1995 + 1995 1996 if (val > 100) 1996 1997 return -EINVAL; 1997 1998 ··· 2000 1999 return -EINVAL; 2001 2000 2002 2001 parent = mem_cgroup_from_cont(cgrp->parent); 2002 + 2003 + cgroup_lock(); 2004 + 2003 2005 /* If under hierarchy, only empty-root can set this value */ 2004 2006 if ((parent->use_hierarchy) || 2005 - (memcg->use_hierarchy && !list_empty(&cgrp->children))) 2007 + (memcg->use_hierarchy && !list_empty(&cgrp->children))) { 2008 + cgroup_unlock(); 2006 2009 return -EINVAL; 2010 + } 2007 2011 2008 2012 spin_lock(&memcg->reclaim_param_lock); 2009 2013 memcg->swappiness = val; 2010 2014 spin_unlock(&memcg->reclaim_param_lock); 2015 + 2016 + cgroup_unlock(); 2011 2017 2012 2018 return 0; 2013 2019 }