]> git.hungrycats.org Git - linux/commitdiff
hwpoison, memcg: forcibly uncharge LRU pages
authorMichal Hocko <mhocko@suse.com>
Fri, 12 May 2017 22:46:26 +0000 (15:46 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 31 Jan 2018 13:46:13 +0000 (14:46 +0100)
commit 18365225f0440d09708ad9daade2ec11275c3df9 upstream.

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 0a31bc97c80c ("mm: memcontrol: rewrite uncharge
API")).  Each charge pins memcg (since e8ea14cc6ead ("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: 0a31bc97c80c ("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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
mm/memcontrol.c
mm/memory-failure.c

index 0afd8444a8d64b2a10ac35bcabaf7bc7571e6654..8f5496b6823d4712a29a44518b228f62c35e7393 100644 (file)
@@ -6500,7 +6500,7 @@ static void uncharge_list(struct list_head *page_list)
                next = page->lru.next;
 
                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);
 
                pc = lookup_page_cgroup(page);
                if (!PageCgroupUsed(pc))
index e14e75754154f4e03cc8111dfbb1f85fea5c20a8..003e434361f2eccd1a60666d0c52efbceed7bcc4 100644 (file)
@@ -548,6 +548,13 @@ static int delete_from_lru_cache(struct page *p)
                 */
                ClearPageActive(p);
                ClearPageUnevictable(p);
+
+               /*
+                * Poisoned page might never drop its ref count to 0 so we have
+                * to uncharge it manually from its memcg.
+                */
+               mem_cgroup_uncharge(p);
+
                /*
                 * drop the page count elevated by isolate_lru_page()
                 */