[PATCH 1/5] mm/vmalloc.c: change purge_ndoes as local static variable

Baoquan He posted 5 patches 8 months, 1 week ago
There is a newer version of this series
[PATCH 1/5] mm/vmalloc.c: change purge_ndoes as local static variable
Posted by Baoquan He 8 months, 1 week ago
Static variable 'purge_ndoes' is defined in global scope, while it's
only used in function __purge_vmap_area_lazy(). It mainly serves to
avoid memory allocation repeatedly, especially when NR_CPUS is big.

While a local static variable can also satisfy the demand, and can
improve code readibility. Hence move its definition into
__purge_vmap_area_lazy().

Signed-off-by: Baoquan He <bhe@redhat.com>
---
 mm/vmalloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 6ee7fc2ec986..aca1905d3397 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -2128,7 +2128,6 @@ static DEFINE_MUTEX(vmap_purge_lock);
 
 /* for per-CPU blocks */
 static void purge_fragmented_blocks_allcpus(void);
-static cpumask_t purge_nodes;
 
 static void
 reclaim_list_global(struct list_head *head)
@@ -2261,6 +2260,7 @@ static bool __purge_vmap_area_lazy(unsigned long start, unsigned long end,
 {
 	unsigned long nr_purged_areas = 0;
 	unsigned int nr_purge_helpers;
+	static cpumask_t purge_nodes;
 	unsigned int nr_purge_nodes;
 	struct vmap_node *vn;
 	int i;
-- 
2.41.0
Re: [PATCH 1/5] mm/vmalloc.c: change purge_ndoes as local static variable
Posted by Vishal Moola (Oracle) 8 months, 1 week ago
On Tue, Apr 15, 2025 at 10:39:48AM +0800, Baoquan He wrote:
> Static variable 'purge_ndoes' is defined in global scope, while it's
> only used in function __purge_vmap_area_lazy(). It mainly serves to
> avoid memory allocation repeatedly, especially when NR_CPUS is big.
> 
> While a local static variable can also satisfy the demand, and can
> improve code readibility. Hence move its definition into
> __purge_vmap_area_lazy().
> 
> Signed-off-by: Baoquan He <bhe@redhat.com>

Reviewed-by: Vishal Moola (Oracle) <vishal.moola@gmail.com>
Re: [PATCH 1/5] mm/vmalloc.c: change purge_ndoes as local static variable
Posted by Shivank Garg 8 months, 1 week ago
On 4/15/2025 8:09 AM, Baoquan He wrote:
> Static variable 'purge_ndoes' is defined in global scope, while it's
> only used in function __purge_vmap_area_lazy(). It mainly serves to
> avoid memory allocation repeatedly, especially when NR_CPUS is big.
> 
> While a local static variable can also satisfy the demand, and can
> improve code readibility. Hence move its definition into
> __purge_vmap_area_lazy().
> 
> Signed-off-by: Baoquan He <bhe@redhat.com>
> ---
>  mm/vmalloc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> index 6ee7fc2ec986..aca1905d3397 100644
> --- a/mm/vmalloc.c
> +++ b/mm/vmalloc.c
> @@ -2128,7 +2128,6 @@ static DEFINE_MUTEX(vmap_purge_lock);
>  
>  /* for per-CPU blocks */
>  static void purge_fragmented_blocks_allcpus(void);
> -static cpumask_t purge_nodes;
>  
>  static void
>  reclaim_list_global(struct list_head *head)
> @@ -2261,6 +2260,7 @@ static bool __purge_vmap_area_lazy(unsigned long start, unsigned long end,
>  {
>  	unsigned long nr_purged_areas = 0;
>  	unsigned int nr_purge_helpers;
> +	static cpumask_t purge_nodes;
>  	unsigned int nr_purge_nodes;
>  	struct vmap_node *vn;
>  	int i;

Reviewed-by: Shivank Garg <shivankg@amd.com>
Tested-by: Shivank Garg <shivankg@amd.com>
Re: [PATCH 1/5] mm/vmalloc.c: change purge_ndoes as local static variable
Posted by Uladzislau Rezki 8 months, 1 week ago
On Tue, Apr 15, 2025 at 10:39:48AM +0800, Baoquan He wrote:
> Static variable 'purge_ndoes' is defined in global scope, while it's
> only used in function __purge_vmap_area_lazy(). It mainly serves to
> avoid memory allocation repeatedly, especially when NR_CPUS is big.
> 
> While a local static variable can also satisfy the demand, and can
> improve code readibility. Hence move its definition into
> __purge_vmap_area_lazy().
> 
> Signed-off-by: Baoquan He <bhe@redhat.com>
> ---
>  mm/vmalloc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> index 6ee7fc2ec986..aca1905d3397 100644
> --- a/mm/vmalloc.c
> +++ b/mm/vmalloc.c
> @@ -2128,7 +2128,6 @@ static DEFINE_MUTEX(vmap_purge_lock);
>  
>  /* for per-CPU blocks */
>  static void purge_fragmented_blocks_allcpus(void);
> -static cpumask_t purge_nodes;
>  
>  static void
>  reclaim_list_global(struct list_head *head)
> @@ -2261,6 +2260,7 @@ static bool __purge_vmap_area_lazy(unsigned long start, unsigned long end,
>  {
>  	unsigned long nr_purged_areas = 0;
>  	unsigned int nr_purge_helpers;
> +	static cpumask_t purge_nodes;
>  	unsigned int nr_purge_nodes;
>  	struct vmap_node *vn;
>  	int i;
> -- 
> 2.41.0
> 
Well. I do not have a strong opinion here. But right, it is only
used inside the function.

Reviewed-by: Uladzislau Rezki (Sony) <urezki@gmail.com>

--
Uladzislau Rezki