From: Mike Rapoport <rppt@kernel.org>
To: Sudarshan Rajagopalan <sudaraja@codeaurora.org>
Cc: Mark Rutland <mark.rutland@arm.com>,
David Hildenbrand <david@redhat.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Anshuman Khandual <anshuman.khandual@arm.com>,
linux-kernel@vger.kernel.org, Steven Price <steven.price@arm.com>,
Suren Baghdasaryan <surenb@google.com>,
Logan Gunthorpe <logang@deltatee.com>,
Will Deacon <will@kernel.org>,
linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH 1/2] mm/memory_hotplug: allow marking of memory sections as hotpluggable
Date: Sat, 17 Oct 2020 11:26:00 +0300 [thread overview]
Message-ID: <20201017082600.GB16395@kernel.org> (raw)
In-Reply-To: <2cba881c51e42cfe5ba213e09273642136e8ef93.1602899443.git.sudaraja@codeaurora.org>
On Fri, Oct 16, 2020 at 07:02:23PM -0700, Sudarshan Rajagopalan wrote:
> Certain architectures such as arm64 doesn't allow boot memory to be
> offlined and removed. Distinguish certain memory sections as
> "hotpluggable" which can be marked by module drivers stating to memory
> hotplug layer that these sections can be offlined and then removed.
I don't quite follow why marking sections as hotpluggable or not should
be done by a device driver. Can you describe in more details your
use-case and why there is a need to add a flag to the memory map?
> This is done by using a separate section memory mab bit and setting it,
> rather than clearing the existing SECTION_IS_EARLY bit.
> This patch introduces SECTION_MARK_HOTPLUGGABLE bit into section mem map.
> Only the allowed sections which are in movable zone and have unmovable
> pages are allowed to be set with this new bit.
>
> Signed-off-by: Sudarshan Rajagopalan <sudaraja@codeaurora.org>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will@kernel.org>
> Cc: Mike Rapoport <rppt@kernel.org>
> Cc: Anshuman Khandual <anshuman.khandual@arm.com>
> Cc: David Hildenbrand <david@redhat.com>
> Cc: Mark Rutland <mark.rutland@arm.com>
> Cc: Steven Price <steven.price@arm.com>
> Cc: Logan Gunthorpe <logang@deltatee.com>
> Cc: Suren Baghdasaryan <surenb@google.com>
> ---
> include/linux/memory_hotplug.h | 1 +
> include/linux/mmzone.h | 9 ++++++++-
> mm/memory_hotplug.c | 20 ++++++++++++++++++++
> mm/sparse.c | 31 +++++++++++++++++++++++++++++++
> 4 files changed, 60 insertions(+), 1 deletion(-)
>
> diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h
> index 375515803cd8..81df45b582c8 100644
> --- a/include/linux/memory_hotplug.h
> +++ b/include/linux/memory_hotplug.h
> @@ -319,6 +319,7 @@ extern int offline_pages(unsigned long start_pfn, unsigned long nr_pages);
> extern int remove_memory(int nid, u64 start, u64 size);
> extern void __remove_memory(int nid, u64 start, u64 size);
> extern int offline_and_remove_memory(int nid, u64 start, u64 size);
> +extern int mark_memory_hotpluggable(unsigned long start, unsigned long end);
>
> #else
> static inline void try_offline_node(int nid) {}
> diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
> index 8379432f4f2f..3df3a4975236 100644
> --- a/include/linux/mmzone.h
> +++ b/include/linux/mmzone.h
> @@ -1247,7 +1247,8 @@ extern size_t mem_section_usage_size(void);
> #define SECTION_HAS_MEM_MAP (1UL<<1)
> #define SECTION_IS_ONLINE (1UL<<2)
> #define SECTION_IS_EARLY (1UL<<3)
> -#define SECTION_MAP_LAST_BIT (1UL<<4)
> +#define SECTION_MARK_HOTPLUGGABLE (1UL<<4)
> +#define SECTION_MAP_LAST_BIT (1UL<<5)
> #define SECTION_MAP_MASK (~(SECTION_MAP_LAST_BIT-1))
> #define SECTION_NID_SHIFT 3
>
> @@ -1278,6 +1279,11 @@ static inline int early_section(struct mem_section *section)
> return (section && (section->section_mem_map & SECTION_IS_EARLY));
> }
>
> +static inline int removable_section(struct mem_section *section)
> +{
> + return (section && (section->section_mem_map & SECTION_MARK_HOTPLUGGABLE));
> +}
> +
> static inline int valid_section_nr(unsigned long nr)
> {
> return valid_section(__nr_to_section(nr));
> @@ -1297,6 +1303,7 @@ static inline int online_section_nr(unsigned long nr)
> void online_mem_sections(unsigned long start_pfn, unsigned long end_pfn);
> #ifdef CONFIG_MEMORY_HOTREMOVE
> void offline_mem_sections(unsigned long start_pfn, unsigned long end_pfn);
> +int section_mark_hotpluggable(struct mem_section *ms);
> #endif
> #endif
>
> diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
> index e9d5ab5d3ca0..503b0de489a0 100644
> --- a/mm/memory_hotplug.c
> +++ b/mm/memory_hotplug.c
> @@ -1860,4 +1860,24 @@ int offline_and_remove_memory(int nid, u64 start, u64 size)
> return rc;
> }
> EXPORT_SYMBOL_GPL(offline_and_remove_memory);
> +
> +int mark_memory_hotpluggable(unsigned long start_pfn, unsigned long end_pfn)
> +{
> + struct mem_section *ms;
> + unsigned long nr;
> + int rc = -EINVAL;
> +
> + if (end_pfn < start_pfn)
> + return rc;
> +
> + for (nr = start_pfn; nr <= end_pfn; nr++) {
> + ms = __pfn_to_section(nr);
> + rc = section_mark_hotpluggable(ms);
> + if (!rc)
> + break;
> + }
> +
> + return rc;
> +}
> +EXPORT_SYMBOL_GPL(mark_memory_hotpluggable);
> #endif /* CONFIG_MEMORY_HOTREMOVE */
> diff --git a/mm/sparse.c b/mm/sparse.c
> index fcc3d176f1ea..cc21c23e2f1d 100644
> --- a/mm/sparse.c
> +++ b/mm/sparse.c
> @@ -13,6 +13,7 @@
> #include <linux/vmalloc.h>
> #include <linux/swap.h>
> #include <linux/swapops.h>
> +#include <linux/page-isolation.h>
>
> #include "internal.h"
> #include <asm/dma.h>
> @@ -644,6 +645,36 @@ void offline_mem_sections(unsigned long start_pfn, unsigned long end_pfn)
> ms->section_mem_map &= ~SECTION_IS_ONLINE;
> }
> }
> +
> +int section_mark_hotpluggable(struct mem_section *ms)
> +{
> + unsigned long section_nr, pfn;
> + bool unmovable;
> + struct page *page;
> +
> + /* section needs to be both valid and present to be marked */
> + if (WARN_ON(!valid_section(ms)) || !present_section(ms))
> + return -EINVAL;
> +
> + /*
> + * now check if this section is removable. This can be done by checking
> + * if section has unmovable pages or not.
> + */
> + section_nr = __section_nr(ms);
> + pfn = section_nr_to_pfn(section_nr);
> + page = pfn_to_page(pfn);
> + unmovable = has_unmovable_pages(page_zone(page), page,
> + MIGRATE_MOVABLE, MEMORY_OFFLINE | REPORT_FAILURE);
> + if (unmovable) {
> + pr_info("section %lu has unmovable pages. Cannot be marked as hotpluggable\n");
> + return -EINVAL;
> + }
> +
> + /* all good! mark section as hotpluggable */
> + ms->section_mem_map |= SECTION_MARK_HOTPLUGGABLE;
> +
> + return 0;
> +}
> #endif
>
> #ifdef CONFIG_SPARSEMEM_VMEMMAP
> --
> Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
> a Linux Foundation Collaborative Project
>
--
Sincerely yours,
Mike.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2020-10-17 8:28 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-17 2:02 [PATCH 0/2] mm/memory_hotplug, arm64: allow certain bootmem sections to be offlinable Sudarshan Rajagopalan
2020-10-17 2:02 ` [PATCH 1/2] mm/memory_hotplug: allow marking of memory sections as hotpluggable Sudarshan Rajagopalan
2020-10-17 8:26 ` Mike Rapoport [this message]
2020-10-17 9:36 ` David Hildenbrand
2020-10-21 9:54 ` Mike Rapoport
2020-10-17 2:02 ` [PATCH 2/2] arm64: allow hotpluggable sections to be offlined Sudarshan Rajagopalan
2020-10-17 7:34 ` David Hildenbrand
2020-10-19 6:56 ` Anshuman Khandual
2020-10-19 6:47 ` [PATCH 0/2] mm/memory_hotplug, arm64: allow certain bootmem sections to be offlinable Anshuman Khandual
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=20201017082600.GB16395@kernel.org \
--to=rppt@kernel.org \
--cc=anshuman.khandual@arm.com \
--cc=catalin.marinas@arm.com \
--cc=david@redhat.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=logang@deltatee.com \
--cc=mark.rutland@arm.com \
--cc=steven.price@arm.com \
--cc=sudaraja@codeaurora.org \
--cc=surenb@google.com \
--cc=will@kernel.org \
/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).