Skip to content

drivers/base/memory: determine and store zone for single-zone memory blocks

David Hildenbrand linux-mm lkml 2 versions – Applied

Status from this message: [merged] drivers-base-node-rename-link_mem_sections-to-register_memory_block_under_node.patch removed from -mm tree

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest2 patches 3 repliesApplied 2/2
  2. v12 patches 5 repliesSuperseded

Changes in v2 from the cover letter

* Keep returning -EINVAL when we have multiple zones
* s/memory_block_set_nid/memory_block_add_nid/ and add proper documentation
* Move sanity "single zone" check after "memory hole" check
* Minor fixes for spelling mistakes

[1] https://lkml.kernel.org/r/[email protected]
[2] https://lkml.kernel.org/r/[email protected]

Patches in v2 All 2 applied

#Subject and filesSizeRepliesApplied
1/2drivers/base/node: rename link_mem_sections() to register_memory_block_under_node()drivers/base/node.c include/linux/node.h mm/memory_hotplug.c+14 -130 repliesApplied
2/2drivers/base/memory: determine and store zone for single-zone memory blocksdrivers/base/memory.c drivers/base/node.c include/linux/memory.h +2 more+125 -573 repliesApplied

Reviews trailers per patch

All 2 patches have a Reviewed-by or Acked-by.

PatchOscar Salvador
1/2A-b
2/2R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH v2 0/2] drivers/base/memory: determine and store zone for single-zone memory blocks

This is based on v5.17-rc3 and:
* [PATCH v1] drivers/base/memory: add memory block to memory group after registration succeeded [1]
* [PATCH v1] drivers/base/node: consolidate node device subsystem initialization in node_dev_init() [2]
Which are already in -next via -mm.

--

I remember talking to Michal in the past about removing test_pages_in_a_zone(), which we use for:
* verifying that a memory block we intend to offline is really only managed by a single zone. We don't support offlining of memory blocks that are managed by multiple zones (e.g., multiple nodes, DMA and DMA32)
* exposing that zone to user space via /sys/devices/system/memory/memory*/valid_zones

Now that I identified some more cases where test_pages_in_a_zone() might go wrong, and we received an UBSAN report (see patch #3), let's get rid of this PFN walker.

So instead of detecting the zone at runtime with test_pages_in_a_zone() by scanning the memmap, let's determine and remember for each memory block if it's managed by a single zone. The stored zone can then be used for the above two cases, avoiding a manual lookup using test_pages_in_a_zone().

This avoids eventually stumbling over uninitialized memmaps in corner cases, especially when ZONE_DEVICE ranges partly fall into memory block (that are responsible for managing System RAM).

Handling memory onlining is easy, because we online to exactly one zone. Handling boot memory is more tricky, because we want to avoid scanning all zones of all nodes to detect possible zones that overlap with the physical memory region of interest. Fortunately, we already have code that determines the applicable nodes for a memory block, to create sysfs links -- we'll hook into that.

Patch #1 is a simple cleanup I had laying around for a longer time. Patch #2 contains the main logic to remove test_pages_in_a_zone() and further details.

v1 -> v2:
* Keep returning -EINVAL when we have multiple zones
* s/memory_block_set_nid/memory_block_add_nid/ and add proper documentation
* Move sanity "single zone" check after "memory hole" check
* Minor fixes for spelling mistakes

[1] https://lkml.kernel.org/r/[email protected]
[2] https://lkml.kernel.org/r/[email protected]

Cc Andrew Morton <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Oscar Salvador <[email protected]>

David Hildenbrand (2):
drivers/base/node: rename link_mem_sections() to
register_memory_block_under_node()
drivers/base/memory: determine and store zone for single-zone memory
blocks

 drivers/base/memory.c          | 101 +++++++++++++++++++++++++++++++--
 drivers/base/node.c            |  18 +++---
 include/linux/memory.h         |  12 ++++
 include/linux/memory_hotplug.h |   6 +-
 include/linux/node.h           |  16 +++---
 mm/memory_hotplug.c            |  56 +++++-------------
 6 files changed, 139 insertions(+), 70 deletions(-)
Signature · 1 line
2.34.1