Skip to content

Commit 8876cc2

Browse files
David Hildenbrandgregkh
authored andcommitted
drivers/base/memory: don't store phys_device in memory blocks
[ Upstream commit e9a2e48 ] No need to store the value for each and every memory block, as we can easily query the value at runtime. Reshuffle the members to optimize the memory layout. Also, let's clarify what the interface once was used for and why it's legacy nowadays. "phys_device" was used on s390x in older versions of lsmem[2]/chmem[3], back when they were still part of s390x-tools. They were later replaced by the variants in linux-utils. For example, RHEL6 and RHEL7 contain lsmem/chmem from s390-utils. RHEL8 switched to versions from util-linux on s390x [4]. "phys_device" was added with sysfs support for memory hotplug in commit 3947be1 ("[PATCH] memory hotplug: sysfs and add/remove functions") in 2005. It always returned 0. s390x started returning something != 0 on some setups (if sclp.rzm is set by HW) in 2010 via commit 57b552b ("memory hotplug/s390: set phys_device"). For s390x, it allowed for identifying which memory block devices belong to the same storage increment (RZM). Only if all memory block devices comprising a single storage increment were offline, the memory could actually be removed in the hypervisor. Since commit e5d709b ("s390/memory hotplug: provide memory_block_size_bytes() function") in 2013 a memory block device spans at least one storage increment - which is why the interface isn't really helpful/used anymore (except by old lsmem/chmem tools). There were once RFC patches to make use of "phys_device" in ACPI context; however, the underlying problem could be solved using different interfaces [1]. [1] https://patchwork.kernel.org/patch/2163871/ [2] https://github.com/ibm-s390-tools/s390-tools/blob/v2.1.0/zconf/lsmem [3] https://github.com/ibm-s390-tools/s390-tools/blob/v2.1.0/zconf/chmem [4] https://bugzilla.redhat.com/show_bug.cgi?id=1504134 Link: https://lkml.kernel.org/r/20210201181347.13262-2-david@redhat.com Signed-off-by: David Hildenbrand <david@redhat.com> Acked-by: Michal Hocko <mhocko@suse.com> Reviewed-by: Oscar Salvador <osalvador@suse.de> Cc: Dave Hansen <dave.hansen@intel.com> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Gerald Schaefer <gerald.schaefer@linux.ibm.com> Cc: Jonathan Corbet <corbet@lwn.net> Cc: "Rafael J. Wysocki" <rafael@kernel.org> Cc: Mauro Carvalho Chehab <mchehab+huawei@kernel.org> Cc: Ilya Dryomov <idryomov@gmail.com> Cc: Vaibhav Jain <vaibhav@linux.ibm.com> Cc: Tom Rix <trix@redhat.com> Cc: Geert Uytterhoeven <geert+renesas@glider.be> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent e4b98e2 commit 8876cc2

4 files changed

Lines changed: 15 additions & 22 deletions

File tree

‎Documentation/ABI/testing/sysfs-devices-memory‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ Date: September 2008
2626
Contact: Badari Pulavarty <pbadari@us.ibm.com>
2727
Description:
2828
The file /sys/devices/system/memory/memoryX/phys_device
29-
is read-only and is designed to show the name of physical
30-
memory device. Implementation is currently incomplete.
29+
is read-only; it is a legacy interface only ever used on s390x
30+
to expose the covered storage increment.
31+
Users: Legacy s390-tools lsmem/chmem
3132

3233
What: /sys/devices/system/memory/memoryX/phys_index
3334
Date: September 2008

‎Documentation/admin-guide/mm/memory-hotplug.rst‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ Under each memory block, you can see 5 files:
160160

161161
"online_movable", "online", "offline" command
162162
which will be performed on all sections in the block.
163-
``phys_device`` read-only: designed to show the name of physical memory
164-
device. This is not well implemented now.
163+
``phys_device`` read-only: legacy interface only ever used on s390x to
164+
expose the covered storage increment.
165165
``removable`` read-only: contains an integer value indicating
166166
whether the memory block is removable or not
167167
removable. A value of 1 indicates that the memory

‎drivers/base/memory.c‎

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -290,20 +290,20 @@ static ssize_t state_store(struct device *dev, struct device_attribute *attr,
290290
}
291291

292292
/*
293-
* phys_device is a bad name for this. What I really want
294-
* is a way to differentiate between memory ranges that
295-
* are part of physical devices that constitute
296-
* a complete removable unit or fru.
297-
* i.e. do these ranges belong to the same physical device,
298-
* s.t. if I offline all of these sections I can then
299-
* remove the physical device?
293+
* Legacy interface that we cannot remove: s390x exposes the storage increment
294+
* covered by a memory block, allowing for identifying which memory blocks
295+
* comprise a storage increment. Since a memory block spans complete
296+
* storage increments nowadays, this interface is basically unused. Other
297+
* archs never exposed != 0.
300298
*/
301299
static ssize_t phys_device_show(struct device *dev,
302300
struct device_attribute *attr, char *buf)
303301
{
304302
struct memory_block *mem = to_memory_block(dev);
303+
unsigned long start_pfn = section_nr_to_pfn(mem->start_section_nr);
305304

306-
return sysfs_emit(buf, "%d\n", mem->phys_device);
305+
return sysfs_emit(buf, "%d\n",
306+
arch_get_memory_phys_device(start_pfn));
307307
}
308308

309309
#ifdef CONFIG_MEMORY_HOTREMOVE
@@ -488,11 +488,7 @@ static DEVICE_ATTR_WO(soft_offline_page);
488488
static DEVICE_ATTR_WO(hard_offline_page);
489489
#endif
490490

491-
/*
492-
* Note that phys_device is optional. It is here to allow for
493-
* differentiation between which *physical* devices each
494-
* section belongs to...
495-
*/
491+
/* See phys_device_show(). */
496492
int __weak arch_get_memory_phys_device(unsigned long start_pfn)
497493
{
498494
return 0;
@@ -574,7 +570,6 @@ int register_memory(struct memory_block *memory)
574570
static int init_memory_block(unsigned long block_id, unsigned long state)
575571
{
576572
struct memory_block *mem;
577-
unsigned long start_pfn;
578573
int ret = 0;
579574

580575
mem = find_memory_block_by_id(block_id);
@@ -588,8 +583,6 @@ static int init_memory_block(unsigned long block_id, unsigned long state)
588583

589584
mem->start_section_nr = block_id * sections_per_block;
590585
mem->state = state;
591-
start_pfn = section_nr_to_pfn(mem->start_section_nr);
592-
mem->phys_device = arch_get_memory_phys_device(start_pfn);
593586
mem->nid = NUMA_NO_NODE;
594587

595588
ret = register_memory(mem);

‎include/linux/memory.h‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ struct memory_block {
2727
unsigned long start_section_nr;
2828
unsigned long state; /* serialized by the dev->lock */
2929
int online_type; /* for passing data to online routine */
30-
int phys_device; /* to which fru does this belong? */
31-
struct device dev;
3230
int nid; /* NID for this memory block */
31+
struct device dev;
3332
};
3433

3534
int arch_get_memory_phys_device(unsigned long start_pfn);

0 commit comments

Comments
 (0)