diff options
| author | Linus Torvalds <torvalds@linux-foundation.org> | 2026-10-23 09:13:11 -1000 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2026-10-23 09:13:11 -1000 |
| commit | 2ee2475e15b4ff8fda89a9edcb77dfd871de1386 (patch) | |
| tree | 36b481233e66ff1c92891d91a7bf7344a6a744bd /include/linux/mmzone.h | |
| parent | c5fd5e67c7812bc40cd897422c1e0d6dd9ed1e2e (diff) | |
| parent | 07ae95d933b84db98696f23e24de078b251561ff (diff) | |
Merge tag 'mm-core-7.4-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/mm/core
Pull core memory management updates from David Hildenbrand:
"This includes updates to:
- MEMHP (Memory Hotplug)
- GUP (Get User Pages)
The main change is:
- Reduce zone contiguity checking overhead during memory hot(un)plug
(Yuan Liu)
Other changes include smaller fixes along with various cleanups"
* tag 'mm-core-7.4-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/mm/core:
mm/memory_hotplug: fix missing rollback in __add_pages()
mm/memory_hotplug: optimize zone contiguous check when changing pfn range
mm/memory_hotplug: make shrink_zone_span() more robust
mm/gup: honour FOLL_PIN in NOMMU __get_user_pages_locked()
mm/gup_test: report actual pinned bytes
mm/gup_test: safely calculate GUP batch size
mm: gup: cleanup the gup_fast_*() call chain
mm: gup: move pmd_protnone() into gup_fast_pmd_leaf()
Diffstat (limited to 'include/linux/mmzone.h')
| -rw-r--r-- | include/linux/mmzone.h | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index 8e4e0bda3b58..d44b04589f48 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -1019,6 +1019,42 @@ struct zone { * cma pages is present pages that are assigned for CMA use * (MIGRATE_CMA). * + * pages_with_online_memmap tracks pages within the zone that have + * an online memory map: present pages and memory holes whose + * memory map has been initialized and pfn_to_online_page() + * succeeds. When spanned_pages == pages_with_online_memmap, + * pfn_to_page() can be performed without further checks on any + * PFN within the zone span. + * + * Note: this counter may temporarily undercount when pages with an + * online memory map exist outside the current zone span. Such pages + * are only created during boot, when initializing the memory map of + * pages that do not fall into any zone span. The undercount itself + * can only happen after boot, during memory hotplug, when growing + * the zone to cover such pages and later shrinking it back, which + * may result in a "too small" value. This is safe: it merely + * prevents detecting a contiguous zone. + * + * Here is an example (page numbers are just for illustration + * purposes): + * after boot: + * [ zone span ] + * [ zone pages ] + * spanned=10, initialized=15, online=10 + * online == spanned -> contiguous + * + * growing after hotplug (hotplug 5): + * [ zone span ] + * [ zone pages ] [ zone pages ] + * spanned=30, initialized=20, online=15 + * online != spanned -> not contiguous + * + * shrinking after hotunplug (hotunplug 5 again): + * [ zone span ] + * [ zone pages ] + * spanned=15, initialized=15, online=10 + * online != spanned -> not contiguous although contiguous + * * So present_pages may be used by memory hotplug or memory power * management logic to figure out unmanaged pages by checking * (present_pages - managed_pages). And managed_pages should be used @@ -1043,6 +1079,7 @@ struct zone { atomic_long_t managed_pages; unsigned long spanned_pages; unsigned long present_pages; + unsigned long pages_with_online_memmap; #if defined(CONFIG_MEMORY_HOTPLUG) unsigned long present_early_pages; #endif @@ -1670,6 +1707,38 @@ static inline bool zone_is_zone_device(const struct zone *zone) } #endif +/** + * zone_is_contiguous - test whether a zone is contiguous + * @zone: the zone to test. + * + * In a contiguous zone, it is valid to call pfn_to_page() on any PFN in the + * spanned zone without requiring pfn_valid() or pfn_to_online_page() checks. + * + * Note that missing synchronization with memory offlining makes any PFN + * traversal prone to races. + * + * ZONE_DEVICE zones are always marked non-contiguous. + * + * Return: true if contiguous, otherwise false. + */ +static inline bool zone_is_contiguous(const struct zone *zone) +{ + return READ_ONCE(zone->contiguous); +} + +static inline void set_zone_contiguous(struct zone *zone) +{ + if (zone_is_zone_device(zone)) + return; + if (zone->spanned_pages == zone->pages_with_online_memmap) + WRITE_ONCE(zone->contiguous, true); +} + +static inline void clear_zone_contiguous(struct zone *zone) +{ + WRITE_ONCE(zone->contiguous, false); +} + /* * Returns true if a zone has pages managed by the buddy allocator. * All the reclaim decisions have to use this function rather than |
