linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "HORIGUCHI NAOYA(堀口 直也)" <naoya.horiguchi@nec.com>
To: Miaohe Lin <linmiaohe@huawei.com>
Cc: Naoya Horiguchi <naoya.horiguchi@linux.dev>,
	"linux-mm@kvack.org" <linux-mm@kvack.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	David Hildenbrand <david@redhat.com>,
	Mike Kravetz <mike.kravetz@oracle.com>,
	Liu Shixin <liushixin2@huawei.com>,
	Yang Shi <shy828301@gmail.com>,
	Oscar Salvador <osalvador@suse.de>,
	Muchun Song <songmuchun@bytedance.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [mm-unstable PATCH v5 3/8] mm, hwpoison, hugetlb: support saving mechanism of raw error pages
Date: Mon, 11 Jul 2022 05:51:07 +0000	[thread overview]
Message-ID: <20220711055047.GA2731632@hori.linux.bs1.fc.nec.co.jp> (raw)
In-Reply-To: <b8f3f0a5-7a3b-1afb-ca1e-73ab384797b7@huawei.com>

On Mon, Jul 11, 2022 at 11:26:34AM +0800, Miaohe Lin wrote:
> On 2022/7/8 13:36, Naoya Horiguchi wrote:
> > From: Naoya Horiguchi <naoya.horiguchi@nec.com>
> > 
> > When handling memory error on a hugetlb page, the error handler tries to
> > dissolve and turn it into 4kB pages.  If it's successfully dissolved,
> > PageHWPoison flag is moved to the raw error page, so that's all right.
> > However, dissolve sometimes fails, then the error page is left as
> > hwpoisoned hugepage. It's useful if we can retry to dissolve it to save
> > healthy pages, but that's not possible now because the information about
> > where the raw error pages is lost.
> > 
> > Use the private field of a few tail pages to keep that information.  The
> > code path of shrinking hugepage pool uses this info to try delayed dissolve.
> > In order to remember multiple errors in a hugepage, a singly-linked list
> > originated from SUBPAGE_INDEX_HWPOISON-th tail page is constructed.  Only
> > simple operations (adding an entry or clearing all) are required and the
> > list is assumed not to be very long, so this simple data structure should
> > be enough.
> > 
> > If we failed to save raw error info, the hwpoison hugepage has errors on
> > unknown subpage, then this new saving mechanism does not work any more,
> > so disable saving new raw error info and freeing hwpoison hugepages.
> > 
> > Signed-off-by: Naoya Horiguchi <naoya.horiguchi@nec.com>
> > Reported-by: kernel test robot <lkp@intel.com>
> > ---
> > v4 -> v5:
> > - fixed build error (reported by kernel test robot).
> > - do not try to undo remove_hugetlb_page() when HPageRawHwpUnreliable is true,
> > - check HPageRawHwpUnreliable() before hugetlb_vmemmap_restore(),
> > - call num_poisoned_pages_inc() in hugetlb_set_page_hwpoison() when kalloc
> >   succeeds,
> > - remove "inline" in the definition of hugetlb_clear_page_hwpoison().
> > 
> > v3 -> v4:
> > - resolve conflict with "mm: hugetlb_vmemmap: improve hugetlb_vmemmap
> >   code readability", use hugetlb_vmemmap_restore() instead of
> >   hugetlb_vmemmap_alloc().
> > 
> > v2 -> v3:
> > - remove duplicate "return ret" lines,
> > - use GFP_ATOMIC instead of GFP_KERNEL,
> > - introduce HPageRawHwpUnreliable pseudo flag (suggested by Muchun),
> > - hugetlb_clear_page_hwpoison removes raw_hwp_page list even if
> >   HPageRawHwpUnreliable is true, (by Miaohe)
> > 
> > v1 -> v2:
> > - support hwpoison hugepage with multiple errors,
> > - moved the new interface functions to mm/memory-failure.c,
> > - define additional subpage index SUBPAGE_INDEX_HWPOISON_UNRELIABLE,
> > - stop freeing/dissolving hwpoison hugepages with unreliable raw error info,
> > - drop hugetlb_clear_page_hwpoison() in dissolve_free_huge_page() because
> >   that's done in update_and_free_page(),
> > - move setting/clearing PG_hwpoison flag to the new interfaces,
> > - checking already hwpoisoned or not on a subpage basis.
> > 
> > ChangeLog since previous post on 4/27:
> > - fixed typo in patch description (by Miaohe)
> > - fixed config value in #ifdef statement (by Miaohe)
> > - added sentences about "multiple hwpoison pages" scenario in patch
> >   description
> > ---
> >  include/linux/hugetlb.h | 18 +++++++++-
> >  mm/hugetlb.c            | 32 ++++++++++++-----
> >  mm/memory-failure.c     | 79 +++++++++++++++++++++++++++++++++++++++--
> >  3 files changed, 116 insertions(+), 13 deletions(-)
> > 
> > diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
> > index 6d0620edf0a6..6fd128b80d57 100644
> > --- a/include/linux/hugetlb.h
> > +++ b/include/linux/hugetlb.h
> > @@ -42,6 +42,9 @@ enum {
> >  	SUBPAGE_INDEX_CGROUP,		/* reuse page->private */
> >  	SUBPAGE_INDEX_CGROUP_RSVD,	/* reuse page->private */
> >  	__MAX_CGROUP_SUBPAGE_INDEX = SUBPAGE_INDEX_CGROUP_RSVD,
> > +#endif
> > +#ifdef CONFIG_MEMORY_FAILURE
> > +	SUBPAGE_INDEX_HWPOISON,
> >  #endif
> >  	__NR_USED_SUBPAGE,
> >  };
> > @@ -551,7 +554,7 @@ generic_hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
> >   *	Synchronization:  Initially set after new page allocation with no
> >   *	locking.  When examined and modified during migration processing
> >   *	(isolate, migrate, putback) the hugetlb_lock is held.
> > - * HPG_temporary - - Set on a page that is temporarily allocated from the buddy
> > + * HPG_temporary - Set on a page that is temporarily allocated from the buddy
> >   *	allocator.  Typically used for migration target pages when no pages
> >   *	are available in the pool.  The hugetlb free page path will
> >   *	immediately free pages with this flag set to the buddy allocator.
> > @@ -561,6 +564,8 @@ generic_hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
> >   * HPG_freed - Set when page is on the free lists.
> >   *	Synchronization: hugetlb_lock held for examination and modification.
> >   * HPG_vmemmap_optimized - Set when the vmemmap pages of the page are freed.
> > + * HPG_raw_hwp_unreliable - Set when the hugetlb page has a hwpoison sub-page
> > + *     that is not tracked by raw_hwp_page list.
> >   */
> >  enum hugetlb_page_flags {
> >  	HPG_restore_reserve = 0,
> > @@ -568,6 +573,7 @@ enum hugetlb_page_flags {
> >  	HPG_temporary,
> >  	HPG_freed,
> >  	HPG_vmemmap_optimized,
> > +	HPG_raw_hwp_unreliable,
> >  	__NR_HPAGEFLAGS,
> >  };
> >  
> > @@ -614,6 +620,7 @@ HPAGEFLAG(Migratable, migratable)
> >  HPAGEFLAG(Temporary, temporary)
> >  HPAGEFLAG(Freed, freed)
> >  HPAGEFLAG(VmemmapOptimized, vmemmap_optimized)
> > +HPAGEFLAG(RawHwpUnreliable, raw_hwp_unreliable)
> >  
> >  #ifdef CONFIG_HUGETLB_PAGE
> >  
> > @@ -796,6 +803,15 @@ extern int dissolve_free_huge_page(struct page *page);
> >  extern int dissolve_free_huge_pages(unsigned long start_pfn,
> >  				    unsigned long end_pfn);
> >  
> > +#ifdef CONFIG_MEMORY_FAILURE
> > +extern int hugetlb_clear_page_hwpoison(struct page *hpage);
> > +#else
> > +static inline int hugetlb_clear_page_hwpoison(struct page *hpage)
> > +{
> > +	return 0;
> > +}
> > +#endif
> > +
> >  #ifdef CONFIG_ARCH_ENABLE_HUGEPAGE_MIGRATION
> >  #ifndef arch_hugetlb_migration_supported
> >  static inline bool arch_hugetlb_migration_supported(struct hstate *h)
> > diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> > index 77119d93a0f9..3956494cc5fb 100644
> > --- a/mm/hugetlb.c
> > +++ b/mm/hugetlb.c
> > @@ -1442,6 +1442,15 @@ static void __remove_hugetlb_page(struct hstate *h, struct page *page,
> >  		h->surplus_huge_pages_node[nid]--;
> >  	}
> >  
> > +	/*
> > +	 * This leaves HPageRawHwpUnreliable pages as leaked hugepages, not
> > +	 * as leaked generic-compound pages.  Otherwise page_mapped() or
> > +	 * folio_mapped() gets slow because for-loop for each subpage is
> > +	 * called.
> > +	 */
> > +	if (HPageRawHwpUnreliable(page))
> > +		return;
> > +
> 
> This patch looks good to me with below several possible problems:
> 
> Should "nr_huge_pages" and "nr_huge_pages_node" be adjusted too? If it's called from dissolve_free_huge_page
> and hugetlb_vmemmap_restore fails, add_hugetlb_page will be called:
> 
> add_hugetlb_page:
> 	...
> 	h->nr_huge_pages++;
> 	h->nr_huge_pages_node[nid]++;
> 	   ^^^^^^^^1. the "nr_huge_pages" and "nr_huge_pages_node" might be incorrect?
> 	...
> 	zeroed = put_page_testzero(page);
> 		 ^^^^^^^^2. VM_BUG_ON_PAGE(page_ref_count(page) == 0, page); will be triggered?
> 
> Or am I miss something?

No, this code breaks the specific case, so I'd like to simply drop this if.
HPageRawHwpUnreliable hugepage should be very rare, and calling page_mapped()
for such a leaked page should be less common, so the impact of the slowdown
should be minimal.

Thanks,
Naoya Horiguchi

  reply	other threads:[~2022-07-11  5:51 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-08  5:36 [mm-unstable PATCH v5 0/8] mm, hwpoison: enable 1GB hugepage support (v5) Naoya Horiguchi
2022-07-08  5:36 ` [mm-unstable PATCH v5 1/8] mm/hugetlb: check gigantic_page_runtime_supported() in return_unused_surplus_pages() Naoya Horiguchi
2022-07-11  1:55   ` Miaohe Lin
2022-07-08  5:36 ` [mm-unstable PATCH v5 2/8] mm/hugetlb: make pud_huge() and follow_huge_pud() aware of non-present pud entry Naoya Horiguchi
2022-07-08  5:36 ` [mm-unstable PATCH v5 3/8] mm, hwpoison, hugetlb: support saving mechanism of raw error pages Naoya Horiguchi
2022-07-11  3:26   ` Miaohe Lin
2022-07-11  5:51     ` HORIGUCHI NAOYA(堀口 直也) [this message]
2022-07-11  7:14       ` Miaohe Lin
2022-07-08  5:36 ` [mm-unstable PATCH v5 4/8] mm, hwpoison: make unpoison aware of raw error info in hwpoisoned hugepage Naoya Horiguchi
2022-07-11  7:09   ` Miaohe Lin
2022-07-11  9:24     ` HORIGUCHI NAOYA(堀口 直也)
2022-07-11 11:13       ` Miaohe Lin
2022-07-08  5:36 ` [mm-unstable PATCH v5 5/8] mm, hwpoison: set PG_hwpoison for busy hugetlb pages Naoya Horiguchi
2022-07-08  5:36 ` [mm-unstable PATCH v5 6/8] mm, hwpoison: make __page_handle_poison returns int Naoya Horiguchi
2022-07-08  5:36 ` [mm-unstable PATCH v5 7/8] mm, hwpoison: skip raw hwpoison page in freeing 1GB hugepage Naoya Horiguchi
2022-07-08  5:36 ` [mm-unstable PATCH v5 8/8] mm, hwpoison: enable memory error handling on " 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=20220711055047.GA2731632@hori.linux.bs1.fc.nec.co.jp \
    --to=naoya.horiguchi@nec.com \
    --cc=akpm@linux-foundation.org \
    --cc=david@redhat.com \
    --cc=linmiaohe@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=liushixin2@huawei.com \
    --cc=mike.kravetz@oracle.com \
    --cc=naoya.horiguchi@linux.dev \
    --cc=osalvador@suse.de \
    --cc=shy828301@gmail.com \
    --cc=songmuchun@bytedance.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox