linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/3] drivers/base/memory: Two cleanups
@ 2025-03-11  0:46 Gavin Shan
  2025-03-11  0:46 ` [PATCH v2 1/3] mm/sparse: Expose for_each_present_section_nr() Gavin Shan
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Gavin Shan @ 2025-03-11  0:46 UTC (permalink / raw)
  To: linux-mm
  Cc: linux-kernel, david, osalvador, gregkh, rafael, dakr, akpm, shan.gavin

The series has two cleanups to drivers/base/memory as below.

PATCH[1-2] Improves add_boot_memory_block() by using for_each_present_section_nr()
           and droping @section_count
PATCH[3]   Corrects the comments to match with 'struct memory_group'

Changelog
=========
v2:
  Expose for_each_present_section_nr() so that it can be used in
  add_boot_memory_block()                                           (Andrew)

Gavin Shan (3):
  mm/sparse: Expose for_each_present_section_nr()
  drivers/base/memory: Improve add_boot_memory_block()
  drivers/base/memory: Correct the field name in the header

 drivers/base/memory.c  | 17 ++++++++---------
 include/linux/memory.h |  2 +-
 include/linux/mmzone.h |  5 +++++
 mm/sparse.c            |  5 -----
 4 files changed, 14 insertions(+), 15 deletions(-)

-- 
2.48.1



^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v2 1/3] mm/sparse: Expose for_each_present_section_nr()
  2025-03-11  0:46 [PATCH v2 0/3] drivers/base/memory: Two cleanups Gavin Shan
@ 2025-03-11  0:46 ` Gavin Shan
  2025-03-11  9:31   ` David Hildenbrand
  2025-03-11  0:46 ` [PATCH v2 2/3] drivers/base/memory: Improve add_boot_memory_block() Gavin Shan
  2025-03-11  0:46 ` [PATCH v2 3/3] drivers/base/memory: Correct the field name in the header Gavin Shan
  2 siblings, 1 reply; 11+ messages in thread
From: Gavin Shan @ 2025-03-11  0:46 UTC (permalink / raw)
  To: linux-mm
  Cc: linux-kernel, david, osalvador, gregkh, rafael, dakr, akpm, shan.gavin

Expose for_each_present_section_nr() to be used by drivers/base/memory
in the next patch.

No functional changes intended.

Signed-off-by: Gavin Shan <gshan@redhat.com>
---
 include/linux/mmzone.h | 5 +++++
 mm/sparse.c            | 5 -----
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index 9540b41894da..0f6646da34d7 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -2097,6 +2097,11 @@ static inline unsigned long next_present_section_nr(unsigned long section_nr)
 	return -1;
 }
 
+#define for_each_present_section_nr(start, section_nr)		\
+	for (section_nr = next_present_section_nr(start - 1);	\
+	     section_nr != -1;					\
+	     section_nr = next_present_section_nr(section_nr))
+
 /*
  * These are _only_ used during initialisation, therefore they
  * can use __initdata ...  They could have names to indicate
diff --git a/mm/sparse.c b/mm/sparse.c
index 133b033d0cba..fe77d523ab8d 100644
--- a/mm/sparse.c
+++ b/mm/sparse.c
@@ -170,11 +170,6 @@ static void __section_mark_present(struct mem_section *ms,
 	ms->section_mem_map |= SECTION_MARKED_PRESENT;
 }
 
-#define for_each_present_section_nr(start, section_nr)		\
-	for (section_nr = next_present_section_nr(start-1);	\
-	     section_nr != -1;								\
-	     section_nr = next_present_section_nr(section_nr))
-
 static inline unsigned long first_present_section_nr(void)
 {
 	return next_present_section_nr(-1);
-- 
2.48.1



^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v2 2/3] drivers/base/memory: Improve add_boot_memory_block()
  2025-03-11  0:46 [PATCH v2 0/3] drivers/base/memory: Two cleanups Gavin Shan
  2025-03-11  0:46 ` [PATCH v2 1/3] mm/sparse: Expose for_each_present_section_nr() Gavin Shan
@ 2025-03-11  0:46 ` Gavin Shan
  2025-03-11  9:34   ` David Hildenbrand
  2025-03-11 15:24   ` Oscar Salvador
  2025-03-11  0:46 ` [PATCH v2 3/3] drivers/base/memory: Correct the field name in the header Gavin Shan
  2 siblings, 2 replies; 11+ messages in thread
From: Gavin Shan @ 2025-03-11  0:46 UTC (permalink / raw)
  To: linux-mm
  Cc: linux-kernel, david, osalvador, gregkh, rafael, dakr, akpm, shan.gavin

It's unnecessary to count the present sections for the specified
block since the block will be added if any section in the block
is present. Besides, for_each_present_section_nr() can be reused
as Andrew Morton suggested.

Improve by using for_each_present_section_nr() and dropping the
unnecessary @section_count.

No functional changes intended.

Signed-off-by: Gavin Shan <gshan@redhat.com>
---
 drivers/base/memory.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index 348c5dbbfa68..f66e9d537c12 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -822,18 +822,17 @@ static int add_memory_block(unsigned long block_id, unsigned long state,
 
 static int __init add_boot_memory_block(unsigned long base_section_nr)
 {
-	int section_count = 0;
 	unsigned long nr;
 
-	for (nr = base_section_nr; nr < base_section_nr + sections_per_block;
-	     nr++)
-		if (present_section_nr(nr))
-			section_count++;
+	for_each_present_section_nr(base_section_nr, nr) {
+		if (nr >= (base_section_nr + sections_per_block))
+			break;
 
-	if (section_count == 0)
-		return 0;
-	return add_memory_block(memory_block_id(base_section_nr),
-				MEM_ONLINE, NULL,  NULL);
+		return add_memory_block(memory_block_id(base_section_nr),
+					MEM_ONLINE, NULL, NULL);
+	}
+
+	return 0;
 }
 
 static int add_hotplug_memory_block(unsigned long block_id,
-- 
2.48.1



^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v2 3/3] drivers/base/memory: Correct the field name in the header
  2025-03-11  0:46 [PATCH v2 0/3] drivers/base/memory: Two cleanups Gavin Shan
  2025-03-11  0:46 ` [PATCH v2 1/3] mm/sparse: Expose for_each_present_section_nr() Gavin Shan
  2025-03-11  0:46 ` [PATCH v2 2/3] drivers/base/memory: Improve add_boot_memory_block() Gavin Shan
@ 2025-03-11  0:46 ` Gavin Shan
  2025-03-11 15:17   ` Oscar Salvador
  2 siblings, 1 reply; 11+ messages in thread
From: Gavin Shan @ 2025-03-11  0:46 UTC (permalink / raw)
  To: linux-mm
  Cc: linux-kernel, david, osalvador, gregkh, rafael, dakr, akpm, shan.gavin

Replace @blocks with @memory_blocks to match with the definition
of struct memory_group.

Signed-off-by: Gavin Shan <gshan@redhat.com>
Acked-by: David Hildenbrand <david@redhat.com>
---
 include/linux/memory.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/memory.h b/include/linux/memory.h
index c0afee5d126e..12daa6ec7d09 100644
--- a/include/linux/memory.h
+++ b/include/linux/memory.h
@@ -25,7 +25,7 @@
 /**
  * struct memory_group - a logical group of memory blocks
  * @nid: The node id for all memory blocks inside the memory group.
- * @blocks: List of all memory blocks belonging to this memory group.
+ * @memory_blocks: List of all memory blocks belonging to this memory group.
  * @present_kernel_pages: Present (online) memory outside ZONE_MOVABLE of this
  *			  memory group.
  * @present_movable_pages: Present (online) memory in ZONE_MOVABLE of this
-- 
2.48.1



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 1/3] mm/sparse: Expose for_each_present_section_nr()
  2025-03-11  0:46 ` [PATCH v2 1/3] mm/sparse: Expose for_each_present_section_nr() Gavin Shan
@ 2025-03-11  9:31   ` David Hildenbrand
  2025-03-11 11:52     ` Gavin Shan
  0 siblings, 1 reply; 11+ messages in thread
From: David Hildenbrand @ 2025-03-11  9:31 UTC (permalink / raw)
  To: Gavin Shan, linux-mm
  Cc: linux-kernel, osalvador, gregkh, rafael, dakr, akpm, shan.gavin

On 11.03.25 01:46, Gavin Shan wrote:
> Expose for_each_present_section_nr() to be used by drivers/base/memory
> in the next patch.
> 
> No functional changes intended.
> 
> Signed-off-by: Gavin Shan <gshan@redhat.com>

Please squash that into the patch that uses it.

-- 
Cheers,

David / dhildenb



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 2/3] drivers/base/memory: Improve add_boot_memory_block()
  2025-03-11  0:46 ` [PATCH v2 2/3] drivers/base/memory: Improve add_boot_memory_block() Gavin Shan
@ 2025-03-11  9:34   ` David Hildenbrand
  2025-03-11 15:24   ` Oscar Salvador
  1 sibling, 0 replies; 11+ messages in thread
From: David Hildenbrand @ 2025-03-11  9:34 UTC (permalink / raw)
  To: Gavin Shan, linux-mm
  Cc: linux-kernel, osalvador, gregkh, rafael, dakr, akpm, shan.gavin

On 11.03.25 01:46, Gavin Shan wrote:
> It's unnecessary to count the present sections for the specified
> block since the block will be added if any section in the block
> is present. Besides, for_each_present_section_nr() can be reused
> as Andrew Morton suggested.
> 
> Improve by using for_each_present_section_nr() and dropping the
> unnecessary @section_count.
> 
> No functional changes intended.
> 
> Signed-off-by: Gavin Shan <gshan@redhat.com>
> ---

Acked-by: David Hildenbrand <david@redhat.com>

-- 
Cheers,

David / dhildenb



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 1/3] mm/sparse: Expose for_each_present_section_nr()
  2025-03-11  9:31   ` David Hildenbrand
@ 2025-03-11 11:52     ` Gavin Shan
  2025-03-11 15:26       ` Oscar Salvador
  0 siblings, 1 reply; 11+ messages in thread
From: Gavin Shan @ 2025-03-11 11:52 UTC (permalink / raw)
  To: David Hildenbrand, linux-mm
  Cc: linux-kernel, osalvador, gregkh, rafael, dakr, akpm, shan.gavin

On 3/11/25 7:31 PM, David Hildenbrand wrote:
> On 11.03.25 01:46, Gavin Shan wrote:
>> Expose for_each_present_section_nr() to be used by drivers/base/memory
>> in the next patch.
>>
>> No functional changes intended.
>>
>> Signed-off-by: Gavin Shan <gshan@redhat.com>
> 
> Please squash that into the patch that uses it.
> 

Yes, but this series has been queued by Andrew Morton. Andrew, would
you mind to squash PATCH[3/1] to PATCH[2/3]? Or I can respin to do that
in v3.

Thanks,
Gavin



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 3/3] drivers/base/memory: Correct the field name in the header
  2025-03-11  0:46 ` [PATCH v2 3/3] drivers/base/memory: Correct the field name in the header Gavin Shan
@ 2025-03-11 15:17   ` Oscar Salvador
  0 siblings, 0 replies; 11+ messages in thread
From: Oscar Salvador @ 2025-03-11 15:17 UTC (permalink / raw)
  To: Gavin Shan
  Cc: linux-mm, linux-kernel, david, gregkh, rafael, dakr, akpm, shan.gavin

On Tue, Mar 11, 2025 at 10:46:57AM +1000, Gavin Shan wrote:
> Replace @blocks with @memory_blocks to match with the definition
> of struct memory_group.
> 
> Signed-off-by: Gavin Shan <gshan@redhat.com>
> Acked-by: David Hildenbrand <david@redhat.com>

Acked-by: Oscar Salvador <osalvador@suse.de>

-- 
Oscar Salvador
SUSE Labs


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 2/3] drivers/base/memory: Improve add_boot_memory_block()
  2025-03-11  0:46 ` [PATCH v2 2/3] drivers/base/memory: Improve add_boot_memory_block() Gavin Shan
  2025-03-11  9:34   ` David Hildenbrand
@ 2025-03-11 15:24   ` Oscar Salvador
  1 sibling, 0 replies; 11+ messages in thread
From: Oscar Salvador @ 2025-03-11 15:24 UTC (permalink / raw)
  To: Gavin Shan
  Cc: linux-mm, linux-kernel, david, gregkh, rafael, dakr, akpm, shan.gavin

On Tue, Mar 11, 2025 at 10:46:56AM +1000, Gavin Shan wrote:
> It's unnecessary to count the present sections for the specified
> block since the block will be added if any section in the block
> is present. Besides, for_each_present_section_nr() can be reused
> as Andrew Morton suggested.
> 
> Improve by using for_each_present_section_nr() and dropping the
> unnecessary @section_count.
> 
> No functional changes intended.
> 
> Signed-off-by: Gavin Shan <gshan@redhat.com>

Acked-by: Oscar Salvador <osalvador@suse.de>

-- 
Oscar Salvador
SUSE Labs


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 1/3] mm/sparse: Expose for_each_present_section_nr()
  2025-03-11 11:52     ` Gavin Shan
@ 2025-03-11 15:26       ` Oscar Salvador
  2025-03-11 23:37         ` Gavin Shan
  0 siblings, 1 reply; 11+ messages in thread
From: Oscar Salvador @ 2025-03-11 15:26 UTC (permalink / raw)
  To: Gavin Shan
  Cc: David Hildenbrand, linux-mm, linux-kernel, gregkh, rafael, dakr,
	akpm, shan.gavin

On Tue, Mar 11, 2025 at 09:52:09PM +1000, Gavin Shan wrote:
> Yes, but this series has been queued by Andrew Morton. Andrew, would
> you mind to squash PATCH[3/1] to PATCH[2/3]? Or I can respin to do that
> in v3.

Since it is in mm-unstable, maybe just resend a v3 with all acks + this
squashed and be done with it.


-- 
Oscar Salvador
SUSE Labs


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 1/3] mm/sparse: Expose for_each_present_section_nr()
  2025-03-11 15:26       ` Oscar Salvador
@ 2025-03-11 23:37         ` Gavin Shan
  0 siblings, 0 replies; 11+ messages in thread
From: Gavin Shan @ 2025-03-11 23:37 UTC (permalink / raw)
  To: Oscar Salvador
  Cc: David Hildenbrand, linux-mm, linux-kernel, gregkh, rafael, dakr,
	akpm, shan.gavin

On 3/12/25 1:26 AM, Oscar Salvador wrote:
> On Tue, Mar 11, 2025 at 09:52:09PM +1000, Gavin Shan wrote:
>> Yes, but this series has been queued by Andrew Morton. Andrew, would
>> you mind to squash PATCH[3/1] to PATCH[2/3]? Or I can respin to do that
>> in v3.
> 
> Since it is in mm-unstable, maybe just resend a v3 with all acks + this
> squashed and be done with it.
> 

Thanks for suggestions. v3 has been sent with the changes.

https://lore.kernel.org/linux-mm/20250311233045.148943-1-gshan@redhat.com/T/#t

Thanks,
Gavin



^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2025-03-11 23:37 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-11  0:46 [PATCH v2 0/3] drivers/base/memory: Two cleanups Gavin Shan
2025-03-11  0:46 ` [PATCH v2 1/3] mm/sparse: Expose for_each_present_section_nr() Gavin Shan
2025-03-11  9:31   ` David Hildenbrand
2025-03-11 11:52     ` Gavin Shan
2025-03-11 15:26       ` Oscar Salvador
2025-03-11 23:37         ` Gavin Shan
2025-03-11  0:46 ` [PATCH v2 2/3] drivers/base/memory: Improve add_boot_memory_block() Gavin Shan
2025-03-11  9:34   ` David Hildenbrand
2025-03-11 15:24   ` Oscar Salvador
2025-03-11  0:46 ` [PATCH v2 3/3] drivers/base/memory: Correct the field name in the header Gavin Shan
2025-03-11 15:17   ` Oscar Salvador

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox