[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220922011252.2266780-3-zi.yan@sent.com>
Date: Wed, 21 Sep 2022 21:12:42 -0400
From: Zi Yan <zi.yan@...t.com>
To: linux-mm@...ck.org
Cc: Zi Yan <ziy@...dia.com>, David Hildenbrand <david@...hat.com>,
Matthew Wilcox <willy@...radead.org>,
Vlastimil Babka <vbabka@...e.cz>,
"Kirill A . Shutemov" <kirill.shutemov@...ux.intel.com>,
Mike Kravetz <mike.kravetz@...cle.com>,
John Hubbard <jhubbard@...dia.com>,
Yang Shi <shy828301@...il.com>,
David Rientjes <rientjes@...gle.com>,
James Houghton <jthoughton@...gle.com>,
Mike Rapoport <rppt@...nel.org>,
Muchun Song <songmuchun@...edance.com>,
Andrew Morton <akpm@...ux-foundation.org>,
linux-kernel@...r.kernel.org
Subject: [PATCH v1 02/12] mm: check page validity when find a buddy page in a non-contiguous zone
From: Zi Yan <ziy@...dia.com>
When MAX_ORDER > section size, buddy page might not be valid when the zone
is non-contiguous. Check it and return NULL if buddy page is not valid.
For PFNs that not aligned to MAX_ORDER (usually at the beginning and end
of a zone), __free_pages_memory() clamps down the order to make sure
invalid PFN will not show up as a buddy PFN.
Signed-off-by: Zi Yan <ziy@...dia.com>
---
mm/internal.h | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/mm/internal.h b/mm/internal.h
index b3002e03c28f..22fb1e6e3541 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -330,12 +330,16 @@ static inline struct page *find_buddy_page_pfn(struct page *page,
unsigned long pfn, unsigned int order, unsigned long *buddy_pfn)
{
unsigned long __buddy_pfn = __find_buddy_pfn(pfn, order);
+ struct zone *zone = page_zone(page);
struct page *buddy;
buddy = page + (__buddy_pfn - pfn);
if (buddy_pfn)
*buddy_pfn = __buddy_pfn;
+ if (unlikely(!zone->contiguous && !pfn_valid(__buddy_pfn)))
+ return NULL;
+
if (page_is_buddy(page, buddy, order))
return buddy;
return NULL;
--
2.35.1
Powered by blists - more mailing lists