Re: [PATCH v2 0/5] Allocate memmap from hotadded memory

From: Oscar Salvador
Date: Wed Jun 26 2019 - 04:28:01 EST


On Wed, Jun 26, 2019 at 10:15:16AM +0200, Oscar Salvador wrote:
> On Wed, Jun 26, 2019 at 10:11:06AM +0200, David Hildenbrand wrote:
> > Back then, I already mentioned that we might have some users that
> > remove_memory() they never added in a granularity it wasn't added. My
> > concerns back then were never fully sorted out.
> >
> > arch/powerpc/platforms/powernv/memtrace.c
> >
> > - Will remove memory in memory block size chunks it never added
> > - What if that memory resides on a DIMM added via MHP_MEMMAP_DEVICE?
> >
> > Will it at least bail out? Or simply break?
> >
> > IOW: I am not yet 100% convinced that MHP_MEMMAP_DEVICE is save to be
> > introduced.
>
> Uhm, I will take a closer look and see if I can clear your concerns.
> TBH, I did not try to use arch/powerpc/platforms/powernv/memtrace.c
> yet.
>
> I will get back to you once I tried it out.

On a second though, it would be quite trivial to implement a check in
remove_memory() that does not allow to remove memory used with MHP_MEMMAP_DEVICE
in a different granularity:

+static bool check_vmemmap_granularity(u64 start, u64 size);
+{
+ unsigned long pfn;
+ unsigned int nr_pages;
+ struct page *p;
+
+ pfn = PHYS_PFN(start);
+ p = pfn_to_page(pfn);
+ nr_pages = size >> PAGE_SIZE;
+
+ if (PageVmemmap(p)) {
+ struct page *h = vmemmap_get_head(p);
+ unsigned long sections = (unsigned long)h->private;
+
+ if (sections * PAGES_PER_SECTION > nr_pages)
+ fail;
+ }
+ no_fail;
+}
+
+
static int __ref try_remove_memory(int nid, u64 start, u64 size)
{
int rc = 0;

BUG_ON(check_hotplug_memory_range(start, size));

mem_hotplug_begin();

+ rc = check_vmemmap_granularity(start, size);
+ if (rc)
+ goto done;


The above is quite hacky, but it gives an idea.
I will try the code from arch/powerpc/platforms/powernv/memtrace.c and see how
can I implement a check.

--
Oscar Salvador
SUSE L3