diff options
author | Andi Kleen <andi@firstfloor.org> | 2009-12-16 06:19:59 -0500 |
---|---|---|
committer | Andi Kleen <ak@linux.intel.com> | 2009-12-16 06:19:59 -0500 |
commit | 4fd466eb46a6a917c317a87fb94bfc7252a0f7ed (patch) | |
tree | 003b28724241a22a41dc9ae067f30beadbf76e6a /mm/memory-failure.c | |
parent | d324236b3333e87c8825b35f2104184734020d35 (diff) |
HWPOISON: add memory cgroup filter
The hwpoison test suite need to inject hwpoison to a collection of
selected task pages, and must not touch pages not owned by them and
thus kill important system processes such as init. (But it's OK to
mis-hwpoison free/unowned pages as well as shared clean pages.
Mis-hwpoison of shared dirty pages will kill all tasks, so the test
suite will target all or non of such tasks in the first place.)
The memory cgroup serves this purpose well. We can put the target
processes under the control of a memory cgroup, and tell the hwpoison
injection code to only kill pages associated with some active memory
cgroup.
The prerequisite for doing hwpoison stress tests with mem_cgroup is,
the mem_cgroup code tracks task pages _accurately_ (unless page is
locked). Which we believe is/should be true.
The benefits are simplification of hwpoison injector code. Also the
mem_cgroup code will automatically be tested by hwpoison test cases.
The alternative interfaces pin-pfn/unpin-pfn can also delegate the
(process and page flags) filtering functions reliably to user space.
However prototype implementation shows that this scheme adds more
complexity than we wanted.
Example test case:
mkdir /cgroup/hwpoison
usemem -m 100 -s 1000 &
echo `jobs -p` > /cgroup/hwpoison/tasks
memcg_ino=$(ls -id /cgroup/hwpoison | cut -f1 -d' ')
echo $memcg_ino > /debug/hwpoison/corrupt-filter-memcg
page-types -p `pidof init` --hwpoison # shall do nothing
page-types -p `pidof usemem` --hwpoison # poison its pages
[AK: Fix documentation]
[Add fix for problem noticed by Li Zefan <lizf@cn.fujitsu.com>;
dentry in the css could be NULL]
CC: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
CC: Hugh Dickins <hugh.dickins@tiscali.co.uk>
CC: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>
CC: Balbir Singh <balbir@linux.vnet.ibm.com>
CC: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
CC: Li Zefan <lizf@cn.fujitsu.com>
CC: Paul Menage <menage@google.com>
CC: Nick Piggin <npiggin@suse.de>
CC: Andi Kleen <andi@firstfloor.org>
Signed-off-by: Wu Fengguang <fengguang.wu@intel.com>
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Diffstat (limited to 'mm/memory-failure.c')
-rw-r--r-- | mm/memory-failure.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 22d2b2028e54..117ef1598469 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c | |||
@@ -100,6 +100,49 @@ static int hwpoison_filter_flags(struct page *p) | |||
100 | return -EINVAL; | 100 | return -EINVAL; |
101 | } | 101 | } |
102 | 102 | ||
103 | /* | ||
104 | * This allows stress tests to limit test scope to a collection of tasks | ||
105 | * by putting them under some memcg. This prevents killing unrelated/important | ||
106 | * processes such as /sbin/init. Note that the target task may share clean | ||
107 | * pages with init (eg. libc text), which is harmless. If the target task | ||
108 | * share _dirty_ pages with another task B, the test scheme must make sure B | ||
109 | * is also included in the memcg. At last, due to race conditions this filter | ||
110 | * can only guarantee that the page either belongs to the memcg tasks, or is | ||
111 | * a freed page. | ||
112 | */ | ||
113 | #ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP | ||
114 | u64 hwpoison_filter_memcg; | ||
115 | EXPORT_SYMBOL_GPL(hwpoison_filter_memcg); | ||
116 | static int hwpoison_filter_task(struct page *p) | ||
117 | { | ||
118 | struct mem_cgroup *mem; | ||
119 | struct cgroup_subsys_state *css; | ||
120 | unsigned long ino; | ||
121 | |||
122 | if (!hwpoison_filter_memcg) | ||
123 | return 0; | ||
124 | |||
125 | mem = try_get_mem_cgroup_from_page(p); | ||
126 | if (!mem) | ||
127 | return -EINVAL; | ||
128 | |||
129 | css = mem_cgroup_css(mem); | ||
130 | /* root_mem_cgroup has NULL dentries */ | ||
131 | if (!css->cgroup->dentry) | ||
132 | return -EINVAL; | ||
133 | |||
134 | ino = css->cgroup->dentry->d_inode->i_ino; | ||
135 | css_put(css); | ||
136 | |||
137 | if (ino != hwpoison_filter_memcg) | ||
138 | return -EINVAL; | ||
139 | |||
140 | return 0; | ||
141 | } | ||
142 | #else | ||
143 | static int hwpoison_filter_task(struct page *p) { return 0; } | ||
144 | #endif | ||
145 | |||
103 | int hwpoison_filter(struct page *p) | 146 | int hwpoison_filter(struct page *p) |
104 | { | 147 | { |
105 | if (hwpoison_filter_dev(p)) | 148 | if (hwpoison_filter_dev(p)) |
@@ -108,6 +151,9 @@ int hwpoison_filter(struct page *p) | |||
108 | if (hwpoison_filter_flags(p)) | 151 | if (hwpoison_filter_flags(p)) |
109 | return -EINVAL; | 152 | return -EINVAL; |
110 | 153 | ||
154 | if (hwpoison_filter_task(p)) | ||
155 | return -EINVAL; | ||
156 | |||
111 | return 0; | 157 | return 0; |
112 | } | 158 | } |
113 | EXPORT_SYMBOL_GPL(hwpoison_filter); | 159 | EXPORT_SYMBOL_GPL(hwpoison_filter); |