* [PATCH 0/2] drivers/base/memory: Two cleanups @ 2025-02-14 6:35 Gavin Shan 2025-02-14 6:35 ` [PATCH 1/2] drivers/base/memory: Simplify add_boot_memory_block() Gavin Shan 2025-02-14 6:35 ` [PATCH 2/2] drivers/base/memory: Correct the field name in the header Gavin Shan 0 siblings, 2 replies; 8+ messages in thread From: Gavin Shan @ 2025-02-14 6:35 UTC (permalink / raw) To: linux-mm; +Cc: linux-kernel, david, osalvador, gregkh, rafael, dakr, akpm The series has two cleanups to drivers/base/memory as below. PATCH[1] Drops @@section_count to simplify add_boot_memory_block() PATCH[2] Corrects the comments to match with 'struct memory_group' Gavin Shan (2): drivers/base/memory: Simplify add_boot_memory_block() drivers/base/memory: Correct the field name in the header drivers/base/memory.c | 15 +++++++-------- include/linux/memory.h | 2 +- 2 files changed, 8 insertions(+), 9 deletions(-) -- 2.48.1 ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/2] drivers/base/memory: Simplify add_boot_memory_block() 2025-02-14 6:35 [PATCH 0/2] drivers/base/memory: Two cleanups Gavin Shan @ 2025-02-14 6:35 ` Gavin Shan 2025-02-14 7:53 ` David Hildenbrand 2025-02-14 22:57 ` Andrew Morton 2025-02-14 6:35 ` [PATCH 2/2] drivers/base/memory: Correct the field name in the header Gavin Shan 1 sibling, 2 replies; 8+ messages in thread From: Gavin Shan @ 2025-02-14 6:35 UTC (permalink / raw) To: linux-mm; +Cc: linux-kernel, david, osalvador, gregkh, rafael, dakr, akpm It's unnecessary to keep the variable @section_count in the function because the device for the specific memory block will be added if any of its memory section is present. The variable @section_count records the number of present memory sections in the specific memory block, which isn't needed. Simplify the function by dropping the variable @section_count. No functional change intended. Signed-off-by: Gavin Shan <gshan@redhat.com> --- drivers/base/memory.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/drivers/base/memory.c b/drivers/base/memory.c index 348c5dbbfa68..208b9b544012 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++; + nr++) { + if (present_section_nr(nr)) { + return add_memory_block(memory_block_id(base_section_nr), + MEM_ONLINE, NULL, NULL); + } + } - if (section_count == 0) - return 0; - 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 related [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] drivers/base/memory: Simplify add_boot_memory_block() 2025-02-14 6:35 ` [PATCH 1/2] drivers/base/memory: Simplify add_boot_memory_block() Gavin Shan @ 2025-02-14 7:53 ` David Hildenbrand 2025-02-14 23:48 ` Gavin Shan 2025-02-14 22:57 ` Andrew Morton 1 sibling, 1 reply; 8+ messages in thread From: David Hildenbrand @ 2025-02-14 7:53 UTC (permalink / raw) To: Gavin Shan, linux-mm; +Cc: linux-kernel, osalvador, gregkh, rafael, dakr, akpm On 14.02.25 07:35, Gavin Shan wrote: > It's unnecessary to keep the variable @section_count in the function > because the device for the specific memory block will be added if > any of its memory section is present. The variable @section_count > records the number of present memory sections in the specific memory > block, which isn't needed. > > Simplify the function by dropping the variable @section_count. No > functional change intended. > > Signed-off-by: Gavin Shan <gshan@redhat.com> > --- > drivers/base/memory.c | 15 +++++++-------- > 1 file changed, 7 insertions(+), 8 deletions(-) > > diff --git a/drivers/base/memory.c b/drivers/base/memory.c > index 348c5dbbfa68..208b9b544012 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++; > + nr++) { > + if (present_section_nr(nr)) { > + return add_memory_block(memory_block_id(base_section_nr), > + MEM_ONLINE, NULL, NULL); > + } Superfluous set of braces for the if statement. Not sure I count this while thing here as a "simplifcation" -- the code is IMHO easier to read without the nested return in the loop body. No strong opinion, though. -- Cheers, David / dhildenb ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] drivers/base/memory: Simplify add_boot_memory_block() 2025-02-14 7:53 ` David Hildenbrand @ 2025-02-14 23:48 ` Gavin Shan 0 siblings, 0 replies; 8+ messages in thread From: Gavin Shan @ 2025-02-14 23:48 UTC (permalink / raw) To: David Hildenbrand, linux-mm Cc: linux-kernel, osalvador, gregkh, rafael, dakr, akpm On 2/14/25 5:53 PM, David Hildenbrand wrote: > On 14.02.25 07:35, Gavin Shan wrote: >> It's unnecessary to keep the variable @section_count in the function >> because the device for the specific memory block will be added if >> any of its memory section is present. The variable @section_count >> records the number of present memory sections in the specific memory >> block, which isn't needed. >> >> Simplify the function by dropping the variable @section_count. No >> functional change intended. >> >> Signed-off-by: Gavin Shan <gshan@redhat.com> >> --- >> drivers/base/memory.c | 15 +++++++-------- >> 1 file changed, 7 insertions(+), 8 deletions(-) >> >> diff --git a/drivers/base/memory.c b/drivers/base/memory.c >> index 348c5dbbfa68..208b9b544012 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++; >> + nr++) { >> + if (present_section_nr(nr)) { >> + return add_memory_block(memory_block_id(base_section_nr), >> + MEM_ONLINE, NULL, NULL); >> + } > > Superfluous set of braces for the if statement. > > Not sure I count this while thing here as a "simplifcation" -- the code is IMHO easier to read without the nested return in the loop body. > > No strong opinion, though. > Indeed. I will use for_each_present_section_nr() as Andrew suggested. With it, one level of the nested if statement can be avoided. The point was to avoid counting the number of present sections in the specified block since the block will be added if any section is present. Thanks, Gavin ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] drivers/base/memory: Simplify add_boot_memory_block() 2025-02-14 6:35 ` [PATCH 1/2] drivers/base/memory: Simplify add_boot_memory_block() Gavin Shan 2025-02-14 7:53 ` David Hildenbrand @ 2025-02-14 22:57 ` Andrew Morton 2025-02-14 23:45 ` Gavin Shan 1 sibling, 1 reply; 8+ messages in thread From: Andrew Morton @ 2025-02-14 22:57 UTC (permalink / raw) To: Gavin Shan; +Cc: linux-mm, linux-kernel, david, osalvador, gregkh, rafael, dakr On Fri, 14 Feb 2025 16:35:03 +1000 Gavin Shan <gshan@redhat.com> wrote: > It's unnecessary to keep the variable @section_count in the function > because the device for the specific memory block will be added if > any of its memory section is present. The variable @section_count > records the number of present memory sections in the specific memory > block, which isn't needed. > > Simplify the function by dropping the variable @section_count. No > functional change intended. > > ... > > 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; mm/sparse.c has a for_each_present_section_nr() - is that usable here? > - nr++) > - if (present_section_nr(nr)) > - section_count++; > + nr++) { > + if (present_section_nr(nr)) { > + return add_memory_block(memory_block_id(base_section_nr), > + MEM_ONLINE, NULL, NULL); > + } > + } > > ... > ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] drivers/base/memory: Simplify add_boot_memory_block() 2025-02-14 22:57 ` Andrew Morton @ 2025-02-14 23:45 ` Gavin Shan 0 siblings, 0 replies; 8+ messages in thread From: Gavin Shan @ 2025-02-14 23:45 UTC (permalink / raw) To: Andrew Morton Cc: linux-mm, linux-kernel, david, osalvador, gregkh, rafael, dakr On 2/15/25 8:57 AM, Andrew Morton wrote: > On Fri, 14 Feb 2025 16:35:03 +1000 Gavin Shan <gshan@redhat.com> wrote: > >> It's unnecessary to keep the variable @section_count in the function >> because the device for the specific memory block will be added if >> any of its memory section is present. The variable @section_count >> records the number of present memory sections in the specific memory >> block, which isn't needed. >> >> Simplify the function by dropping the variable @section_count. No >> functional change intended. >> >> ... >> >> 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; > > mm/sparse.c has a for_each_present_section_nr() - is that usable here? > It should be fine to use it. I will add one preparatory patch to expose for_each_present_section_nr(). With it, the nested if statements can also be avoided, Something like below. for_each_present_section_nr(base_section_nr - 1, nr) { if (nr >= base_section_nr + sections_per_block) break; return add_memory_block(memory_block_id(nr), MEM_ONLINE, NULL, NULL); } return 0; >> - nr++) >> - if (present_section_nr(nr)) >> - section_count++; >> + nr++) { >> + if (present_section_nr(nr)) { >> + return add_memory_block(memory_block_id(base_section_nr), >> + MEM_ONLINE, NULL, NULL); >> + } >> + } >> Thanks, Gavin ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 2/2] drivers/base/memory: Correct the field name in the header 2025-02-14 6:35 [PATCH 0/2] drivers/base/memory: Two cleanups Gavin Shan 2025-02-14 6:35 ` [PATCH 1/2] drivers/base/memory: Simplify add_boot_memory_block() Gavin Shan @ 2025-02-14 6:35 ` Gavin Shan 2025-02-14 7:54 ` David Hildenbrand 1 sibling, 1 reply; 8+ messages in thread From: Gavin Shan @ 2025-02-14 6:35 UTC (permalink / raw) To: linux-mm; +Cc: linux-kernel, david, osalvador, gregkh, rafael, dakr, akpm Replace @blocks with @memory_blocks to match with the definition of struct memory_group. Signed-off-by: Gavin Shan <gshan@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 related [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] drivers/base/memory: Correct the field name in the header 2025-02-14 6:35 ` [PATCH 2/2] drivers/base/memory: Correct the field name in the header Gavin Shan @ 2025-02-14 7:54 ` David Hildenbrand 0 siblings, 0 replies; 8+ messages in thread From: David Hildenbrand @ 2025-02-14 7:54 UTC (permalink / raw) To: Gavin Shan, linux-mm; +Cc: linux-kernel, osalvador, gregkh, rafael, dakr, akpm On 14.02.25 07:35, 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> > --- > 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 Acked-by: David Hildenbrand <david@redhat.com> -- Cheers, David / dhildenb ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2025-02-14 23:48 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-02-14 6:35 [PATCH 0/2] drivers/base/memory: Two cleanups Gavin Shan 2025-02-14 6:35 ` [PATCH 1/2] drivers/base/memory: Simplify add_boot_memory_block() Gavin Shan 2025-02-14 7:53 ` David Hildenbrand 2025-02-14 23:48 ` Gavin Shan 2025-02-14 22:57 ` Andrew Morton 2025-02-14 23:45 ` Gavin Shan 2025-02-14 6:35 ` [PATCH 2/2] drivers/base/memory: Correct the field name in the header Gavin Shan 2025-02-14 7:54 ` David Hildenbrand
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.