From nobody Sun Feb 8 15:37:53 2026 Received: from mail-wr1-f73.google.com (mail-wr1-f73.google.com [209.85.221.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 564F225B672 for ; Fri, 28 Feb 2025 09:52:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740736346; cv=none; b=W4VIXt2wXZ2Osdisx3sbcUVekxuQ/i3fSwrih9QS1eO36fFzkX5K3DiEzjtqxKCxHKQHnBPHEPkiqUa8rZO0AEPO02vxyEZXMGv2WGgIaUmzOvtW/dMo2Ry5TrA1gPN2HTlUUUzu9GhEW0BQf//P2OtuBPjE29xbZ/cJyYm18VQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740736346; c=relaxed/simple; bh=xG2WMXZKKbUfHfELCIo//n83d9/Xao8BvJm7eA4V9IY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=JO7A3TV/ZQi5AeoS4BcmND75hGRto3INZDiNX53w6ojhxbr/mBlhj2A2YQcBgzJcmFifthNqZYUngUcLBsYkdO8KohHxXEA8KevNEdo+2oVicIZf03dCCPwE+EFY9MlnK+GbJG5hwVBpUI0Gypw9xtZVxa+pJOMIe31NUXql9bA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jackmanb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=AWbaRhJT; arc=none smtp.client-ip=209.85.221.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jackmanb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="AWbaRhJT" Received: by mail-wr1-f73.google.com with SMTP id ffacd0b85a97d-38f3bac2944so884245f8f.3 for ; Fri, 28 Feb 2025 01:52:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1740736342; x=1741341142; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=FW/4Itowb9kTuUXQ1y/EpM+Euvfc88hrYXKaBKarQSo=; b=AWbaRhJT3u1aAy054wIrDkeueyZ8soS5oTW+p6HO5QdMrC03I3Tx5Rri5DQHBe3ovX jjVR+xzf8ZCpW1JyG31wEFGjOJGm/TdmM75+H9Tz1BJrp+uuXaDG++NNBQELxeNJr81J BNUVTG5IJCoIc6QQAOVXXjl346tXQw25/SNDEQxNGWjVSEuc5om75nVeMpsI9R9UmZz2 6JWfbpXajgWoM23ocEk4L2wqb7no8sAVwiDtL2eUQhtENCUkpGYI2eKzwwpbeUYGobsH Gk3q2swohOhzjmVSs+D5/SHb3WLae1Ap3E0myr4A224t8ncn3NLBnAjjNYlS+jC6aVJH Wwkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740736342; x=1741341142; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=FW/4Itowb9kTuUXQ1y/EpM+Euvfc88hrYXKaBKarQSo=; b=V+1nTJ/4sG7VT6seb2eUhB9L59i8SylbArChmiuMFV7eITnNUVPOlJcy3J5D13uk4v fcyJ6wJPEdJj5/KVjPUGQ1pzKukhYzSTpgrw8h2vlE7DouUo73/hqi+uuZ1+O1X5GMtt MsPxVJQbOyxA2TEixltHNcYVLzzumT5u5hSy7sJERallXzpXI68BKHXBsiMQ49fetTVL zeLipRSVkpqypvHL6Ni53epx56Pp804BQodYAfqwQCjwHN18yNcYHOVRrVmPtIiYvaeB jwc7GxCIyz9FiUJ6B4A0NpIEqFtZKhLJZhlvWoLdaYs3DyME3lsE89oukXfFU2eoewV7 ySkw== X-Forwarded-Encrypted: i=1; AJvYcCXPjnrDJIf4sNx35Xm0qFPG7FvauNt6kKIER8u0f6SQd4/KyTGeEu/iHFp98KK0pl6nqVMUWzk3Juz8Uhg=@vger.kernel.org X-Gm-Message-State: AOJu0YzuR3Grr0AwPQrxor2yy/RwODAl/R848DwJy0gM9Mc2tWhT63/K Tm7gEg/ZOqZI6MLygVrTua/KF9/T1cY7xbN12xaBntY2H3W+AwyYQoOZJZh5vnSntltJrbmTLKc 233UG1jEiJg== X-Google-Smtp-Source: AGHT+IEu3+m482P1YPLRHuGe76vpYm6iwFvrHH/RmgK/tMNHmvSUd2hMzMyhtzJdg3Ovfa7XhnTfdGvRY/hbwQ== X-Received: from wmbez14.prod.google.com ([2002:a05:600c:83ce:b0:439:8664:577a]) (user=jackmanb job=prod-delivery.src-stubby-dispatcher) by 2002:a5d:5988:0:b0:38f:30a3:5208 with SMTP id ffacd0b85a97d-390eca48478mr2569251f8f.39.1740736342806; Fri, 28 Feb 2025 01:52:22 -0800 (PST) Date: Fri, 28 Feb 2025 09:52:17 +0000 In-Reply-To: <20250228-clarify-steal-v4-0-cb2ef1a4e610@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250228-clarify-steal-v4-0-cb2ef1a4e610@google.com> X-Mailer: b4 0.15-dev Message-ID: <20250228-clarify-steal-v4-1-cb2ef1a4e610@google.com> Subject: [PATCH v4 1/2] mm/page_alloc: Clarify terminology in migratetype fallback code From: Brendan Jackman To: Andrew Morton Cc: Vlastimil Babka , Mel Gorman , Michal Hocko , Johannes Weiner , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Brendan Jackman , Yosry Ahmed Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable This code is rather confusing because: 1. "Steal" is sometimes used to refer to the general concept of allocating from a from a block of a fallback migratetype (steal_suitable_fallback()) but sometimes it refers specifically to converting a whole block's migratetype (can_steal_fallback()). 2. can_steal_fallback() sounds as though it's answering the question "am I functionally permitted to allocate from that other type" but in fact it is encoding a heuristic preference. 3. The same piece of data has different names in different places: can_steal vs whole_block. This reinforces point 2 because it looks like the different names reflect a shift in intent from "am I allowed to steal" to "do I want to steal", but no such shift exists. Fix 1. by avoiding the term "steal" in ambiguous contexts. Start using the term "claim" to refer to the special case of stealing the entire block. Fix 2. by using "should" instead of "can", and also rename its parameters and add some commentary to make it more explicit what they mean. Fix 3. by adopting the new "claim" terminology universally for this set of variables. Reviewed-by: Vlastimil Babka Signed-off-by: Brendan Jackman --- mm/compaction.c | 4 ++-- mm/internal.h | 2 +- mm/page_alloc.c | 72 ++++++++++++++++++++++++++++-------------------------= ---- 3 files changed, 39 insertions(+), 39 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index 0992106d4ea751f7f1f8ebf7c75cd433d676cbe0..550ce50218075509ccb5f9485fd= 84f5d1f3d23a7 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -2333,7 +2333,7 @@ static enum compact_result __compact_finished(struct = compact_control *cc) ret =3D COMPACT_NO_SUITABLE_PAGE; for (order =3D cc->order; order < NR_PAGE_ORDERS; order++) { struct free_area *area =3D &cc->zone->free_area[order]; - bool can_steal; + bool claim_block; =20 /* Job done if page is free of the right migratetype */ if (!free_area_empty(area, migratetype)) @@ -2350,7 +2350,7 @@ static enum compact_result __compact_finished(struct = compact_control *cc) * other migratetype buddy lists. */ if (find_suitable_fallback(area, order, migratetype, - true, &can_steal) !=3D -1) + true, &claim_block) !=3D -1) /* * Movable pages are OK in any pageblock. If we are * stealing for a non-movable allocation, make sure diff --git a/mm/internal.h b/mm/internal.h index b07550db2bfd1d152fa90f91b3687b0fa1a9f653..aa30282a774ae26349944a75da8= 54ae6a3da2a98 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -863,7 +863,7 @@ static inline void init_cma_pageblock(struct page *page) =20 =20 int find_suitable_fallback(struct free_area *area, unsigned int order, - int migratetype, bool only_stealable, bool *can_steal); + int migratetype, bool claim_only, bool *claim_block); =20 static inline bool free_area_empty(struct free_area *area, int migratetype) { diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 5d8e274c8b1d500d263a17ef36fe190f60b88196..441c9d9cc5f8edbae1f4169207f= 5de9f32586f34 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1942,22 +1942,22 @@ static inline bool boost_watermark(struct zone *zon= e) =20 /* * When we are falling back to another migratetype during allocation, try = to - * steal extra free pages from the same pageblocks to satisfy further - * allocations, instead of polluting multiple pageblocks. + * claim entire blocks to satisfy further allocations, instead of polluting + * multiple pageblocks. * - * If we are stealing a relatively large buddy page, it is likely there wi= ll - * be more free pages in the pageblock, so try to steal them all. For - * reclaimable and unmovable allocations, we steal regardless of page size, - * as fragmentation caused by those allocations polluting movable pagebloc= ks - * is worse than movable allocations stealing from unmovable and reclaimab= le - * pageblocks. + * If we are stealing a relatively large buddy page, it is likely there wi= ll be + * more free pages in the pageblock, so try to claim the whole block. For + * reclaimable and unmovable allocations, we try to claim the whole block + * regardless of page size, as fragmentation caused by those allocations + * polluting movable pageblocks is worse than movable allocations stealing= from + * unmovable and reclaimable pageblocks. */ -static bool can_steal_fallback(unsigned int order, int start_mt) +static bool should_try_claim_block(unsigned int order, int start_mt) { /* * Leaving this order check is intended, although there is * relaxed order check in next check. The reason is that - * we can actually steal whole pageblock if this condition met, + * we can actually claim the whole pageblock if this condition met, * but, below check doesn't guarantee it and that is just heuristic * so could be changed anytime. */ @@ -1970,7 +1970,7 @@ static bool can_steal_fallback(unsigned int order, in= t start_mt) * reclaimable pages that are closest to the request size. After a * while, memory compaction may occur to form large contiguous pages, * and the next movable allocation may not need to steal. Unmovable and - * reclaimable allocations need to actually steal pages. + * reclaimable allocations need to actually claim the whole block. */ if (order >=3D pageblock_order / 2 || start_mt =3D=3D MIGRATE_RECLAIMABLE || @@ -1983,12 +1983,14 @@ static bool can_steal_fallback(unsigned int order, = int start_mt) =20 /* * Check whether there is a suitable fallback freepage with requested orde= r. - * If only_stealable is true, this function returns fallback_mt only if - * we can steal other freepages all together. This would help to reduce + * Sets *claim_block to instruct the caller whether it should convert a wh= ole + * pageblock to the returned migratetype. + * If only_claim is true, this function returns fallback_mt only if + * we would do this whole-block claiming. This would help to reduce * fragmentation due to mixed migratetype pages in one pageblock. */ int find_suitable_fallback(struct free_area *area, unsigned int order, - int migratetype, bool only_stealable, bool *can_steal) + int migratetype, bool only_claim, bool *claim_block) { int i; int fallback_mt; @@ -1996,19 +1998,16 @@ int find_suitable_fallback(struct free_area *area, = unsigned int order, if (area->nr_free =3D=3D 0) return -1; =20 - *can_steal =3D false; + *claim_block =3D false; for (i =3D 0; i < MIGRATE_PCPTYPES - 1 ; i++) { fallback_mt =3D fallbacks[migratetype][i]; if (free_area_empty(area, fallback_mt)) continue; =20 - if (can_steal_fallback(order, migratetype)) - *can_steal =3D true; + if (should_try_claim_block(order, migratetype)) + *claim_block =3D true; =20 - if (!only_stealable) - return fallback_mt; - - if (*can_steal) + if (*claim_block || !only_claim) return fallback_mt; } =20 @@ -2016,14 +2015,14 @@ int find_suitable_fallback(struct free_area *area, = unsigned int order, } =20 /* - * This function implements actual steal behaviour. If order is large enou= gh, we - * can claim the whole pageblock for the requested migratetype. If not, we= check - * the pageblock for constituent pages; if at least half of the pages are = free - * or compatible, we can still claim the whole block, so pages freed in the - * future will be put on the correct free list. + * This function implements actual block claiming behaviour. If order is l= arge + * enough, we can claim the whole pageblock for the requested migratetype.= If + * not, we check the pageblock for constituent pages; if at least half of = the + * pages are free or compatible, we can still claim the whole block, so pa= ges + * freed in the future will be put on the correct free list. */ static struct page * -try_to_steal_block(struct zone *zone, struct page *page, +try_to_claim_block(struct zone *zone, struct page *page, int current_order, int order, int start_type, int block_type, unsigned int alloc_flags) { @@ -2091,11 +2090,12 @@ try_to_steal_block(struct zone *zone, struct page *= page, /* * Try finding a free buddy page on the fallback list. * - * This will attempt to steal a whole pageblock for the requested type + * This will attempt to claim a whole pageblock for the requested type * to ensure grouping of such requests in the future. * - * If a whole block cannot be stolen, regress to __rmqueue_smallest() - * logic to at least break up as little contiguity as possible. + * If a whole block cannot be claimed, steal an individual page, regressin= g to + * __rmqueue_smallest() logic to at least break up as little contiguity as + * possible. * * The use of signed ints for order and current_order is a deliberate * deviation from the rest of this file, to make the for loop @@ -2112,7 +2112,7 @@ __rmqueue_fallback(struct zone *zone, int order, int = start_migratetype, int min_order =3D order; struct page *page; int fallback_mt; - bool can_steal; + bool claim_block; =20 /* * Do not steal pages from freelists belonging to other pageblocks @@ -2131,15 +2131,15 @@ __rmqueue_fallback(struct zone *zone, int order, in= t start_migratetype, --current_order) { area =3D &(zone->free_area[current_order]); fallback_mt =3D find_suitable_fallback(area, current_order, - start_migratetype, false, &can_steal); + start_migratetype, false, &claim_block); if (fallback_mt =3D=3D -1) continue; =20 - if (!can_steal) + if (!claim_block) break; =20 page =3D get_page_from_free_area(area, fallback_mt); - page =3D try_to_steal_block(zone, page, current_order, order, + page =3D try_to_claim_block(zone, page, current_order, order, start_migratetype, fallback_mt, alloc_flags); if (page) @@ -2149,11 +2149,11 @@ __rmqueue_fallback(struct zone *zone, int order, in= t start_migratetype, if (alloc_flags & ALLOC_NOFRAGMENT) return NULL; =20 - /* No luck stealing blocks. Find the smallest fallback page */ + /* No luck claiming pageblock. Find the smallest fallback page */ for (current_order =3D order; current_order < NR_PAGE_ORDERS; current_ord= er++) { area =3D &(zone->free_area[current_order]); fallback_mt =3D find_suitable_fallback(area, current_order, - start_migratetype, false, &can_steal); + start_migratetype, false, &claim_block); if (fallback_mt =3D=3D -1) continue; =20 --=20 2.48.1.711.g2feabab25a-goog From nobody Sun Feb 8 15:37:53 2026 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5192425B67E for ; Fri, 28 Feb 2025 09:52:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740736348; cv=none; b=ExWwVaRXBdVk3CKieogJfBuVzBy2dYxKEO/laDP1CatXeioqVBAoibJKIRNhw45Mos9/ZtFIvvfPKorbitDBzmTZPu+0f84aOOx8s5Q+45muHcs/DZqcRkstmGT10upA9lM2xLmE0F0I4mKFwDVYQyUn1LDGEQNgTllNB5+Syko= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740736348; c=relaxed/simple; bh=Oy/AgJ+iKO+epYA8MI/4Dr7jfnlyxcVb/cWIeswoGYQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=R6dDo0PT6a1XoxaYJMT3jiu4+ycSMNa+/KDYshHJrAgSck0z9t8Pj1PPIiw6hXn6etLXkV/awRD16liNsg0tpKev/MJ5XzX+jUcoH0bXJVhRL/NICCEH8pPg3kNd3VJNITf4NslE0TQUNVv5gywCYruibu5No2ZWKKfPmbB19V4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jackmanb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=WAH1ZaSU; arc=none smtp.client-ip=209.85.128.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jackmanb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="WAH1ZaSU" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-43941ad86d4so10062535e9.2 for ; Fri, 28 Feb 2025 01:52:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1740736344; x=1741341144; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=HO3rm5+cQOMI85a/kqJJUn+V+LGjTUrNi05UBywCRJg=; b=WAH1ZaSUwb04MVgCb5VX1mUNokoOjYPJFYxVr6mVI0kgfPHEPSkpcy3YI2xSvUEvHt Ips3OXe74n6vWlFvd0SxVba5wCVQOvmRCugR24dU202EhxIFQGvuf3ZKbu8gjdQyMBU/ dA9vm6j0SYRioY9vHm2iNs6XJfEu3L4j3q6Ov1TFp5rws60eVrQZiDdiHv9KP67/dzcN +8Uu6sN41D8dNZqqb9qHVnD+y7B9mR+0qfNcpkFoPUqEjfkja3cJd60VF5K3iYiISmaz q8QLtU03CPp1tTdngai+E63J+gI8sHUq8KBRVr8UsRj+q90Dc2ckXeyS0nhlHecJpDvw mnog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740736344; x=1741341144; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=HO3rm5+cQOMI85a/kqJJUn+V+LGjTUrNi05UBywCRJg=; b=TEa4rGOZrT81zdiXDGoov+dU8eezfBp4c50V1uu5yGf/qv2P0xejKWVmAUm8aEmNlt qbqApq9B7CaYI50Bd+QMPfmmgU59xIjxTjAYpLZvdUV6f+Ci62kRgwmbYkIgFU6VRl9T S5A0tB5mc6VmG8iczmOZCjTI+vHVz9775y3wxKjUf8qIlsv4knU4OHdtQ670dKsk2y3d G2uMb2JjEggNT3SxqikyxshBdzeBS0GyKIDqetmBXHc0Qdv3NSs4OmUOWhr5XBLBMQgk Rj2aNyVYMzkcGK1iYFp5BrfFXxoreeYU7kbbXQEVXMfWzpPnI8LakDVPV+6Iio4bHRpZ bSTw== X-Forwarded-Encrypted: i=1; AJvYcCXUk7IMpDC7usaNkaiOKs+vIhgD/EsRDndpyNRUJrrRgs5Fh+iQHKmA5HxmaX/hYeHlup+OLjLPgzXe5B4=@vger.kernel.org X-Gm-Message-State: AOJu0YxSMujvA/eAv7g7PRr9Fn6v61/VoTW4sXybpRBO3dEq+S+OQmaD 8V0jz0rvztbKaNUdJhhvPO0TNDV6frsHnt8g6OHNEpB7LVPILW256B6L16qOLu+clw5qdMe6/vO oCMzRtc6PQg== X-Google-Smtp-Source: AGHT+IE1A0Dj6yDwVQ5f1BronRrhiqIk/3BQtEj5r1ew6jfrtBzSUFcUVO/MsKCaxzJF66E3L65r+gpQTCtWGQ== X-Received: from wmbbh18.prod.google.com ([2002:a05:600c:3d12:b0:439:8e3e:b51b]) (user=jackmanb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:190a:b0:439:9c0e:3709 with SMTP id 5b1f17b1804b1-43ba66e6b0emr22738525e9.8.1740736344709; Fri, 28 Feb 2025 01:52:24 -0800 (PST) Date: Fri, 28 Feb 2025 09:52:18 +0000 In-Reply-To: <20250228-clarify-steal-v4-0-cb2ef1a4e610@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250228-clarify-steal-v4-0-cb2ef1a4e610@google.com> X-Mailer: b4 0.15-dev Message-ID: <20250228-clarify-steal-v4-2-cb2ef1a4e610@google.com> Subject: [PATCH v4 2/2] mm/page_alloc: Clarify should_claim_block() commentary From: Brendan Jackman To: Andrew Morton Cc: Vlastimil Babka , Mel Gorman , Michal Hocko , Johannes Weiner , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Brendan Jackman , Yosry Ahmed Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable There's lots of text here but it's a little hard to follow, this is an attempt to break it up and align its structure more closely with the code. Reword the top-level function comment to just explain what question the function answers from the point of view of the caller. Break up the internal logic into different sections that can have their own commentary describing why that part of the rationale is present. Note the page_group_by_mobility_disabled logic is not explained in the commentary, that is outside the scope of this patch... Signed-off-by: Brendan Jackman Reviewed-by: Vlastimil Babka --- mm/page_alloc.c | 46 ++++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 441c9d9cc5f8edbae1f4169207f5de9f32586f34..17ba5d758aa539370947b6f894e= 5fce7de6c5c5e 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1941,16 +1941,9 @@ static inline bool boost_watermark(struct zone *zone) } =20 /* - * When we are falling back to another migratetype during allocation, try = to - * claim entire blocks to satisfy further allocations, instead of polluting - * multiple pageblocks. - * - * If we are stealing a relatively large buddy page, it is likely there wi= ll be - * more free pages in the pageblock, so try to claim the whole block. For - * reclaimable and unmovable allocations, we try to claim the whole block - * regardless of page size, as fragmentation caused by those allocations - * polluting movable pageblocks is worse than movable allocations stealing= from - * unmovable and reclaimable pageblocks. + * When we are falling back to another migratetype during allocation, shou= ld we + * try to claim an entire block to satisfy further allocations, instead of + * polluting multiple pageblocks? */ static bool should_try_claim_block(unsigned int order, int start_mt) { @@ -1965,19 +1958,32 @@ static bool should_try_claim_block(unsigned int ord= er, int start_mt) return true; =20 /* - * Movable pages won't cause permanent fragmentation, so when you alloc - * small pages, you just need to temporarily steal unmovable or - * reclaimable pages that are closest to the request size. After a - * while, memory compaction may occur to form large contiguous pages, - * and the next movable allocation may not need to steal. Unmovable and - * reclaimable allocations need to actually claim the whole block. + * Above a certain threshold, always try to claim, as it's likely there + * will be more free pages in the pageblock. */ - if (order >=3D pageblock_order / 2 || - start_mt =3D=3D MIGRATE_RECLAIMABLE || - start_mt =3D=3D MIGRATE_UNMOVABLE || - page_group_by_mobility_disabled) + if (order >=3D pageblock_order / 2) return true; =20 + /* + * Unmovable/reclaimable allocations would cause permanent + * fragmentations if they fell back to allocating from a movable block + * (polluting it), so we try to claim the whole block regardless of the + * allocation size. Later movable allocations can always steal from this + * block, which is less problematic. + */ + if (start_mt =3D=3D MIGRATE_RECLAIMABLE || start_mt =3D=3D MIGRATE_UNMOVA= BLE) + return true; + + if (page_group_by_mobility_disabled) + return true; + + /* + * Movable pages won't cause permanent fragmentation, so when you alloc + * small pages, we just need to temporarily steal unmovable or + * reclaimable pages that are closest to the request size. After a + * while, memory compaction may occur to form large contiguous pages, + * and the next movable allocation may not need to steal. + */ return false; } =20 --=20 2.48.1.711.g2feabab25a-goog