From: Zi Yan <zi.yan@sent.com>
To: linux-mm@kvack.org
Cc: David Hildenbrand <david@redhat.com>,
Matthew Wilcox <willy@infradead.org>,
Vlastimil Babka <vbabka@suse.cz>,
"Kirill A . Shutemov" <kirill.shutemov@linux.intel.com>,
Mike Kravetz <mike.kravetz@oracle.com>,
John Hubbard <jhubbard@nvidia.com>,
Yang Shi <shy828301@gmail.com>,
David Rientjes <rientjes@google.com>,
James Houghton <jthoughton@google.com>,
Mike Rapoport <rppt@kernel.org>,
linux-kernel@vger.kernel.org
Subject: [RFC PATCH v2 04/12] mm: adapt deferred struct page init to new MAX_ORDER.
Date: Thu, 11 Aug 2022 19:16:35 -0400 [thread overview]
Message-ID: <20220811231643.1012912-5-zi.yan@sent.com> (raw)
In-Reply-To: <20220811231643.1012912-1-zi.yan@sent.com>
From: Zi Yan <ziy@nvidia.com>
deferred_init only initializes first section of a zone and defers the
rest and the rest of the zone will be initialized in size of a section.
When MAX_ORDER grows beyond a section size, early_page_uninitialised()
did not prevent pages beyond first section from initialization, since it
only checked the starting pfn and assumes MAX_ORDER is smaller than
a section size. In addition, deferred_init_maxorder() uses
MAX_ORDER_NR_PAGES as the initialization unit, which can cause the
initialized chunk of memory overlapping with other initialization jobs.
For the first issue, make early_page_uninitialised() decrease the order
for non-deferred memory initialization when it is bigger than first
section. For the second issue, when adjust pfn alignment in
deferred_init_maxorder(), make sure the alignment is not bigger than
a section size.
Signed-off-by: Zi Yan <ziy@nvidia.com>
---
mm/internal.h | 2 +-
mm/memblock.c | 6 ++++--
mm/page_alloc.c | 26 +++++++++++++++++++-------
3 files changed, 24 insertions(+), 10 deletions(-)
diff --git a/mm/internal.h b/mm/internal.h
index 1433e3a6fdd0..cbe745670c6e 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -355,7 +355,7 @@ extern int __isolate_free_page(struct page *page, unsigned int order);
extern void __putback_isolated_page(struct page *page, unsigned int order,
int mt);
extern void memblock_free_pages(struct page *page, unsigned long pfn,
- unsigned int order);
+ unsigned int *order);
extern void __free_pages_core(struct page *page, unsigned int order);
extern void prep_compound_page(struct page *page, unsigned int order);
extern void post_alloc_hook(struct page *page, unsigned int order,
diff --git a/mm/memblock.c b/mm/memblock.c
index d1525463c05e..dc2ce6df8fe3 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -1640,7 +1640,9 @@ void __init memblock_free_late(phys_addr_t base, phys_addr_t size)
end = PFN_DOWN(base + size);
for (; cursor < end; cursor++) {
- memblock_free_pages(pfn_to_page(cursor), cursor, 0);
+ unsigned int order = 0;
+
+ memblock_free_pages(pfn_to_page(cursor), cursor, &order);
totalram_pages_inc();
}
}
@@ -2035,7 +2037,7 @@ static void __init __free_pages_memory(unsigned long start, unsigned long end)
while (start + (1UL << order) > end)
order--;
- memblock_free_pages(pfn_to_page(start), start, order);
+ memblock_free_pages(pfn_to_page(start), start, &order);
start += (1UL << order);
}
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 07ad8074950f..3f3af7cd5164 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -463,13 +463,19 @@ static inline bool deferred_pages_enabled(void)
}
/* Returns true if the struct page for the pfn is uninitialised */
-static inline bool __meminit early_page_uninitialised(unsigned long pfn)
+static inline bool __meminit early_page_uninitialised(unsigned long pfn, unsigned int *order)
{
int nid = early_pfn_to_nid(pfn);
if (node_online(nid) && pfn >= NODE_DATA(nid)->first_deferred_pfn)
return true;
+ /* clamp down order to not exceed first_deferred_pfn */
+ if (order)
+ *order = min_t(unsigned int,
+ *order,
+ ilog2(NODE_DATA(nid)->first_deferred_pfn - pfn));
+
return false;
}
@@ -515,7 +521,7 @@ static inline bool deferred_pages_enabled(void)
return false;
}
-static inline bool early_page_uninitialised(unsigned long pfn)
+static inline bool early_page_uninitialised(unsigned long pfn, unsigned int *order)
{
return false;
}
@@ -1644,7 +1650,7 @@ static void __meminit init_reserved_page(unsigned long pfn)
pg_data_t *pgdat;
int nid, zid;
- if (!early_page_uninitialised(pfn))
+ if (!early_page_uninitialised(pfn, NULL))
return;
nid = early_pfn_to_nid(pfn);
@@ -1800,11 +1806,11 @@ int __meminit early_pfn_to_nid(unsigned long pfn)
#endif /* CONFIG_NUMA */
void __init memblock_free_pages(struct page *page, unsigned long pfn,
- unsigned int order)
+ unsigned int *order)
{
- if (early_page_uninitialised(pfn))
+ if (early_page_uninitialised(pfn, order))
return;
- __free_pages_core(page, order);
+ __free_pages_core(page, *order);
}
/*
@@ -2030,7 +2036,13 @@ static unsigned long __init
deferred_init_maxorder(u64 *i, struct zone *zone, unsigned long *start_pfn,
unsigned long *end_pfn)
{
- unsigned long mo_pfn = ALIGN(*start_pfn + 1, MAX_ORDER_NR_PAGES);
+ /*
+ * deferred_init_memmap_chunk gives out jobs with max size to
+ * PAGES_PER_SECTION. Do not align mo_pfn beyond that.
+ */
+ unsigned long align = min_t(unsigned long,
+ MAX_ORDER_NR_PAGES, PAGES_PER_SECTION);
+ unsigned long mo_pfn = ALIGN(*start_pfn + 1, align);
unsigned long spfn = *start_pfn, epfn = *end_pfn;
unsigned long nr_pages = 0;
u64 j = *i;
--
2.35.1
next prev parent reply other threads:[~2022-08-11 23:16 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-11 23:16 [RFC PATCH v2 00/12] Make MAX_ORDER adjustable as a kernel boot time parameter Zi Yan
2022-08-11 23:16 ` [RFC PATCH v2 01/12] arch: mm: rename FORCE_MAX_ZONEORDER to ARCH_FORCE_MAX_ORDER Zi Yan
2022-08-13 15:36 ` Mike Rapoport
2022-08-15 12:53 ` Zi Yan
2022-08-11 23:16 ` [RFC PATCH v2 02/12] mm: rectify MAX_ORDER semantics to be the largest page order from buddy allocator Zi Yan
2022-08-11 23:16 ` [RFC PATCH v2 03/12] mm: replace MAX_ORDER when it is used to indicate max physical contiguity Zi Yan
2022-08-11 23:16 ` Zi Yan [this message]
2022-08-11 23:16 ` [RFC PATCH v2 05/12] mm: prevent pageblock size being larger than section size Zi Yan
2022-08-11 23:16 ` [RFC PATCH v2 06/12] fs: proc: use pageblock_nr_pages for reschedule period in read_kcore() Zi Yan
2022-08-23 10:36 ` David Hildenbrand
2022-08-11 23:16 ` [RFC PATCH v2 07/12] virtio: virtio_balloon: use pageblock_order instead of MAX_ORDER Zi Yan
2022-08-11 23:16 ` [RFC PATCH v2 08/12] mm/page_reporting: set page_reporting_order to -1 to prevent it running Zi Yan
2022-08-11 23:16 ` [RFC PATCH v2 09/12] mm: Make MAX_ORDER of buddy allocator configurable via Kconfig SET_MAX_ORDER Zi Yan
[not found] ` <becc0751-9ce9-6fab-8e58-477e962e54c5@infradead.org>
2022-08-13 2:37 ` Zi Yan
2022-08-11 23:16 ` [RFC PATCH v2 10/12] mm: convert MAX_ORDER sized static arrays to dynamic ones Zi Yan
2022-08-11 23:16 ` [RFC PATCH v2 11/12] mm: introduce MIN_MAX_ORDER to replace MAX_ORDER as compile time constant Zi Yan
2022-08-11 23:16 ` [RFC PATCH v2 12/12] mm: make MAX_ORDER a kernel boot time parameter Zi Yan
[not found] ` <2e15fc72-5483-b901-5a54-d4a4529d61d9@infradead.org>
2022-08-13 2:38 ` Zi Yan
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=20220811231643.1012912-5-zi.yan@sent.com \
--to=zi.yan@sent.com \
--cc=david@redhat.com \
--cc=jhubbard@nvidia.com \
--cc=jthoughton@google.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mike.kravetz@oracle.com \
--cc=rientjes@google.com \
--cc=rppt@kernel.org \
--cc=shy828301@gmail.com \
--cc=vbabka@suse.cz \
--cc=willy@infradead.org \
--cc=ziy@nvidia.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;
as well as URLs for NNTP newsgroup(s).