mm/page_alloc: simplify lowmem_reserve max calculation
Subsystems (2)
PATCH 1/1 mm/page_alloc: simplify lowmem_reserve max calculation
From: Ye Liu <[email protected]>
Use max() macro to simplify the calculation of maximum lowmem_reserve value in calculate_totalreserve_pages(), instead of open-coding the comparison. The functionality remains identical.
--- mm/page_alloc.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
mm/page_alloc.c +1 -2
@@ -6236,8 +6236,7 @@ static void calculate_totalreserve_pages(void)/* Find valid and maximum lowmem_reserve in the zone */ for (j = i; j <MAX_NR_ZONES ; j++) { -if (zone->lowmem_reserve[j] > max) - max = zone->lowmem_reserve[j]; + max =max (max, zone->lowmem_reserve[j]); }/* we treat the high watermark as reserved pages. */
Signature · 1 line
2.43.0
Quoted 7 lines · Ye Liu
From: Ye Liu <[email protected]>
Use
max()macro to simplify the calculation of maximumlowmem_reservevalue incalculate_totalreserve_pages(), instead of open-coding the comparison. The functionality remains identical.Signed-off-by Ye Liu <[email protected]>
You can remove the {} from the for block as well now.
Quoted 10 lines · Johannes Weiner
Quoted 7 lines · Ye Liu
From: Ye Liu <[email protected]>
Use
max()macro to simplify the calculation of maximumlowmem_reservevalue incalculate_totalreserve_pages(), instead of open-coding the comparison. The functionality remains identical.Signed-off-by Ye Liu <[email protected]>You can remove the {} from the for block as well now.
I agree to delete it, but I noticed a patch has been added to the -mm mm-new branch by Andrew Morton[1]. What should I do now? Send v2 ?
Or send a new patch? If this is my first time, please feel free to give me some advice. [1]:https://lore.kernel.org/all/[email protected]/
Quoted 2 lines
Acked-by Johannes Weiner <[email protected]>
Signature · 2 lines
Thanks, Ye Liu
Zi Yan
reviewerQuoted 8 lines · Ye Liu
Quoted 7 lines · Johannes Weiner
Quoted 6 lines · Ye Liu
From: Ye Liu <[email protected]>
Use
max()macro to simplify the calculation of maximumlowmem_reservevalue incalculate_totalreserve_pages(), instead of open-coding the comparison. The functionality remains identical.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Ye Liu <[email protected]>You can remove the {} from the for block as well now.
I agree to delete it, but I noticed a patch has been added to the -mm mm-new branch by Andrew Morton[1]. What should I do now? Send v2 ?
Or send a new patch? If this is my first time, please feel free to give me some advice. [1]:https://lore.kernel.org/all/[email protected]/
If you read the message carefully, you will see:
“Please do not hesitate to respond to
review feedback and post updated versions to replace or incrementally fixup patches in mm-new.”
So feel free to send v2.
Best Regards,
Yan, Zi
Zi Yan
reviewerQuoted 16 lines · Ye Liu
From: Ye Liu <[email protected]>
Use
max()macro to simplify the calculation of maximumlowmem_reservevalue incalculate_totalreserve_pages(), instead of open-coding the comparison. The functionality remains identical.Signed-off-by Ye Liu <[email protected]>--- mm/page_alloc.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)mm/page_alloc.c +0
-0
mm/page_alloc.c static void calculate_totalreserve_pages(void) · line 6240
Quoted 7 lines
mm/page_alloc.c +1
-2@@ -6236,8 +6236,7 @@ static void calculate_totalreserve_pages(void)/* Find valid and maximum lowmem_reserve in the zone */ for (j = i; j <MAX_NR_ZONES ; j++) { -if (zone->lowmem_reserve[j] > max) - max = zone->lowmem_reserve[j]; + max =max (max, zone->lowmem_reserve[j]); }
There is a “if (max > managed_pages)” below. Maybe convert that as well?
Feel free to add Acked-by: Zi Yan <[email protected]>.
Best Regards,
Yan, Zi
Quoted 19 lines · Zi Yan
Quoted 17 lines · Ye Liu
From: Ye Liu <[email protected]>
Use
max()macro to simplify the calculation of maximumlowmem_reservevalue incalculate_totalreserve_pages(), instead of open-coding the comparison. The functionality remains identical.Signed-off-by Ye Liu <[email protected]>--- mm/page_alloc.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)mm/page_alloc.c +0
-0@@ -6236,8 +6236,7 @@ static void calculate_totalreserve_pages(void)
Quoted 8 lines
mm/page_alloc.c static void calculate_totalreserve_pages(void) · line 6240
Quoted 6 lines
mm/page_alloc.c +1
-2/* Find valid and maximum lowmem_reserve in the zone */ for (j = i; j <MAX_NR_ZONES ; j++) { -if (zone->lowmem_reserve[j] > max) - max = zone->lowmem_reserve[j]; + max =max (max, zone->lowmem_reserve[j]); }There is a “if (max > managed_pages)” below. Maybe convert that as well?
I should use min() here, but I noticed the two variables have different types:
one is 'long' and the other is 'unsigned long'. So, I should use min_t(). But then again, why is lowmem_reserve of type 'long'?
It should be a non-negative number, right?
Is it possible to change the type of lowmem_reserve to 'unsigned long' and change all uses of it at the same time? Is it necessary?
Quoted 5 lines
Feel free to add Acked-by: Zi Yan <[email protected]>.
Best Regards,
Yan, Zi
Signature · 2 lines
Thanks, Ye Liu
Zi Yan
reviewerQuoted 29 lines · Ye Liu
Quoted 19 lines · Zi Yan
Quoted 17 lines · Ye Liu
From: Ye Liu <[email protected]>
Use
max()macro to simplify the calculation of maximumlowmem_reservevalue incalculate_totalreserve_pages(), instead of open-coding the comparison. The functionality remains identical.Signed-off-by Ye Liu <[email protected]>--- mm/page_alloc.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)mm/page_alloc.c +0
-0@@ -6236,8 +6236,7 @@ static void calculate_totalreserve_pages(void)Quoted 8 lines
mm/page_alloc.c static void calculate_totalreserve_pages(void) · line 6240
Quoted 6 lines
mm/page_alloc.c +1
-2/* Find valid and maximum lowmem_reserve in the zone */ for (j = i; j <MAX_NR_ZONES ; j++) { -if (zone->lowmem_reserve[j] > max) - max = zone->lowmem_reserve[j]; + max =max (max, zone->lowmem_reserve[j]); }There is a “if (max > managed_pages)” below. Maybe convert that as well?
Quoted 3 lines
I should use
min()here, but I noticed the two variables have different types:
one is 'long' and the other is 'unsigned long'. So, I should usemin_t(). But then again, why islowmem_reserveof type 'long'?
Based on commit 3484b2de9499 ("mm: rearrange zone fields into read-only, page alloc, statistics and page reclaim lines”), lowmem_reserve type is changed due to the watermark calculation. Looking at current __zone_watermark_ok(), the comment above free_pages -= ... says free_pages may go negative and later free_pages is compared with lowmem_reserve.
Quoted 3 lines
It should be a non-negative number, right?
Is it possible to change the type oflowmem_reserveto 'unsigned long' and change all uses of it at the same time? Is it necessary?
In calculate_totalreserve_pages(), max cannot be negative, so you probably can use min_t(unsigned long, max, managed_pages) and without changing lowmem_reserve type.
Quoted 10 lines
Quoted 6 lines
Feel free to add Acked-by: Zi Yan <[email protected]>.
Best Regards,
Yan, ZiSignature · 2 lines
Thanks, Ye Liu
Best Regards,
Yan, Zi