aboutsummaryrefslogtreecommitdiffstats
path: root/mm/memory-failure.c
diff options
context:
space:
mode:
authorXishi Qiu <qiuxishi@huawei.com>2013-02-22 19:34:00 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2013-02-23 20:50:15 -0500
commitfa8dd8a92dccc1b29cefd7f51334285d6ed35281 (patch)
tree3fcb74a3164d9f6f9cfed8c81b526916cf2bbdfb /mm/memory-failure.c
parent0ebff32c3637e0ed551c017eb9599ac108ab36aa (diff)
memory-failure: do code refactor of soft_offline_page()
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. Signed-off-by: Xishi Qiu <qiuxishi@huawei.com> Signed-off-by: Jiang Liu <jiang.liu@huawei.com> Suggested-by: Andrew Morton <akpm@linux-foundation.org> Cc: Borislav Petkov <bp@alien8.de> Cc: Wanpeng Li <liwanp@linux.vnet.ibm.com> Cc: Andi Kleen <andi@firstfloor.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/memory-failure.c')
-rw-r--r--mm/memory-failure.c34
1 files changed, 20 insertions, 14 deletions
diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index 1a9242c53315..f4c9fa1149e2 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -1421,12 +1421,13 @@ static int soft_offline_huge_page(struct page *page, int flags)
1421 1421
1422 if (PageHWPoison(hpage)) { 1422 if (PageHWPoison(hpage)) {
1423 pr_info("soft offline: %#lx hugepage already poisoned\n", pfn); 1423 pr_info("soft offline: %#lx hugepage already poisoned\n", pfn);
1424 return -EBUSY; 1424 ret = -EBUSY;
1425 goto out;
1425 } 1426 }
1426 1427
1427 ret = get_any_page(page, pfn, flags); 1428 ret = get_any_page(page, pfn, flags);
1428 if (ret < 0) 1429 if (ret < 0)
1429 return ret; 1430 goto out;
1430 if (ret == 0) 1431 if (ret == 0)
1431 goto done; 1432 goto done;
1432 1433
@@ -1437,14 +1438,14 @@ static int soft_offline_huge_page(struct page *page, int flags)
1437 if (ret) { 1438 if (ret) {
1438 pr_info("soft offline: %#lx: migration failed %d, type %lx\n", 1439 pr_info("soft offline: %#lx: migration failed %d, type %lx\n",
1439 pfn, ret, page->flags); 1440 pfn, ret, page->flags);
1440 return ret; 1441 goto out;
1441 } 1442 }
1442done: 1443done:
1443 /* keep elevated page count for bad page */ 1444 /* keep elevated page count for bad page */
1444 atomic_long_add(1 << compound_trans_order(hpage), &mce_bad_pages); 1445 atomic_long_add(1 << compound_trans_order(hpage), &mce_bad_pages);
1445 set_page_hwpoison_huge_page(hpage); 1446 set_page_hwpoison_huge_page(hpage);
1446 dequeue_hwpoisoned_huge_page(hpage); 1447 dequeue_hwpoisoned_huge_page(hpage);
1447 1448out:
1448 return ret; 1449 return ret;
1449} 1450}
1450 1451
@@ -1476,24 +1477,28 @@ int soft_offline_page(struct page *page, int flags)
1476 unsigned long pfn = page_to_pfn(page); 1477 unsigned long pfn = page_to_pfn(page);
1477 struct page *hpage = compound_trans_head(page); 1478 struct page *hpage = compound_trans_head(page);
1478 1479
1479 if (PageHuge(page)) 1480 if (PageHuge(page)) {
1480 return soft_offline_huge_page(page, flags); 1481 ret = soft_offline_huge_page(page, flags);
1482 goto out;
1483 }
1481 if (PageTransHuge(hpage)) { 1484 if (PageTransHuge(hpage)) {
1482 if (PageAnon(hpage) && unlikely(split_huge_page(hpage))) { 1485 if (PageAnon(hpage) && unlikely(split_huge_page(hpage))) {
1483 pr_info("soft offline: %#lx: failed to split THP\n", 1486 pr_info("soft offline: %#lx: failed to split THP\n",
1484 pfn); 1487 pfn);
1485 return -EBUSY; 1488 ret = -EBUSY;
1489 goto out;
1486 } 1490 }
1487 } 1491 }
1488 1492
1489 if (PageHWPoison(page)) { 1493 if (PageHWPoison(page)) {
1490 pr_info("soft offline: %#lx page already poisoned\n", pfn); 1494 pr_info("soft offline: %#lx page already poisoned\n", pfn);
1491 return -EBUSY; 1495 ret = -EBUSY;
1496 goto out;
1492 } 1497 }
1493 1498
1494 ret = get_any_page(page, pfn, flags); 1499 ret = get_any_page(page, pfn, flags);
1495 if (ret < 0) 1500 if (ret < 0)
1496 return ret; 1501 goto out;
1497 if (ret == 0) 1502 if (ret == 0)
1498 goto done; 1503 goto done;
1499 1504
@@ -1512,14 +1517,15 @@ int soft_offline_page(struct page *page, int flags)
1512 */ 1517 */
1513 ret = get_any_page(page, pfn, 0); 1518 ret = get_any_page(page, pfn, 0);
1514 if (ret < 0) 1519 if (ret < 0)
1515 return ret; 1520 goto out;
1516 if (ret == 0) 1521 if (ret == 0)
1517 goto done; 1522 goto done;
1518 } 1523 }
1519 if (!PageLRU(page)) { 1524 if (!PageLRU(page)) {
1520 pr_info("soft_offline: %#lx: unknown non LRU page type %lx\n", 1525 pr_info("soft_offline: %#lx: unknown non LRU page type %lx\n",
1521 pfn, page->flags); 1526 pfn, page->flags);
1522 return -EIO; 1527 ret = -EIO;
1528 goto out;
1523 } 1529 }
1524 1530
1525 /* 1531 /*
@@ -1575,12 +1581,12 @@ int soft_offline_page(struct page *page, int flags)
1575 pfn, ret, page_count(page), page->flags); 1581 pfn, ret, page_count(page), page->flags);
1576 } 1582 }
1577 if (ret) 1583 if (ret)
1578 return ret; 1584 goto out;
1579 1585
1580done: 1586done:
1581 /* keep elevated page count for bad page */ 1587 /* keep elevated page count for bad page */
1582 atomic_long_add(1, &mce_bad_pages); 1588 atomic_long_inc(&mce_bad_pages);
1583 SetPageHWPoison(page); 1589 SetPageHWPoison(page);
1584 1590out:
1585 return ret; 1591 return ret;
1586} 1592}