[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250815023500.36893-1-ye.liu@linux.dev>
Date: Fri, 15 Aug 2025 10:34:59 +0800
From: Ye Liu <ye.liu@...ux.dev>
To: Andrew Morton <akpm@...ux-foundation.org>,
Vlastimil Babka <vbabka@...e.cz>
Cc: Ye Liu <liuye@...inos.cn>,
Johannes Weiner <hannes@...xchg.org>,
Zi Yan <ziy@...dia.com>,
Suren Baghdasaryan <surenb@...gle.com>,
Michal Hocko <mhocko@...e.com>,
Brendan Jackman <jackmanb@...gle.com>,
linux-mm@...ck.org,
linux-kernel@...r.kernel.org
Subject: [PATCH v2] mm/page_alloc: simplify lowmem_reserve max calculation
From: Ye Liu <liuye@...inos.cn>
Use max() to find the maximum lowmem_reserve value and min_t() to
cap it to managed_pages in calculate_totalreserve_pages(), instead
of open-coding the comparisons. No functional change.
Signed-off-by: Ye Liu <liuye@...inos.cn>
Acked-by: Johannes Weiner <hannes@...xchg.org>
Acked-by: Zi Yan <ziy@...dia.com>
Changes in v2:
- Drop unnecessary braces
- Replace "if (max > managed_pages)" with min_t()
- Link to v1:https://lore.kernel.org/all/20250814090053.22241-1-ye.liu@linux.dev/
---
mm/page_alloc.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 64872214bc7d..2617fd2f4b73 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -6235,16 +6235,13 @@ static void calculate_totalreserve_pages(void)
unsigned long managed_pages = zone_managed_pages(zone);
/* 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];
- }
+ for (j = i; j < MAX_NR_ZONES; j++)
+ max = max(max, zone->lowmem_reserve[j]);
/* we treat the high watermark as reserved pages. */
max += high_wmark_pages(zone);
- if (max > managed_pages)
- max = managed_pages;
+ min_t(unsigned long, max, managed_pages);
pgdat->totalreserve_pages += max;
--
2.43.0
Powered by blists - more mailing lists