Re: [RFC v2 2/2] mm/memory_hotplug: Shrink spanned pages when offlining memory

From: Pasha Tatashin
Date: Wed Aug 29 2018 - 19:09:07 EST



On 8/17/18 11:41 AM, Oscar Salvador wrote:
> From: Oscar Salvador <osalvador@xxxxxxx>
>
> Currently, we decrement zone/node spanned_pages when we
> remove memory and not when we offline it.
>
> This, besides of not being consistent with the current code,
> implies that we can access steal pages if we never get to online
> that memory.
>
> In order to prevent that, we have to move all zone/pages stuff to
> the offlining memory stage.
> Removing memory path should only care about memory sections and memory
> blocks.
>
> Another thing to notice here is that this is not so easy to be done
> as HMM/devm have a particular handling of memory-hotplug.
> They do not go through the common path, and so, they do not
> call either offline_pages() nor online_pages().
>
> All they care about is to add the sections, move the pages to
> ZONE_DEVICE, and in some cases, to create the linear mapping.
>
> In order to do this more smooth, two new functions are created
> to deal with these particular cases:
>
> del_device_memory
> add_device_memory
>
> add_device_memory is in charge of
>
> a) calling either arch_add_memory() or add_pages(), depending on whether
> we want a linear mapping
> b) online the memory sections that correspond to the pfn range
> c) calling move_pfn_range_to_zone() being zone ZONE_DEVICE to
> expand zone/pgdat spanned pages and initialize its pages
>
> del_device_memory, on the other hand, is in charge of
>
> a) offline the memory sections that correspond to the pfn range
> b) calling shrink_pages(), which shrinks node/zone spanned pages.
> c) calling either arch_remove_memory() or __remove_pages(), depending on
> whether we need to tear down the linear mapping or not
>
> These two functions are called from:
>
> add_device_memory:
> - devm_memremap_pages()
> - hmm_devmem_pages_create()
>
> del_device_memory:
> - devm_memremap_pages_release()
> - hmm_devmem_release()
>
> I think that this will get easier as soon as [1] gets merged.
>
> Finally, shrink_pages() is moved to offline_pages(), so now,
> all pages/zone handling is being taken care in online/offline_pages stage.
>
> [1] https://lkml.org/lkml/2018/6/19/110
>
> Signed-off-by: Oscar Salvador <osalvador@xxxxxxx>
> ---
> arch/ia64/mm/init.c | 4 +-
> arch/powerpc/mm/mem.c | 10 +--
> arch/sh/mm/init.c | 4 +-
> arch/x86/mm/init_32.c | 4 +-
> arch/x86/mm/init_64.c | 8 +--
> include/linux/memory_hotplug.h | 9 ++-
> kernel/memremap.c | 14 ++--
> kernel/resource.c | 16 +++++
> mm/hmm.c | 32 ++++-----
> mm/memory_hotplug.c | 143 +++++++++++++++++++++++++++--------------
> mm/sparse.c | 4 +-
> 11 files changed, 145 insertions(+), 103 deletions(-)

Hi Oscar,

I have been studying this patch, and do not see anything bad about it
except that it begs to be split into smaller patches. I think you can
send this work as a series without RFC if this patch is split into 3 or
so patches. I will review that series.

Thank you,
Pavel