From patchwork Tue Feb 25 15:29:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brendan Jackman X-Patchwork-Id: 13990123 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id EBE4CC021BB for ; Tue, 25 Feb 2025 15:30:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 67DE7280006; Tue, 25 Feb 2025 10:30:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 62B5B280003; Tue, 25 Feb 2025 10:30:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4F35D280006; Tue, 25 Feb 2025 10:30:03 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 315E4280003 for ; Tue, 25 Feb 2025 10:30:03 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 9232A1216B7 for ; Tue, 25 Feb 2025 15:30:02 +0000 (UTC) X-FDA: 83158852644.19.E9B2EE2 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) by imf15.hostedemail.com (Postfix) with ESMTP id ADDADA001F for ; Tue, 25 Feb 2025 15:30:00 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=mWnTjOCj; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf15.hostedemail.com: domain of 39-G9ZwgKCPYhYaikYlZemmejc.amkjglsv-kkitYai.mpe@flex--jackmanb.bounces.google.com designates 209.85.128.73 as permitted sender) smtp.mailfrom=39-G9ZwgKCPYhYaikYlZemmejc.amkjglsv-kkitYai.mpe@flex--jackmanb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1740497400; a=rsa-sha256; cv=none; b=OvfEceK/QKpvUOCs/ZWSh9q5kLhQ0Vw1ae0AJ46tm9T9tRKjsGBhJIHgVIU1eBpM+Lru8Y mnaacfHjRQMXQ2rkSsguK4C5PellC1OQn52c8IkoobuqAstkBgncY1ZuqZKY5600jejLQJ 20qBcuT8tW7HY+bGvqSKFxt0PAPzQsU= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=mWnTjOCj; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf15.hostedemail.com: domain of 39-G9ZwgKCPYhYaikYlZemmejc.amkjglsv-kkitYai.mpe@flex--jackmanb.bounces.google.com designates 209.85.128.73 as permitted sender) smtp.mailfrom=39-G9ZwgKCPYhYaikYlZemmejc.amkjglsv-kkitYai.mpe@flex--jackmanb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1740497400; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=NLwoRANke7kr877qFcAfj/lJYQPtzdEo7Afw90Odwbs=; b=PuMqoVSHciDb8IYUbAVr7PwXn5pyNm9E9vJZn/Od1Ex+n7af9hMrdP9SpcHeWUdAIxsxzh FmfL3oUMlb4BMqwdinVcC81RWMaKM0+87O10IjSbk/75LQ+8RRGoF5rsjcE7hA0hwfkotx Kvton3bW5xfyH/IpcqEqB6lb62wx/LA= Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-43995bff469so45977515e9.2 for ; Tue, 25 Feb 2025 07:30:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1740497399; x=1741102199; darn=kvack.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=NLwoRANke7kr877qFcAfj/lJYQPtzdEo7Afw90Odwbs=; b=mWnTjOCjopsm5TBqTFzE5yT6vU6/cBA9GZe7bZQhASv8AHxdExfMe6AaVveen/Ez8U IwR+R9pdY/ujOZpGTV77zncFGf4gB0Ptklsvsbp+VVmyuEHbIUGYckC/YHCgmFLmVjyy IAEGN8B16z+x1CyQXk30orvU9l1O9dNkukCU7mol+kaq6BZjFkIPPG3gyU/MFNb1sd6g Fo4HxBvg5M6h2WSe5r3d+qDVWfCAXvkXuyZuxYoihavILAmDQR1HcUpXo41vx2wY4v/+ 0vpkdI8f15/C3iqsG1klP/+ESnymDtMBSxH0812NKFrNX1vrHoIYt/dPb+rc7qeJl6sq 9uWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740497399; x=1741102199; 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=NLwoRANke7kr877qFcAfj/lJYQPtzdEo7Afw90Odwbs=; b=QOWSX0fRlGYeMYOrPbg4hFofD8iPLtB2hzdJfQ6hp1h1Ijye9UWihG4YcKIh5Mld3N xMDL3sHxgRmjIb1qostQmpUgyFSQUQCP39q9+klmn1t8aKc3vRoQ+Hwy6p06B2q5OO7d AdPoqgS6McnBZZJl2+KXBFtWuRkRmuZy5NjGpYj+kntvlsky3bBZ9qeTojRsT4kXxxjq FGSDWrXalvbr7CBBxTeNt2Kqk73vKbN+yfqhd0lNscRyW/kjqYIg6uLjZgU7oVEFFVXm guhB+/9R6lruKIxPjveMrMpjwZJQ/na+Tyx2ZxyzR3VoCjifx9a7ckcnNL4my5fcmzRI fFOQ== X-Forwarded-Encrypted: i=1; AJvYcCV5XQbHTbtnjQX4TjtRQZa6b8w6jamNMkkwjzQTLeYwiPCcBXTs4+YwqwXtzGe42MLhgfZiICLaPA==@kvack.org X-Gm-Message-State: AOJu0Yz7zwCJtJmeWbsnCi9lKzNtwScHHvdzg1U1m6uBoLrYtz7LVSXx NQs0XGFy6Qme8UF3DONH+J6sQWzvTWAbKCKxVOQ58VlGrtbD/XMPbntG7S+mZbD+fQzrvt6Qcjg 3yU85aJh8Dg== X-Google-Smtp-Source: AGHT+IGO83dLwzMAW2+OSLdDNKSAMPRJx7wbGvVzqnB7FL9rEUp8ltEN+IEPBCHAKKIyLKaCJmNhINOp203v6A== X-Received: from wmbed10.prod.google.com ([2002:a05:600c:614a:b0:439:985c:9199]) (user=jackmanb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:1910:b0:439:98f6:8bc8 with SMTP id 5b1f17b1804b1-439aebcf61dmr138093215e9.26.1740497399462; Tue, 25 Feb 2025 07:29:59 -0800 (PST) Date: Tue, 25 Feb 2025 15:29:49 +0000 In-Reply-To: <20250225-clarify-steal-v3-0-f2550ead0139@google.com> Mime-Version: 1.0 References: <20250225-clarify-steal-v3-0-f2550ead0139@google.com> X-Mailer: b4 0.15-dev Message-ID: <20250225-clarify-steal-v3-2-f2550ead0139@google.com> Subject: [PATCH v3 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 X-Rspam-User: X-Rspamd-Queue-Id: ADDADA001F X-Rspamd-Server: rspam12 X-Stat-Signature: cdt7i9k7izrd4ke3t1h7wnh1ifrsm39w X-HE-Tag: 1740497400-155485 X-HE-Meta: U2FsdGVkX1+VeMsBdMxK9lv5hcx9BP3/9rsy7WrLaLYundiYhpnREz+xTqBXA1niYr01AOOubEAfz0wDtkXQuZbsNnIshIJjvlfxezRRfGJYAC6h+v77AxijI8cIm8ORzbKcVDrK8itQ5aZYzpLQGwjXySTrqWBIzYbqURHtIsKXA9qs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50WSsYFxaNyY7Pj1pJcKrvvW0ZHNYvQQwiAhEChHa7nP92CxwLKS2aTAwskBn1DUJu9j3EdDcLslhW6xL34Oo+FxWA2cDUX0FqmaUEjYxIpnul6qyoprlE1kc+A3BJaetdLKhKvzXE+PO/vIDBAPGaLj24ok/4mln9E4uO+kwg1XAN6rOzSNzdhdmzuV8PFH3+4nbf/wkixSTgoAqimiXpkmxioF8Liysx6UgDVpmg9Yi54M3Gz+KVptAS3UANm8P6PudE6NXVxLd83xRCl3rq4QVT6bOCQwnoxAt99vhYzUi/MMNw+AxW7u7HnbmjqerrRkDiKRNiYyd902sB81R X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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_groupy_by_mobility_disabled logic is not explained in the commentary, that is outside the scope of this patch... Signed-off-by: Brendan Jackman --- mm/page_alloc.c | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 5e694046ef92965b34d4831e96d92f02681a8b45..475ec1284033acec69da4a39dd4e7d7fbaee6d0f 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1941,16 +1941,9 @@ static inline bool boost_watermark(struct zone *zone) } /* - * 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 will be - * more free pages in the pageblock, so try to claim the whole block. For - * reclaimable and unmovable allocations, we 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, should we + * try to claim an entire block to satisfy further allocations, instead of + * polluting multiple pageblocks? */ static bool should_claim_block(unsigned int order, int start_mt) { @@ -1964,6 +1957,26 @@ static bool should_claim_block(unsigned int order, int start_mt) if (order >= pageblock_order) return true; + /* + * Above a certain threshold, always try to claim, as it's likely there + * will be more free pages in the pageblock. + */ + if (order >= pageblock_order / 2) + return true; + + /* + * 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 == MIGRATE_RECLAIMABLE || start_mt == MIGRATE_UNMOVABLE) + return true; + + if (page_group_by_mobility_disabled) + return true; + /* * Movable pages won't cause permanent fragmentation, so when you alloc * small pages, you just need to temporarily steal unmovable or @@ -1972,12 +1985,6 @@ static bool should_claim_block(unsigned int order, int start_mt) * and the next movable allocation may not need to steal. Unmovable and * reclaimable allocations need to actually claim the whole block. */ - if (order >= pageblock_order / 2 || - start_mt == MIGRATE_RECLAIMABLE || - start_mt == MIGRATE_UNMOVABLE || - page_group_by_mobility_disabled) - return true; - return false; }