Skip to content

Commit fada9ae

Browse files
David Hildenbrandtorvalds
authored andcommitted
drivers/base/memory.c: drop pages_correctly_probed()
pages_correctly_probed() is a leftover from ancient times. It dates back to commit 3947be1 ("[PATCH] memory hotplug: sysfs and add/remove functions"), where Pg_reserved checks were added as a sfety net: /* * The probe routines leave the pages reserved, just * as the bootmem code does. Make sure they're still * that way. */ The checks were refactored quite a bit over the years, especially in commit b77eab7 ("mm/memory_hotplug: optimize probe routine"), where checks for present, valid, and online sections were added. Hotplugged memory is added via add_memory(), which will create the full memmap for the hotplugged memory, and mark all sections valid and present. Only full memory blocks are onlined/offlined, so we also cannot have an inconsistency in that regard (especially, memory blocks with some sections being online and some being offline). 1. Boot memory always starts online. Since commit c5e79ef ("mm/memory_hotplug.c: don't allow to online/offline memory blocks with holes") we disallow to offline any memory with holes. Therefore, we never online memory with holes. Present and validity checks are superfluous. 2. Only complete memory blocks are onlined/offlined (and especially, the state - online or offline - is stored for whole memory blocks). Besides the core, only arch/powerpc/platforms/powernv/memtrace.c manually calls offline_pages() and fiddels with memory block states. But it also only offlines complete memory blocks. 3. To make any of these conditions trigger, something would have to be terribly messed up in the core. (e.g., online/offline only some sections of a memory block). 4. Memory unplug properly makes sure that all sysfs attributes were removed (and therefore, that all threads left the sysfs handlers). We don't have to worry about zombie devices at this point. 5. The valid_section_nr(section_nr) check is actually dead code, as it would never have been reached due to the WARN_ON_ONCE(!pfn_valid(pfn)). No wonder we haven't seen any of these errors in a long time (or even ever, according to my search). Let's just get rid of them. Now, all checks that could hinder onlining and offlining are completely contained in online_pages()/offline_pages(). Signed-off-by: David Hildenbrand <david@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: "Rafael J. Wysocki" <rafael@kernel.org> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Michal Hocko <mhocko@suse.com> Cc: Dan Williams <dan.j.williams@intel.com> Cc: Pavel Tatashin <pasha.tatashin@soleen.com> Cc: Anshuman Khandual <anshuman.khandual@arm.com> Link: http://lkml.kernel.org/r/20200127110424.5757-3-david@redhat.com Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 68c3a6a commit fada9ae

1 file changed

Lines changed: 0 additions & 42 deletions

File tree

‎drivers/base/memory.c‎

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -144,45 +144,6 @@ int memory_notify(unsigned long val, void *v)
144144
return blocking_notifier_call_chain(&memory_chain, val, v);
145145
}
146146

147-
/*
148-
* The probe routines leave the pages uninitialized, just as the bootmem code
149-
* does. Make sure we do not access them, but instead use only information from
150-
* within sections.
151-
*/
152-
static bool pages_correctly_probed(unsigned long start_pfn)
153-
{
154-
unsigned long section_nr = pfn_to_section_nr(start_pfn);
155-
unsigned long section_nr_end = section_nr + sections_per_block;
156-
unsigned long pfn = start_pfn;
157-
158-
/*
159-
* memmap between sections is not contiguous except with
160-
* SPARSEMEM_VMEMMAP. We lookup the page once per section
161-
* and assume memmap is contiguous within each section
162-
*/
163-
for (; section_nr < section_nr_end; section_nr++) {
164-
if (WARN_ON_ONCE(!pfn_valid(pfn)))
165-
return false;
166-
167-
if (!present_section_nr(section_nr)) {
168-
pr_warn("section %ld pfn[%lx, %lx) not present\n",
169-
section_nr, pfn, pfn + PAGES_PER_SECTION);
170-
return false;
171-
} else if (!valid_section_nr(section_nr)) {
172-
pr_warn("section %ld pfn[%lx, %lx) no valid memmap\n",
173-
section_nr, pfn, pfn + PAGES_PER_SECTION);
174-
return false;
175-
} else if (online_section_nr(section_nr)) {
176-
pr_warn("section %ld pfn[%lx, %lx) is already online\n",
177-
section_nr, pfn, pfn + PAGES_PER_SECTION);
178-
return false;
179-
}
180-
pfn += PAGES_PER_SECTION;
181-
}
182-
183-
return true;
184-
}
185-
186147
/*
187148
* MEMORY_HOTPLUG depends on SPARSEMEM in mm/Kconfig, so it is
188149
* OK to have direct references to sparsemem variables in here.
@@ -199,9 +160,6 @@ memory_block_action(unsigned long start_section_nr, unsigned long action,
199160

200161
switch (action) {
201162
case MEM_ONLINE:
202-
if (!pages_correctly_probed(start_pfn))
203-
return -EBUSY;
204-
205163
ret = online_pages(start_pfn, nr_pages, online_type, nid);
206164
break;
207165
case MEM_OFFLINE:

0 commit comments

Comments
 (0)