diff mbox series

[3/3] mm: sparse: remove __section_nr() function

Message ID 20210702094132.6276-4-ohoono.kwon@samsung.com (mailing list archive)
State New
Headers show
Series mm: sparse: remove __section_nr() function | expand

Commit Message

권오훈 July 2, 2021, 9:41 a.m. UTC
__section_nr() was used to convert struct mem_section * to section_nr.

With CONFIG_SPARSEMEM_EXTREME enabled, however, __section_nr() can be
costly since it iterates all section roots to check if the given
mem_section is in its range.

On the other hand, __nr_to_section() which converts section_nr to
mem_section can be done in O(1).

The only users of __section_nr() was section_mark_present() and
find_memory_block().

Since I changed both functions to use section_nr directly in the
preceeding patches, let's remove __section_nr() which has no users.

Signed-off-by: Ohhoon Kwon <ohoono.kwon@samsung.com>
---
 include/linux/mmzone.h |  1 -
 mm/sparse.c            | 26 --------------------------
 2 files changed, 27 deletions(-)

Comments

Michal Hocko July 2, 2021, 12:18 p.m. UTC | #1
On Fri 02-07-21 18:41:32, Ohhoon Kwon wrote:
> __section_nr() was used to convert struct mem_section * to section_nr.
> 
> With CONFIG_SPARSEMEM_EXTREME enabled, however, __section_nr() can be
> costly since it iterates all section roots to check if the given
> mem_section is in its range.
> 
> On the other hand, __nr_to_section() which converts section_nr to
> mem_section can be done in O(1).
> 
> The only users of __section_nr() was section_mark_present() and
> find_memory_block().
> 
> Since I changed both functions to use section_nr directly in the
> preceeding patches, let's remove __section_nr() which has no users.
> 
> Signed-off-by: Ohhoon Kwon <ohoono.kwon@samsung.com>

I would go with a much shorter changelog. The function is not used
anymore so it can be simply dropped.
Acked-by: Michal Hocko <mhocko@suse.com>

> ---
>  include/linux/mmzone.h |  1 -
>  mm/sparse.c            | 26 --------------------------
>  2 files changed, 27 deletions(-)
> 
> diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
> index 0d53eba1c383..8931f95cf885 100644
> --- a/include/linux/mmzone.h
> +++ b/include/linux/mmzone.h
> @@ -1321,7 +1321,6 @@ static inline struct mem_section *__nr_to_section(unsigned long nr)
>  		return NULL;
>  	return &mem_section[SECTION_NR_TO_ROOT(nr)][nr & SECTION_ROOT_MASK];
>  }
> -extern unsigned long __section_nr(struct mem_section *ms);
>  extern size_t mem_section_usage_size(void);
>  
>  /*
> diff --git a/mm/sparse.c b/mm/sparse.c
> index 4a2700e9a65f..1b32d15593e4 100644
> --- a/mm/sparse.c
> +++ b/mm/sparse.c
> @@ -108,32 +108,6 @@ static inline int sparse_index_init(unsigned long section_nr, int nid)
>  }
>  #endif
>  
> -#ifdef CONFIG_SPARSEMEM_EXTREME
> -unsigned long __section_nr(struct mem_section *ms)
> -{
> -	unsigned long root_nr;
> -	struct mem_section *root = NULL;
> -
> -	for (root_nr = 0; root_nr < NR_SECTION_ROOTS; root_nr++) {
> -		root = __nr_to_section(root_nr * SECTIONS_PER_ROOT);
> -		if (!root)
> -			continue;
> -
> -		if ((ms >= root) && (ms < (root + SECTIONS_PER_ROOT)))
> -		     break;
> -	}
> -
> -	VM_BUG_ON(!root);
> -
> -	return (root_nr * SECTIONS_PER_ROOT) + (ms - root);
> -}
> -#else
> -unsigned long __section_nr(struct mem_section *ms)
> -{
> -	return (unsigned long)(ms - mem_section[0]);
> -}
> -#endif
> -
>  /*
>   * During early boot, before section_mem_map is used for an actual
>   * mem_map, we use section_mem_map to store the section's NUMA
> -- 
> 2.17.1
David Hildenbrand July 2, 2021, 5:57 p.m. UTC | #2
On 02.07.21 14:18, Michal Hocko wrote:
> On Fri 02-07-21 18:41:32, Ohhoon Kwon wrote:
>> __section_nr() was used to convert struct mem_section * to section_nr.
>>
>> With CONFIG_SPARSEMEM_EXTREME enabled, however, __section_nr() can be
>> costly since it iterates all section roots to check if the given
>> mem_section is in its range.
>>
>> On the other hand, __nr_to_section() which converts section_nr to
>> mem_section can be done in O(1).
>>
>> The only users of __section_nr() was section_mark_present() and
>> find_memory_block().
>>
>> Since I changed both functions to use section_nr directly in the
>> preceeding patches, let's remove __section_nr() which has no users.
>>
>> Signed-off-by: Ohhoon Kwon <ohoono.kwon@samsung.com>
> 
> I would go with a much shorter changelog. The function is not used
> anymore so it can be simply dropped.
> Acked-by: Michal Hocko <mhocko@suse.com>

Agreed, also avoid the use of "I" in patches.

Use something like

"As the last users of __section_nr() are gone, let's remove now unused 
__section_nr()."

Reviewed-by: David Hildenbrand <david@redhat.com>
diff mbox series

Patch

diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index 0d53eba1c383..8931f95cf885 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -1321,7 +1321,6 @@  static inline struct mem_section *__nr_to_section(unsigned long nr)
 		return NULL;
 	return &mem_section[SECTION_NR_TO_ROOT(nr)][nr & SECTION_ROOT_MASK];
 }
-extern unsigned long __section_nr(struct mem_section *ms);
 extern size_t mem_section_usage_size(void);
 
 /*
diff --git a/mm/sparse.c b/mm/sparse.c
index 4a2700e9a65f..1b32d15593e4 100644
--- a/mm/sparse.c
+++ b/mm/sparse.c
@@ -108,32 +108,6 @@  static inline int sparse_index_init(unsigned long section_nr, int nid)
 }
 #endif
 
-#ifdef CONFIG_SPARSEMEM_EXTREME
-unsigned long __section_nr(struct mem_section *ms)
-{
-	unsigned long root_nr;
-	struct mem_section *root = NULL;
-
-	for (root_nr = 0; root_nr < NR_SECTION_ROOTS; root_nr++) {
-		root = __nr_to_section(root_nr * SECTIONS_PER_ROOT);
-		if (!root)
-			continue;
-
-		if ((ms >= root) && (ms < (root + SECTIONS_PER_ROOT)))
-		     break;
-	}
-
-	VM_BUG_ON(!root);
-
-	return (root_nr * SECTIONS_PER_ROOT) + (ms - root);
-}
-#else
-unsigned long __section_nr(struct mem_section *ms)
-{
-	return (unsigned long)(ms - mem_section[0]);
-}
-#endif
-
 /*
  * During early boot, before section_mem_map is used for an actual
  * mem_map, we use section_mem_map to store the section's NUMA