Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2122453pxa; Mon, 24 Aug 2020 05:59:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx0+C+Q+2zkoNuehiNgTKqyTbWEZx1u0idH47zpA11RMkeidLmpOHw2J2OpBuKBhf+AQjFD X-Received: by 2002:a17:906:e17:: with SMTP id l23mr5257385eji.13.1598273993890; Mon, 24 Aug 2020 05:59:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598273993; cv=none; d=google.com; s=arc-20160816; b=k1NUWtieEIvDAndUsUCjVMlGAtnpbOfptWZIpLOzPm75f+nFogt3DQ6ZkqEAa5XzLO 8HVp2h94yiSGDSZUYc5cShUvic5tU5MyZDeQQ/nHCMwAeQ+W07V1Npg4twBFdkdR/6oh bNLhO+JM2qGmm1SW/rKuS2w83E3V5BcP1lhqu63/VHKdaLf6iqd6WZ3ZKumcxxj8KVa6 qRNrrI0LPcoBVyWAJSl3SZGZD64wB+YaaRNCmbxTJk6nFAwTF0IXkF5+0P/JRS7eonDL vSRI+hRceEvxAqfE7wbVq0d6nflYjo2g4x3jJIIQNICTsa8gfzGjNthpk6TzlMOL9uSp cOPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=HPZ+2rV2xGsJkDjg0A8ZYXsKU/LeVS0+ZucPi8qHZMs=; b=EyxIiJjSAi+CA215i6JbL1O4VNnzU13AEdQl2VLnzLnP6n8Ncun5AMwoaJ6ZWYcXN3 uqEhv2U6PF9yYCoXs0Y8fI1RUCL0hjba20IDS1PbsctN5Jp7YZpDnPHEeymbbZPIEr4C +b0nRv6PlK8+teB17Rx7mb67redl9X+gX58F0sxeh4+V2WZetY3MlUgtz9DWPMhcd5zS EuJDkJVuCNABw7FCBtC+VGMId+/U+ITxTU+awNKBQ4R54m2ZK5jE8vgVjVp84HC1dKjU lxu662QaJvy74ZEQs0QXpXFgkWBmccOtFxlYlID3TrqIsZjr3u1kKK+VifPwdBAySEoJ rznw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z1si5359578ejd.673.2020.08.24.05.59.30; Mon, 24 Aug 2020 05:59:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1728014AbgHXM4p (ORCPT + 99 others); Mon, 24 Aug 2020 08:56:45 -0400 Received: from out30-42.freemail.mail.aliyun.com ([115.124.30.42]:43108 "EHLO out30-42.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727851AbgHXMze (ORCPT ); Mon, 24 Aug 2020 08:55:34 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R691e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01f04397;MF=alex.shi@linux.alibaba.com;NM=1;PH=DS;RN=23;SR=0;TI=SMTPD_---0U6k9-bl_1598273712; Received: from aliy80.localdomain(mailfrom:alex.shi@linux.alibaba.com fp:SMTPD_---0U6k9-bl_1598273712) by smtp.aliyun-inc.com(127.0.0.1); Mon, 24 Aug 2020 20:55:23 +0800 From: Alex Shi To: akpm@linux-foundation.org, mgorman@techsingularity.net, tj@kernel.org, hughd@google.com, khlebnikov@yandex-team.ru, daniel.m.jordan@oracle.com, willy@infradead.org, hannes@cmpxchg.org, lkp@intel.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, shakeelb@google.com, iamjoonsoo.kim@lge.com, richard.weiyang@gmail.com, kirill@shutemov.name, alexander.duyck@gmail.com, rong.a.chen@intel.com, mhocko@suse.com, vdavydov.dev@gmail.com, shy828301@gmail.com Cc: Alexander Duyck , Stephen Rothwell Subject: [PATCH v18 29/32] mm: Identify compound pages sooner in isolate_migratepages_block Date: Mon, 24 Aug 2020 20:55:02 +0800 Message-Id: <1598273705-69124-30-git-send-email-alex.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1598273705-69124-1-git-send-email-alex.shi@linux.alibaba.com> References: <1598273705-69124-1-git-send-email-alex.shi@linux.alibaba.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alexander Duyck Since we are holding a reference to the page much sooner in isolate_migratepages_block we can move the PageCompound check out of the LRU locked section and instead just place it after get_page_unless_zero. By doing this we can allow any of the items that might trigger a failure to trigger a failure for the compound page rather than the order 0 page and as a result we should be able to process the pageblock faster. In addition by testing for PageCompound sooner we can avoid having the LRU flag cleared and then reset in the exception case. As a result this should prevent possible races where another thread might be attempting to pull the LRU pages from the list. Signed-off-by: Alexander Duyck Signed-off-by: Alex Shi Cc: Andrew Morton Cc: Stephen Rothwell Cc: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org --- mm/compaction.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index 6bf5ccd8fcf6..a0e48d079124 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -984,6 +984,24 @@ static bool too_many_isolated(pg_data_t *pgdat) if (unlikely(!get_page_unless_zero(page))) goto isolate_fail; + /* + * Page is compound. We know the order before we know if it is + * on the LRU so we cannot assume it is THP. However since the + * page will have the LRU validated shortly we can use the value + * to skip over this page for now or validate the LRU is set and + * then isolate the entire compound page if we are isolating to + * generate a CMA page. + */ + if (PageCompound(page)) { + const unsigned int order = compound_order(page); + + if (likely(order < MAX_ORDER)) + low_pfn += (1UL << order) - 1; + + if (!cc->alloc_contig) + goto isolate_fail_put; + } + if (__isolate_lru_page_prepare(page, isolate_mode) != 0) goto isolate_fail_put; @@ -1009,23 +1027,8 @@ static bool too_many_isolated(pg_data_t *pgdat) if (test_and_set_skip(cc, page, low_pfn)) goto isolate_abort; } - - /* - * Page become compound since the non-locked check, - * and it's on LRU. It can only be a THP so the order - * is safe to read and it's 0 for tail pages. - */ - if (unlikely(PageCompound(page) && !cc->alloc_contig)) { - low_pfn += compound_nr(page) - 1; - SetPageLRU(page); - goto isolate_fail_put; - } } - /* The whole page is taken off the LRU; skip the tail pages. */ - if (PageCompound(page)) - low_pfn += compound_nr(page) - 1; - /* Successfully isolated */ del_page_from_lru_list(page, lruvec, page_lru(page)); mod_node_page_state(page_pgdat(page), -- 1.8.3.1