Commit 18365225 authored by Michal Hocko's avatar Michal Hocko Committed by Linus Torvalds
Browse files

hwpoison, memcg: forcibly uncharge LRU pages

Laurent Dufour has noticed that hwpoinsoned pages are kept charged.  In
his particular case he has hit a bad_page("page still charged to
cgroup") when onlining a hwpoison page.  While this looks like something
that shouldn't happen in the first place because onlining hwpages and
returning them to the page allocator makes only little sense it shows a
real problem.

hwpoison pages do not get freed usually so we do not uncharge them (at
least not since commit 0a31bc97 ("mm: memcontrol: rewrite uncharge
API")).  Each charge pins memcg (since e8ea14cc ("mm: memcontrol:
take a css reference for each charged page")) as well and so the
mem_cgroup and the associated state will never go away.  Fix this leak
by forcibly uncharging a LRU hwpoisoned page in delete_from_lru_cache().
We also have to tweak uncharge_list because it cannot rely on zero ref
count for these pages.

[ coding-style fixes]
Fixes: 0a31bc97 ("mm: memcontrol: rewrite uncharge API")

Signed-off-by: default avatarMichal Hocko <>
Reported-by: default avatarLaurent Dufour <>
Tested-by: default avatarLaurent Dufour <>
Reviewed-by: default avatarBalbir Singh <>
Reviewed-by: default avatarNaoya Horiguchi <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
parent deac8429
...@@ -5528,7 +5528,7 @@ static void uncharge_list(struct list_head *page_list) ...@@ -5528,7 +5528,7 @@ static void uncharge_list(struct list_head *page_list)
next = page->; next = page->;
VM_BUG_ON_PAGE(PageLRU(page), page); VM_BUG_ON_PAGE(PageLRU(page), page);
VM_BUG_ON_PAGE(page_count(page), page); VM_BUG_ON_PAGE(!PageHWPoison(page) && page_count(page), page);
if (!page->mem_cgroup) if (!page->mem_cgroup)
continue; continue;
...@@ -539,6 +539,13 @@ static int delete_from_lru_cache(struct page *p) ...@@ -539,6 +539,13 @@ static int delete_from_lru_cache(struct page *p)
*/ */
ClearPageActive(p); ClearPageActive(p);
ClearPageUnevictable(p); ClearPageUnevictable(p);
* Poisoned page might never drop its ref count to 0 so we have
* to uncharge it manually from its memcg.
/* /*
* drop the page count elevated by isolate_lru_page() * drop the page count elevated by isolate_lru_page()
*/ */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment