From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.5 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 32650C00A89 for ; Fri, 30 Oct 2020 14:50:09 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8058622227 for ; Fri, 30 Oct 2020 14:50:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8058622227 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id EA0E16B0062; Fri, 30 Oct 2020 10:50:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E50376B006E; Fri, 30 Oct 2020 10:50:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D18FD6B007B; Fri, 30 Oct 2020 10:50:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0153.hostedemail.com [216.40.44.153]) by kanga.kvack.org (Postfix) with ESMTP id A3AEA6B0062 for ; Fri, 30 Oct 2020 10:50:07 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 3BC9A1EE6 for ; Fri, 30 Oct 2020 14:50:07 +0000 (UTC) X-FDA: 77428876854.25.mint18_5f1276927296 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin25.hostedemail.com (Postfix) with ESMTP id 1A6A01804E3A9 for ; Fri, 30 Oct 2020 14:50:07 +0000 (UTC) X-HE-Tag: mint18_5f1276927296 X-Filterd-Recvd-Size: 3811 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf34.hostedemail.com (Postfix) with ESMTP for ; Fri, 30 Oct 2020 14:50:06 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 52D8FAF55; Fri, 30 Oct 2020 14:50:05 +0000 (UTC) Subject: Re: [PATCH] mm/compaction: count pages and stop correctly during page isolation. To: Zi Yan , Andrew Morton , linux-mm@kvack.org Cc: Rik van Riel , linux-kernel@vger.kernel.org References: <20201029200435.3386066-1-zi.yan@sent.com> From: Vlastimil Babka Message-ID: <16bdfad8-05f9-6ecf-0db6-c2dcf8e60309@suse.cz> Date: Fri, 30 Oct 2020 15:50:04 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.3.3 MIME-Version: 1.0 In-Reply-To: <20201029200435.3386066-1-zi.yan@sent.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit 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: On 10/29/20 9:04 PM, Zi Yan wrote: > From: Zi Yan > > In isolate_migratepages_block, when cc->alloc_contig is true, we are > able to isolate compound pages, nr_migratepages and nr_isolated did not > count compound pages correctly, causing us to isolate more pages than we > thought. Use thp_nr_pages to count pages. Otherwise, we might be trapped > in too_many_isolated while loop, since the actual isolated pages can go > up to COMPACT_CLUSTER_MAX*512=16384, where COMPACT_CLUSTER_MAX is 32, > since we stop isolation after cc->nr_migratepages reaches to > COMPACT_CLUSTER_MAX. I wonder if a better fix would be to adjust the too_many_isolated() check so that if we have non-zero cc->nr_migratepages, we bail out from further isolation and migrate what we have immediately, instead of looping. Because I can also imagine a hypothetical situation where multiple threads in parallel cause too_many_isolated() to be true, and will all loop there forever. The proposed fix should prevent such situation as well, AFAICT. > In addition, after we fix the issue above, cc->nr_migratepages could > never be equal to COMPACT_CLUSTER_MAX if compound pages are isolated, > thus page isolation could not stop as we intended. Change the isolation > stop condition to >=. > > Signed-off-by: Zi Yan > --- > mm/compaction.c | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/mm/compaction.c b/mm/compaction.c > index ee1f8439369e..0683a4999581 100644 > --- a/mm/compaction.c > +++ b/mm/compaction.c > @@ -1012,8 +1012,8 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, > > isolate_success: > list_add(&page->lru, &cc->migratepages); > - cc->nr_migratepages++; > - nr_isolated++; > + cc->nr_migratepages += thp_nr_pages(page); > + nr_isolated += thp_nr_pages(page); > > /* > * Avoid isolating too much unless this block is being > @@ -1021,7 +1021,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, > * or a lock is contended. For contention, isolate quickly to > * potentially remove one source of contention. > */ > - if (cc->nr_migratepages == COMPACT_CLUSTER_MAX && > + if (cc->nr_migratepages >= COMPACT_CLUSTER_MAX && > !cc->rescan && !cc->contended) { > ++low_pfn; > break; > @@ -1132,7 +1132,7 @@ isolate_migratepages_range(struct compact_control *cc, unsigned long start_pfn, > if (!pfn) > break; > > - if (cc->nr_migratepages == COMPACT_CLUSTER_MAX) > + if (cc->nr_migratepages >= COMPACT_CLUSTER_MAX) > break; > } > >