A few fixup patches for memory failure
Subsystems (2)
Miaohe Lin
maintainerv4 cover A few fixup patches for memory failure
Hi everyone,
This series contains a patch to avoid calling invalidate_inode_page() with unexpected pages and another one to make non-LRU movable pages unhandlable. More details can be found in the respective changelogs. Thanks!
---v3->v4:
fix typo and drop "bool movable" per David. Thanks David.v2->v3:
drop patch "mm/memory-failure.c: fix race with changing page compound again" collect reviewed-by and acked-by tag
fix stale commit id in the commit logv1->v2:
drop "mm/memory-failure.c: fix wrong user reference report" make non-LRU movable pages unhandlable
fix confusing commit log and introduce MF_MSG_DIFFERENT_PAGE_SIZE Many thanks Naoya, Mike and Yang Shi for review!
---
Miaohe Lin (2):
mm/memory-failure.c: avoid calling invalidate_inode_page() with
unexpected pages
mm/memory-failure.c: make non-LRU movable pages unhandlable
mm/memory-failure.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-)
Signature · 1 line
2.23.0
Miaohe Lin
maintainerPATCH v4 1/2 mm/memory-failure.c: avoid calling invalidate_inode_page() with unexpected pages
invalidate_inode_page() can invalidate the pages in the swap cache because the check of page->mapping != mapping is removed via Matthew's patch titled "mm/truncate: Inline invalidate_complete_page() into its one caller". But invalidate_inode_page() is not expected to deal with the pages in the swap cache. Also non-lru movable page can reach here too. They're not page cache pages. Skip these pages by checking PageSwapCache and PageLRU to fix this unexpected issue.
--- mm/memory-failure.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/memory-failure.c +1 -1
@@ -2178,7 +2178,7 @@ static int __soft_offline_page(struct page *page)return 0 ; } -if (!PageHuge (page)) +if (!PageHuge (page) &&PageLRU (page) && !PageSwapCache (page))/* * Try to invalidate first. This should work for * non dirty unmapped page cache pages.
Signature · 1 line
2.23.0
Re: [PATCH v4 1/2] mm/memory-failure.c: avoid calling invalidate_inode_page() with unexpected pages
Quoted 7 lines · Miaohe Lin
invalidate_inode_page()can invalidate the pages in the swap cache because the check ofpage->mapping!= mapping is removed via Matthew's patch titled "mm/truncate: Inlineinvalidate_complete_page()into its one caller". Butinvalidate_inode_page()is not expected to deal with the pages in the swap cache. Also non-lru movable page can reach here too. They're not page cache pages. Skip these pages by checking PageSwapCache and PageLRU to fix this unexpected issue.
I disagree with this changelog.
invalidate_inode_page() should not be called for pages which are not in the page cache.
And then the patch shouldn't test PageLRU (which is actually wrong) or PageSwapCache(). It should simply be:
+ if (!PageHuge(page) && !PageAnon(page))
Quoted 22 lines
Signed-off-by Miaohe Lin <[email protected]>--- mm/memory-failure.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/memory-failure.c +1
-1@@ -2178,7 +2178,7 @@ static int __soft_offline_page(struct page *page)return 0 ; } -if (!PageHuge (page)) +if (!PageHuge (page) &&PageLRU (page) && !PageSwapCache (page))/* * Try to invalidate first. This should work for * non dirty unmapped page cache pages. Signature · 1 line
2.23.0
Miaohe Lin
maintainerRe: [PATCH v4 1/2] mm/memory-failure.c: avoid calling invalidate_inode_page() with unexpected pages
Quoted 9 lines · Matthew Wilcox
Quoted 7 lines · Miaohe Lin
invalidate_inode_page()can invalidate the pages in the swap cache because the check ofpage->mapping!= mapping is removed via Matthew's patch titled "mm/truncate: Inlineinvalidate_complete_page()into its one caller". Butinvalidate_inode_page()is not expected to deal with the pages in the swap cache. Also non-lru movable page can reach here too. They're not page cache pages. Skip these pages by checking PageSwapCache and PageLRU to fix this unexpected issue.
Quoted 8 lines
I disagree with this changelog.
invalidate_inode_page()should not be called for pages which are not in the page cache.And then the patch shouldn't test PageLRU (which is actually wrong) or
PageSwapCache(). It should simply be:Review
Quoted 1 line
(quoted diff) +1
-0+ if (!PageHuge(page) && !PageAnon(page))
If we reach here, the page can be one of the PageHuge, __PageMovable and PageLRU. If above code is used, __PageMovable can pass the check and enter the invalidate_inode_page unexpectedly. So I think PageLRU check is necessary here. But it seems PageSwapCache is only reliable when PageAnon, so might we should do:
+ if (!PageHuge(page) && PageLRU(page) && !PageAnon(page))
Am I miss something? Many thanks for comment.
Quoted 26 lines
Quoted 23 lines
Signed-off-by Miaohe Lin <[email protected]>--- mm/memory-failure.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)mm/memory-failure.c +1
-1@@ -2178,7 +2178,7 @@ static int __soft_offline_page(struct page *page)return 0 ; } -if (!PageHuge (page)) +if (!PageHuge (page) &&PageLRU (page) && !PageSwapCache (page))/* * Try to invalidate first. This should work for * non dirty unmapped page cache pages. Signature · 1 line
2.23.0.
Miaohe Lin
maintainerPATCH v4 2/2 mm/memory-failure.c: make non-LRU movable pages unhandlable
In reply to Miaohe LinWe can not really handle non-LRU movable pages in memory failure. Typically they are balloon, zsmalloc, etc. Assuming we run into a base (4K) non-LRU movable page, we could reach as far as identify_page_state(), it should not fall into any category except me_unknown. For the non-LRU compound movable pages, they could be taken for transhuge pages but it's unexpected to split non-LRU movable pages using split_huge_page_to_list in memory_failure. So we could just simply make non-LRU movable pages unhandlable to avoid these possible nasty cases.
--- mm/memory-failure.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
mm/memory-failure.c +11 -7
@@ -1176,12 +1176,16 @@ void ClearPageHWPoisonTakenOff(struct page *page)* does not return true for hugetlb or device memory pages, so it's assumed * to be called only in the context where we never have such pages. */ -static inline bool HWPoisonHandlable (struct page *page) +static inline bool HWPoisonHandlable (struct page *page,unsigned long flags) { -return PageLRU (page) ||__PageMovable (page) ||is_free_buddy_page (page); +/* Soft offline could migrate non-LRU movable pages. */ +if ((flags &MF_SOFT_OFFLINE ) &&__PageMovable (page)) +return true; + +return PageLRU (page) ||is_free_buddy_page (page); } -static int __get_hwpoison_page (struct page *page) +static int __get_hwpoison_page (struct page *page,unsigned long flags) {struct page *head =compound_head (page);int ret =0 ;
@@ -1196,7 +1200,7 @@ static int __get_hwpoison_page(struct page *page)* for any unsupported type of page in order to reduce the risk of * unexpected races caused by taking a page refcount. */ -if (!HWPoisonHandlable (head)) +if (!HWPoisonHandlable (head, flags))return -EBUSY ;if (get_page_unless_zero (head)) {
@@ -1221,7 +1225,7 @@ static int get_any_page(struct page *p, unsigned long flags) try_again:if (!count_increased) { - ret =__get_hwpoison_page (p); + ret =__get_hwpoison_page (p, flags);if (!ret) {if (page_count (p)) {/* We raced with an allocation, retry. */
@@ -1249,7 +1253,7 @@ static int get_any_page(struct page *p, unsigned long flags) } } -if (PageHuge (p) ||HWPoisonHandlable (p)) { +if (PageHuge (p) ||HWPoisonHandlable (p, flags)) { ret =1 ; }else {/*
@@ -2296,7 +2300,7 @@ int soft_offline_page(unsigned long pfn, int flags) retry:get_online_mems (); - ret =get_hwpoison_page (page, flags); + ret =get_hwpoison_page (page, flags |MF_SOFT_OFFLINE );put_online_mems ();if (ret >0 ) {
Signature · 1 line
2.23.0