Skip to content

Commit 1836522

Browse files
Michal Hockotorvalds
authored andcommitted
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 0a31bc9 ("mm: memcontrol: rewrite uncharge API")). Each charge pins memcg (since e8ea14c ("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. [akpm@linux-foundation.org: coding-style fixes] Fixes: 0a31bc9 ("mm: memcontrol: rewrite uncharge API") Link: http://lkml.kernel.org/r/20170502185507.GB19165@dhcp22.suse.cz Signed-off-by: Michal Hocko <mhocko@suse.com> Reported-by: Laurent Dufour <ldufour@linux.vnet.ibm.com> Tested-by: Laurent Dufour <ldufour@linux.vnet.ibm.com> Reviewed-by: Balbir Singh <bsingharora@gmail.com> Reviewed-by: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent deac842 commit 1836522

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

mm/memcontrol.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5528,7 +5528,7 @@ static void uncharge_list(struct list_head *page_list)
55285528
next = page->lru.next;
55295529

55305530
VM_BUG_ON_PAGE(PageLRU(page), page);
5531-
VM_BUG_ON_PAGE(page_count(page), page);
5531+
VM_BUG_ON_PAGE(!PageHWPoison(page) && page_count(page), page);
55325532

55335533
if (!page->mem_cgroup)
55345534
continue;

mm/memory-failure.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,13 @@ static int delete_from_lru_cache(struct page *p)
539539
*/
540540
ClearPageActive(p);
541541
ClearPageUnevictable(p);
542+
543+
/*
544+
* Poisoned page might never drop its ref count to 0 so we have
545+
* to uncharge it manually from its memcg.
546+
*/
547+
mem_cgroup_uncharge(p);
548+
542549
/*
543550
* drop the page count elevated by isolate_lru_page()
544551
*/

0 commit comments

Comments
 (0)