Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp3824028ybl; Tue, 20 Aug 2019 02:51:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqyUzAC6qAcDJBpQ2BH7AgWpsyTUeRUQ0IoXtx9wAxNfQvg4f8K6SdoluofVhvdoQbLn8M3+ X-Received: by 2002:a17:902:9698:: with SMTP id n24mr28162055plp.14.1566294701328; Tue, 20 Aug 2019 02:51:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566294701; cv=none; d=google.com; s=arc-20160816; b=x9n8Til76C9fLz+/SCJIzxcYdcm8uiNJICPrxdpEdjNEcGDD4yCbl+8809cA6i9HgW hcl1m/oBtaLMu7JzzfGw9lo+GdqBLrtFvAxsnmSOX6Q3S+6u6kdUqQ9dcZkXDJQnFEKi j/DCX45BJZI2j2GJG5eO4fo2KvPiUaiz84o04HZ/7Nv3VnjqNiHdpMsCB2ADqlEwo1hH hS0vWwGMnnkZ/N2KrFEtjPqGYm4zv/AFV7/JOvYIQTc6NLKO0p3sIu8cF9IxVzxZjYuO m8QMdVgggK+7EXQH9BYXpl7kY0J9JsfrUOddIzn+pmIFEsxD4SZCIzeOIfi4IXxVjvkc IBig== 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=+hyp2OOaZWZ/IqeujBQ/Nb3sv2I8Qpj7EHCputn9B7A=; b=vTeaRkoCKpXnlAFsEs6oUI+Lb9VxsADVycB4e3zEsdDRshM4U8kYgNX2/zbo4nNcwB 8z6KReUbKUsw4HRliRN8tpFxQqXFPfbDcLnWBMd6EHR9UmmntCmkPqCS686Oa+vtGjHd AwMyydLH2XTHZLjYRKUSmfUijOU223IsWwmqqIgtUT5zX7IsDJHK6n9P3SVIZYVf+3F7 zXfNokyq5Z7vYBx4+cN9Dk7BOiGKdVegoepwI7i5y/f4t8hee+t8uRVCQT1gOBGrouEL b8XLSV3EtC9sFOIApMe1vFSLx59qUarMV8h6IqWjgiwjF25zEEYPNfxlIKgvI6kcUeYg 88AA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id b31si11999302pgb.128.2019.08.20.02.51.26; Tue, 20 Aug 2019 02:51:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1729739AbfHTJtp (ORCPT + 99 others); Tue, 20 Aug 2019 05:49:45 -0400 Received: from out30-45.freemail.mail.aliyun.com ([115.124.30.45]:59724 "EHLO out30-45.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728426AbfHTJtn (ORCPT ); Tue, 20 Aug 2019 05:49:43 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R151e4;CH=green;DM=||false|;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01f04446;MF=alex.shi@linux.alibaba.com;NM=1;PH=DS;RN=10;SR=0;TI=SMTPD_---0TZztT4P_1566294573; Received: from localhost(mailfrom:alex.shi@linux.alibaba.com fp:SMTPD_---0TZztT4P_1566294573) by smtp.aliyun-inc.com(127.0.0.1); Tue, 20 Aug 2019 17:49:34 +0800 From: Alex Shi To: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrew Morton , Mel Gorman , Tejun Heo Cc: Alex Shi , Vlastimil Babka , Qian Cai , Andrey Ryabinin Subject: [PATCH 04/14] lru/compaction: use per lruvec lock in isolate_migratepages_block Date: Tue, 20 Aug 2019 17:48:27 +0800 Message-Id: <1566294517-86418-5-git-send-email-alex.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1566294517-86418-1-git-send-email-alex.shi@linux.alibaba.com> References: <1566294517-86418-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 Using lruvec locking to replace pgdat lru_lock. and then unfold compact_unlock_should_abort() to fit the replacement. Signed-off-by: Alex Shi Cc: Mel Gorman Cc: Vlastimil Babka Cc: Qian Cai Cc: Andrey Ryabinin Cc: Andrew Morton Cc: Tejun Heo Cc: cgroups@vger.kernel.org Cc: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org --- mm/compaction.c | 48 ++++++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index 9a737f343183..8877f38410d8 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -785,7 +785,7 @@ static bool too_many_isolated(pg_data_t *pgdat) unsigned long nr_scanned = 0, nr_isolated = 0; struct lruvec *lruvec; unsigned long flags = 0; - bool locked = false; + struct lruvec *locked_lruvec = NULL; struct page *page = NULL, *valid_page = NULL; unsigned long start_pfn = low_pfn; bool skip_on_failure = false; @@ -845,11 +845,20 @@ static bool too_many_isolated(pg_data_t *pgdat) * contention, to give chance to IRQs. Abort completely if * a fatal signal is pending. */ - if (!(low_pfn % SWAP_CLUSTER_MAX) - && compact_unlock_should_abort(&pgdat->lruvec.lru_lock, - flags, &locked, cc)) { - low_pfn = 0; - goto fatal_pending; + if (!(low_pfn % SWAP_CLUSTER_MAX)) { + if (locked_lruvec) { + spin_unlock_irqrestore(&locked_lruvec->lru_lock, flags); + locked_lruvec = NULL; + } + + if (fatal_signal_pending(current)) { + cc->contended = true; + + low_pfn = 0; + goto fatal_pending; + } + + cond_resched(); } if (!pfn_valid_within(low_pfn)) @@ -918,10 +927,10 @@ static bool too_many_isolated(pg_data_t *pgdat) */ if (unlikely(__PageMovable(page)) && !PageIsolated(page)) { - if (locked) { - spin_unlock_irqrestore(&pgdat->lruvec.lru_lock, + if (locked_lruvec) { + spin_unlock_irqrestore(&locked_lruvec->lru_lock, flags); - locked = false; + locked_lruvec = NULL; } if (!isolate_movable_page(page, isolate_mode)) @@ -947,10 +956,14 @@ static bool too_many_isolated(pg_data_t *pgdat) if (!(cc->gfp_mask & __GFP_FS) && page_mapping(page)) goto isolate_fail; + lruvec = mem_cgroup_page_lruvec(page, pgdat); + /* If we already hold the lock, we can skip some rechecking */ - if (!locked) { - locked = compact_lock_irqsave(&pgdat->lruvec.lru_lock, - &flags, cc); + if (lruvec != locked_lruvec) { + if (compact_lock_irqsave(&lruvec->lru_lock, &flags, cc)) + locked_lruvec = lruvec; + + sync_lruvec_pgdat(lruvec, pgdat); /* Try get exclusive access under lock */ if (!skip_updated) { @@ -974,7 +987,6 @@ static bool too_many_isolated(pg_data_t *pgdat) } } - lruvec = mem_cgroup_page_lruvec(page, pgdat); /* Try isolate the page */ if (__isolate_lru_page(page, isolate_mode) != 0) @@ -1015,9 +1027,9 @@ static bool too_many_isolated(pg_data_t *pgdat) * page anyway. */ if (nr_isolated) { - if (locked) { - spin_unlock_irqrestore(&pgdat->lruvec.lru_lock, flags); - locked = false; + if (locked_lruvec) { + spin_unlock_irqrestore(&locked_lruvec->lru_lock, flags); + locked_lruvec = NULL; } putback_movable_pages(&cc->migratepages); cc->nr_migratepages = 0; @@ -1042,8 +1054,8 @@ static bool too_many_isolated(pg_data_t *pgdat) low_pfn = end_pfn; isolate_abort: - if (locked) - spin_unlock_irqrestore(&pgdat->lruvec.lru_lock, flags); + if (locked_lruvec) + spin_unlock_irqrestore(&locked_lruvec->lru_lock, flags); /* * Updated the cached scanner pfn once the pageblock has been scanned -- 1.8.3.1