From: Sumanth Korikkar <sumanthk@linux.ibm.com>
To: linux-mm <linux-mm@kvack.org>,
Andrew Morton <akpm@linux-foundation.org>,
David Hildenbrand <david@redhat.com>
Cc: Oscar Salvador <osalvador@suse.de>,
Michal Hocko <mhocko@suse.com>,
"Aneesh Kumar K.V" <aneesh.kumar@linux.ibm.com>,
Anshuman Khandual <anshuman.khandual@arm.com>,
Gerald Schaefer <gerald.schaefer@linux.ibm.com>,
Sumanth Korikkar <sumanthk@linux.ibm.com>,
Alexander Gordeev <agordeev@linux.ibm.com>,
Heiko Carstens <hca@linux.ibm.com>,
Vasily Gorbik <gor@linux.ibm.com>,
linux-s390 <linux-s390@vger.kernel.org>,
LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH v2 2/7] mm/memory_hotplug: avoid poisoning memmap during mhp addition phase
Date: Thu, 23 Nov 2023 10:23:38 +0100 [thread overview]
Message-ID: <20231123092343.1703707-3-sumanthk@linux.ibm.com> (raw)
In-Reply-To: <20231123092343.1703707-1-sumanthk@linux.ibm.com>
When memory block is marked inaccessible, avoid page_init_poison() on
memmap during memory hotplug addition phase. Instead, perform it later
when the memory is physically accessible in memory hotplug online phase.
When the memory block is marked accessible (by default turned on without
passing any mhp_flags), page poisoning initialization on memmap is
performed in sparse_add_section().
Page init poisining on memmap is performed with cond_resched(). This
reflects the functionality of commit d33695b16a9f ("mm/memory_hotplug:
poison memmap in remove_pfn_range_from_zone()")
Architectures can pass MHP_OFFLINE_INACCESSIBLE mhp_flag in add_memory()
to mark the memory block as initially inaccessible during memory hotplug
addition phase.
Signed-off-by: Sumanth Korikkar <sumanthk@linux.ibm.com>
---
drivers/base/memory.c | 3 ++-
include/linux/memory_hotplug.h | 2 +-
mm/memory_hotplug.c | 27 ++++++++++++++++++++++++++-
mm/sparse.c | 3 ++-
4 files changed, 31 insertions(+), 4 deletions(-)
diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index 51915d5c3f88..cbff43b2ef44 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -209,7 +209,8 @@ static int memory_block_online(struct memory_block *mem)
mem_hotplug_begin();
if (nr_vmemmap_pages) {
- ret = mhp_init_memmap_on_memory(start_pfn, nr_vmemmap_pages, zone);
+ ret = mhp_init_memmap_on_memory(start_pfn, nr_vmemmap_pages,
+ zone, mem->inaccessible);
if (ret)
goto out;
}
diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h
index 8988cd5ad55d..791bc019e992 100644
--- a/include/linux/memory_hotplug.h
+++ b/include/linux/memory_hotplug.h
@@ -164,7 +164,7 @@ extern void adjust_present_page_count(struct page *page,
long nr_pages);
/* VM interface that may be used by firmware interface */
extern int mhp_init_memmap_on_memory(unsigned long pfn, unsigned long nr_pages,
- struct zone *zone);
+ struct zone *zone, bool mhp_off_inaccessible);
extern void mhp_deinit_memmap_on_memory(unsigned long pfn, unsigned long nr_pages);
extern int online_pages(unsigned long pfn, unsigned long nr_pages,
struct zone *zone, struct memory_group *group);
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index 1e02eba166b0..ac7cfc09502d 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -1083,8 +1083,25 @@ void adjust_present_page_count(struct page *page, struct memory_group *group,
group->present_kernel_pages += nr_pages;
}
+static void page_init_poison_with_resched(unsigned long start_pfn, unsigned long nr_pages)
+{
+ const unsigned long end_pfn = start_pfn + nr_pages;
+ unsigned long pfn, cur_nr_pages;
+
+ /* Poison struct pages because they are now uninitialized again. */
+ for (pfn = start_pfn; pfn < end_pfn; pfn += cur_nr_pages) {
+ cond_resched();
+
+ /* Select all remaining pages up to the next section boundary */
+ cur_nr_pages =
+ min(end_pfn - pfn, SECTION_ALIGN_UP(pfn + 1) - pfn);
+ page_init_poison(pfn_to_page(pfn),
+ sizeof(struct page) * cur_nr_pages);
+ }
+}
+
int mhp_init_memmap_on_memory(unsigned long pfn, unsigned long nr_pages,
- struct zone *zone)
+ struct zone *zone, bool mhp_off_inaccessible)
{
unsigned long end_pfn = pfn + nr_pages;
int ret, i;
@@ -1092,6 +1109,14 @@ int mhp_init_memmap_on_memory(unsigned long pfn, unsigned long nr_pages,
ret = kasan_add_zero_shadow(__va(PFN_PHYS(pfn)), PFN_PHYS(nr_pages));
if (ret)
return ret;
+ /*
+ * Memory block is accessible at this stage and hence poison the struct
+ * pages now. If the memory block is accessible during memory hotplug
+ * addition phase, then page poisining is already performed in
+ * sparse_add_section().
+ */
+ if (mhp_off_inaccessible)
+ page_init_poison_with_resched(pfn, nr_pages);
move_pfn_range_to_zone(zone, pfn, nr_pages, NULL, MIGRATE_UNMOVABLE);
for (i = 0; i < nr_pages; i++)
diff --git a/mm/sparse.c b/mm/sparse.c
index 77d91e565045..3991c717b769 100644
--- a/mm/sparse.c
+++ b/mm/sparse.c
@@ -907,7 +907,8 @@ int __meminit sparse_add_section(int nid, unsigned long start_pfn,
* Poison uninitialized struct pages in order to catch invalid flags
* combinations.
*/
- page_init_poison(memmap, sizeof(struct page) * nr_pages);
+ if (!altmap || !altmap->inaccessible)
+ page_init_poison(memmap, sizeof(struct page) * nr_pages);
ms = __nr_to_section(section_nr);
set_section_nid(section_nr, nid);
--
2.39.2
next prev parent reply other threads:[~2023-11-23 9:24 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-23 9:23 [PATCH v2 0/7] implement "memmap on memory" feature on s390 Sumanth Korikkar
2023-11-23 9:23 ` [PATCH v2 1/7] mm/memory_hotplug: introduce mhp_flag MHP_OFFLINE_INACCESSIBLE Sumanth Korikkar
2023-11-24 18:04 ` David Hildenbrand
2023-11-23 9:23 ` Sumanth Korikkar [this message]
2023-11-23 9:23 ` [PATCH v2 3/7] mm/memory_hotplug: introduce MEM_PREPARE_ONLINE/MEM_FINISH_OFFLINE notifiers Sumanth Korikkar
2023-11-23 9:23 ` [PATCH v2 4/7] s390/mm: allocate vmemmap pages from self-contained memory range Sumanth Korikkar
2023-11-23 9:23 ` [PATCH v2 5/7] s390/sclp: remove unhandled memory notifier type Sumanth Korikkar
2023-11-23 9:23 ` [PATCH v2 6/7] s390/mm: implement MEM_PREPARE_ONLINE/MEM_FINISH_OFFLINE notifiers Sumanth Korikkar
2023-11-23 9:23 ` [PATCH v2 7/7] s390: enable MHP_MEMMAP_ON_MEMORY Sumanth Korikkar
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=20231123092343.1703707-3-sumanthk@linux.ibm.com \
--to=sumanthk@linux.ibm.com \
--cc=agordeev@linux.ibm.com \
--cc=akpm@linux-foundation.org \
--cc=aneesh.kumar@linux.ibm.com \
--cc=anshuman.khandual@arm.com \
--cc=david@redhat.com \
--cc=gerald.schaefer@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-s390@vger.kernel.org \
--cc=mhocko@suse.com \
--cc=osalvador@suse.de \
/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