* [PATCH] mm/page_alloc: simplify lowmem_reserve max calculation @ 2025-08-14 9:00 Ye Liu 2025-08-14 14:07 ` Johannes Weiner 2025-08-14 14:47 ` Zi Yan 0 siblings, 2 replies; 7+ messages in thread From: Ye Liu @ 2025-08-14 9:00 UTC (permalink / raw) To: Andrew Morton, Vlastimil Babka Cc: Ye Liu, Suren Baghdasaryan, Michal Hocko, Brendan Jackman, Johannes Weiner, Zi Yan, linux-mm, linux-kernel From: Ye Liu <liuye@kylinos.cn> 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. Signed-off-by: Ye Liu <liuye@kylinos.cn> --- mm/page_alloc.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 64872214bc7d..8a55a4951d19 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -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. */ -- 2.43.0 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] mm/page_alloc: simplify lowmem_reserve max calculation 2025-08-14 9:00 [PATCH] mm/page_alloc: simplify lowmem_reserve max calculation Ye Liu @ 2025-08-14 14:07 ` Johannes Weiner 2025-08-15 1:59 ` Ye Liu 2025-08-14 14:47 ` Zi Yan 1 sibling, 1 reply; 7+ messages in thread From: Johannes Weiner @ 2025-08-14 14:07 UTC (permalink / raw) To: Ye Liu Cc: Andrew Morton, Vlastimil Babka, Ye Liu, Suren Baghdasaryan, Michal Hocko, Brendan Jackman, Zi Yan, linux-mm, linux-kernel On Thu, Aug 14, 2025 at 05:00:52PM +0800, Ye Liu wrote: > From: Ye Liu <liuye@kylinos.cn> > > 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. > > Signed-off-by: Ye Liu <liuye@kylinos.cn> You can remove the {} from the for block as well now. Acked-by: Johannes Weiner <hannes@cmpxchg.org> ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] mm/page_alloc: simplify lowmem_reserve max calculation 2025-08-14 14:07 ` Johannes Weiner @ 2025-08-15 1:59 ` Ye Liu 2025-08-15 2:01 ` Zi Yan 0 siblings, 1 reply; 7+ messages in thread From: Ye Liu @ 2025-08-15 1:59 UTC (permalink / raw) To: Johannes Weiner Cc: Andrew Morton, Vlastimil Babka, Ye Liu, Suren Baghdasaryan, Michal Hocko, Brendan Jackman, Zi Yan, linux-mm, linux-kernel 在 2025/8/14 22:07, Johannes Weiner 写道: > On Thu, Aug 14, 2025 at 05:00:52PM +0800, Ye Liu wrote: >> From: Ye Liu <liuye@kylinos.cn> >> >> 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. >> >> Signed-off-by: Ye Liu <liuye@kylinos.cn> > > 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/20250815004917.03FD7C4CEED@smtp.kernel.org/ > > Acked-by: Johannes Weiner <hannes@cmpxchg.org> -- Thanks, Ye Liu ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] mm/page_alloc: simplify lowmem_reserve max calculation 2025-08-15 1:59 ` Ye Liu @ 2025-08-15 2:01 ` Zi Yan 0 siblings, 0 replies; 7+ messages in thread From: Zi Yan @ 2025-08-15 2:01 UTC (permalink / raw) To: Ye Liu Cc: Johannes Weiner, Andrew Morton, Vlastimil Babka, Ye Liu, Suren Baghdasaryan, Michal Hocko, Brendan Jackman, linux-mm, linux-kernel On 14 Aug 2025, at 21:59, Ye Liu wrote: > 在 2025/8/14 22:07, Johannes Weiner 写道: >> On Thu, Aug 14, 2025 at 05:00:52PM +0800, Ye Liu wrote: >>> From: Ye Liu <liuye@kylinos.cn> >>> >>> 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. >>> >>> Signed-off-by: Ye Liu <liuye@kylinos.cn> >> >> 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/20250815004917.03FD7C4CEED@smtp.kernel.org/ 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 ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] mm/page_alloc: simplify lowmem_reserve max calculation 2025-08-14 9:00 [PATCH] mm/page_alloc: simplify lowmem_reserve max calculation Ye Liu 2025-08-14 14:07 ` Johannes Weiner @ 2025-08-14 14:47 ` Zi Yan 2025-08-15 1:38 ` Ye Liu 1 sibling, 1 reply; 7+ messages in thread From: Zi Yan @ 2025-08-14 14:47 UTC (permalink / raw) To: Ye Liu Cc: Andrew Morton, Vlastimil Babka, Ye Liu, Suren Baghdasaryan, Michal Hocko, Brendan Jackman, Johannes Weiner, linux-mm, linux-kernel On 14 Aug 2025, at 5:00, Ye Liu wrote: > From: Ye Liu <liuye@kylinos.cn> > > 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. > > Signed-off-by: Ye Liu <liuye@kylinos.cn> > --- > mm/page_alloc.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index 64872214bc7d..8a55a4951d19 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -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 <ziy@nvidia.com>. Best Regards, Yan, Zi ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] mm/page_alloc: simplify lowmem_reserve max calculation 2025-08-14 14:47 ` Zi Yan @ 2025-08-15 1:38 ` Ye Liu 2025-08-15 1:59 ` Zi Yan 0 siblings, 1 reply; 7+ messages in thread From: Ye Liu @ 2025-08-15 1:38 UTC (permalink / raw) To: Zi Yan Cc: Andrew Morton, Vlastimil Babka, Ye Liu, Suren Baghdasaryan, Michal Hocko, Brendan Jackman, Johannes Weiner, linux-mm, linux-kernel 在 2025/8/14 22:47, Zi Yan 写道: > On 14 Aug 2025, at 5:00, Ye Liu wrote: > >> From: Ye Liu <liuye@kylinos.cn> >> >> 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. >> >> Signed-off-by: Ye Liu <liuye@kylinos.cn> >> --- >> mm/page_alloc.c | 3 +-- >> 1 file changed, 1 insertion(+), 2 deletions(-) >> >> diff --git a/mm/page_alloc.c b/mm/page_alloc.c >> index 64872214bc7d..8a55a4951d19 100644 >> --- a/mm/page_alloc.c >> +++ b/mm/page_alloc.c >> @@ -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? 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? > > Feel free to add Acked-by: Zi Yan <ziy@nvidia.com>. > > Best Regards, > Yan, Zi -- Thanks, Ye Liu ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] mm/page_alloc: simplify lowmem_reserve max calculation 2025-08-15 1:38 ` Ye Liu @ 2025-08-15 1:59 ` Zi Yan 0 siblings, 0 replies; 7+ messages in thread From: Zi Yan @ 2025-08-15 1:59 UTC (permalink / raw) To: Ye Liu Cc: Andrew Morton, Vlastimil Babka, Ye Liu, Suren Baghdasaryan, Michal Hocko, Brendan Jackman, Johannes Weiner, linux-mm, linux-kernel On 14 Aug 2025, at 21:38, Ye Liu wrote: > 在 2025/8/14 22:47, Zi Yan 写道: >> On 14 Aug 2025, at 5:00, Ye Liu wrote: >> >>> From: Ye Liu <liuye@kylinos.cn> >>> >>> 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. >>> >>> Signed-off-by: Ye Liu <liuye@kylinos.cn> >>> --- >>> mm/page_alloc.c | 3 +-- >>> 1 file changed, 1 insertion(+), 2 deletions(-) >>> >>> diff --git a/mm/page_alloc.c b/mm/page_alloc.c >>> index 64872214bc7d..8a55a4951d19 100644 >>> --- a/mm/page_alloc.c >>> +++ b/mm/page_alloc.c >>> @@ -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? > > 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'? 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. > 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? 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. > >> >> Feel free to add Acked-by: Zi Yan <ziy@nvidia.com>. >> >> Best Regards, >> Yan, Zi > > -- > Thanks, > Ye Liu Best Regards, Yan, Zi ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-08-15 2:01 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-08-14 9:00 [PATCH] mm/page_alloc: simplify lowmem_reserve max calculation Ye Liu 2025-08-14 14:07 ` Johannes Weiner 2025-08-15 1:59 ` Ye Liu 2025-08-15 2:01 ` Zi Yan 2025-08-14 14:47 ` Zi Yan 2025-08-15 1:38 ` Ye Liu 2025-08-15 1:59 ` Zi Yan
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).