diff mbox series

[2/3] vmalloc: Switch to for_each_vmap_node() helper

Message ID 20250408151549.77937-2-urezki@gmail.com (mailing list archive)
State New
Headers show
Series [1/3] vmalloc: Add for_each_vmap_node() helper | expand

Commit Message

Uladzislau Rezki (Sony) April 8, 2025, 3:15 p.m. UTC
There are places which can be updated easily to use the
helper to iterate over all vmap-nodes. This is what this
patch does.

The aim is to improve readability and simplify the code.

Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
---
 mm/vmalloc.c | 36 +++++++++++++-----------------------
 1 file changed, 13 insertions(+), 23 deletions(-)

Comments

kernel test robot April 9, 2025, 5:39 p.m. UTC | #1
Hi Uladzislau,

kernel test robot noticed the following build warnings:

[auto build test WARNING on akpm-mm/mm-everything]
[also build test WARNING on linus/master v6.15-rc1 next-20250409]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Uladzislau-Rezki-Sony/vmalloc-Switch-to-for_each_vmap_node-helper/20250408-231807
base:   https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link:    https://lore.kernel.org/r/20250408151549.77937-2-urezki%40gmail.com
patch subject: [PATCH 2/3] vmalloc: Switch to for_each_vmap_node() helper
config: sparc-randconfig-002-20250409 (https://download.01.org/0day-ci/archive/20250410/202504100130.OjlBJLkQ-lkp@intel.com/config)
compiler: sparc-linux-gcc (GCC) 7.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250410/202504100130.OjlBJLkQ-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202504100130.OjlBJLkQ-lkp@intel.com/

All warnings (new ones prefixed by >>):

   mm/vmalloc.c: In function 'vmap_init_nodes':
>> mm/vmalloc.c:5087:9: warning: unused variable 'n' [-Wunused-variable]
     int i, n;
            ^


vim +/n +5087 mm/vmalloc.c

7fa8cee003166e Uladzislau Rezki (Sony  2024-01-02  5083) 
d093602919ad59 Uladzislau Rezki (Sony  2024-01-02  5084) static void vmap_init_nodes(void)
d093602919ad59 Uladzislau Rezki (Sony  2024-01-02  5085) {
d093602919ad59 Uladzislau Rezki (Sony  2024-01-02  5086) 	struct vmap_node *vn;
8f33a2ff307248 Uladzislau Rezki (Sony  2024-01-02 @5087) 	int i, n;
8f33a2ff307248 Uladzislau Rezki (Sony  2024-01-02  5088)
Andrew Morton April 10, 2025, 12:32 a.m. UTC | #2
On Thu, 10 Apr 2025 01:39:24 +0800 kernel test robot <lkp@intel.com> wrote:

> | Reported-by: kernel test robot <lkp@intel.com>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202504100130.OjlBJLkQ-lkp@intel.com/
> 
> All warnings (new ones prefixed by >>):
> 
>    mm/vmalloc.c: In function 'vmap_init_nodes':
> >> mm/vmalloc.c:5087:9: warning: unused variable 'n' [-Wunused-variable]
>      int i, n;
>             ^

Thanks, I added

--- a/mm/vmalloc.c~vmalloc-switch-to-for_each_vmap_node-helper-fix
+++ a/mm/vmalloc.c
@@ -5084,7 +5084,7 @@ static void __init vmap_init_free_space(
 static void vmap_init_nodes(void)
 {
 	struct vmap_node *vn;
-	int i, n;
+	int i;
 
 #if BITS_PER_LONG == 64
 	/*
@@ -5101,7 +5101,7 @@ static void vmap_init_nodes(void)
 	 * set of cores. Therefore a per-domain purging is supposed to
 	 * be added as well as a per-domain balancing.
 	 */
-	n = clamp_t(unsigned int, num_possible_cpus(), 1, 128);
+	int n = clamp_t(unsigned int, num_possible_cpus(), 1, 128);
 
 	if (n > 1) {
 		vn = kmalloc_array(n, sizeof(*vn), GFP_NOWAIT | __GFP_NOWARN);
Uladzislau Rezki (Sony) April 10, 2025, 9:34 a.m. UTC | #3
On Wed, Apr 09, 2025 at 05:32:17PM -0700, Andrew Morton wrote:
> On Thu, 10 Apr 2025 01:39:24 +0800 kernel test robot <lkp@intel.com> wrote:
> 
> > | Reported-by: kernel test robot <lkp@intel.com>
> > | Closes: https://lore.kernel.org/oe-kbuild-all/202504100130.OjlBJLkQ-lkp@intel.com/
> > 
> > All warnings (new ones prefixed by >>):
> > 
> >    mm/vmalloc.c: In function 'vmap_init_nodes':
> > >> mm/vmalloc.c:5087:9: warning: unused variable 'n' [-Wunused-variable]
> >      int i, n;
> >             ^
> 
> Thanks, I added
> 
> --- a/mm/vmalloc.c~vmalloc-switch-to-for_each_vmap_node-helper-fix
> +++ a/mm/vmalloc.c
> @@ -5084,7 +5084,7 @@ static void __init vmap_init_free_space(
>  static void vmap_init_nodes(void)
>  {
>  	struct vmap_node *vn;
> -	int i, n;
> +	int i;
>  
>  #if BITS_PER_LONG == 64
>  	/*
> @@ -5101,7 +5101,7 @@ static void vmap_init_nodes(void)
>  	 * set of cores. Therefore a per-domain purging is supposed to
>  	 * be added as well as a per-domain balancing.
>  	 */
> -	n = clamp_t(unsigned int, num_possible_cpus(), 1, 128);
> +	int n = clamp_t(unsigned int, num_possible_cpus(), 1, 128);
>  
>  	if (n > 1) {
>  		vn = kmalloc_array(n, sizeof(*vn), GFP_NOWAIT | __GFP_NOWARN);
> _
> 
I was about to send a fix for build warning. Thank you Andrew for sorting this out :)

--
Uladzislau Rezki
diff mbox series

Patch

diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index e42ea20713dc7..3ff9acd64c077 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -1061,12 +1061,11 @@  find_vmap_area_exceed_addr_lock(unsigned long addr, struct vmap_area **va)
 {
 	unsigned long va_start_lowest;
 	struct vmap_node *vn;
-	int i;
 
 repeat:
-	for (i = 0, va_start_lowest = 0; i < nr_vmap_nodes; i++) {
-		vn = &vmap_nodes[i];
+	va_start_lowest = 0;
 
+	for_each_vmap_node(vn) {
 		spin_lock(&vn->busy.lock);
 		*va = __find_vmap_area_exceed_addr(addr, &vn->busy.root);
 
@@ -4946,11 +4945,8 @@  static void show_purge_info(struct seq_file *m)
 {
 	struct vmap_node *vn;
 	struct vmap_area *va;
-	int i;
-
-	for (i = 0; i < nr_vmap_nodes; i++) {
-		vn = &vmap_nodes[i];
 
+	for_each_vmap_node(vn) {
 		spin_lock(&vn->lazy.lock);
 		list_for_each_entry(va, &vn->lazy.head, list) {
 			seq_printf(m, "0x%pK-0x%pK %7ld unpurged vm_area\n",
@@ -4966,11 +4962,8 @@  static int vmalloc_info_show(struct seq_file *m, void *p)
 	struct vmap_node *vn;
 	struct vmap_area *va;
 	struct vm_struct *v;
-	int i;
-
-	for (i = 0; i < nr_vmap_nodes; i++) {
-		vn = &vmap_nodes[i];
 
+	for_each_vmap_node(vn) {
 		spin_lock(&vn->busy.lock);
 		list_for_each_entry(va, &vn->busy.head, list) {
 			if (!va->vm) {
@@ -5123,8 +5116,7 @@  static void vmap_init_nodes(void)
 	}
 #endif
 
-	for (n = 0; n < nr_vmap_nodes; n++) {
-		vn = &vmap_nodes[n];
+	for_each_vmap_node(vn) {
 		vn->busy.root = RB_ROOT;
 		INIT_LIST_HEAD(&vn->busy.head);
 		spin_lock_init(&vn->busy.lock);
@@ -5145,15 +5137,13 @@  static void vmap_init_nodes(void)
 static unsigned long
 vmap_node_shrink_count(struct shrinker *shrink, struct shrink_control *sc)
 {
-	unsigned long count;
+	unsigned long count = 0;
 	struct vmap_node *vn;
-	int i, j;
-
-	for (count = 0, i = 0; i < nr_vmap_nodes; i++) {
-		vn = &vmap_nodes[i];
+	int i;
 
-		for (j = 0; j < MAX_VA_SIZE_PAGES; j++)
-			count += READ_ONCE(vn->pool[j].len);
+	for_each_vmap_node(vn) {
+		for (i = 0; i < MAX_VA_SIZE_PAGES; i++)
+			count += READ_ONCE(vn->pool[i].len);
 	}
 
 	return count ? count : SHRINK_EMPTY;
@@ -5162,10 +5152,10 @@  vmap_node_shrink_count(struct shrinker *shrink, struct shrink_control *sc)
 static unsigned long
 vmap_node_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
 {
-	int i;
+	struct vmap_node *vn;
 
-	for (i = 0; i < nr_vmap_nodes; i++)
-		decay_va_pool_node(&vmap_nodes[i], true);
+	for_each_vmap_node(vn)
+		decay_va_pool_node(vn, true);
 
 	return SHRINK_STOP;
 }