MCE: fix an error of mce_bad_pages statistics
Subsystems (2)
PATCH v4 2/3 MCE: fix an error of mce_bad_pages statistics
There are too many return points randomly intermingled with some "goto done" return points. So adjust the function structure, one for the success path, the other for the failure path. Use atomic_long_inc instead of atomic_long_add.
--- mm/memory-failure.c | 34 ++++++++++++++++++++-------------- 1 files changed, 20 insertions(+), 14 deletions(-)
mm/memory-failure.c +20 -14
@@ -1421,12 +1421,13 @@ static int soft_offline_huge_page(struct page *page, int flags)if (PageHWPoison (hpage)) {pr_info ("soft offline: %#lx hugepage already poisoned\n" , pfn); -return -EBUSY ; + ret = -EBUSY ; + goto out; } ret =get_any_page (page, pfn, flags);if (ret <0 ) -return ret; + goto out;if (ret ==0 ) goto done;
@@ -1437,14 +1438,14 @@ static int soft_offline_huge_page(struct page *page, int flags)if (ret) {pr_info ("soft offline: %#lx: migration failed %d, type %lx\n" , pfn, ret, page->flags); -return ret; + goto out; } done:/* keep elevated page count for bad page */ atomic_long_add (1 <<compound_trans_order (hpage), &mce_bad_pages);set_page_hwpoison_huge_page (hpage);dequeue_hwpoisoned_huge_page (hpage); - +out:return ret; }
@@ -1476,24 +1477,28 @@ int soft_offline_page(struct page *page, int flags)unsigned long pfn =page_to_pfn (page);struct page *hpage =compound_trans_head (page); -if (PageHuge (page)) -return soft_offline_huge_page (page, flags); +if (PageHuge (page)) { + ret =soft_offline_huge_page (page, flags); + goto out; + }if (PageTransHuge (hpage)) {if (PageAnon (hpage) &&unlikely (split_huge_page (hpage))) {pr_info ("soft offline: %#lx: failed to split THP\n" , pfn); -return -EBUSY ; + ret = -EBUSY ; + goto out; } }if (PageHWPoison (page)) {pr_info ("soft offline: %#lx page already poisoned\n" , pfn); -return -EBUSY ; + ret = -EBUSY ; + goto out; } ret =get_any_page (page, pfn, flags);if (ret <0 ) -return ret; + goto out;if (ret ==0 ) goto done;
@@ -1512,14 +1517,15 @@ int soft_offline_page(struct page *page, int flags)*/ ret =get_any_page (page, pfn,0 );if (ret <0 ) -return ret; + goto out;if (ret ==0 ) goto done; }if (!PageLRU (page)) {pr_info ("soft_offline: %#lx: unknown non LRU page type %lx\n" , pfn, page->flags); -return -EIO ; + ret = -EIO ; + goto out; }/*
@@ -1574,12 +1580,12 @@ int soft_offline_page(struct page *page, int flags) pfn, ret, page_count(page), page->flags); }if (ret) -return ret; + goto out; done:/* keep elevated page count for bad page */ -atomic_long_add (1 , &mce_bad_pages); +atomic_long_inc (&mce_bad_pages);SetPageHWPoison (page); - +out:return ret; }
Signature · 8 lines
1.7.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
mm/memory-failure.c static int soft_offline_huge_page(struct page *page, int flags) · line 1425
Quoted 5 lines
mm/memory-failure.c +2
-1if (PageHWPoison (hpage)) {pr_info ("soft offline: %#lx hugepage already poisoned\n" , pfn); -return -EBUSY ; + ret = -EBUSY ; + goto out;
Doesn't look like a code improvement to me. Single return is easier and simpler.
-Andi
Quoted 7 lines
mm/memory-failure.c +1
-0+out:return ret; }Signature · 1 line
1.7.1
Signature · 7 lines
[email protected] -- Speaking for myself only. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH RESEND v4 2/3 MCE: do code refactor of soft_offline_page
In reply to Xishi QiuThere are too many return points randomly intermingled with some "goto done" return points. So adjust the function structure, one for the success path, the other for the failure path. Use atomic_long_inc instead of atomic_long_add.
--- mm/memory-failure.c | 34 ++++++++++++++++++++-------------- 1 files changed, 20 insertions(+), 14 deletions(-)
mm/memory-failure.c +20 -14
@@ -1421,12 +1421,13 @@ static int soft_offline_huge_page(struct page *page, int flags)if (PageHWPoison (hpage)) {pr_info ("soft offline: %#lx hugepage already poisoned\n" , pfn); -return -EBUSY ; + ret = -EBUSY ; + goto out; } ret =get_any_page (page, pfn, flags);if (ret <0 ) -return ret; + goto out;if (ret ==0 ) goto done;
@@ -1437,14 +1438,14 @@ static int soft_offline_huge_page(struct page *page, int flags)if (ret) {pr_info ("soft offline: %#lx: migration failed %d, type %lx\n" , pfn, ret, page->flags); -return ret; + goto out; } done:/* keep elevated page count for bad page */ atomic_long_add (1 <<compound_trans_order (hpage), &mce_bad_pages);set_page_hwpoison_huge_page (hpage);dequeue_hwpoisoned_huge_page (hpage); - +out:return ret; }
@@ -1476,24 +1477,28 @@ int soft_offline_page(struct page *page, int flags)unsigned long pfn =page_to_pfn (page);struct page *hpage =compound_trans_head (page); -if (PageHuge (page)) -return soft_offline_huge_page (page, flags); +if (PageHuge (page)) { + ret =soft_offline_huge_page (page, flags); + goto out; + }if (PageTransHuge (hpage)) {if (PageAnon (hpage) &&unlikely (split_huge_page (hpage))) {pr_info ("soft offline: %#lx: failed to split THP\n" , pfn); -return -EBUSY ; + ret = -EBUSY ; + goto out; } }if (PageHWPoison (page)) {pr_info ("soft offline: %#lx page already poisoned\n" , pfn); -return -EBUSY ; + ret = -EBUSY ; + goto out; } ret =get_any_page (page, pfn, flags);if (ret <0 ) -return ret; + goto out;if (ret ==0 ) goto done;
@@ -1512,14 +1517,15 @@ int soft_offline_page(struct page *page, int flags)*/ ret =get_any_page (page, pfn,0 );if (ret <0 ) -return ret; + goto out;if (ret ==0 ) goto done; }if (!PageLRU (page)) {pr_info ("soft_offline: %#lx: unknown non LRU page type %lx\n" , pfn, page->flags); -return -EIO ; + ret = -EIO ; + goto out; }/*
@@ -1574,12 +1580,12 @@ int soft_offline_page(struct page *page, int flags) pfn, ret, page_count(page), page->flags); }if (ret) -return ret; + goto out; done:/* keep elevated page count for bad page */ -atomic_long_add (1 , &mce_bad_pages); +atomic_long_inc (&mce_bad_pages);SetPageHWPoison (page); - +out:return ret; }
Signature · 12 lines
1.7.1 . -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>