From: David Hildenbrand <david@redhat.com>
To: Vishal Verma <vishal.l.verma@intel.com>,
Andrew Morton <akpm@linux-foundation.org>,
Oscar Salvador <osalvador@suse.de>,
Dan Williams <dan.j.williams@intel.com>,
Dave Jiang <dave.jiang@intel.com>
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org,
Huang Ying <ying.huang@intel.com>,
Dave Hansen <dave.hansen@linux.intel.com>,
"Aneesh Kumar K.V" <aneesh.kumar@linux.ibm.com>,
Michal Hocko <mhocko@suse.com>,
Jonathan Cameron <Jonathan.Cameron@Huawei.com>,
Jeff Moyer <jmoyer@redhat.com>
Subject: Re: [PATCH v7 2/3] mm/memory_hotplug: split memmap_on_memory requests across memblocks
Date: Mon, 30 Oct 2023 11:20:21 +0100 [thread overview]
Message-ID: <4df63333-de57-4a58-a110-77b4fdfa6a9e@redhat.com> (raw)
In-Reply-To: <20231025-vv-kmem_memmap-v7-2-4a76d7652df5@intel.com>
On 26.10.23 00:44, Vishal Verma wrote:
> The MHP_MEMMAP_ON_MEMORY flag for hotplugged memory is restricted to
> 'memblock_size' chunks of memory being added. Adding a larger span of
> memory precludes memmap_on_memory semantics.
>
> For users of hotplug such as kmem, large amounts of memory might get
> added from the CXL subsystem. In some cases, this amount may exceed the
> available 'main memory' to store the memmap for the memory being added.
> In this case, it is useful to have a way to place the memmap on the
> memory being added, even if it means splitting the addition into
> memblock-sized chunks.
>
> Change add_memory_resource() to loop over memblock-sized chunks of
> memory if caller requested memmap_on_memory, and if other conditions for
> it are met. Teach try_remove_memory() to also expect that a memory
> range being removed might have been split up into memblock sized chunks,
> and to loop through those as needed.
>
> This does preclude being able to use PUD mappings in the direct map; a
> proposal to how this could be optimized in the future is laid out
> here[1].
Almost there, I think :)
>
> +static int create_altmaps_and_memory_blocks(int nid, struct memory_group *group,
> + u64 start, u64 size)
> +{
> + unsigned long memblock_size = memory_block_size_bytes();
> + u64 cur_start;
> + int ret;
> +
> + for (cur_start = start; cur_start < start + size;
> + cur_start += memblock_size) {
> + struct mhp_params params = { .pgprot =
> + pgprot_mhp(PAGE_KERNEL) };
> + struct vmem_altmap mhp_altmap = {
> + .base_pfn = PHYS_PFN(cur_start),
> + .end_pfn = PHYS_PFN(cur_start + memblock_size - 1),
> + };
> +
> + mhp_altmap.free = memory_block_memmap_on_memory_pages();
> + params.altmap = kmemdup(&mhp_altmap, sizeof(struct vmem_altmap),
> + GFP_KERNEL);
> + if (!params.altmap)
> + return -ENOMEM;
Best to cleanup here instead of handling it in the caller [as noted by
Vishal, we might not be doing that yet]. Using
remove_memory_blocks_and_altmaps() on the fully processed range sounds
reasonable.
maybe something like
ret = arch_add_memory(nid, cur_start, memblock_size, ¶ms);
if (ret) {
kfree(params.altmap);
goto out;
}
ret = create_memory_block_devices(cur_start, memblock_size,
params.altmap, group);
if (ret) {
arch_remove_memory(cur_start, memblock_size, NULL);
kfree(params.altmap);
goto out;
}
if (ret && cur_start != start)
remove_memory_blocks_and_altmaps(start, cur_start - start);
return ret;
> +
> + /* call arch's memory hotadd */
> + ret = arch_add_memory(nid, cur_start, memblock_size, ¶ms);
> + if (ret < 0) {
> + kfree(params.altmap);
> + return ret;
> + }
> +
> + /* create memory block devices after memory was added */
> + ret = create_memory_block_devices(cur_start, memblock_size,
> + params.altmap, group);
> + if (ret) {
> + arch_remove_memory(cur_start, memblock_size, NULL);
> + kfree(params.altmap);
> + return ret;
> + }
> + }
> +
> + return 0;
> +}
> +
[...]
> static int check_cpu_on_node(int nid)
> {
> int cpu;
> @@ -2146,11 +2186,69 @@ void try_offline_node(int nid)
> }
> EXPORT_SYMBOL(try_offline_node);
>
> -static int __ref try_remove_memory(u64 start, u64 size)
> +static void __ref remove_memory_blocks_and_altmaps(u64 start, u64 size)
> {
> - struct memory_block *mem;
> - int rc = 0, nid = NUMA_NO_NODE;
> + unsigned long memblock_size = memory_block_size_bytes();
> struct vmem_altmap *altmap = NULL;
> + struct memory_block *mem;
> + u64 cur_start;
> + int rc;
> +
> + /*
> + * For memmap_on_memory, the altmaps could have been added on
> + * a per-memblock basis. Loop through the entire range if so,
> + * and remove each memblock and its altmap.
> + */
/*
* altmaps where added on a per-memblock basis; we have to process
* each individual memory block.
*/
> + for (cur_start = start; cur_start < start + size;
> + cur_start += memblock_size) {
> + rc = walk_memory_blocks(cur_start, memblock_size, &mem,
> + test_has_altmap_cb);
> + if (rc) {
> + altmap = mem->altmap;
> + /*
> + * Mark altmap NULL so that we can add a debug
> + * check on memblock free.
> + */
> + mem->altmap = NULL;
> + }
Simpler (especially, we know that there must be an altmap):
mem = find_memory_block(pfn_to_section_nr(cur_start));
altmap = mem->altmap;
mem->altmap = NULL;
I think we might be able to remove test_has_altmap_cb() then.
> +
> + remove_memory_block_devices(cur_start, memblock_size);
> +
> + arch_remove_memory(cur_start, memblock_size, altmap);
> +
> + /* Verify that all vmemmap pages have actually been freed. */
> + if (altmap) {
There must be an altmap, so this can be done unconditionally.
> + WARN(altmap->alloc, "Altmap not fully unmapped");
> + kfree(altmap);
> + }
> + }
> +}
--
Cheers,
David / dhildenb
next prev parent reply other threads:[~2023-10-30 10:20 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-25 22:44 [PATCH v7 0/3] mm: use memmap_on_memory semantics for dax/kmem Vishal Verma
2023-10-25 22:44 ` [PATCH v7 1/3] mm/memory_hotplug: replace an open-coded kmemdup() in add_memory_resource() Vishal Verma
2023-10-25 22:44 ` [PATCH v7 2/3] mm/memory_hotplug: split memmap_on_memory requests across memblocks Vishal Verma
2023-10-30 2:46 ` Huang, Ying
2023-10-30 10:20 ` David Hildenbrand [this message]
2023-10-31 2:14 ` Verma, Vishal L
2023-10-31 10:13 ` David Hildenbrand
2023-10-25 22:44 ` [PATCH v7 3/3] dax/kmem: allow kmem to add memory with memmap_on_memory Vishal Verma
2023-10-30 2:57 ` Huang, Ying
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=4df63333-de57-4a58-a110-77b4fdfa6a9e@redhat.com \
--to=david@redhat.com \
--cc=Jonathan.Cameron@Huawei.com \
--cc=akpm@linux-foundation.org \
--cc=aneesh.kumar@linux.ibm.com \
--cc=dan.j.williams@intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=dave.jiang@intel.com \
--cc=jmoyer@redhat.com \
--cc=linux-cxl@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
--cc=nvdimm@lists.linux.dev \
--cc=osalvador@suse.de \
--cc=vishal.l.verma@intel.com \
--cc=ying.huang@intel.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