Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp5574776rwb; Tue, 1 Aug 2023 05:03:57 -0700 (PDT) X-Google-Smtp-Source: APBJJlHsvKRaxKz72OL5vKWK0qPsrKU57C+hzZXImaJNt3c6zSGnLJp1Bq327V6sVx+Fm6W+15NP X-Received: by 2002:a05:6a21:7189:b0:115:5ed5:34d3 with SMTP id wq9-20020a056a21718900b001155ed534d3mr9592310pzb.20.1690891437148; Tue, 01 Aug 2023 05:03:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690891437; cv=none; d=google.com; s=arc-20160816; b=QW8t8U0OXvvd/QX1/I1aMgV0OIKJK/CbBums3cNGrY8JVW96iyyzltFHXltsA2Us7t uQzwTqHf2OZb2bpk36gMUKZRQrBlcDc0/Fta4eL93maakW9+XERyJ9eK5xo4qiK3z7Kc ujcM/zDyL0ibhBnYIzSgw+uYh569liUez+JTBZOZvqVFa0qvfSuLt4jjaa87oslr1IFa cKFOnrHnZ6JBviKMbh5vfL7N7CEBS+1h3WnRVRUyEwYlne8BFQISEVdRWu+Bb7cOkpnr upnUiINaL8yUgcZRm83ij+KRz+7KJRMimBiAFchhLkWSsMakzfH4YH3H6CqmYnwcoxQM j+6A== 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=H6JMYGd/wqte3oNek4mbRTEzIawGdT/9O8/XXt9uW3w=; fh=0Wbr7uULYy2bTeg6NYUaVd7dfyD9piG34HCUYzlSs60=; b=VvNaHQC9bms67G3S2ck6RZvqqqaWAel8zllMgc4AQ8MkUNq8bfEsV/2c/v6dfkHkGp kp2CSlh3GPFMemoPCHNwhRlyJtVBIWmo5Eh+TU7ol0Np5xyCuyOcYZ3+gjlSxJUoKQ+c QnfRBe9DxTBO0F2ugnrl49X32jQUfcSeKV0s3YvQh5B1phpI70HbznOiWCtP/zz7zpxj Q4wA7xIXYBOxZjEhYgqYmGum0J5hHbDD0yHOeokT43nIvI77RpBBwJ2SA4lgQlPsZXid N4/jThH9rvT/PN3YwLu4/qOUTcZLDYhhWRTrBrsB0ajTxyN0mlco841t+qoJMfg49IL4 H22Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k198-20020a636fcf000000b0056457fb5761si2511145pgc.586.2023.08.01.05.03.44; Tue, 01 Aug 2023 05:03:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232733AbjHALJn (ORCPT + 99 others); Tue, 1 Aug 2023 07:09:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232571AbjHALJU (ORCPT ); Tue, 1 Aug 2023 07:09:20 -0400 Received: from out30-98.freemail.mail.aliyun.com (out30-98.freemail.mail.aliyun.com [115.124.30.98]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62C2949F6 for ; Tue, 1 Aug 2023 04:03:28 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R201e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046051;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0Vor2y66_1690887804; Received: from 30.97.48.66(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0Vor2y66_1690887804) by smtp.aliyun-inc.com; Tue, 01 Aug 2023 19:03:25 +0800 Message-ID: <8e445d60-e8b1-7172-4577-20e7f28d1e9d@linux.alibaba.com> Date: Tue, 1 Aug 2023 19:03:52 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH] mm: compaction: fix endless looping over same migrate block To: Johannes Weiner , Andrew Morton Cc: Vlastimil Babka , Mel Gorman , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20230731172450.1632195-1-hannes@cmpxchg.org> From: Baolin Wang In-Reply-To: <20230731172450.1632195-1-hannes@cmpxchg.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-10.0 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 8/1/2023 1:24 AM, Johannes Weiner wrote: > During stress testing, the following situation was observed: > > 70 root 39 19 0 0 0 R 100.0 0.0 959:29.92 khugepaged > 310936 root 20 0 84416 25620 512 R 99.7 1.5 642:37.22 hugealloc > > Tracing shows isolate_migratepages_block() endlessly looping over the > first block in the DMA zone: > > hugealloc-310936 [001] ..... 237297.415718: mm_compaction_finished: node=0 zone=DMA order=9 ret=no_suitable_page > hugealloc-310936 [001] ..... 237297.415718: mm_compaction_isolate_migratepages: range=(0x1 ~ 0x400) nr_scanned=513 nr_taken=0 > hugealloc-310936 [001] ..... 237297.415718: mm_compaction_finished: node=0 zone=DMA order=9 ret=no_suitable_page > hugealloc-310936 [001] ..... 237297.415718: mm_compaction_isolate_migratepages: range=(0x1 ~ 0x400) nr_scanned=513 nr_taken=0 > hugealloc-310936 [001] ..... 237297.415718: mm_compaction_finished: node=0 zone=DMA order=9 ret=no_suitable_page > hugealloc-310936 [001] ..... 237297.415718: mm_compaction_isolate_migratepages: range=(0x1 ~ 0x400) nr_scanned=513 nr_taken=0 > hugealloc-310936 [001] ..... 237297.415718: mm_compaction_finished: node=0 zone=DMA order=9 ret=no_suitable_page > hugealloc-310936 [001] ..... 237297.415718: mm_compaction_isolate_migratepages: range=(0x1 ~ 0x400) nr_scanned=513 nr_taken=0 > > The problem is that the functions tries to test and set the skip bit > once on the block, to avoid skipping on its own skip-set, using > pageblock_aligned() on the pfn as a test. But because this is the DMA > zone which starts at pfn 1, this is never true for the first block, > and the skip bit isn't set or tested at all. As a result, > fast_find_migrateblock() returns the same pageblock over and over. > > If the pfn isn't pageblock-aligned, also check if it's the start of > the zone to ensure test-and-set-exactly-once on unaligned ranges. > > Thanks to Vlastimil Babka for the help in debugging this. > > Fixes: 90ed667c03fe ("Revert "Revert "mm/compaction: fix set skip in fast_find_migrateblock""") > Signed-off-by: Johannes Weiner Reviewed-by: Baolin Wang > --- > mm/compaction.c | 8 +++++--- > 1 file changed, 5 insertions(+), 3 deletions(-) > > diff --git a/mm/compaction.c b/mm/compaction.c > index dbc9f86b1934..eacca2794e47 100644 > --- a/mm/compaction.c > +++ b/mm/compaction.c > @@ -912,11 +912,12 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, > > /* > * Check if the pageblock has already been marked skipped. > - * Only the aligned PFN is checked as the caller isolates > + * Only the first PFN is checked as the caller isolates > * COMPACT_CLUSTER_MAX at a time so the second call must > * not falsely conclude that the block should be skipped. > */ > - if (!valid_page && pageblock_aligned(low_pfn)) { > + if (!valid_page && (pageblock_aligned(low_pfn) || > + low_pfn == cc->zone->zone_start_pfn)) { > if (!isolation_suitable(cc, page)) { > low_pfn = end_pfn; > folio = NULL; > @@ -2002,7 +2003,8 @@ static isolate_migrate_t isolate_migratepages(struct compact_control *cc) > * before making it "skip" so other compaction instances do > * not scan the same block. > */ > - if (pageblock_aligned(low_pfn) && > + if ((pageblock_aligned(low_pfn) || > + low_pfn == cc->zone->zone_start_pfn) && > !fast_find_block && !isolation_suitable(cc, page)) > continue; >