linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: Sumanth Korikkar <sumanthk@linux.ibm.com>,
	linux-mm <linux-mm@kvack.org>,
	Andrew Morton <akpm@linux-foundation.org>
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>,
	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: Re: [PATCH v4 1/5] mm/memory_hotplug: introduce MEM_PREPARE_ONLINE/MEM_FINISH_OFFLINE notifiers
Date: Tue, 28 Nov 2023 12:08:58 +0100	[thread overview]
Message-ID: <1e15544f-ba35-4be6-b77a-f3e1daafe24a@redhat.com> (raw)
In-Reply-To: <20231128110342.102096-2-sumanthk@linux.ibm.com>

On 28.11.23 12:03, Sumanth Korikkar wrote:
> Introduce  MEM_PREPARE_ONLINE/MEM_FINISH_OFFLINE memory notifiers to
> prepare the transition of memory to and from a physically accessible
> state. This enhancement is crucial for implementing the "memmap on
> memory" feature for s390 in a subsequent patch.
> 
> Platforms such as x86 can support physical memory hotplug via ACPI. When
> there is physical memory hotplug, ACPI event leads to the memory
> addition with the following callchain:
> acpi_memory_device_add()
>    -> acpi_memory_enable_device()
>       -> __add_memory()
> 
> After this, the hotplugged memory is physically accessible, and altmap
> support prepared, before the "memmap on memory" initialization in
> memory_block_online() is called.
> 
> On s390, memory hotplug works in a different way. The available hotplug
> memory has to be defined upfront in the hypervisor, but it is made
> physically accessible only when the user sets it online via sysfs,
> currently in the MEM_GOING_ONLINE notifier. This is too late and "memmap
> on memory" initialization is performed before calling MEM_GOING_ONLINE
> notifier.
> 
> During the memory hotplug addition phase, altmap support is prepared and
> during the memory onlining phase s390 requires memory to be physically
> accessible and then subsequently initiate the "memmap on memory"
> initialization process.
> 
> The memory provider will handle new MEM_PREPARE_ONLINE /
> MEM_FINISH_OFFLINE notifications and make the memory accessible.
> 
> The mhp_flag MHP_OFFLINE_INACCESSIBLE is introduced and is relevant when
> used along with MHP_MEMMAP_ON_MEMORY, because the altmap cannot be
> written (e.g., poisoned) when adding memory -- before it is set online.
> This allows for adding memory with an altmap that is not currently made
> available by a hypervisor. When onlining that memory, the hypervisor can
> be instructed to make that memory accessible via the new notifiers and
> the onlining phase will not require any memory allocations, which is
> helpful in low-memory situations.
> 
> All architectures ignore unknown memory notifiers.  Therefore, the
> introduction of these new notifiers does not result in any functional
> modifications across architectures.
> 
> Suggested-by: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
> Suggested-by: David Hildenbrand <david@redhat.com>
> Signed-off-by: Sumanth Korikkar <sumanthk@linux.ibm.com>
> ---
>   drivers/base/memory.c          | 23 ++++++++++++++++++++++-
>   include/linux/memory.h         |  9 +++++++++
>   include/linux/memory_hotplug.h | 18 +++++++++++++++++-
>   include/linux/memremap.h       |  1 +
>   mm/memory_hotplug.c            | 13 ++++++++++++-
>   mm/sparse.c                    |  3 ++-
>   6 files changed, 63 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/base/memory.c b/drivers/base/memory.c
> index 8a13babd826c..b99bcc70d6e5 100644
> --- a/drivers/base/memory.c
> +++ b/drivers/base/memory.c
> @@ -188,6 +188,7 @@ static int memory_block_online(struct memory_block *mem)
>   	unsigned long start_pfn = section_nr_to_pfn(mem->start_section_nr);
>   	unsigned long nr_pages = PAGES_PER_SECTION * sections_per_block;
>   	unsigned long nr_vmemmap_pages = 0;
> +	struct memory_notify arg;
>   	struct zone *zone;
>   	int ret;
>   
> @@ -207,9 +208,19 @@ static int memory_block_online(struct memory_block *mem)
>   	if (mem->altmap)
>   		nr_vmemmap_pages = mem->altmap->free;
>   
> +	arg.altmap_start_pfn = start_pfn;
> +	arg.altmap_nr_pages = nr_vmemmap_pages;
> +	arg.start_pfn = start_pfn + nr_vmemmap_pages;
> +	arg.nr_pages = nr_pages - nr_vmemmap_pages;
>   	mem_hotplug_begin();
> +	ret = memory_notify(MEM_PREPARE_ONLINE, &arg);
> +	ret = notifier_to_errno(ret);
> +	if (ret)
> +		goto out_notifier;
> +
>   	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->altmap->inaccessible);
>   		if (ret)
>   			goto out;
>   	}
> @@ -231,7 +242,11 @@ static int memory_block_online(struct memory_block *mem)
>   					  nr_vmemmap_pages);
>   
>   	mem->zone = zone;
> +	mem_hotplug_done();
> +	return ret;
>   out:
> +	memory_notify(MEM_FINISH_OFFLINE, &arg);
> +out_notifier:
>   	mem_hotplug_done();
>   	return ret;
>   }
> @@ -244,6 +259,7 @@ static int memory_block_offline(struct memory_block *mem)
>   	unsigned long start_pfn = section_nr_to_pfn(mem->start_section_nr);
>   	unsigned long nr_pages = PAGES_PER_SECTION * sections_per_block;
>   	unsigned long nr_vmemmap_pages = 0;
> +	struct memory_notify arg;
>   	int ret;
>   
>   	if (!mem->zone)
> @@ -275,6 +291,11 @@ static int memory_block_offline(struct memory_block *mem)
>   		mhp_deinit_memmap_on_memory(start_pfn, nr_vmemmap_pages);
>   
>   	mem->zone = NULL;
> +	arg.altmap_start_pfn = start_pfn;
> +	arg.altmap_nr_pages = nr_vmemmap_pages;
> +	arg.start_pfn = start_pfn + nr_vmemmap_pages;
> +	arg.nr_pages = nr_pages - nr_vmemmap_pages;
> +	memory_notify(MEM_FINISH_OFFLINE, &arg);
>   out:
>   	mem_hotplug_done();
>   	return ret;
> diff --git a/include/linux/memory.h b/include/linux/memory.h
> index f53cfdaaaa41..939a16bd5cea 100644
> --- a/include/linux/memory.h
> +++ b/include/linux/memory.h
> @@ -96,8 +96,17 @@ int set_memory_block_size_order(unsigned int order);
>   #define	MEM_GOING_ONLINE	(1<<3)
>   #define	MEM_CANCEL_ONLINE	(1<<4)
>   #define	MEM_CANCEL_OFFLINE	(1<<5)
> +#define	MEM_PREPARE_ONLINE	(1<<6)
> +#define	MEM_FINISH_OFFLINE	(1<<7)
>   
>   struct memory_notify {
> +	/*
> +	 * The altmap_start_pfn and altmap_nr_pages fields are designated for
> +	 * specifying the altmap range and are exclusively intended for use in
> +	 * MEM_PREPARE_ONLINE/MEM_FINISH_OFFLINE notifiers.
> +	 */
> +	unsigned long altmap_start_pfn;
> +	unsigned long altmap_nr_pages;
>   	unsigned long start_pfn;
>   	unsigned long nr_pages;
>   	int status_change_nid_normal;

Maybe we should do something like:

union {
	/* For MEM_PREPARE_ONLINE/MEM_FINISH_OFFLINE ... */
	struct {
		unsigned long altmap_start_pfn;
		unnsigned long altmap_nr_pages;
	};
	/* For all others ... */
	struct {
		int status_change_nid_normal;
		...
	};
}

Acked-by: David Hildenbrand <david@redhat.com>

-- 
Cheers,

David / dhildenb



      parent reply	other threads:[~2023-11-28 11:09 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-28 11:03 [PATCH v4 0/5] implement "memmap on memory" feature on s390 Sumanth Korikkar
2023-11-28 11:03 ` [PATCH v4 2/5] s390/mm: allocate vmemmap pages from self-contained memory range Sumanth Korikkar
2023-11-28 11:03 ` [PATCH v4 3/5] s390/sclp: remove unhandled memory notifier type Sumanth Korikkar
2023-11-28 11:03 ` [PATCH v4 4/5] s390/mm: implement MEM_PREPARE_ONLINE/MEM_FINISH_OFFLINE notifiers Sumanth Korikkar
2023-11-28 11:12   ` David Hildenbrand
     [not found] ` <20231128110342.102096-2-sumanthk@linux.ibm.com>
2023-11-28 11:08   ` David Hildenbrand [this message]

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=1e15544f-ba35-4be6-b77a-f3e1daafe24a@redhat.com \
    --to=david@redhat.com \
    --cc=agordeev@linux.ibm.com \
    --cc=akpm@linux-foundation.org \
    --cc=aneesh.kumar@linux.ibm.com \
    --cc=anshuman.khandual@arm.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 \
    --cc=sumanthk@linux.ibm.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