Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp1374842rdb; Wed, 6 Dec 2023 17:57:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IGmZNKM5EndnulAnTRco2PhWz7ypWs87iTo3ef9reljqBcxXatgI6ciKR8UvJ6RxRqN8CiN X-Received: by 2002:a17:90a:d347:b0:286:7c14:6d0a with SMTP id i7-20020a17090ad34700b002867c146d0amr4516937pjx.10.1701914223708; Wed, 06 Dec 2023 17:57:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701914223; cv=none; d=google.com; s=arc-20160816; b=JTWskysTluSmGnNL9f5KyWc4O/H/kqsHHGWPib2m1iUgO31nCEMvYVsClU2PsVOY+f KtHVX8Jqi2KfdpqWMJOZVgowWhGDNZjsXtyHqviUQeIwSUuZWDkFnZaJtbZFMKzC3mMW riWPokIq4rUgdgXq3T/XDUjkYVQ1qjXlr+vATBPVGJ3s7IZDWPJ6+r1VSG/SGYIDnUx1 CaxB/xDWzicaFBg2MXNxNB29FPq/6Jg06U1z+AryBo2FnCKdIJ87cPV6FS4wkqSG4fAl hwAwC75KzkNw4kQ2tIr9R2tpGoqFaK6uYPm51kKacSGnqTmkSL1a9yuormCX0aR3cOzQ TXLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:subject:user-agent:mime-version:date:message-id; bh=9jXoxeON9WAqdIteja77oHJj/32q89zIZccGXZEYypI=; fh=uHzj7AlmkI2bpIUN6lK4gBEVBQ+7KPpKIHptx1fCheM=; b=lS31Ad0NZqbHS0rGkz5e9sADQT9fkPvF63k/rMGtR63Iculkvcix7VtWwrEq/RB1qf dJ7+91jUPwhRZYjp5WBakJmlUB3KiJGFqWt1mIwHEIdOiLMCOmjcF53vggYSaNRuQpKM /bODf/+tEoCKCzYcRvSwNG/b2ciywUSsEIqJ2pkiFu8cTMfapNb+1sp5ui1YLH340wfW BsocbUXLf8G6gHlRiuXNehCfeczkpC7Hzy169hlpRut5z8atjEeQDUux1ImNAJPm0zls LmMIVHbr+gMnt/sqjd8IznAnc7KtIf5wFdHzcGfTuLCeOkvMFwzOiiCR7QZljxq2VWf0 cG1Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id my7-20020a17090b4c8700b002865290780csi154377pjb.26.2023.12.06.17.57.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 17:57:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 94EC080DD860; Wed, 6 Dec 2023 17:57:00 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230527AbjLGB4p (ORCPT + 99 others); Wed, 6 Dec 2023 20:56:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229582AbjLGB4n (ORCPT ); Wed, 6 Dec 2023 20:56:43 -0500 Received: from out30-97.freemail.mail.aliyun.com (out30-97.freemail.mail.aliyun.com [115.124.30.97]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D58E6B9 for ; Wed, 6 Dec 2023 17:56:49 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R531e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045176;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=11;SR=0;TI=SMTPD_---0VxzqEAE_1701914205; Received: from 30.97.48.44(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0VxzqEAE_1701914205) by smtp.aliyun-inc.com; Thu, 07 Dec 2023 09:56:46 +0800 Message-ID: <3d1ff4c8-5163-41fd-be12-34545c3556ec@linux.alibaba.com> Date: Thu, 7 Dec 2023 09:57:05 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] mm: compaction: avoid fast_isolate_freepages blindly choose improper pageblock To: Barry Song <21cnbao@gmail.com>, akpm@linux-foundation.org, 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 References: <20231206110054.61617-1-v-songbaohua@oppo.com> From: Baolin Wang In-Reply-To: <20231206110054.61617-1-v-songbaohua@oppo.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Wed, 06 Dec 2023 17:57:00 -0800 (PST) On 12/6/2023 7:00 PM, Barry Song wrote: > 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 LGTM. Thanks. Reviewed-by: Baolin Wang > --- > 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; > } > }