Re: [PATCH v5 1/2] mm/memory_hotplug: split memmap_on_memory requests across memblocks

From: Verma, Vishal L
Date: Fri Oct 06 2023 - 18:02:10 EST


On Fri, 2023-10-06 at 14:52 +0200, David Hildenbrand wrote:
> On 05.10.23 20:31, Vishal Verma wrote:
> >
<..>
> > @@ -2167,47 +2221,28 @@ static int __ref try_remove_memory(u64 start, u64 size)
> >         if (rc)
> >                 return rc;
> >  
> > +       mem_hotplug_begin();
> > +
> >         /*
> > -        * We only support removing memory added with MHP_MEMMAP_ON_MEMORY in
> > -        * the same granularity it was added - a single memory block.
> > +        * 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.
> >          */
> >         if (mhp_memmap_on_memory()) {
> > -               rc = walk_memory_blocks(start, size, &mem, test_has_altmap_cb);
> > -               if (rc) {
> > -                       if (size != memory_block_size_bytes()) {
> > -                               pr_warn("Refuse to remove %#llx - %#llx,"
> > -                                       "wrong granularity\n",
> > -                                       start, start + size);
> > -                               return -EINVAL;
> > -                       }
> > -                       altmap = mem->altmap;
> > -                       /*
> > -                        * Mark altmap NULL so that we can add a debug
> > -                        * check on memblock free.
> > -                        */
> > -                       mem->altmap = NULL;
> > -               }
> > +               unsigned long memblock_size = memory_block_size_bytes();
> > +               u64 cur_start;
> > +
> > +               for (cur_start = start; cur_start < start + size;
> > +                    cur_start += memblock_size)
> > +                       remove_memory_block_and_altmap(nid, cur_start,
> > +                                                      memblock_size);
> > +       } else {
> > +               remove_memory_block_and_altmap(nid, start, size);
>
> Better call remove_memory_block_devices() and arch_remove_memory(start,
> size, altmap) here explicitly instead of using
> remove_memory_block_and_altmap() that really can only handle a single
> memory block with any inputs.
>
I'm not sure I follow. Even in the non memmap_on_memory case, we'd have
to walk_memory_blocks() to get to the memory_block->altmap, right?

Or is there a more direct way? If we have to walk_memory_blocks, what's
the advantage of calling those directly instead of calling the helper
created above?

Agreed with and fixed up all the other comments.