diff mbox series

[RFC,v2,01/16] mm,hwpoison: cleanup unused PageHuge() check

Message ID 20191017142123.24245-2-osalvador@suse.de (mailing list archive)
State New, archived
Headers show
Series Hwpoison rework {hard,soft}-offline | expand

Commit Message

Oscar Salvador Oct. 17, 2019, 2:21 p.m. UTC
From: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>

Drop the PageHuge check since memory_failure forks into memory_failure_hugetlb()
for hugetlb pages.

Signed-off-by: Oscar Salvador <osalvador@suse.de>
Signed-off-by: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
---
 mm/memory-failure.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

Comments

Michal Hocko Oct. 18, 2019, 11:48 a.m. UTC | #1
On Thu 17-10-19 16:21:08, Oscar Salvador wrote:
> From: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
> 
> Drop the PageHuge check since memory_failure forks into memory_failure_hugetlb()
> for hugetlb pages.
> 
> Signed-off-by: Oscar Salvador <osalvador@suse.de>
> Signed-off-by: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>

s-o-b chain is reversed.

The code is a bit confusing. Doesn't this check aim for THP? AFAICS
PageTransHuge(hpage) will split the THP or fail so PageTransHuge
shouldn't be possible anymore, right? But why does hwpoison_user_mappings
still work with hpage then?

> ---
>  mm/memory-failure.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/mm/memory-failure.c b/mm/memory-failure.c
> index 05c8c6df25e6..2cbadb58c7df 100644
> --- a/mm/memory-failure.c
> +++ b/mm/memory-failure.c
> @@ -1345,10 +1345,7 @@ int memory_failure(unsigned long pfn, int flags)
>  	 * page_remove_rmap() in try_to_unmap_one(). So to determine page status
>  	 * correctly, we save a copy of the page flags at this time.
>  	 */
> -	if (PageHuge(p))
> -		page_flags = hpage->flags;
> -	else
> -		page_flags = p->flags;
> +	page_flags = p->flags;
>  
>  	/*
>  	 * unpoison always clear PG_hwpoison inside page lock
> -- 
> 2.12.3
Naoya Horiguchi Oct. 21, 2019, 7 a.m. UTC | #2
On Fri, Oct 18, 2019 at 01:48:32PM +0200, Michal Hocko wrote:
> On Thu 17-10-19 16:21:08, Oscar Salvador wrote:
> > From: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
> > 
> > Drop the PageHuge check since memory_failure forks into memory_failure_hugetlb()
> > for hugetlb pages.
> > 
> > Signed-off-by: Oscar Salvador <osalvador@suse.de>
> > Signed-off-by: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
> 
> s-o-b chain is reversed.
> 
> The code is a bit confusing. Doesn't this check aim for THP?

No, PageHuge() is false for thp, so this if branch is just dead code.

> AFAICS
> PageTransHuge(hpage) will split the THP or fail so PageTransHuge
> shouldn't be possible anymore, right?

Yes, that's right.

> But why does hwpoison_user_mappings
> still work with hpage then?

hwpoison_user_mappings() is called both from memory_failure() and
from memory_failure_hugetlb(), so it need handle both cases.

Thanks,
Naoya Horiguchi

> 
> > ---
> >  mm/memory-failure.c | 5 +----
> >  1 file changed, 1 insertion(+), 4 deletions(-)
> > 
> > diff --git a/mm/memory-failure.c b/mm/memory-failure.c
> > index 05c8c6df25e6..2cbadb58c7df 100644
> > --- a/mm/memory-failure.c
> > +++ b/mm/memory-failure.c
> > @@ -1345,10 +1345,7 @@ int memory_failure(unsigned long pfn, int flags)
> >  	 * page_remove_rmap() in try_to_unmap_one(). So to determine page status
> >  	 * correctly, we save a copy of the page flags at this time.
> >  	 */
> > -	if (PageHuge(p))
> > -		page_flags = hpage->flags;
> > -	else
> > -		page_flags = p->flags;
> > +	page_flags = p->flags;
> >  
> >  	/*
> >  	 * unpoison always clear PG_hwpoison inside page lock
> > -- 
> > 2.12.3
> 
> -- 
> Michal Hocko
> SUSE Labs
>
Michal Hocko Oct. 21, 2019, 12:16 p.m. UTC | #3
On Mon 21-10-19 07:00:46, Naoya Horiguchi wrote:
> On Fri, Oct 18, 2019 at 01:48:32PM +0200, Michal Hocko wrote:
> > On Thu 17-10-19 16:21:08, Oscar Salvador wrote:
> > > From: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
> > > 
> > > Drop the PageHuge check since memory_failure forks into memory_failure_hugetlb()
> > > for hugetlb pages.
> > > 
> > > Signed-off-by: Oscar Salvador <osalvador@suse.de>
> > > Signed-off-by: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
> > 
> > s-o-b chain is reversed.
> > 
> > The code is a bit confusing. Doesn't this check aim for THP?
> 
> No, PageHuge() is false for thp, so this if branch is just dead code.
> 
> > AFAICS
> > PageTransHuge(hpage) will split the THP or fail so PageTransHuge
> > shouldn't be possible anymore, right?
> 
> Yes, that's right.
> 
> > But why does hwpoison_user_mappings
> > still work with hpage then?
> 
> hwpoison_user_mappings() is called both from memory_failure() and
> from memory_failure_hugetlb(), so it need handle both cases.

Thanks for the clarification. Maybe the changelog could be more explicit
because the code is quite confusing.
Aneesh Kumar K.V Nov. 12, 2019, 12:22 p.m. UTC | #4
Naoya Horiguchi <n-horiguchi@ah.jp.nec.com> writes:

> On Fri, Oct 18, 2019 at 01:48:32PM +0200, Michal Hocko wrote:
>> On Thu 17-10-19 16:21:08, Oscar Salvador wrote:
>> > From: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
>> > 
>> > Drop the PageHuge check since memory_failure forks into memory_failure_hugetlb()
>> > for hugetlb pages.
>> > 
>> > Signed-off-by: Oscar Salvador <osalvador@suse.de>
>> > Signed-off-by: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
>> 
>> s-o-b chain is reversed.
>> 
>> The code is a bit confusing. Doesn't this check aim for THP?
>
> No, PageHuge() is false for thp, so this if branch is just dead code.

memory_failure()
{

	if (PageTransHuge(hpage)) {
		lock_page(p);
		if (!PageAnon(p) || unlikely(split_huge_page(p))) {
			unlock_page(p);
			if (!PageAnon(p))
				pr_err("Memory failure: %#lx: non anonymous thp\n",
					pfn);
			else
				pr_err("Memory failure: %#lx: thp split failed\n",
					pfn);
			if (TestClearPageHWPoison(p))
				num_poisoned_pages_dec();
			put_hwpoison_page(p);
			return -EBUSY;
		}
		unlock_page(p);
		VM_BUG_ON_PAGE(!page_count(p), p);
		hpage = compound_head(p);
	}

}

Do we need that hpage = compund_head(p) conversion there? We should just
be able to say hpage = p, or even better after this change use p
directly instead of hpage in the code following?

-aneesh
Naoya Horiguchi Nov. 13, 2019, 6:02 a.m. UTC | #5
On Tue, Nov 12, 2019 at 05:52:58PM +0530, Aneesh Kumar K.V wrote:
> Naoya Horiguchi <n-horiguchi@ah.jp.nec.com> writes:
> 
> > On Fri, Oct 18, 2019 at 01:48:32PM +0200, Michal Hocko wrote:
> >> On Thu 17-10-19 16:21:08, Oscar Salvador wrote:
> >> > From: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
> >> > 
> >> > Drop the PageHuge check since memory_failure forks into memory_failure_hugetlb()
> >> > for hugetlb pages.
> >> > 
> >> > Signed-off-by: Oscar Salvador <osalvador@suse.de>
> >> > Signed-off-by: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
> >> 
> >> s-o-b chain is reversed.
> >> 
> >> The code is a bit confusing. Doesn't this check aim for THP?
> >
> > No, PageHuge() is false for thp, so this if branch is just dead code.
> 
> memory_failure()
> {
> 
> 	if (PageTransHuge(hpage)) {
> 		lock_page(p);
> 		if (!PageAnon(p) || unlikely(split_huge_page(p))) {
> 			unlock_page(p);
> 			if (!PageAnon(p))
> 				pr_err("Memory failure: %#lx: non anonymous thp\n",
> 					pfn);
> 			else
> 				pr_err("Memory failure: %#lx: thp split failed\n",
> 					pfn);
> 			if (TestClearPageHWPoison(p))
> 				num_poisoned_pages_dec();
> 			put_hwpoison_page(p);
> 			return -EBUSY;
> 		}
> 		unlock_page(p);
> 		VM_BUG_ON_PAGE(!page_count(p), p);
> 		hpage = compound_head(p);
> 	}
> 
> }
> 
> Do we need that hpage = compund_head(p) conversion there? We should just
> be able to say hpage = p, or even better after this change use p
> directly instead of hpage in the code following?

Thanks for the comment, the target page never be in compound_page
(without races leading to MF_MSG_DIFFERENT_COMPOUND path), so hpage
shouldn't be used afterward.  We also have obsolete comment, so
I feel like the following changes:

  diff --git a/mm/memory-failure.c b/mm/memory-failure.c
  index 392ac277b17d..c9df0f183d6c 100644
  --- a/mm/memory-failure.c
  +++ b/mm/memory-failure.c
  @@ -1319,7 +1319,6 @@ int memory_failure(unsigned long pfn, int flags)
   		}
   		unlock_page(p);
   		VM_BUG_ON_PAGE(!page_count(p), p);
  -		hpage = compound_head(p);
   	}
   
   	/*
  @@ -1391,11 +1390,8 @@ int memory_failure(unsigned long pfn, int flags)
   	/*
   	 * Now take care of user space mappings.
   	 * Abort on fail: __delete_from_page_cache() assumes unmapped page.
  -	 *
  -	 * When the raw error page is thp tail page, hpage points to the raw
  -	 * page after thp split.
   	 */
  -	if (!hwpoison_user_mappings(p, pfn, flags, &hpage)) {
  +	if (!hwpoison_user_mappings(p, pfn, flags, &p)) {
   		action_result(pfn, MF_MSG_UNMAP_FAILED, MF_IGNORED);
   		res = -EBUSY;
   		goto out;

Thanks,
Naoya Horiguchi
diff mbox series

Patch

diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index 05c8c6df25e6..2cbadb58c7df 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -1345,10 +1345,7 @@  int memory_failure(unsigned long pfn, int flags)
 	 * page_remove_rmap() in try_to_unmap_one(). So to determine page status
 	 * correctly, we save a copy of the page flags at this time.
 	 */
-	if (PageHuge(p))
-		page_flags = hpage->flags;
-	else
-		page_flags = p->flags;
+	page_flags = p->flags;
 
 	/*
 	 * unpoison always clear PG_hwpoison inside page lock