From patchwork Wed Dec 6 11:00:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Barry Song <21cnbao@gmail.com> X-Patchwork-Id: 13481534 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 711B1C4167B for ; Wed, 6 Dec 2023 11:01:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0FFB36B007D; Wed, 6 Dec 2023 06:01:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 061F26B00B2; Wed, 6 Dec 2023 06:01:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E92836B00B3; Wed, 6 Dec 2023 06:01:18 -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 D9E9F6B00B0 for ; Wed, 6 Dec 2023 06:01:18 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 9AD12A019D for ; Wed, 6 Dec 2023 11:01:18 +0000 (UTC) X-FDA: 81536101836.05.A467C5B Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) by imf16.hostedemail.com (Postfix) with ESMTP id 8D93A180012 for ; Wed, 6 Dec 2023 11:01:15 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=fxAOByiW; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf16.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.216.44 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1701860475; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=1tmT8glKoA1mZRisM7CPsvj8rp8Fj5zx5XkNMnqVUSc=; b=jkSjgci9tdJ/H82Dr0JdvwVEVrNEPuRtZ5ymT6KjExJHjt+qbTajd2gc2n5aegeH3e9aND xf0fI7IbHlWDZi6OYNNlyaWwTmB5VSQBjeoWKbmZk54OLI4eeMBC6yt5vjFJARLUcCGh+b O8w1LPvvmceeo3qgXXYu7bQyrbHBapM= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=fxAOByiW; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf16.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.216.44 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701860475; a=rsa-sha256; cv=none; b=C9FXWo9v/zgneCntImUQmISAiE8EPVzpjuohveJ7G+v++a1H4GBQZ9ztFbb+yqaW+AHtRj TsE2JD/dkJzV8b6V7mJFlps5h8lpWTcg9JE7gKt1xrKTbss8R3KIm0efxEtl1cYUnuwu+7 UoTSyiLAp1Zi+YTJsutDTTIens9vlOQ= Received: by mail-pj1-f44.google.com with SMTP id 98e67ed59e1d1-286fb44eb16so753885a91.3 for ; Wed, 06 Dec 2023 03:01:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701860474; x=1702465274; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=1tmT8glKoA1mZRisM7CPsvj8rp8Fj5zx5XkNMnqVUSc=; b=fxAOByiWwitbYa0wd1v+qQEW7hl3HF2QEEOJd7vevlM/jf9D/xWOjDKQGC18yPmPJ1 NjIXdg5HI0Q02JDoDNm4eTvEmZGIC7lVGDfsmWO2yCP1KiDhJ3NbaZXnlsgP1icCezbw 2land/DiREoVJDCW9iwjh+JqXeneyLD5Rm5/x1TZqKRhPNM+WYaaFqyiwBV6dYOP05+m 4FG2Jbjmg/tDP9Nwk+BOsgM1rF8C+gQOhGz0wV7qn8y/+CJduQ0OA7J7l4KvijpMObeE rmED0hMoM03IV2cR88hIf7dAuzSBruKcQxzHsjn+CZ5wQsqm7oaZTG+B13STMGJPkRF6 DiWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701860474; x=1702465274; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=1tmT8glKoA1mZRisM7CPsvj8rp8Fj5zx5XkNMnqVUSc=; b=bdoLaHKRcsfLT5dpw8lA7cp9qaE4JbgthqF9B9BCVxoppg9iuYBTrwLMI5Pr5YonEq 4CY1yFPV6UN2Yd/vUYr33vFAw5nZjX4ebZAjd1YroNreCv2e2rTck6mF7QZJ0LUTOzvi ErAZIwN3WaJjgIU7x0bqVaGRCR+YlEmDwuNX5WpCu6PFfKWwifH+rj+vp0SWFZh5M0TO UX+s14I/HrSlf4wmE+oxySUn1tI2r/qn7qET1Tk51kbEqse2XUN2T+KyAaKAMysorBdq EiwP28D/QzOZXUKRx+wFsDWtoDA+OMcvBPyv7yyjwCR4zYwRYGF2g+MjYKC0VvpDvr8Q Xqow== X-Gm-Message-State: AOJu0Yybp81f2ZYE/Zubn8oq+Z1v7U724T09NzRAZAvE1Br5T3Wu9fxn MinICjqS3F5wB+s11UfV5vc= X-Google-Smtp-Source: AGHT+IHx7ucyQlMtsTNmJN9r41T5q107P/StLlN5xh8J201NqlkG/DiIJrTjHmbSAtKaWa/izz8gaA== X-Received: by 2002:a17:90a:e7c2:b0:286:e2bb:26a4 with SMTP id kb2-20020a17090ae7c200b00286e2bb26a4mr426280pjb.40.1701860474132; Wed, 06 Dec 2023 03:01:14 -0800 (PST) Received: from barry-desktop.hub ([2407:7000:8942:5500:c02a:270e:39c4:ae78]) by smtp.gmail.com with ESMTPSA id r17-20020a17090a941100b00263f41a655esm10890158pjo.43.2023.12.06.03.01.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 03:01:13 -0800 (PST) From: Barry Song <21cnbao@gmail.com> X-Google-Original-From: Barry Song To: akpm@linux-foundation.org, baolin.wang@linux.alibaba.com, linux-mm@kvack.org Cc: david@redhat.com, hannes@cmpxchg.org, huzhanyuan@oppo.com, linux-kernel@vger.kernel.org, mgorman@techsingularity.net, shikemeng@huaweicloud.com, v-songbaohua@oppo.com, willy@infradead.org Subject: [PATCH] mm: compaction: avoid fast_isolate_freepages blindly choose improper pageblock Date: Thu, 7 Dec 2023 00:00:54 +1300 Message-Id: <20231206110054.61617-1-v-songbaohua@oppo.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: 5t6gqpij133gqn83k6ohspcnys3fgxct X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 8D93A180012 X-HE-Tag: 1701860475-225845 X-HE-Meta: U2FsdGVkX1+ho4EovPCnjmmoXybq7dLwoOsl8uSP3ViXpiHuwq8RXEysLQi66ZBOw+U+LC9ksZMbyVGtQ//C1Iu+2CI1yGLJUM6Mvp/CUYj1Oa8YRVGytBYQNNdnV6kr2ij6drgA3JjbO2ySdctMXlGhqqpy8lCrZz8KuMM/lt7UPZhvjqgJcksV0PWiEgq7JL/xDR/1kBQwPjP+FJHE5miEUTgTNCpSalQtPWPNXoas3VetIeqpSKmVCDMHy5Ndj1m5FZSSLGA+AIi3j8ESzpasziXIQlwHXxdN5fuPmXXSJOygZ6CBmtqen7hwInWBXijOIQpCGXszOhpShiRNsWlOyAhfAY7n/70Nde8zwkAobP5qJplGyHsBoi0SNVXKbnrOMY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v9yV/WlngLkTrJSp0L+IgINv0Wi5b0c9e7zbsQDRwew6+C+TjgwaiyOu3dnK2gMmcOA1IUJZNqzkomOwjeNfeyJQcITXYUoLV0Mx/PR+b/etnMPgN7K6w== 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: Testing shows fast_isolate_freepages can blindly choose an unsuitable pageblock from time to time particularly while the min mark is used from XXX path: if (!page) { cc->fast_search_fail++; if (scan_start) { /* * Use the highest PFN found above min. If one was * not found, be pessimistic for direct compaction * and use the min mark. */ if (highest >= min_pfn) { page = pfn_to_page(highest); cc->free_pfn = highest; } else { if (cc->direct_compaction && pfn_valid(min_pfn)) { /* XXX */ page = pageblock_pfn_to_page(min_pfn, min(pageblock_end_pfn(min_pfn), zone_end_pfn(cc->zone)), cc->zone); cc->free_pfn = min_pfn; } } } } The reason is that no code is doing any check on the min_pfn min_pfn = pageblock_start_pfn(cc->free_pfn - (distance >> 1)); In contrast, slow path of isolate_freepages() is always skipping unsuitable pageblocks in a decent way. This issue doesn't happen quite often. When running 25 machines with 16GiB memory for one night, most of them can hit this unexpected code path. However the frequency isn't like many times per second. It might be one time in a couple of hours. Thus, it is very hard to measure the visible performance impact in my machines though the affection of choosing the unsuitable migration_target should be negative in theory. I feel it's still worth fixing this to at least make the code theoretically self-explanatory as it is quite odd an unsuitable migration_target can be still migration_target. Reported-by: Zhanyuan Hu Signed-off-by: Barry Song Reviewed-by: Baolin Wang Acked-by: Mel Gorman --- v1: move the fix to the specific min_pfn path with respect to Baolin's comment rfc: https://lore.kernel.org/linux-mm/20231129104530.63787-1-v-songbaohua@oppo.com/#t mm/compaction.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/compaction.c b/mm/compaction.c index 01ba298739dd..de15a2ef0af5 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -1611,6 +1611,9 @@ static void fast_isolate_freepages(struct compact_control *cc) min(pageblock_end_pfn(min_pfn), zone_end_pfn(cc->zone)), cc->zone); + if (page && !suitable_migration_target(cc, page)) + page = NULL; + cc->free_pfn = min_pfn; } }