mm/mmap: use SZ_{8M, 128M} helper macro

Message ID 20240126085905.2835513-1-yajun.deng@linux.dev
State New
Headers
Series mm/mmap: use SZ_{8M, 128M} helper macro |

Commit Message

Yajun Deng Jan. 26, 2024, 8:59 a.m. UTC
  Use SZ_{8M, 128M} macro intead of the number in init_user_reserve and
reserve_mem_notifier.

Signed-off-by: Yajun Deng <yajun.deng@linux.dev>
---
 mm/mmap.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
  

Comments

Mike Rapoport Jan. 30, 2024, 9:11 a.m. UTC | #1
On Fri, Jan 26, 2024 at 04:59:05PM +0800, Yajun Deng wrote:
> Use SZ_{8M, 128M} macro intead of the number in init_user_reserve and
> reserve_mem_notifier.
> 
> Signed-off-by: Yajun Deng <yajun.deng@linux.dev>
> ---
>  mm/mmap.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/mm/mmap.c b/mm/mmap.c
> index 476de5daf598..f90924b2a6d2 100644
> --- a/mm/mmap.c
> +++ b/mm/mmap.c
> @@ -3845,7 +3845,7 @@ static int init_user_reserve(void)
>  
>  	free_kbytes = K(global_zone_page_state(NR_FREE_PAGES));
>  
> -	sysctl_user_reserve_kbytes = min(free_kbytes / 32, 1UL << 17);
> +	sysctl_user_reserve_kbytes = min(free_kbytes / 32, SZ_128M);

(1UL << 17) != SZ_128M

>  	return 0;
>  }
>  subsys_initcall(init_user_reserve);
> @@ -3866,7 +3866,7 @@ static int init_admin_reserve(void)
>  
>  	free_kbytes = K(global_zone_page_state(NR_FREE_PAGES));
>  
> -	sysctl_admin_reserve_kbytes = min(free_kbytes / 32, 1UL << 13);
> +	sysctl_admin_reserve_kbytes = min(free_kbytes / 32, SZ_8M);
>  	return 0;
>  }
>  subsys_initcall(init_admin_reserve);
> @@ -3898,12 +3898,12 @@ static int reserve_mem_notifier(struct notifier_block *nb,
>  	case MEM_ONLINE:
>  		/* Default max is 128MB. Leave alone if modified by operator. */
>  		tmp = sysctl_user_reserve_kbytes;
> -		if (0 < tmp && tmp < (1UL << 17))
> +		if (tmp > 0 && tmp < SZ_128M)
>  			init_user_reserve();
>  
>  		/* Default max is 8MB.  Leave alone if modified by operator. */
>  		tmp = sysctl_admin_reserve_kbytes;
> -		if (0 < tmp && tmp < (1UL << 13))
> +		if (tmp > 0 && tmp < SZ_8M)

(1UL << 13) != SZ_8M

>  			init_admin_reserve();
>  
>  		break;
> -- 
> 2.25.1
> 
>
  
Yajun Deng Jan. 30, 2024, 9:25 a.m. UTC | #2
On 2024/1/30 17:11, Mike Rapoport wrote:
> On Fri, Jan 26, 2024 at 04:59:05PM +0800, Yajun Deng wrote:
>> Use SZ_{8M, 128M} macro intead of the number in init_user_reserve and
>> reserve_mem_notifier.
>>
>> Signed-off-by: Yajun Deng <yajun.deng@linux.dev>
>> ---
>>   mm/mmap.c | 8 ++++----
>>   1 file changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/mm/mmap.c b/mm/mmap.c
>> index 476de5daf598..f90924b2a6d2 100644
>> --- a/mm/mmap.c
>> +++ b/mm/mmap.c
>> @@ -3845,7 +3845,7 @@ static int init_user_reserve(void)
>>   
>>   	free_kbytes = K(global_zone_page_state(NR_FREE_PAGES));
>>   
>> -	sysctl_user_reserve_kbytes = min(free_kbytes / 32, 1UL << 17);
>> +	sysctl_user_reserve_kbytes = min(free_kbytes / 32, SZ_128M);
> (1UL << 17) != SZ_128M
I am sorry for this, I didn't realize that the unit was kbyte.
>
>>   	return 0;
>>   }
>>   subsys_initcall(init_user_reserve);
>> @@ -3866,7 +3866,7 @@ static int init_admin_reserve(void)
>>   
>>   	free_kbytes = K(global_zone_page_state(NR_FREE_PAGES));
>>   
>> -	sysctl_admin_reserve_kbytes = min(free_kbytes / 32, 1UL << 13);
>> +	sysctl_admin_reserve_kbytes = min(free_kbytes / 32, SZ_8M);
>>   	return 0;
>>   }
>>   subsys_initcall(init_admin_reserve);
>> @@ -3898,12 +3898,12 @@ static int reserve_mem_notifier(struct notifier_block *nb,
>>   	case MEM_ONLINE:
>>   		/* Default max is 128MB. Leave alone if modified by operator. */
>>   		tmp = sysctl_user_reserve_kbytes;
>> -		if (0 < tmp && tmp < (1UL << 17))
>> +		if (tmp > 0 && tmp < SZ_128M)
>>   			init_user_reserve();
>>   
>>   		/* Default max is 8MB.  Leave alone if modified by operator. */
>>   		tmp = sysctl_admin_reserve_kbytes;
>> -		if (0 < tmp && tmp < (1UL << 13))
>> +		if (tmp > 0 && tmp < SZ_8M)
> (1UL << 13) != SZ_8M
>
>>   			init_admin_reserve();
>>   
>>   		break;
>> -- 
>> 2.25.1
>>
>>
  

Patch

diff --git a/mm/mmap.c b/mm/mmap.c
index 476de5daf598..f90924b2a6d2 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -3845,7 +3845,7 @@  static int init_user_reserve(void)
 
 	free_kbytes = K(global_zone_page_state(NR_FREE_PAGES));
 
-	sysctl_user_reserve_kbytes = min(free_kbytes / 32, 1UL << 17);
+	sysctl_user_reserve_kbytes = min(free_kbytes / 32, SZ_128M);
 	return 0;
 }
 subsys_initcall(init_user_reserve);
@@ -3866,7 +3866,7 @@  static int init_admin_reserve(void)
 
 	free_kbytes = K(global_zone_page_state(NR_FREE_PAGES));
 
-	sysctl_admin_reserve_kbytes = min(free_kbytes / 32, 1UL << 13);
+	sysctl_admin_reserve_kbytes = min(free_kbytes / 32, SZ_8M);
 	return 0;
 }
 subsys_initcall(init_admin_reserve);
@@ -3898,12 +3898,12 @@  static int reserve_mem_notifier(struct notifier_block *nb,
 	case MEM_ONLINE:
 		/* Default max is 128MB. Leave alone if modified by operator. */
 		tmp = sysctl_user_reserve_kbytes;
-		if (0 < tmp && tmp < (1UL << 17))
+		if (tmp > 0 && tmp < SZ_128M)
 			init_user_reserve();
 
 		/* Default max is 8MB.  Leave alone if modified by operator. */
 		tmp = sysctl_admin_reserve_kbytes;
-		if (0 < tmp && tmp < (1UL << 13))
+		if (tmp > 0 && tmp < SZ_8M)
 			init_admin_reserve();
 
 		break;