linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] Fix hugetlb free path race with memory errors
@ 2023-07-11 22:09 Mike Kravetz
  2023-07-11 22:09 ` [PATCH 1/2] hugetlb: Do not clear hugetlb dtor until allocating vmemmap Mike Kravetz
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Mike Kravetz @ 2023-07-11 22:09 UTC (permalink / raw)
  To: linux-mm, linux-kernel
  Cc: Jiaqi Yan, Naoya Horiguchi, Muchun Song, Miaohe Lin,
	Axel Rasmussen, James Houghton, Michal Hocko, Andrew Morton,
	Mike Kravetz

In the discussion of Jiaqi Yan's series "Improve hugetlbfs read on
HWPOISON hugepages" the race window was discovered.
https://lore.kernel.org/linux-mm/20230616233447.GB7371@monkey/

Freeing a hugetlb page back to low level memory allocators is performed
in two steps.
1) Under hugetlb lock, remove page from hugetlb lists and clear destructor
2) Outside lock, allocate vmemmap if necessary and call low level free
Between these two steps, the hugetlb page will appear as a normal
compound page.  However, vmemmap for tail pages could be missing.
If a memory error occurs at this time, we could try to update page
flags non-existant page structs.

A much more detailed description is in the first patch.

The first patch addresses the race window.  However, it adds a
hugetlb_lock lock/unlock cycle to every vmemmap optimized hugetlb
page free operation.  This could lead to slowdowns if one is freeing
a large number of hugetlb pages.

The second path optimizes the update_and_free_pages_bulk routine
to only take the lock once in bulk operations.

The second patch is technically not a bug fix, but includes a Fixes
tag and Cc stable to avoid a performance regression.  It can be
combined with the first, but was done separately make reviewing easier.

Mike Kravetz (2):
  hugetlb: Do not clear hugetlb dtor until allocating vmemmap
  hugetlb: optimize update_and_free_pages_bulk to avoid lock cycles

 mm/hugetlb.c | 110 +++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 85 insertions(+), 25 deletions(-)

-- 
2.41.0



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-07-13 17:34 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-11 22:09 [PATCH 0/2] Fix hugetlb free path race with memory errors Mike Kravetz
2023-07-11 22:09 ` [PATCH 1/2] hugetlb: Do not clear hugetlb dtor until allocating vmemmap Mike Kravetz
2023-07-12  8:03   ` Muchun Song
2023-07-12 18:14     ` Mike Kravetz
2023-07-13  0:22       ` Mike Kravetz
2023-07-11 22:09 ` [PATCH 2/2] hugetlb: optimize update_and_free_pages_bulk to avoid lock cycles Mike Kravetz
2023-07-13 17:34 ` [PATCH 0/2] Fix hugetlb free path race with memory errors Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).