Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp1373176rdb; Wed, 6 Dec 2023 17:51:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IEOhMFkACiKnRdznk+BqDSgGC+0ZETWFerzDL6JiJF8VhM71pSCEbO2w00bYIslt1aTd7om X-Received: by 2002:a17:902:8d87:b0:1d0:8be8:bb6f with SMTP id v7-20020a1709028d8700b001d08be8bb6fmr4900786plo.38.1701913860563; Wed, 06 Dec 2023 17:51:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701913860; cv=none; d=google.com; s=arc-20160816; b=I5e1Zh9Jiu8mIetG7b1dhyQDnR0CZAfapcKpyYsFBCwA5TifJdsVg7UV4cMMvVc2mk VhjejGFOHjRR2gMzTuTfIpo02ne42cZY6FMkBa3ITi1a3ibpackjNGb1A0tkVdJEeAW6 /UGRMzDp31sD520Klv+SFxDMi93y47Pjo3xaxTuJ+JHEZrpjbD1QJh5QIFNYAxKmqHkX 1JHGIbhrAcuocXHmgaTG2GEGCoGCV6FbQvEBOrG6U8Q1bBVpJVmy8BHgYP4chwv0YGe+ 2bAYp1kwSW7N2aJu18ISt3eneP2rupq4a/R2kxPEgSy275+5h5rGiMS59ou5qvrglKN8 CC+A== 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=cOXofNaYT7bCLIPf0IVxa+gen4k9vGpH66opZCquatc=; fh=QhxWEwtRJ95X+A3Os2gN8CmSRM58me25bcpOQXTR8Lk=; b=mYsqeBGHw+dkoEPGNH2We48H5dPWPQzWw+v+FYBjNxl2Xmu806kSYMSQ8UTfufYCw6 NH/GINJDYo8hJsG/iV89jWIjkoNCtvNjyzmX/y2wUfBOZa1RWkZhgm7Vzk0PXCycqnm8 Dn83Lmpiw0OnuTsmcaLtKIHjxwaraxwL/R+0K6syHiAcNtyaDXTQLl787P3sFOliK983 JcPc6MQc70AylB0s6iTfANRR3GqpJOEjK1TBtV46MSnsjWfX3szTGzMRZ3t4KvsIcqcf pycctF/QQGfOKczkgZQleVe0YspDzCdbBH4jSPLoinRcCK0Y5KW1Q9ioqAHiPSkwVuep 2FIA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id bj3-20020a056a02018300b005ac2af99d30si246122pgb.705.2023.12.06.17.51.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 17:51:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 139F48031D0E; Wed, 6 Dec 2023 17:50:58 -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 S1442998AbjLGBuY (ORCPT + 99 others); Wed, 6 Dec 2023 20:50:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1441937AbjLGBuX (ORCPT ); Wed, 6 Dec 2023 20:50:23 -0500 Received: from out30-132.freemail.mail.aliyun.com (out30-132.freemail.mail.aliyun.com [115.124.30.132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB06819E for ; Wed, 6 Dec 2023 17:50:28 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R121e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046056;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=11;SR=0;TI=SMTPD_---0VxztXU1_1701913824; Received: from 30.97.48.44(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0VxztXU1_1701913824) by smtp.aliyun-inc.com; Thu, 07 Dec 2023 09:50:25 +0800 Message-ID: <1ba8b967-8f35-4144-8b7c-836b288ca8d6@linux.alibaba.com> Date: Thu, 7 Dec 2023 09:50:43 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH] mm: compaction: avoid fast_isolate_freepages blindly choose improper pageblock To: Barry Song <21cnbao@gmail.com> Cc: akpm@linux-foundation.org, linux-mm@kvack.org, david@redhat.com, shikemeng@huaweicloud.com, willy@infradead.org, mgorman@techsingularity.net, hannes@cmpxchg.org, linux-kernel@vger.kernel.org, Barry Song , Zhanyuan Hu References: <20231129104530.63787-1-v-songbaohua@oppo.com> <079610c2-04ed-4495-8eb7-518b04f911f7@linux.alibaba.com> From: Baolin Wang In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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:50:58 -0800 (PST) On 12/6/2023 6:18 PM, Barry Song wrote: > On Wed, Dec 6, 2023 at 10:54 PM Baolin Wang > wrote: >> >> >> >> On 11/29/2023 6:45 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; >>> } >>> } >>> } >>> } >> >> Yes, the min_pfn can be an unsuitable migration target. But I think we >> can just add the suitable_migration_target() validation into 'min_pfn' >> case? Since other cases must be suitable target which found from >> MIGRATE_MOVABLE free list. Something like below: >> >> diff --git a/mm/compaction.c b/mm/compaction.c >> index 01ba298739dd..4e8eb4571909 100644 >> --- a/mm/compaction.c >> +++ b/mm/compaction.c >> @@ -1611,6 +1611,8 @@ static void fast_isolate_freepages(struct >> compact_control *cc) >> >> min(pageblock_end_pfn(min_pfn), >> >> zone_end_pfn(cc->zone)), >> cc->zone); >> + if >> (!suitable_migration_target(cc, page)) >> + page = NULL; >> cc->free_pfn = min_pfn; >> } >> } >> > > yes. this makes more senses. > >> By the way, I wonder if this patch can improve the efficiency of >> compaction in your test case? > > This happens not quite often. when running 25 machines for > one night, most of them can hit this unexpected code path. > but the frequency isn't many times in one second. it might > be one time in a couple of hours. > > so it is very difficult to measure the visible performance impact > in my machines though the affection of choosing the unsuitable > migration_target should be negative. OK. Fair enough. > > I feel like it's worth fixing this to at least make the code theoretically > self-explanatory? as it is quite odd unsuitable_migration_target can > be still migration_target? > >> >>> In contrast, slow path is skipping unsuitable pageblocks in a decent way. >>> >>> I don't know if it is an intended design or just an oversight. But >>> it seems more sensible to skip unsuitable pageblock. >>> >>> Reported-by: Zhanyuan Hu >>> Signed-off-by: Barry Song >>> --- >>> mm/compaction.c | 6 ++++++ >>> 1 file changed, 6 insertions(+) >>> >>> diff --git a/mm/compaction.c b/mm/compaction.c >>> index 01ba298739dd..98c485a25614 100644 >>> --- a/mm/compaction.c >>> +++ b/mm/compaction.c >>> @@ -1625,6 +1625,12 @@ static void fast_isolate_freepages(struct compact_control *cc) >>> cc->total_free_scanned += nr_scanned; >>> if (!page) >>> return; >>> + /* >>> + * Otherwise, we can blindly choose an improper pageblock especially >>> + * while using the min mark >>> + */ >>> + if (!suitable_migration_target(cc, page)) >>> + return; >>> >>> low_pfn = page_to_pfn(page); >>> fast_isolate_around(cc, low_pfn); > > Thanks > Barry