linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 00/11] mm/memory_hotplug: Shrink zones before removing memory
@ 2019-08-29  7:00 David Hildenbrand
  2019-08-29  7:00 ` [PATCH v3 01/11] mm/memremap: Get rid of memmap_init_zone_device() David Hildenbrand
                   ` (11 more replies)
  0 siblings, 12 replies; 22+ messages in thread
From: David Hildenbrand @ 2019-08-29  7:00 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-mm, David Hildenbrand, Aneesh Kumar K . V, Andrew Morton,
	Dan Williams, Michal Hocko, Alexander Duyck, Alexander Potapenko,
	Andrey Konovalov, Andy Lutomirski, Anshuman Khandual, Arun KS,
	Benjamin Herrenschmidt, Borislav Petkov, Catalin Marinas,
	Christian Borntraeger, Christophe Leroy, Dave Airlie,
	Dave Hansen, Fenghua Yu, Gerald Schaefer, Greg Kroah-Hartman,
	Halil Pasic, Heiko Carstens, H. Peter Anvin, Ingo Molnar,
	Ira Weiny, Jason Gunthorpe, John Hubbard, Jun Yao,
	Kirill A. Shutemov, Logan Gunthorpe, Mark Rutland,
	Masahiro Yamada, Matthew Wilcox (Oracle),
	Mel Gorman, Michael Ellerman, Mike Rapoport, Mike Rapoport,
	Oscar Salvador, Oscar Salvador, Paul Mackerras, Pavel Tatashin,
	Pavel Tatashin, Peter Zijlstra, Qian Cai, Rich Felker,
	Robin Murphy, Souptick Joarder, Stephen Rothwell, Steve Capper,
	Thomas Gleixner, Tom Lendacky, Tony Luck, Vasily Gorbik,
	Vlastimil Babka, Wei Yang, Wei Yang, Will Deacon, Yang Shi,
	Yoshinori Sato, Yu Zhao

This is the successor of "[PATCH v2 0/6] mm/memory_hotplug: Consider all
zones when removing memory". I decided to go one step further and finally
factor out the shrinking of zones from memory removal code. Zones are now
fixed up when offlining memory/onlining of memory fails/before removing
ZONE_DEVICE memory.

I guess only patch #1 is debatable - it is certainly not a blocker for
the other stuff in this series, it just doesn't seem to be 100% safe. I
am not quite sure if we have a real performance issue here, let's hear
what people think.

--------------------------------------------------------------------------

Example:

:/# cat /proc/zoneinfo
Node 1, zone  Movable
        spanned  0
        present  0
        managed  0
:/# echo "online_movable" > /sys/devices/system/memory/memory41/state 
:/# echo "online_movable" > /sys/devices/system/memory/memory43/state
:/# cat /proc/zoneinfo
Node 1, zone  Movable
        spanned  98304
        present  65536
        managed  65536
:/# echo 0 > /sys/devices/system/memory/memory43/online
:/# cat /proc/zoneinfo
Node 1, zone  Movable
        spanned  32768
        present  32768
        managed  32768
:/# echo 0 > /sys/devices/system/memory/memory41/online
:/# cat /proc/zoneinfo
Node 1, zone  Movable
        spanned  0
        present  0
        managed  0

--------------------------------------------------------------------------

This series fixes various issues:
1. Memory removal can currently crash the system in case the first
memory block was never onlined.

2. Zone shrinking code can crash the system when trying to look at
uninitialized memmaps.

3. Removing memory with different/multiple/no zones for affected memory
blocks does not properly shring zones. It really only works correcty in the
case all memory blocks were onlined to the same zone.

4. In case memory onlining fails, the zones are not fixed up again.

--------------------------------------------------------------------------

For !ZONE_DEVICE memory, zones are now fixed up when offlining memory. This
now works very reliable.

For ZONE_DEVICE memory, the zone is fixed up before removing memory. I
haven't tested it, but we should no longer be able to crash the system
BUT there is a fundamental issue remaining that has to be sorted out next:
How to detect which memmaps of ZONE_DEVICE memory is valid. The current
fix I implemented is ugly and has to go.

For !ZONE_DEVICE memory we can look at the SECTION_IS_ONLINE flag to
decide whether the memmap was initialized. We can't easily use the same for
ZONE_DEVICE memory, especially, because we have subsection hotplug there.
While we have "present" masks for subsections ("memory was added") we don't
have something similar for "online/active". This could probably be one
thing to look into in the future: Use SECTION_IS_ONLINE also for
ZONE_DEVICE memory and remember in a subsection bitmap which subsections
are actually online/active.

I'll leave that exercise to the ZONE_DEVICE folks. From a memory block
onlining/offlining point of view things should be clean now.

While we could still have false positives for ZONE_DEVICE memory when
trying to shrink zones, we should no longer crash - which improves
the situation heavily.

Fact: set_zone_contiguous() is even more broken (false positives) for
ZONE_DEVICE memory: it will never set a zone contiguous because we are
missing the exact same functionality: How to detect whether a memmap was
initialized, so we can trust the zone values.

--------------------------------------------------------------------------

A bunch of prepararions and cleanups included. I only tested on x86
with DIMMs so far.

Cc: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Michal Hocko <mhocko@suse.com>

David Hildenbrand (11):
  mm/memremap: Get rid of memmap_init_zone_device()
  mm/memory_hotplug: Simplify shrink_pgdat_span()
  mm/memory_hotplug: We always have a zone in
    find_(smallest|biggest)_section_pfn
  mm/memory_hotplug: Drop local variables in shrink_zone_span()
  mm/memory_hotplug: Optimize zone shrinking code when checking for
    holes
  mm/memory_hotplug: Fix crashes in shrink_zone_span()
  mm/memory_hotplug: Exit early in __remove_pages() on BUGs
  mm: Exit early in set_zone_contiguous() if already contiguous
  mm/memory_hotplug: Remove pages from a zone before removing memory
  mm/memory_hotplug: Remove zone parameter from __remove_pages()
  mm/memory_hotplug: Cleanup __remove_pages()

 arch/arm64/mm/mmu.c            |   4 +-
 arch/ia64/mm/init.c            |   4 +-
 arch/powerpc/mm/mem.c          |   3 +-
 arch/s390/mm/init.c            |   4 +-
 arch/sh/mm/init.c              |   4 +-
 arch/x86/mm/init_32.c          |   4 +-
 arch/x86/mm/init_64.c          |   4 +-
 include/linux/memory_hotplug.h |   9 +-
 include/linux/mm.h             |   4 +-
 mm/memory_hotplug.c            | 215 +++++++++++++++------------------
 mm/memremap.c                  |  19 +--
 mm/page_alloc.c                |  45 +++----
 12 files changed, 136 insertions(+), 183 deletions(-)

-- 
2.21.0



^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2019-08-29 16:55 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-29  7:00 [PATCH v3 00/11] mm/memory_hotplug: Shrink zones before removing memory David Hildenbrand
2019-08-29  7:00 ` [PATCH v3 01/11] mm/memremap: Get rid of memmap_init_zone_device() David Hildenbrand
2019-08-29 16:39   ` Alexander Duyck
2019-08-29 16:55     ` David Hildenbrand
2019-08-29  7:00 ` [PATCH v3 02/11] mm/memory_hotplug: Simplify shrink_pgdat_span() David Hildenbrand
2019-08-29  7:00 ` [PATCH v3 03/11] mm/memory_hotplug: We always have a zone in find_(smallest|biggest)_section_pfn David Hildenbrand
2019-08-29  7:00 ` [PATCH v3 04/11] mm/memory_hotplug: Drop local variables in shrink_zone_span() David Hildenbrand
2019-08-29  7:00 ` [PATCH v3 05/11] mm/memory_hotplug: Optimize zone shrinking code when checking for holes David Hildenbrand
2019-08-29  7:00 ` [PATCH v3 06/11] mm/memory_hotplug: Fix crashes in shrink_zone_span() David Hildenbrand
2019-08-29  7:00 ` [PATCH v3 07/11] mm/memory_hotplug: Exit early in __remove_pages() on BUGs David Hildenbrand
2019-08-29  7:00 ` [PATCH v3 08/11] mm: Exit early in set_zone_contiguous() if already contiguous David Hildenbrand
2019-08-29  7:00 ` [PATCH v3 09/11] mm/memory_hotplug: Remove pages from a zone before removing memory David Hildenbrand
2019-08-29  7:00 ` [PATCH v3 10/11] mm/memory_hotplug: Remove zone parameter from __remove_pages() David Hildenbrand
2019-08-29  7:00 ` [PATCH v3 11/11] mm/memory_hotplug: Cleanup __remove_pages() David Hildenbrand
2019-08-29  8:23 ` [PATCH v3 00/11] mm/memory_hotplug: Shrink zones before removing memory Michal Hocko
2019-08-29 11:33   ` David Hildenbrand
2019-08-29 11:43     ` David Hildenbrand
2019-08-29 12:08       ` David Hildenbrand
2019-08-29 12:15         ` Michal Hocko
2019-08-29 12:29           ` David Hildenbrand
2019-08-29 15:19             ` Michal Hocko
2019-08-29 15:28               ` David Hildenbrand

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox