All of lore.kernel.org
 help / color / mirror / Atom feed
From: Naoya Horiguchi <naoya.horiguchi@linux.dev>
To: Miaohe Lin <linmiaohe@huawei.com>,
	Mike Kravetz <mike.kravetz@oracle.com>,
	"linux-mm@kvack.org" <linux-mm@kvack.org>,
	Andrew Morton <akpm@linux-foundation.org>
Cc: Yang Shi <shy828301@gmail.com>,
	Dan Carpenter <dan.carpenter@oracle.com>,
	naoya.horiguchi@nec.com,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: [PATCH 4/3] mm, hugetlb, hwpoison: separate branch for free and in-use hugepage
Date: Fri, 15 Apr 2022 13:18:48 +0900	[thread overview]
Message-ID: <20220415041848.GA3034499@ik1-406-35019.vs.sakura.ne.jp> (raw)
In-Reply-To: <20220415021233.GA3357039@hori.linux.bs1.fc.nec.co.jp>

From: Naoya Horiguchi <naoya.horiguchi@nec.com>

We know that HPageFreed pages should have page refcount 0, so
get_page_unless_zero() always fails and returns 0.  So explicitly separate
the branch based on page state for minor optimization and better readability.

Suggested-by: Mike Kravetz <mike.kravetz@oracle.com>
Suggested-by: Miaohe Lin <linmiaohe@huawei.com>
Signed-off-by: Naoya Horiguchi <naoya.horiguchi@nec.com>
---
 mm/hugetlb.c        | 4 +++-
 mm/memory-failure.c | 4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index e38cbfdf3e61..3638f166e554 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -6786,7 +6786,9 @@ int get_hwpoison_huge_page(struct page *page, bool *hugetlb)
 	spin_lock_irq(&hugetlb_lock);
 	if (PageHeadHuge(page)) {
 		*hugetlb = true;
-		if (HPageFreed(page) || HPageMigratable(page))
+		if (HPageFreed(page))
+			ret = 0;
+		else if (HPageMigratable(page))
 			ret = get_page_unless_zero(page);
 		else
 			ret = -EBUSY;
diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index 5e3ad640f5bb..661079a37f29 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -1517,7 +1517,9 @@ int __get_huge_page_for_hwpoison(unsigned long pfn, int flags)
 	if (flags & MF_COUNT_INCREASED) {
 		ret = 1;
 		count_increased = true;
-	} else if (HPageFreed(head) || HPageMigratable(head)) {
+	} else if (HPageFreed(head)) {
+		ret = 0;
+	} else if (HPageMigratable(head)) {
 		ret = get_page_unless_zero(head);
 		if (ret)
 			count_increased = true;
-- 
2.23.0


  reply	other threads:[~2022-04-15  4:19 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-08 13:53 [PATCH v8 0/3] mm/hwpoison: fix race between hugetlb free/demotion and memory_failure_hugetlb() Naoya Horiguchi
2022-04-08 13:53 ` [PATCH v8 1/3] " Naoya Horiguchi
2022-04-09  2:33   ` Miaohe Lin
2022-04-14 17:56   ` Mike Kravetz
2022-04-15  1:55     ` Miaohe Lin
2022-04-15  2:12       ` HORIGUCHI NAOYA(堀口 直也)
2022-04-15  4:18         ` Naoya Horiguchi [this message]
2022-04-15 15:11           ` [PATCH 4/3] mm, hugetlb, hwpoison: separate branch for free and in-use hugepage Mike Kravetz
2022-04-16  1:06           ` Miaohe Lin
2022-04-08 13:53 ` [PATCH v8 2/3] mm/hwpoison: put page in already hwpoisoned case with MF_COUNT_INCREASED Naoya Horiguchi
2022-04-09  2:04   ` Miaohe Lin
2022-04-14 19:41   ` Mike Kravetz
2022-04-08 13:53 ` [PATCH v8 3/3] Revert "mm/memory-failure.c: fix race with changing page compound again" Naoya Horiguchi
2022-04-09  2:07   ` Miaohe Lin
2022-04-14 17:59   ` Mike Kravetz
2022-04-08 23:47 ` [PATCH v8 0/3] mm/hwpoison: fix race between hugetlb free/demotion and memory_failure_hugetlb() Andrew Morton
2022-04-09  2:31   ` Naoya Horiguchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220415041848.GA3034499@ik1-406-35019.vs.sakura.ne.jp \
    --to=naoya.horiguchi@linux.dev \
    --cc=akpm@linux-foundation.org \
    --cc=dan.carpenter@oracle.com \
    --cc=linmiaohe@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mike.kravetz@oracle.com \
    --cc=naoya.horiguchi@nec.com \
    --cc=shy828301@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.