From patchwork Mon Feb 24 12:37:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brendan Jackman X-Patchwork-Id: 13987984 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 7DCBFC021A6 for ; Mon, 24 Feb 2025 12:37:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 146F16B0092; Mon, 24 Feb 2025 07:37:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0D021280001; Mon, 24 Feb 2025 07:37:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EB0346B0095; Mon, 24 Feb 2025 07:37:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id C5EFD6B0092 for ; Mon, 24 Feb 2025 07:37:42 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 721901412E7 for ; Mon, 24 Feb 2025 12:37:42 +0000 (UTC) X-FDA: 83154789564.22.934FB3E Received: from mail-wr1-f73.google.com (mail-wr1-f73.google.com [209.85.221.73]) by imf25.hostedemail.com (Postfix) with ESMTP id 9A589A0012 for ; Mon, 24 Feb 2025 12:37:40 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="lNpb/f7i"; spf=pass (imf25.hostedemail.com: domain of 3E2i8ZwgKCBo902AC0D16EE6B4.2ECB8DKN-CCAL02A.EH6@flex--jackmanb.bounces.google.com designates 209.85.221.73 as permitted sender) smtp.mailfrom=3E2i8ZwgKCBo902AC0D16EE6B4.2ECB8DKN-CCAL02A.EH6@flex--jackmanb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1740400660; 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=9H3uAh8z39ZL705dy+lsEsP19JzvEAhzwdccc5XF6GE=; b=iKfdMYgwLrERaxMV+RWJ03txOGZxKtc3EcEQf67kxbYCQIFkLoYIsCGwz9OlNF8FfrcHfZ fOXbsyumCnlYVVbZf8pcfnZgIsZO3ylGCuKrXE9iSxA5NHYhlN+OTQQljfXPwoYse6+G9E moTyZVz1HLHbY/pK0hxn0zIvReIkxOc= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="lNpb/f7i"; spf=pass (imf25.hostedemail.com: domain of 3E2i8ZwgKCBo902AC0D16EE6B4.2ECB8DKN-CCAL02A.EH6@flex--jackmanb.bounces.google.com designates 209.85.221.73 as permitted sender) smtp.mailfrom=3E2i8ZwgKCBo902AC0D16EE6B4.2ECB8DKN-CCAL02A.EH6@flex--jackmanb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1740400660; a=rsa-sha256; cv=none; b=XUcBvgBnU+cmwt6LenxeS7ZYzpYHFwGfZjqDAI95Kw6+lNbO5CYrH9nuc/AE7tI+lMkEd6 E6J5p5q1japP95enxSedV68p00Za9Pe+7Kzrsgkk8ip2epjtP4M5yJIVP8xM07xIki39/c 2l/a4xnrH85sZiwJOsI0lbaRZF5adeY= Received: by mail-wr1-f73.google.com with SMTP id ffacd0b85a97d-38f2726c0faso3935935f8f.0 for ; Mon, 24 Feb 2025 04:37:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1740400659; x=1741005459; 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=9H3uAh8z39ZL705dy+lsEsP19JzvEAhzwdccc5XF6GE=; b=lNpb/f7i/Tdq5Cq+jVYhckLH70dHK9kp+0R85Ov5JABLVHxpZND6CbKX0V7fSAQc5w JQy/dhUnTjkLZRQl1f21efCFFoeHptnDqdRKFdNCR7lkc6smQzhyw6yJdFWdlitHs3i0 lI6NQbvOu/u96VFqYdGTwtpxm0YTXnPhCu1j0l8hKJ6YoCnOfVo7HeE+nM2rtBwhiyem YDC5kauSeRnd2Pc5PN1zPhfhuLYf6cgiunzxI3mO2s8WSAiseT0vwBn+XLYyT7z1wwvx 1loeLNttNVyqgIFd99m1ButYUb1Hxm63RnJtdXUkp5ven/GHMgBrU57kZNlMW/dLS/K8 Hknw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740400659; x=1741005459; 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=9H3uAh8z39ZL705dy+lsEsP19JzvEAhzwdccc5XF6GE=; b=pKfx0rkWLu2aIX7HxnN/5TGdP0V9nPp3gNLF2F0B/flEFO+bseEBGKCkQY/5z4VxW3 chX2E+nzUTCjuSekAa9li3+gm0cVT+jDr3qJ3gmKB4R1lH7DxOq+xHk18QOBv3Cg+JZq zmkuwPWJ3EnbHPDgH2m/ScIXeaIteMEUWByUJmuGJNubZ3QOQc+PVSNkqYX/+E8Otq5/ 94PH0gH+oHCKnw0CBppV/OdpTnzAiAgRQNCYS1IZWbSd/SdHdtEDplY/oN1CGmtgGTpu DcfYAkTr57Oop/WT23LQGixgwx+eqiFRG7IPtY5AxoDPYAZO0ukyM5YrwCqGPB5UAoY2 se0A== X-Forwarded-Encrypted: i=1; AJvYcCVRNWaqVmA5i6DPWdNaVEJW9MzremRlfxdldIIp7j9evSqdyxx/riqY9+jdIbwO5/5WcrrytQ9Dow==@kvack.org X-Gm-Message-State: AOJu0YxPwsttdTGX0tE+ZDrA05qaWun3ebtkDDnJGk3y+Bb9N2wFU2v4 TTKEcqg31W/1oUZ0M+pCXagZf48D+P8k/PQ2Pg+kEU3TTaLU8EwzuoXCx8dlP76Wxd1yG3ATAEG dleN8NDsk2g== X-Google-Smtp-Source: AGHT+IG06C12mCh6DOgP0VK1wSYmbo1aaL50c6VFj4ZklSRSFPy/ILkeB2EyUg8/wsegGye3DKVKomcDzBRQ8g== X-Received: from wmsp10.prod.google.com ([2002:a05:600c:1d8a:b0:439:8664:577a]) (user=jackmanb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6000:4006:b0:38f:2856:7dc2 with SMTP id ffacd0b85a97d-38f6e95d596mr12371877f8f.18.1740400659184; Mon, 24 Feb 2025 04:37:39 -0800 (PST) Date: Mon, 24 Feb 2025 12:37:29 +0000 In-Reply-To: <20250224-clarify-steal-v2-0-be24da656764@google.com> Mime-Version: 1.0 References: <20250224-clarify-steal-v2-0-be24da656764@google.com> X-Mailer: b4 0.15-dev Message-ID: <20250224-clarify-steal-v2-2-be24da656764@google.com> Subject: [PATCH v2 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-Server: rspam08 X-Rspamd-Queue-Id: 9A589A0012 X-Stat-Signature: i6cyqjphefstntbh37twzn3ant3w5ekm X-HE-Tag: 1740400660-698548 X-HE-Meta: U2FsdGVkX18tVJ8p+Jaje8H6fwkdb11KbLN5VPBceCDP+mA9NwMzmEzuetQNYkTQM9wrkLYoJwHHxhL6EgTX+eIhfHjEc1WkDymhRqsyDV7dqvx4Vu2y05qyvZQEZ0t2rZxwh3LdvoXbSreCL7fLY1LUni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7xC5Etk82fokTzHhDV1ylTkCh/1b54SsxSQkA5zjR+QSTUHzL/mn/SfHemVVrq5nzHdxSX7qrpDWixA3TD4pO3cJU7AYGQZ8API02oe4i7OwYQuNiM4TwLRuxSXg9PobqDu0T7n6/lZHrMW9xnSWYnyvaRc4PKhowXyP8UsPDo2pr96XFF6YWjXaNSLCgy5W6U3R8HFl08KEJEpJ6CflFD2tttTb4jwke5e3mwOUWwibL7bg5CxvnXKSsz8G5ocLXaAp2oHQQjzt2pVydi/D+XYbf13fND4YzrtCHU8PcoNiS/D7w4P9P9mcAoI7tsZtJf08ZEBRIkVUD9/5493jvauZk/DZ9SOH4Xk/VLxgQMnf4i 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 50d6c503474fa4c1d21b5bf5dbfd3eb0eef2c415..547cdba789d8f3f04c5aab04ba7e74cb54c1261b 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1826,16 +1826,9 @@ static void change_pageblock_range(struct page *pageblock_page, } /* - * 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) { @@ -1849,6 +1842,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 @@ -1857,12 +1870,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; }