linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] Optimize __vmalloc_node_range_noprof function.
@ 2025-03-03  9:44 Liu Ye
  2025-03-03  9:44 ` [PATCH 1/4] mm/vmalloc: Remove unnecessary size ALIGN in __vmalloc_node_range_noprof Liu Ye
                   ` (4 more replies)
  0 siblings, 5 replies; 13+ messages in thread
From: Liu Ye @ 2025-03-03  9:44 UTC (permalink / raw)
  To: akpm; +Cc: urezki, hch, linux-mm, linux-kernel, Liu Ye

The use of variables real_size and real_align in function 
__vmalloc_node_range_noprof is unreadable. Optimize it in four patches.

Liu Ye (4):
  mm/vmalloc: Remove unnecessary size ALIGN in
    __vmalloc_node_range_noprof
  mm/vmalloc: Size should be used instead of real_size in
    __vmalloc_node_range_noprof
  mm/vmalloc: Remove the real_size variable to simplify the code in
    __vmalloc_node_range_noprof
  mm/vmalloc: Rename the variable real_align to original_align to
    prevent misunderstanding

 mm/vmalloc.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

-- 
2.25.1



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

* [PATCH 1/4] mm/vmalloc: Remove unnecessary size ALIGN in __vmalloc_node_range_noprof
  2025-03-03  9:44 [PATCH 0/4] Optimize __vmalloc_node_range_noprof function Liu Ye
@ 2025-03-03  9:44 ` Liu Ye
  2025-03-03 18:30   ` Uladzislau Rezki
  2025-03-03  9:44 ` [PATCH 2/4] mm/vmalloc: Size should be used instead of real_size " Liu Ye
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 13+ messages in thread
From: Liu Ye @ 2025-03-03  9:44 UTC (permalink / raw)
  To: akpm; +Cc: urezki, hch, linux-mm, linux-kernel, Liu Ye

The same operation already exists in the function __get_vm_area_node,
so delete the duplicate operation to simplify the code.

Signed-off-by: Liu Ye <liuye@kylinos.cn>
---
 mm/vmalloc.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index dc658d4af181..20d9b9de84b1 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -3798,7 +3798,6 @@ void *__vmalloc_node_range_noprof(unsigned long size, unsigned long align,
 			shift = arch_vmap_pte_supported_shift(size);
 
 		align = max(real_align, 1UL << shift);
-		size = ALIGN(real_size, 1UL << shift);
 	}
 
 again:
-- 
2.25.1



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

* [PATCH 2/4] mm/vmalloc: Size should be used instead of real_size in __vmalloc_node_range_noprof
  2025-03-03  9:44 [PATCH 0/4] Optimize __vmalloc_node_range_noprof function Liu Ye
  2025-03-03  9:44 ` [PATCH 1/4] mm/vmalloc: Remove unnecessary size ALIGN in __vmalloc_node_range_noprof Liu Ye
@ 2025-03-03  9:44 ` Liu Ye
  2025-03-03  9:44 ` [PATCH 3/4] mm/vmalloc: Remove the real_size variable to simplify the code " Liu Ye
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 13+ messages in thread
From: Liu Ye @ 2025-03-03  9:44 UTC (permalink / raw)
  To: akpm; +Cc: urezki, hch, linux-mm, linux-kernel, Liu Ye

According to the logic of the code, this should be size instead of
real_size. Although there is no functional problem at present,
it is recommended to modify it to enhance readability.

Signed-off-by: Liu Ye <liuye@kylinos.cn>
---
 mm/vmalloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 20d9b9de84b1..e311ee33f9ef 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -3801,7 +3801,7 @@ void *__vmalloc_node_range_noprof(unsigned long size, unsigned long align,
 	}
 
 again:
-	area = __get_vm_area_node(real_size, align, shift, VM_ALLOC |
+	area = __get_vm_area_node(size, align, shift, VM_ALLOC |
 				  VM_UNINITIALIZED | vm_flags, start, end, node,
 				  gfp_mask, caller);
 	if (!area) {
-- 
2.25.1



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

* [PATCH 3/4] mm/vmalloc: Remove the real_size variable to simplify the code in __vmalloc_node_range_noprof
  2025-03-03  9:44 [PATCH 0/4] Optimize __vmalloc_node_range_noprof function Liu Ye
  2025-03-03  9:44 ` [PATCH 1/4] mm/vmalloc: Remove unnecessary size ALIGN in __vmalloc_node_range_noprof Liu Ye
  2025-03-03  9:44 ` [PATCH 2/4] mm/vmalloc: Size should be used instead of real_size " Liu Ye
@ 2025-03-03  9:44 ` Liu Ye
  2025-03-03  9:44 ` [PATCH 4/4] mm/vmalloc: Rename the variable real_align to original_align to prevent misunderstanding Liu Ye
  2025-03-03 16:09 ` [PATCH 0/4] Optimize __vmalloc_node_range_noprof function Uladzislau Rezki
  4 siblings, 0 replies; 13+ messages in thread
From: Liu Ye @ 2025-03-03  9:44 UTC (permalink / raw)
  To: akpm; +Cc: urezki, hch, linux-mm, linux-kernel, Liu Ye

The use of the real_size variable causes code redundancy,
so it is removed to simplify the code.

Signed-off-by: Liu Ye <liuye@kylinos.cn>
---
 mm/vmalloc.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index e311ee33f9ef..b4d2010e5105 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -3770,7 +3770,6 @@ void *__vmalloc_node_range_noprof(unsigned long size, unsigned long align,
 	struct vm_struct *area;
 	void *ret;
 	kasan_vmalloc_flags_t kasan_flags = KASAN_VMALLOC_NONE;
-	unsigned long real_size = size;
 	unsigned long real_align = align;
 	unsigned int shift = PAGE_SHIFT;
 
@@ -3780,7 +3779,7 @@ void *__vmalloc_node_range_noprof(unsigned long size, unsigned long align,
 	if ((size >> PAGE_SHIFT) > totalram_pages()) {
 		warn_alloc(gfp_mask, NULL,
 			"vmalloc error: size %lu, exceeds total pages",
-			real_size);
+			size);
 		return NULL;
 	}
 
@@ -3808,7 +3807,7 @@ void *__vmalloc_node_range_noprof(unsigned long size, unsigned long align,
 		bool nofail = gfp_mask & __GFP_NOFAIL;
 		warn_alloc(gfp_mask, NULL,
 			"vmalloc error: size %lu, vm_struct allocation failed%s",
-			real_size, (nofail) ? ". Retrying." : "");
+			size, (nofail) ? ". Retrying." : "");
 		if (nofail) {
 			schedule_timeout_uninterruptible(1);
 			goto again;
@@ -3860,7 +3859,7 @@ void *__vmalloc_node_range_noprof(unsigned long size, unsigned long align,
 	    (gfp_mask & __GFP_SKIP_ZERO))
 		kasan_flags |= KASAN_VMALLOC_INIT;
 	/* KASAN_VMALLOC_PROT_NORMAL already set if required. */
-	area->addr = kasan_unpoison_vmalloc(area->addr, real_size, kasan_flags);
+	area->addr = kasan_unpoison_vmalloc(area->addr, size, kasan_flags);
 
 	/*
 	 * In this function, newly allocated vm_struct has VM_UNINITIALIZED
@@ -3869,9 +3868,8 @@ void *__vmalloc_node_range_noprof(unsigned long size, unsigned long align,
 	 */
 	clear_vm_uninitialized_flag(area);
 
-	size = PAGE_ALIGN(size);
 	if (!(vm_flags & VM_DEFER_KMEMLEAK))
-		kmemleak_vmalloc(area, size, gfp_mask);
+		kmemleak_vmalloc(area, PAGE_ALIGN(size), gfp_mask);
 
 	return area->addr;
 
@@ -3879,7 +3877,6 @@ void *__vmalloc_node_range_noprof(unsigned long size, unsigned long align,
 	if (shift > PAGE_SHIFT) {
 		shift = PAGE_SHIFT;
 		align = real_align;
-		size = real_size;
 		goto again;
 	}
 
-- 
2.25.1



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

* [PATCH 4/4] mm/vmalloc: Rename the variable real_align to original_align to prevent misunderstanding
  2025-03-03  9:44 [PATCH 0/4] Optimize __vmalloc_node_range_noprof function Liu Ye
                   ` (2 preceding siblings ...)
  2025-03-03  9:44 ` [PATCH 3/4] mm/vmalloc: Remove the real_size variable to simplify the code " Liu Ye
@ 2025-03-03  9:44 ` Liu Ye
  2025-03-03 16:09 ` [PATCH 0/4] Optimize __vmalloc_node_range_noprof function Uladzislau Rezki
  4 siblings, 0 replies; 13+ messages in thread
From: Liu Ye @ 2025-03-03  9:44 UTC (permalink / raw)
  To: akpm; +Cc: urezki, hch, linux-mm, linux-kernel, Liu Ye

The real prefix is generally used to indicate the adjusted value of a
parameter, but according to the code logic, it should indicate the
original value, so it is recommended to rename it to original_align.

Signed-off-by: Liu Ye <liuye@kylinos.cn>
---
 mm/vmalloc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index b4d2010e5105..a8488452b70b 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -3770,7 +3770,7 @@ void *__vmalloc_node_range_noprof(unsigned long size, unsigned long align,
 	struct vm_struct *area;
 	void *ret;
 	kasan_vmalloc_flags_t kasan_flags = KASAN_VMALLOC_NONE;
-	unsigned long real_align = align;
+	unsigned long original_align = align;
 	unsigned int shift = PAGE_SHIFT;
 
 	if (WARN_ON_ONCE(!size))
@@ -3796,7 +3796,7 @@ void *__vmalloc_node_range_noprof(unsigned long size, unsigned long align,
 		else
 			shift = arch_vmap_pte_supported_shift(size);
 
-		align = max(real_align, 1UL << shift);
+		align = max(original_align, 1UL << shift);
 	}
 
 again:
@@ -3876,7 +3876,7 @@ void *__vmalloc_node_range_noprof(unsigned long size, unsigned long align,
 fail:
 	if (shift > PAGE_SHIFT) {
 		shift = PAGE_SHIFT;
-		align = real_align;
+		align = original_align;
 		goto again;
 	}
 
-- 
2.25.1



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

* Re: [PATCH 0/4] Optimize __vmalloc_node_range_noprof function.
  2025-03-03  9:44 [PATCH 0/4] Optimize __vmalloc_node_range_noprof function Liu Ye
                   ` (3 preceding siblings ...)
  2025-03-03  9:44 ` [PATCH 4/4] mm/vmalloc: Rename the variable real_align to original_align to prevent misunderstanding Liu Ye
@ 2025-03-03 16:09 ` Uladzislau Rezki
  2025-03-04  5:58   ` Dev Jain
  4 siblings, 1 reply; 13+ messages in thread
From: Uladzislau Rezki @ 2025-03-03 16:09 UTC (permalink / raw)
  To: Liu Ye; +Cc: akpm, urezki, hch, linux-mm, linux-kernel

On Mon, Mar 03, 2025 at 05:44:06PM +0800, Liu Ye wrote:
> The use of variables real_size and real_align in function 
> __vmalloc_node_range_noprof is unreadable. Optimize it in four patches.
> 
> Liu Ye (4):
>   mm/vmalloc: Remove unnecessary size ALIGN in
>     __vmalloc_node_range_noprof
>   mm/vmalloc: Size should be used instead of real_size in
>     __vmalloc_node_range_noprof
>   mm/vmalloc: Remove the real_size variable to simplify the code in
>     __vmalloc_node_range_noprof
>   mm/vmalloc: Rename the variable real_align to original_align to
>     prevent misunderstanding
> 
>  mm/vmalloc.c | 20 ++++++++------------
>  1 file changed, 8 insertions(+), 12 deletions(-)
> 
> -- 
Let me double check it. Quick question, this series does not
introduce any functional change?

--
Uladzislau Rezki


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

* Re: [PATCH 1/4] mm/vmalloc: Remove unnecessary size ALIGN in __vmalloc_node_range_noprof
  2025-03-03  9:44 ` [PATCH 1/4] mm/vmalloc: Remove unnecessary size ALIGN in __vmalloc_node_range_noprof Liu Ye
@ 2025-03-03 18:30   ` Uladzislau Rezki
  2025-03-05  1:46     ` liuye
  0 siblings, 1 reply; 13+ messages in thread
From: Uladzislau Rezki @ 2025-03-03 18:30 UTC (permalink / raw)
  To: Liu Ye; +Cc: akpm, urezki, hch, linux-mm, linux-kernel

On Mon, Mar 03, 2025 at 05:44:07PM +0800, Liu Ye wrote:
> The same operation already exists in the function __get_vm_area_node,
> so delete the duplicate operation to simplify the code.
> 
> Signed-off-by: Liu Ye <liuye@kylinos.cn>
> ---
>  mm/vmalloc.c | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> index dc658d4af181..20d9b9de84b1 100644
> --- a/mm/vmalloc.c
> +++ b/mm/vmalloc.c
> @@ -3798,7 +3798,6 @@ void *__vmalloc_node_range_noprof(unsigned long size, unsigned long align,
>  			shift = arch_vmap_pte_supported_shift(size);
>  
>  		align = max(real_align, 1UL << shift);
> -		size = ALIGN(real_size, 1UL << shift);
>  	}
>  
>  again:
> -- 
> 2.25.1
> 
There is a mess with:

 unsigned long real_size = size;
 unsigned long real_align = align;

"real_size" and "real_align". Those are useless. What is about:

diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 5c88d0e90c20..a381ffee1595 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -3771,8 +3771,6 @@ void *__vmalloc_node_range_noprof(unsigned long size, unsigned long align,
 	struct vm_struct *area;
 	void *ret;
 	kasan_vmalloc_flags_t kasan_flags = KASAN_VMALLOC_NONE;
-	unsigned long real_size = size;
-	unsigned long real_align = align;
 	unsigned int shift = PAGE_SHIFT;
 
 	if (WARN_ON_ONCE(!size))
@@ -3781,7 +3779,7 @@ void *__vmalloc_node_range_noprof(unsigned long size, unsigned long align,
 	if ((size >> PAGE_SHIFT) > totalram_pages()) {
 		warn_alloc(gfp_mask, NULL,
 			"vmalloc error: size %lu, exceeds total pages",
-			real_size);
+			size);
 		return NULL;
 	}
 
@@ -3798,19 +3796,18 @@ void *__vmalloc_node_range_noprof(unsigned long size, unsigned long align,
 		else
 			shift = arch_vmap_pte_supported_shift(size);
 
-		align = max(real_align, 1UL << shift);
-		size = ALIGN(real_size, 1UL << shift);
+		align = max(align, 1UL << shift);
 	}
 
 again:
-	area = __get_vm_area_node(real_size, align, shift, VM_ALLOC |
+	area = __get_vm_area_node(size, align, shift, VM_ALLOC |
 				  VM_UNINITIALIZED | vm_flags, start, end, node,
 				  gfp_mask, caller);
 	if (!area) {
 		bool nofail = gfp_mask & __GFP_NOFAIL;
 		warn_alloc(gfp_mask, NULL,
 			"vmalloc error: size %lu, vm_struct allocation failed%s",
-			real_size, (nofail) ? ". Retrying." : "");
+			size, (nofail) ? ". Retrying." : "");
 		if (nofail) {
 			schedule_timeout_uninterruptible(1);
 			goto again;
@@ -3860,7 +3857,7 @@ void *__vmalloc_node_range_noprof(unsigned long size, unsigned long align,
 	    (gfp_mask & __GFP_SKIP_ZERO))
 		kasan_flags |= KASAN_VMALLOC_INIT;
 	/* KASAN_VMALLOC_PROT_NORMAL already set if required. */
-	area->addr = kasan_unpoison_vmalloc(area->addr, real_size, kasan_flags);
+	area->addr = kasan_unpoison_vmalloc(area->addr, size, kasan_flags);
 
 	/*
 	 * In this function, newly allocated vm_struct has VM_UNINITIALIZED
@@ -3878,8 +3875,6 @@ void *__vmalloc_node_range_noprof(unsigned long size, unsigned long align,
 fail:
 	if (shift > PAGE_SHIFT) {
 		shift = PAGE_SHIFT;
-		align = real_align;
-		size = real_size;
 		goto again;
 	}
 
?

--
Uladzislau Rezki


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

* Re: [PATCH 0/4] Optimize __vmalloc_node_range_noprof function.
  2025-03-03 16:09 ` [PATCH 0/4] Optimize __vmalloc_node_range_noprof function Uladzislau Rezki
@ 2025-03-04  5:58   ` Dev Jain
  2025-03-05  1:33     ` liuye
  0 siblings, 1 reply; 13+ messages in thread
From: Dev Jain @ 2025-03-04  5:58 UTC (permalink / raw)
  To: Uladzislau Rezki, Liu Ye; +Cc: akpm, hch, linux-mm, linux-kernel



On 03/03/25 9:39 pm, Uladzislau Rezki wrote:
> On Mon, Mar 03, 2025 at 05:44:06PM +0800, Liu Ye wrote:
>> The use of variables real_size and real_align in function
>> __vmalloc_node_range_noprof is unreadable. Optimize it in four patches.
>>
>> Liu Ye (4):
>>    mm/vmalloc: Remove unnecessary size ALIGN in
>>      __vmalloc_node_range_noprof
>>    mm/vmalloc: Size should be used instead of real_size in
>>      __vmalloc_node_range_noprof
>>    mm/vmalloc: Remove the real_size variable to simplify the code in
>>      __vmalloc_node_range_noprof
>>    mm/vmalloc: Rename the variable real_align to original_align to
>>      prevent misunderstanding
>>
>>   mm/vmalloc.c | 20 ++++++++------------
>>   1 file changed, 8 insertions(+), 12 deletions(-)
>>
>> -- 
> Let me double check it. Quick question, this series does not
> introduce any functional change?

Yeah, the cover letter subject is misleading. IMHO it should be more 
like "Refactor" instead of "Optimize".
> 
> --
> Uladzislau Rezki
> 



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

* Re: [PATCH 0/4] Optimize __vmalloc_node_range_noprof function.
  2025-03-04  5:58   ` Dev Jain
@ 2025-03-05  1:33     ` liuye
  0 siblings, 0 replies; 13+ messages in thread
From: liuye @ 2025-03-05  1:33 UTC (permalink / raw)
  To: Dev Jain, Uladzislau Rezki; +Cc: akpm, hch, linux-mm, linux-kernel


在 2025/3/4 13:58, Dev Jain 写道:
>
>
> On 03/03/25 9:39 pm, Uladzislau Rezki wrote:
>> On Mon, Mar 03, 2025 at 05:44:06PM +0800, Liu Ye wrote:
>>> The use of variables real_size and real_align in function
>>> __vmalloc_node_range_noprof is unreadable. Optimize it in four patches.
>>>
>>> Liu Ye (4):
>>>    mm/vmalloc: Remove unnecessary size ALIGN in
>>>      __vmalloc_node_range_noprof
>>>    mm/vmalloc: Size should be used instead of real_size in
>>>      __vmalloc_node_range_noprof
>>>    mm/vmalloc: Remove the real_size variable to simplify the code in
>>>      __vmalloc_node_range_noprof
>>>    mm/vmalloc: Rename the variable real_align to original_align to
>>>      prevent misunderstanding
>>>
>>>   mm/vmalloc.c | 20 ++++++++------------
>>>   1 file changed, 8 insertions(+), 12 deletions(-)
>>>
>>> -- 
>> Let me double check it. Quick question, this series does not
>> introduce any functional change?
>
> Yeah, the cover letter subject is misleading. IMHO it should be more like "Refactor" instead of "Optimize".

Yes, refactoring is more accurate, regarding real_size and real_align.

>>
>> -- 
>> Uladzislau Rezki
>>
>


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

* Re: [PATCH 1/4] mm/vmalloc: Remove unnecessary size ALIGN in __vmalloc_node_range_noprof
  2025-03-03 18:30   ` Uladzislau Rezki
@ 2025-03-05  1:46     ` liuye
  2025-03-05 10:02       ` Baoquan He
  0 siblings, 1 reply; 13+ messages in thread
From: liuye @ 2025-03-05  1:46 UTC (permalink / raw)
  To: Uladzislau Rezki; +Cc: akpm, hch, linux-mm, linux-kernel


在 2025/3/4 02:30, Uladzislau Rezki 写道:
> On Mon, Mar 03, 2025 at 05:44:07PM +0800, Liu Ye wrote:
>> The same operation already exists in the function __get_vm_area_node,
>> so delete the duplicate operation to simplify the code.
>>
>> Signed-off-by: Liu Ye <liuye@kylinos.cn>
>> ---
>>  mm/vmalloc.c | 1 -
>>  1 file changed, 1 deletion(-)
>>
>> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
>> index dc658d4af181..20d9b9de84b1 100644
>> --- a/mm/vmalloc.c
>> +++ b/mm/vmalloc.c
>> @@ -3798,7 +3798,6 @@ void *__vmalloc_node_range_noprof(unsigned long size, unsigned long align,
>>  			shift = arch_vmap_pte_supported_shift(size);
>>  
>>  		align = max(real_align, 1UL << shift);
>> -		size = ALIGN(real_size, 1UL << shift);
>>  	}
>>  
>>  again:
>> -- 
>> 2.25.1
>>
> There is a mess with:
>
>  unsigned long real_size = size;
>  unsigned long real_align = align;
>
> "real_size" and "real_align". Those are useless. What is about:

Sorry, the order of the patches may be misleading.

The correct order is as follows:

PATCH1.  mm/vmalloc: Size should be used instead of real_size "
PATCH2.  mm/vmalloc: Remove unnecessary size ALIGN in __vmalloc_node_range_noprof                 
PATCH3.  mm/vmalloc: Remove the real_size variable to simplify the code "
PATCH4.  mm/vmalloc: Rename the variable real_align to original_align to prevent misunderstanding

If PATCH1 is the correct fix, then consider PATCH2, PATCH3, and PATCH4.

> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> index 5c88d0e90c20..a381ffee1595 100644
> --- a/mm/vmalloc.c
> +++ b/mm/vmalloc.c
> @@ -3771,8 +3771,6 @@ void *__vmalloc_node_range_noprof(unsigned long size, unsigned long align,
>  	struct vm_struct *area;
>  	void *ret;
>  	kasan_vmalloc_flags_t kasan_flags = KASAN_VMALLOC_NONE;
> -	unsigned long real_size = size;
> -	unsigned long real_align = align;
>  	unsigned int shift = PAGE_SHIFT;
>  
>  	if (WARN_ON_ONCE(!size))
> @@ -3781,7 +3779,7 @@ void *__vmalloc_node_range_noprof(unsigned long size, unsigned long align,
>  	if ((size >> PAGE_SHIFT) > totalram_pages()) {
>  		warn_alloc(gfp_mask, NULL,
>  			"vmalloc error: size %lu, exceeds total pages",
> -			real_size);
> +			size);
>  		return NULL;
>  	}
>  
> @@ -3798,19 +3796,18 @@ void *__vmalloc_node_range_noprof(unsigned long size, unsigned long align,
>  		else
>  			shift = arch_vmap_pte_supported_shift(size);
>  
> -		align = max(real_align, 1UL << shift);
> -		size = ALIGN(real_size, 1UL << shift);
> +		align = max(align, 1UL << shift);
>  	}
>  
>  again:
> -	area = __get_vm_area_node(real_size, align, shift, VM_ALLOC |
> +	area = __get_vm_area_node(size, align, shift, VM_ALLOC |
>  				  VM_UNINITIALIZED | vm_flags, start, end, node,
>  				  gfp_mask, caller);
>  	if (!area) {
>  		bool nofail = gfp_mask & __GFP_NOFAIL;
>  		warn_alloc(gfp_mask, NULL,
>  			"vmalloc error: size %lu, vm_struct allocation failed%s",
> -			real_size, (nofail) ? ". Retrying." : "");
> +			size, (nofail) ? ". Retrying." : "");
>  		if (nofail) {
>  			schedule_timeout_uninterruptible(1);
>  			goto again;
> @@ -3860,7 +3857,7 @@ void *__vmalloc_node_range_noprof(unsigned long size, unsigned long align,
>  	    (gfp_mask & __GFP_SKIP_ZERO))
>  		kasan_flags |= KASAN_VMALLOC_INIT;
>  	/* KASAN_VMALLOC_PROT_NORMAL already set if required. */
> -	area->addr = kasan_unpoison_vmalloc(area->addr, real_size, kasan_flags);
> +	area->addr = kasan_unpoison_vmalloc(area->addr, size, kasan_flags);
>  
>  	/*
>  	 * In this function, newly allocated vm_struct has VM_UNINITIALIZED
> @@ -3878,8 +3875,6 @@ void *__vmalloc_node_range_noprof(unsigned long size, unsigned long align,
>  fail:
>  	if (shift > PAGE_SHIFT) {
>  		shift = PAGE_SHIFT;
> -		align = real_align;
> -		size = real_size;
>  		goto again;
>  	}
>  
> ?
>
> --
> Uladzislau Rezki


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

* Re: [PATCH 1/4] mm/vmalloc: Remove unnecessary size ALIGN in __vmalloc_node_range_noprof
  2025-03-05  1:46     ` liuye
@ 2025-03-05 10:02       ` Baoquan He
  2025-03-05 10:06         ` Uladzislau Rezki
  0 siblings, 1 reply; 13+ messages in thread
From: Baoquan He @ 2025-03-05 10:02 UTC (permalink / raw)
  To: liuye; +Cc: Uladzislau Rezki, akpm, hch, linux-mm, linux-kernel

On 03/05/25 at 09:46am, liuye wrote:
> 
> 在 2025/3/4 02:30, Uladzislau Rezki 写道:
> > On Mon, Mar 03, 2025 at 05:44:07PM +0800, Liu Ye wrote:
> >> The same operation already exists in the function __get_vm_area_node,
> >> so delete the duplicate operation to simplify the code.
> >>
> >> Signed-off-by: Liu Ye <liuye@kylinos.cn>
> >> ---
> >>  mm/vmalloc.c | 1 -
> >>  1 file changed, 1 deletion(-)
> >>
> >> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> >> index dc658d4af181..20d9b9de84b1 100644
> >> --- a/mm/vmalloc.c
> >> +++ b/mm/vmalloc.c
> >> @@ -3798,7 +3798,6 @@ void *__vmalloc_node_range_noprof(unsigned long size, unsigned long align,
> >>  			shift = arch_vmap_pte_supported_shift(size);
> >>  
> >>  		align = max(real_align, 1UL << shift);
> >> -		size = ALIGN(real_size, 1UL << shift);
> >>  	}
> >>  
> >>  again:
> >> -- 
> >> 2.25.1
> >>
> > There is a mess with:
> >
> >  unsigned long real_size = size;
> >  unsigned long real_align = align;
> >
> > "real_size" and "real_align". Those are useless. What is about:
> 
> Sorry, the order of the patches may be misleading.
> 
> The correct order is as follows:
> 
> PATCH1.  mm/vmalloc: Size should be used instead of real_size "
> PATCH2.  mm/vmalloc: Remove unnecessary size ALIGN in __vmalloc_node_range_noprof                 
> PATCH3.  mm/vmalloc: Remove the real_size variable to simplify the code "
> PATCH4.  mm/vmalloc: Rename the variable real_align to original_align to prevent misunderstanding
> 
> If PATCH1 is the correct fix, then consider PATCH2, PATCH3, and PATCH4.

Well, seems the patch split is done too subtly. It's only about the
size/align inside one function, maybe one patch is enough in this case.
My personal opinion.

> 
> > diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> > index 5c88d0e90c20..a381ffee1595 100644
> > --- a/mm/vmalloc.c
> > +++ b/mm/vmalloc.c
> > @@ -3771,8 +3771,6 @@ void *__vmalloc_node_range_noprof(unsigned long size, unsigned long align,
> >  	struct vm_struct *area;
> >  	void *ret;
> >  	kasan_vmalloc_flags_t kasan_flags = KASAN_VMALLOC_NONE;
> > -	unsigned long real_size = size;
> > -	unsigned long real_align = align;
> >  	unsigned int shift = PAGE_SHIFT;
> >  
> >  	if (WARN_ON_ONCE(!size))
> > @@ -3781,7 +3779,7 @@ void *__vmalloc_node_range_noprof(unsigned long size, unsigned long align,
> >  	if ((size >> PAGE_SHIFT) > totalram_pages()) {
> >  		warn_alloc(gfp_mask, NULL,
> >  			"vmalloc error: size %lu, exceeds total pages",
> > -			real_size);
> > +			size);
> >  		return NULL;
> >  	}
> >  
> > @@ -3798,19 +3796,18 @@ void *__vmalloc_node_range_noprof(unsigned long size, unsigned long align,
> >  		else
> >  			shift = arch_vmap_pte_supported_shift(size);
> >  
> > -		align = max(real_align, 1UL << shift);
> > -		size = ALIGN(real_size, 1UL << shift);
> > +		align = max(align, 1UL << shift);
> >  	}
> >  
> >  again:
> > -	area = __get_vm_area_node(real_size, align, shift, VM_ALLOC |
> > +	area = __get_vm_area_node(size, align, shift, VM_ALLOC |
> >  				  VM_UNINITIALIZED | vm_flags, start, end, node,
> >  				  gfp_mask, caller);
> >  	if (!area) {
> >  		bool nofail = gfp_mask & __GFP_NOFAIL;
> >  		warn_alloc(gfp_mask, NULL,
> >  			"vmalloc error: size %lu, vm_struct allocation failed%s",
> > -			real_size, (nofail) ? ". Retrying." : "");
> > +			size, (nofail) ? ". Retrying." : "");
> >  		if (nofail) {
> >  			schedule_timeout_uninterruptible(1);
> >  			goto again;
> > @@ -3860,7 +3857,7 @@ void *__vmalloc_node_range_noprof(unsigned long size, unsigned long align,
> >  	    (gfp_mask & __GFP_SKIP_ZERO))
> >  		kasan_flags |= KASAN_VMALLOC_INIT;
> >  	/* KASAN_VMALLOC_PROT_NORMAL already set if required. */
> > -	area->addr = kasan_unpoison_vmalloc(area->addr, real_size, kasan_flags);
> > +	area->addr = kasan_unpoison_vmalloc(area->addr, size, kasan_flags);
> >  
> >  	/*
> >  	 * In this function, newly allocated vm_struct has VM_UNINITIALIZED
> > @@ -3878,8 +3875,6 @@ void *__vmalloc_node_range_noprof(unsigned long size, unsigned long align,
> >  fail:
> >  	if (shift > PAGE_SHIFT) {
> >  		shift = PAGE_SHIFT;
> > -		align = real_align;
> > -		size = real_size;
> >  		goto again;
> >  	}
> >  
> > ?
> >
> > --
> > Uladzislau Rezki
> 



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

* Re: [PATCH 1/4] mm/vmalloc: Remove unnecessary size ALIGN in __vmalloc_node_range_noprof
  2025-03-05 10:02       ` Baoquan He
@ 2025-03-05 10:06         ` Uladzislau Rezki
  2025-03-06  1:32           ` liuye
  0 siblings, 1 reply; 13+ messages in thread
From: Uladzislau Rezki @ 2025-03-05 10:06 UTC (permalink / raw)
  To: Baoquan He, liuye
  Cc: liuye, Uladzislau Rezki, akpm, hch, linux-mm, linux-kernel

On Wed, Mar 05, 2025 at 06:02:19PM +0800, Baoquan He wrote:
> On 03/05/25 at 09:46am, liuye wrote:
> > 
> > 在 2025/3/4 02:30, Uladzislau Rezki 写道:
> > > On Mon, Mar 03, 2025 at 05:44:07PM +0800, Liu Ye wrote:
> > >> The same operation already exists in the function __get_vm_area_node,
> > >> so delete the duplicate operation to simplify the code.
> > >>
> > >> Signed-off-by: Liu Ye <liuye@kylinos.cn>
> > >> ---
> > >>  mm/vmalloc.c | 1 -
> > >>  1 file changed, 1 deletion(-)
> > >>
> > >> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> > >> index dc658d4af181..20d9b9de84b1 100644
> > >> --- a/mm/vmalloc.c
> > >> +++ b/mm/vmalloc.c
> > >> @@ -3798,7 +3798,6 @@ void *__vmalloc_node_range_noprof(unsigned long size, unsigned long align,
> > >>  			shift = arch_vmap_pte_supported_shift(size);
> > >>  
> > >>  		align = max(real_align, 1UL << shift);
> > >> -		size = ALIGN(real_size, 1UL << shift);
> > >>  	}
> > >>  
> > >>  again:
> > >> -- 
> > >> 2.25.1
> > >>
> > > There is a mess with:
> > >
> > >  unsigned long real_size = size;
> > >  unsigned long real_align = align;
> > >
> > > "real_size" and "real_align". Those are useless. What is about:
> > 
> > Sorry, the order of the patches may be misleading.
> > 
> > The correct order is as follows:
> > 
> > PATCH1.  mm/vmalloc: Size should be used instead of real_size "
> > PATCH2.  mm/vmalloc: Remove unnecessary size ALIGN in __vmalloc_node_range_noprof                 
> > PATCH3.  mm/vmalloc: Remove the real_size variable to simplify the code "
> > PATCH4.  mm/vmalloc: Rename the variable real_align to original_align to prevent misunderstanding
> > 
> > If PATCH1 is the correct fix, then consider PATCH2, PATCH3, and PATCH4.
> 
> Well, seems the patch split is done too subtly. It's only about the
> size/align inside one function, maybe one patch is enough in this case.
> My personal opinion.
> 
I agree. One patch would be enough.

--
Uladzislau Rezki


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

* Re: [PATCH 1/4] mm/vmalloc: Remove unnecessary size ALIGN in __vmalloc_node_range_noprof
  2025-03-05 10:06         ` Uladzislau Rezki
@ 2025-03-06  1:32           ` liuye
  0 siblings, 0 replies; 13+ messages in thread
From: liuye @ 2025-03-06  1:32 UTC (permalink / raw)
  To: Uladzislau Rezki, Baoquan He; +Cc: akpm, hch, linux-mm, linux-kernel



在 2025/3/5 18:06, Uladzislau Rezki 写道:
> On Wed, Mar 05, 2025 at 06:02:19PM +0800, Baoquan He wrote:
>> On 03/05/25 at 09:46am, liuye wrote:
>>>
>>> 在 2025/3/4 02:30, Uladzislau Rezki 写道:
>>>> On Mon, Mar 03, 2025 at 05:44:07PM +0800, Liu Ye wrote:
>>>>> The same operation already exists in the function __get_vm_area_node,
>>>>> so delete the duplicate operation to simplify the code.
>>>>>
>>>>> Signed-off-by: Liu Ye <liuye@kylinos.cn>
>>>>> ---
>>>>>  mm/vmalloc.c | 1 -
>>>>>  1 file changed, 1 deletion(-)
>>>>>
>>>>> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
>>>>> index dc658d4af181..20d9b9de84b1 100644
>>>>> --- a/mm/vmalloc.c
>>>>> +++ b/mm/vmalloc.c
>>>>> @@ -3798,7 +3798,6 @@ void *__vmalloc_node_range_noprof(unsigned long size, unsigned long align,
>>>>>  			shift = arch_vmap_pte_supported_shift(size);
>>>>>  
>>>>>  		align = max(real_align, 1UL << shift);
>>>>> -		size = ALIGN(real_size, 1UL << shift);
>>>>>  	}
>>>>>  
>>>>>  again:
>>>>> -- 
>>>>> 2.25.1
>>>>>
>>>> There is a mess with:
>>>>
>>>>  unsigned long real_size = size;
>>>>  unsigned long real_align = align;
>>>>
>>>> "real_size" and "real_align". Those are useless. What is about:
>>>
>>> Sorry, the order of the patches may be misleading.
>>>
>>> The correct order is as follows:
>>>
>>> PATCH1.  mm/vmalloc: Size should be used instead of real_size "
>>> PATCH2.  mm/vmalloc: Remove unnecessary size ALIGN in __vmalloc_node_range_noprof                 
>>> PATCH3.  mm/vmalloc: Remove the real_size variable to simplify the code "
>>> PATCH4.  mm/vmalloc: Rename the variable real_align to original_align to prevent misunderstanding
>>>
>>> If PATCH1 is the correct fix, then consider PATCH2, PATCH3, and PATCH4.
>>
>> Well, seems the patch split is done too subtly. It's only about the
>> size/align inside one function, maybe one patch is enough in this case.
>> My personal opinion.
>>
> I agree. One patch would be enough.
> 

At first, I only wanted to use one patch, but to better understand, I split it up.
I can integrate it later and resend a new patch, and add a detailed description in the commit message.

Thanks,
Liu Ye

> --
> Uladzislau Rezki


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

end of thread, other threads:[~2025-03-06  1:32 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-03  9:44 [PATCH 0/4] Optimize __vmalloc_node_range_noprof function Liu Ye
2025-03-03  9:44 ` [PATCH 1/4] mm/vmalloc: Remove unnecessary size ALIGN in __vmalloc_node_range_noprof Liu Ye
2025-03-03 18:30   ` Uladzislau Rezki
2025-03-05  1:46     ` liuye
2025-03-05 10:02       ` Baoquan He
2025-03-05 10:06         ` Uladzislau Rezki
2025-03-06  1:32           ` liuye
2025-03-03  9:44 ` [PATCH 2/4] mm/vmalloc: Size should be used instead of real_size " Liu Ye
2025-03-03  9:44 ` [PATCH 3/4] mm/vmalloc: Remove the real_size variable to simplify the code " Liu Ye
2025-03-03  9:44 ` [PATCH 4/4] mm/vmalloc: Rename the variable real_align to original_align to prevent misunderstanding Liu Ye
2025-03-03 16:09 ` [PATCH 0/4] Optimize __vmalloc_node_range_noprof function Uladzislau Rezki
2025-03-04  5:58   ` Dev Jain
2025-03-05  1:33     ` liuye

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