Skip to content

Commit 249be85

Browse files
committed
Merge branch 'akpm' (patches from Andrew)
Merge yet more updates from Andrew Morton: "The rest of MM and a kernel-wide procfs cleanup. Summary of the more significant patches: - Patch series "mm/memory_hotplug: Factor out memory block devicehandling", v3. David Hildenbrand. Some spring-cleaning of the memory hotplug code, notably in drivers/base/memory.c - "mm: thp: fix false negative of shmem vma's THP eligibility". Yang Shi. Fix /proc/pid/smaps output for THP pages used in shmem. - "resource: fix locking in find_next_iomem_res()" + 1. Nadav Amit. Bugfix and speedup for kernel/resource.c - Patch series "mm: Further memory block device cleanups", David Hildenbrand. More spring-cleaning of the memory hotplug code. - Patch series "mm: Sub-section memory hotplug support". Dan Williams. Generalise the memory hotplug code so that pmem can use it more completely. Then remove the hacks from the libnvdimm code which were there to work around the memory-hotplug code's constraints. - "proc/sysctl: add shared variables for range check", Matteo Croce. We have about 250 instances of int zero; ... .extra1 = &zero, in the tree. This is a tree-wide sweep to make all those private "zero"s and "one"s use global variables. Alas, it isn't practical to make those two global integers const" * emailed patches from Andrew Morton <akpm@linux-foundation.org>: (38 commits) proc/sysctl: add shared variables for range check mm: migrate: remove unused mode argument mm/sparsemem: cleanup 'section number' data types libnvdimm/pfn: stop padding pmem namespaces to section alignment libnvdimm/pfn: fix fsdax-mode namespace info-block zero-fields mm/devm_memremap_pages: enable sub-section remap mm: document ZONE_DEVICE memory-model implications mm/sparsemem: support sub-section hotplug mm/sparsemem: prepare for sub-section ranges mm: kill is_dev_zone() helper mm/hotplug: kill is_dev_zone() usage in __remove_pages() mm/sparsemem: convert kmalloc_section_memmap() to populate_section_memmap() mm/hotplug: prepare shrink_{zone, pgdat}_span for sub-section removal mm/sparsemem: add helpers track active portions of a section at boot mm/sparsemem: introduce a SECTION_IS_EARLY flag mm/sparsemem: introduce struct mem_section_usage drivers/base/memory.c: get rid of find_memory_block_hinted() mm/memory_hotplug: move and simplify walk_memory_blocks() mm/memory_hotplug: rename walk_memory_range() and pass start+size instead of pfns mm: make register_mem_sect_under_node() static ...
2 parents 3bfe1fc + eec4844 commit 249be85

71 files changed

Lines changed: 1087 additions & 1020 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Documentation/filesystems/proc.txt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,8 +486,8 @@ replaced by copy-on-write) part of the underlying shmem object out on swap.
486486
"SwapPss" shows proportional swap share of this mapping. Unlike "Swap", this
487487
does not take into account swapped out page of underlying shmem objects.
488488
"Locked" indicates whether the mapping is locked in memory or not.
489-
"THPeligible" indicates whether the mapping is eligible for THP pages - 1 if
490-
true, 0 otherwise.
489+
"THPeligible" indicates whether the mapping is eligible for allocating THP
490+
pages - 1 if true, 0 otherwise. It just shows the current status.
491491

492492
"VmFlags" field deserves a separate description. This member represents the kernel
493493
flags associated with the particular virtual memory area in two letter encoded

‎Documentation/vm/memory-model.rst‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,43 @@ that is eventually passed to vmemmap_populate() through a long chain
181181
of function calls. The vmemmap_populate() implementation may use the
182182
`vmem_altmap` along with :c:func:`altmap_alloc_block_buf` helper to
183183
allocate memory map on the persistent memory device.
184+
185+
ZONE_DEVICE
186+
===========
187+
The `ZONE_DEVICE` facility builds upon `SPARSEMEM_VMEMMAP` to offer
188+
`struct page` `mem_map` services for device driver identified physical
189+
address ranges. The "device" aspect of `ZONE_DEVICE` relates to the fact
190+
that the page objects for these address ranges are never marked online,
191+
and that a reference must be taken against the device, not just the page
192+
to keep the memory pinned for active use. `ZONE_DEVICE`, via
193+
:c:func:`devm_memremap_pages`, performs just enough memory hotplug to
194+
turn on :c:func:`pfn_to_page`, :c:func:`page_to_pfn`, and
195+
:c:func:`get_user_pages` service for the given range of pfns. Since the
196+
page reference count never drops below 1 the page is never tracked as
197+
free memory and the page's `struct list_head lru` space is repurposed
198+
for back referencing to the host device / driver that mapped the memory.
199+
200+
While `SPARSEMEM` presents memory as a collection of sections,
201+
optionally collected into memory blocks, `ZONE_DEVICE` users have a need
202+
for smaller granularity of populating the `mem_map`. Given that
203+
`ZONE_DEVICE` memory is never marked online it is subsequently never
204+
subject to its memory ranges being exposed through the sysfs memory
205+
hotplug api on memory block boundaries. The implementation relies on
206+
this lack of user-api constraint to allow sub-section sized memory
207+
ranges to be specified to :c:func:`arch_add_memory`, the top-half of
208+
memory hotplug. Sub-section support allows for 2MB as the cross-arch
209+
common alignment granularity for :c:func:`devm_memremap_pages`.
210+
211+
The users of `ZONE_DEVICE` are:
212+
213+
* pmem: Map platform persistent memory to be used as a direct-I/O target
214+
via DAX mappings.
215+
216+
* hmm: Extend `ZONE_DEVICE` with `->page_fault()` and `->page_free()`
217+
event callbacks to allow a device-driver to coordinate memory management
218+
events related to device-memory, typically GPU memory. See
219+
Documentation/vm/hmm.rst.
220+
221+
* p2pdma: Create `struct page` objects to allow peer devices in a
222+
PCI/-E topology to coordinate direct-DMA operations between themselves,
223+
i.e. bypass host memory.

‎arch/arm64/mm/mmu.c‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,4 +1074,21 @@ int arch_add_memory(int nid, u64 start, u64 size,
10741074
return __add_pages(nid, start >> PAGE_SHIFT, size >> PAGE_SHIFT,
10751075
restrictions);
10761076
}
1077+
void arch_remove_memory(int nid, u64 start, u64 size,
1078+
struct vmem_altmap *altmap)
1079+
{
1080+
unsigned long start_pfn = start >> PAGE_SHIFT;
1081+
unsigned long nr_pages = size >> PAGE_SHIFT;
1082+
struct zone *zone;
1083+
1084+
/*
1085+
* FIXME: Cleanup page tables (also in arch_add_memory() in case
1086+
* adding fails). Until then, this function should only be used
1087+
* during memory hotplug (adding memory), not for memory
1088+
* unplug. ARCH_ENABLE_MEMORY_HOTREMOVE must not be
1089+
* unlocked yet.
1090+
*/
1091+
zone = page_zone(pfn_to_page(start_pfn));
1092+
__remove_pages(zone, start_pfn, nr_pages, altmap);
1093+
}
10771094
#endif

‎arch/ia64/mm/init.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,6 @@ int arch_add_memory(int nid, u64 start, u64 size,
681681
return ret;
682682
}
683683

684-
#ifdef CONFIG_MEMORY_HOTREMOVE
685684
void arch_remove_memory(int nid, u64 start, u64 size,
686685
struct vmem_altmap *altmap)
687686
{
@@ -693,4 +692,3 @@ void arch_remove_memory(int nid, u64 start, u64 size,
693692
__remove_pages(zone, start_pfn, nr_pages, altmap);
694693
}
695694
#endif
696-
#endif

‎arch/powerpc/mm/mem.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ int __ref arch_add_memory(int nid, u64 start, u64 size,
125125
return __add_pages(nid, start_pfn, nr_pages, restrictions);
126126
}
127127

128-
#ifdef CONFIG_MEMORY_HOTREMOVE
129128
void __ref arch_remove_memory(int nid, u64 start, u64 size,
130129
struct vmem_altmap *altmap)
131130
{
@@ -151,7 +150,6 @@ void __ref arch_remove_memory(int nid, u64 start, u64 size,
151150
pr_warn("Hash collision while resizing HPT\n");
152151
}
153152
#endif
154-
#endif /* CONFIG_MEMORY_HOTPLUG */
155153

156154
#ifndef CONFIG_NEED_MULTIPLE_NODES
157155
void __init mem_topology_setup(void)

‎arch/powerpc/platforms/powernv/memtrace.c‎

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,23 +70,23 @@ static int change_memblock_state(struct memory_block *mem, void *arg)
7070
/* called with device_hotplug_lock held */
7171
static bool memtrace_offline_pages(u32 nid, u64 start_pfn, u64 nr_pages)
7272
{
73-
u64 end_pfn = start_pfn + nr_pages - 1;
73+
const unsigned long start = PFN_PHYS(start_pfn);
74+
const unsigned long size = PFN_PHYS(nr_pages);
7475

75-
if (walk_memory_range(start_pfn, end_pfn, NULL,
76-
check_memblock_online))
76+
if (walk_memory_blocks(start, size, NULL, check_memblock_online))
7777
return false;
7878

79-
walk_memory_range(start_pfn, end_pfn, (void *)MEM_GOING_OFFLINE,
80-
change_memblock_state);
79+
walk_memory_blocks(start, size, (void *)MEM_GOING_OFFLINE,
80+
change_memblock_state);
8181

8282
if (offline_pages(start_pfn, nr_pages)) {
83-
walk_memory_range(start_pfn, end_pfn, (void *)MEM_ONLINE,
84-
change_memblock_state);
83+
walk_memory_blocks(start, size, (void *)MEM_ONLINE,
84+
change_memblock_state);
8585
return false;
8686
}
8787

88-
walk_memory_range(start_pfn, end_pfn, (void *)MEM_OFFLINE,
89-
change_memblock_state);
88+
walk_memory_blocks(start, size, (void *)MEM_OFFLINE,
89+
change_memblock_state);
9090

9191

9292
return true;
@@ -242,9 +242,8 @@ static int memtrace_online(void)
242242
*/
243243
if (!memhp_auto_online) {
244244
lock_device_hotplug();
245-
walk_memory_range(PFN_DOWN(ent->start),
246-
PFN_UP(ent->start + ent->size - 1),
247-
NULL, online_mem_block);
245+
walk_memory_blocks(ent->start, ent->size, NULL,
246+
online_mem_block);
248247
unlock_device_hotplug();
249248
}
250249

‎arch/s390/appldata/appldata_base.c‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -220,15 +220,13 @@ appldata_timer_handler(struct ctl_table *ctl, int write,
220220
void __user *buffer, size_t *lenp, loff_t *ppos)
221221
{
222222
int timer_active = appldata_timer_active;
223-
int zero = 0;
224-
int one = 1;
225223
int rc;
226224
struct ctl_table ctl_entry = {
227225
.procname = ctl->procname,
228226
.data = &timer_active,
229227
.maxlen = sizeof(int),
230-
.extra1 = &zero,
231-
.extra2 = &one,
228+
.extra1 = SYSCTL_ZERO,
229+
.extra2 = SYSCTL_ONE,
232230
};
233231

234232
rc = proc_douintvec_minmax(&ctl_entry, write, buffer, lenp, ppos);
@@ -255,13 +253,12 @@ appldata_interval_handler(struct ctl_table *ctl, int write,
255253
void __user *buffer, size_t *lenp, loff_t *ppos)
256254
{
257255
int interval = appldata_interval;
258-
int one = 1;
259256
int rc;
260257
struct ctl_table ctl_entry = {
261258
.procname = ctl->procname,
262259
.data = &interval,
263260
.maxlen = sizeof(int),
264-
.extra1 = &one,
261+
.extra1 = SYSCTL_ONE,
265262
};
266263

267264
rc = proc_dointvec_minmax(&ctl_entry, write, buffer, lenp, ppos);
@@ -289,13 +286,11 @@ appldata_generic_handler(struct ctl_table *ctl, int write,
289286
struct list_head *lh;
290287
int rc, found;
291288
int active;
292-
int zero = 0;
293-
int one = 1;
294289
struct ctl_table ctl_entry = {
295290
.data = &active,
296291
.maxlen = sizeof(int),
297-
.extra1 = &zero,
298-
.extra2 = &one,
292+
.extra1 = SYSCTL_ZERO,
293+
.extra2 = SYSCTL_ONE,
299294
};
300295

301296
found = 0;

‎arch/s390/kernel/topology.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -587,15 +587,13 @@ static int topology_ctl_handler(struct ctl_table *ctl, int write,
587587
{
588588
int enabled = topology_is_enabled();
589589
int new_mode;
590-
int zero = 0;
591-
int one = 1;
592590
int rc;
593591
struct ctl_table ctl_entry = {
594592
.procname = ctl->procname,
595593
.data = &enabled,
596594
.maxlen = sizeof(int),
597-
.extra1 = &zero,
598-
.extra2 = &one,
595+
.extra1 = SYSCTL_ZERO,
596+
.extra2 = SYSCTL_ONE,
599597
};
600598

601599
rc = proc_douintvec_minmax(&ctl_entry, write, buffer, lenp, ppos);

‎arch/s390/mm/init.c‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,9 @@ int arch_add_memory(int nid, u64 start, u64 size,
273273
unsigned long size_pages = PFN_DOWN(size);
274274
int rc;
275275

276+
if (WARN_ON_ONCE(restrictions->altmap))
277+
return -EINVAL;
278+
276279
rc = vmem_add_mapping(start, size);
277280
if (rc)
278281
return rc;
@@ -283,16 +286,15 @@ int arch_add_memory(int nid, u64 start, u64 size,
283286
return rc;
284287
}
285288

286-
#ifdef CONFIG_MEMORY_HOTREMOVE
287289
void arch_remove_memory(int nid, u64 start, u64 size,
288290
struct vmem_altmap *altmap)
289291
{
290-
/*
291-
* There is no hardware or firmware interface which could trigger a
292-
* hot memory remove on s390. So there is nothing that needs to be
293-
* implemented.
294-
*/
295-
BUG();
292+
unsigned long start_pfn = start >> PAGE_SHIFT;
293+
unsigned long nr_pages = size >> PAGE_SHIFT;
294+
struct zone *zone;
295+
296+
zone = page_zone(pfn_to_page(start_pfn));
297+
__remove_pages(zone, start_pfn, nr_pages, altmap);
298+
vmem_remove_mapping(start, size);
296299
}
297-
#endif
298300
#endif /* CONFIG_MEMORY_HOTPLUG */

‎arch/sh/mm/init.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,6 @@ int memory_add_physaddr_to_nid(u64 addr)
429429
EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);
430430
#endif
431431

432-
#ifdef CONFIG_MEMORY_HOTREMOVE
433432
void arch_remove_memory(int nid, u64 start, u64 size,
434433
struct vmem_altmap *altmap)
435434
{
@@ -440,5 +439,4 @@ void arch_remove_memory(int nid, u64 start, u64 size,
440439
zone = page_zone(pfn_to_page(start_pfn));
441440
__remove_pages(zone, start_pfn, nr_pages, altmap);
442441
}
443-
#endif
444442
#endif /* CONFIG_MEMORY_HOTPLUG */

0 commit comments

Comments
 (0)