drivers/base/memory.c: don't store end_section_nr in memory blocks
authorDavid Hildenbrand <david@redhat.com>
Mon, 23 Sep 2019 22:35:49 +0000 (15:35 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 24 Sep 2019 22:54:09 +0000 (15:54 -0700)
Each memory block spans the same amount of sections/pages/bytes.  The size
is determined before the first memory block is created.  No need to store
what we can easily calculate - and the calculations even look simpler now.

Michal brought up the idea of variable-sized memory blocks.  However, if
we ever implement something like this, we will need an API compatibility
switch and reworks at various places (most code assumes a fixed memory
block size).  So let's cleanup what we have right now.

While at it, fix the variable naming in register_mem_sect_under_node() -
we no longer talk about a single section.

Link: http://lkml.kernel.org/r/20190809110200.2746-1-david@redhat.com
Signed-off-by: David Hildenbrand <david@redhat.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Pavel Tatashin <pasha.tatashin@soleen.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Oscar Salvador <osalvador@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
drivers/base/memory.c
drivers/base/node.c
include/linux/memory.h
mm/memory_hotplug.c

index 763154c82eb33ebf63a5188c2d8666356f456341..6bea4f3f8040dd77c87cf34647b26515061a76a1 100644 (file)
@@ -656,7 +656,6 @@ static int init_memory_block(struct memory_block **memory,
                return -ENOMEM;
 
        mem->start_section_nr = block_id * sections_per_block;
-       mem->end_section_nr = mem->start_section_nr + sections_per_block - 1;
        mem->state = state;
        start_pfn = section_nr_to_pfn(mem->start_section_nr);
        mem->phys_device = arch_get_memory_phys_device(start_pfn);
index 840c95baa1d879e2975c4dd798a54673b4579ab7..257449cf061f12f31f2c1ae45cc683a0ca13cc8a 100644 (file)
@@ -756,13 +756,13 @@ static int __ref get_nid_for_pfn(unsigned long pfn)
 static int register_mem_sect_under_node(struct memory_block *mem_blk,
                                         void *arg)
 {
+       unsigned long memory_block_pfns = memory_block_size_bytes() / PAGE_SIZE;
+       unsigned long start_pfn = section_nr_to_pfn(mem_blk->start_section_nr);
+       unsigned long end_pfn = start_pfn + memory_block_pfns - 1;
        int ret, nid = *(int *)arg;
-       unsigned long pfn, sect_start_pfn, sect_end_pfn;
+       unsigned long pfn;
 
-       sect_start_pfn = section_nr_to_pfn(mem_blk->start_section_nr);
-       sect_end_pfn = section_nr_to_pfn(mem_blk->end_section_nr);
-       sect_end_pfn += PAGES_PER_SECTION - 1;
-       for (pfn = sect_start_pfn; pfn <= sect_end_pfn; pfn++) {
+       for (pfn = start_pfn; pfn <= end_pfn; pfn++) {
                int page_nid;
 
                /*
index b3d9df060626a45c77503c16bd049ebe4c499a16..0ebb105eb261554cceac2d006f38cbeced91b278 100644 (file)
@@ -25,7 +25,6 @@
 
 struct memory_block {
        unsigned long start_section_nr;
-       unsigned long end_section_nr;
        unsigned long state;            /* serialized by the dev->lock */
        int section_count;              /* serialized by mem_sysfs_mutex */
        int online_type;                /* for passing data to online routine */
index 5b8811945bbba7b360e8234f337586ae51292785..3706a137d8808e03191c5a255ee94140b8670327 100644 (file)
@@ -1654,7 +1654,7 @@ static int check_memblock_offlined_cb(struct memory_block *mem, void *arg)
                phys_addr_t beginpa, endpa;
 
                beginpa = PFN_PHYS(section_nr_to_pfn(mem->start_section_nr));
-               endpa = PFN_PHYS(section_nr_to_pfn(mem->end_section_nr + 1))-1;
+               endpa = beginpa + memory_block_size_bytes() - 1;
                pr_warn("removing memory fails, because memory [%pa-%pa] is onlined\n",
                        &beginpa, &endpa);