Re: [PATCH 1/2] mm/mempolicy: Simplify weighted interleave bulk alloc calculations

From: David Hildenbrand
Date: Thu Jun 26 2025 - 17:51:48 EST


On 26.06.25 22:09, Joshua Hahn wrote:
Simplify the math used to figure out how many pages should be allocated
per node. Instead of making conditional additions and deletions, we can just
make them unconditional by using min(). No functional changes intended.

Signed-off-by: Joshua Hahn <joshua.hahnjy@xxxxxxxxx>

---
mm/mempolicy.c | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index 3b1dfd08338b..78ad74a0e249 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -2645,18 +2645,15 @@ static unsigned long alloc_pages_bulk_weighted_interleave(gfp_t gfp,
for (i = 0; i < nnodes; i++) {
node = next_node_in(prev_node, nodes);
weight = weights[node];
- node_pages = weight * rounds;
- /* If a delta exists, add this node's portion of the delta */
- if (delta > weight) {
- node_pages += weight;
- delta -= weight;
- } else if (delta) {
- /* when delta is depleted, resume from that node */
- node_pages += delta;
+ /* when delta is depleted, resume from that node */
+ if (delta && delta < weight) {
resume_node = node;
resume_weight = weight - delta;
- delta = 0;
}
+ /* Add the node's portion of the delta, if there is one */
+ node_pages = weight * rounds + min(delta, weight);
+ delta -= min(delta, weight);
+

LGTM, but took me a second (and it's a bit late ...)

Acked-by: David Hildenbrand <david@xxxxxxxxxx>

--
Cheers,

David / dhildenb