From patchwork Thu Aug 13 04:02:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Duyck X-Patchwork-Id: 11711651 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DCD82618 for ; Thu, 13 Aug 2020 04:02:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9B01520771 for ; Thu, 13 Aug 2020 04:02:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="p7aKYuuO" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9B01520771 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D7F508D0003; Thu, 13 Aug 2020 00:02:28 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D2DFE8D0001; Thu, 13 Aug 2020 00:02:28 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C1DF68D0003; Thu, 13 Aug 2020 00:02:28 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0121.hostedemail.com [216.40.44.121]) by kanga.kvack.org (Postfix) with ESMTP id A901F8D0001 for ; Thu, 13 Aug 2020 00:02:28 -0400 (EDT) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 69E4A5DCD for ; Thu, 13 Aug 2020 04:02:28 +0000 (UTC) X-FDA: 77144198376.14.sound09_5e0f2dd26ff1 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin14.hostedemail.com (Postfix) with ESMTP id 39D8318229818 for ; Thu, 13 Aug 2020 04:02:28 +0000 (UTC) X-Spam-Summary: 1,0,0,3d989c0059484599,d41d8cd98f00b204,alexander.duyck@gmail.com,,RULES_HIT:41:69:152:355:379:960:966:973:988:989:1260:1277:1311:1313:1314:1345:1359:1431:1437:1515:1516:1518:1535:1543:1593:1594:1711:1730:1747:1777:1792:2196:2199:2393:2559:2562:3138:3139:3140:3141:3142:3355:3865:3866:3868:3870:3871:3872:4118:4250:4321:4385:5007:6120:6261:6653:6742:7576:7903:8957:9413:9592:10004:10400:11026:11473:11658:11914:12043:12114:12291:12296:12297:12438:12517:12519:12555:12679:12683:12760:12986:13153:13228:13868:14096:14097:14181:14687:14721:21080:21444:21451:21611:21627:21666:21987:30054,0,RBL:209.85.222.195:@gmail.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100;04yf6ubrjrzztoi3h8cdi36cr899rypwhjqxncq8cgxfzky9w6xyo6znxfhbx46.aendubqkpcuh9c7rrndkwbsfx71xy3kkxtydwzbzi78ytexqnqr84dkmrbxrire.h-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:23,LUA_SUMMARY:n one X-HE-Tag: sound09_5e0f2dd26ff1 X-Filterd-Recvd-Size: 7369 Received: from mail-qk1-f195.google.com (mail-qk1-f195.google.com [209.85.222.195]) by imf41.hostedemail.com (Postfix) with ESMTP for ; Thu, 13 Aug 2020 04:02:27 +0000 (UTC) Received: by mail-qk1-f195.google.com with SMTP id 62so4151271qkj.7 for ; Wed, 12 Aug 2020 21:02:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=XtxT1MTxM5ARJ+08eWr2bJ37iwug5sulaz41RNmMU7k=; b=p7aKYuuOYtZex8EmSHqns2ZVG6wtpk4+BJY6vTjOWkw9WYj2eijkenTtU70ZLdXWyE GQrZFDJrpyqGeq6kIv3KfpWbtPJ0thdDxLNyrRk32/WBCYNISKcCW1gOEnlUnynVrMY2 unbACAKixzD21x1yKI8PZY26drlVM4slXcE4ZnTDk6FPDyy+BNskGWk2LNwClTmLWpAu UjT5Bc1jXlMXNnfJWxGeJA8NmE7vREmRF9Qo3Ym76m44t8HmrT4uKcB10SnYiSsdX/cE iy1vSkyE7G/EC5PmTx5uC0TRNuQGC48FnnYA5zPE0xjrCLLM1NZltN3VJwV6S0aaW5+/ OkVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=XtxT1MTxM5ARJ+08eWr2bJ37iwug5sulaz41RNmMU7k=; b=mxnl0kAu5xB/qt2hGMDZ030AlOKaWCCnpXUROruesVgbqfXfNIXL7Lva4vQOgnwT+M jEobkvyZrV7turnnVji2G4RVnqwunbZo/eitlsF/xGJMiTzeyHtt9XFWFz5pL42sKol2 vpgd4hoD+I1zfbJy8hkzydK1ER6T0eZyCH62sbucAELbkPUgn0Y+DbUSnm7PFZLyY50l Oaw0nDU3MEG8Q3J0FjezylvMaxXMri6MfosazqolR6vgbJvzzO6kj3ZPXvUzY69aQ9yC asLmb2PQET5PuGe2NBigYwF87YV+EQOHlCeAQJet+qmpXCAbiv2+p7rx5nEUXMGbnhwt PpSA== X-Gm-Message-State: AOAM532535O+Ph//bHe2N+dL97ltu6AC/UNNc6lryNdA3hkuQAm8eXDM TFaUaXLHwRdbhh9QL9QiIM0= X-Google-Smtp-Source: ABdhPJx3h8V1BGcujSWy01LeHbHKLGD8NBYz+86psVF7eNMM6naaE4zznE3jh+HZ/CMxH6oUQbTbFQ== X-Received: by 2002:a05:620a:10ab:: with SMTP id h11mr2890878qkk.219.1597291347120; Wed, 12 Aug 2020 21:02:27 -0700 (PDT) Received: from localhost.localdomain ([2001:470:b:9c3:9e5c:8eff:fe4f:f2d0]) by smtp.gmail.com with ESMTPSA id s4sm4959859qtn.34.2020.08.12.21.02.24 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Aug 2020 21:02:26 -0700 (PDT) Subject: [RFC PATCH 1/3] mm: Drop locked from isolate_migratepages_block From: Alexander Duyck To: alex.shi@linux.alibaba.com Cc: yang.shi@linux.alibaba.com, lkp@intel.com, rong.a.chen@intel.com, khlebnikov@yandex-team.ru, kirill@shutemov.name, hughd@google.com, linux-kernel@vger.kernel.org, alexander.duyck@gmail.com, daniel.m.jordan@oracle.com, linux-mm@kvack.org, shakeelb@google.com, willy@infradead.org, hannes@cmpxchg.org, tj@kernel.org, cgroups@vger.kernel.org, akpm@linux-foundation.org, richard.weiyang@gmail.com, mgorman@techsingularity.net, iamjoonsoo.kim@lge.com Date: Wed, 12 Aug 2020 21:02:24 -0700 Message-ID: <20200813040224.13054.96724.stgit@localhost.localdomain> In-Reply-To: <20200813035100.13054.25671.stgit@localhost.localdomain> References: <20200813035100.13054.25671.stgit@localhost.localdomain> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Rspamd-Queue-Id: 39D8318229818 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 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: From: Alexander Duyck We can drop the need for the locked variable by making use of the lruvec_holds_page_lru_lock function. By doing this we can avoid some rcu locking ugliness for the case where the lruvec is still holding the LRU lock associated with the page. Instead we can just use the lruvec and if it is NULL we assume the lock was released. Signed-off-by: Alexander Duyck --- mm/compaction.c | 45 ++++++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index b99c96c4862d..5021a18ef722 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -803,9 +803,8 @@ static bool too_many_isolated(pg_data_t *pgdat) { pg_data_t *pgdat = cc->zone->zone_pgdat; unsigned long nr_scanned = 0, nr_isolated = 0; - struct lruvec *lruvec; + struct lruvec *lruvec = NULL; unsigned long flags = 0; - struct lruvec *locked = NULL; struct page *page = NULL, *valid_page = NULL; unsigned long start_pfn = low_pfn; bool skip_on_failure = false; @@ -866,9 +865,9 @@ static bool too_many_isolated(pg_data_t *pgdat) * a fatal signal is pending. */ if (!(low_pfn % SWAP_CLUSTER_MAX)) { - if (locked) { - unlock_page_lruvec_irqrestore(locked, flags); - locked = NULL; + if (lruvec) { + unlock_page_lruvec_irqrestore(lruvec, flags); + lruvec = NULL; } if (fatal_signal_pending(current)) { @@ -949,9 +948,9 @@ static bool too_many_isolated(pg_data_t *pgdat) */ if (unlikely(__PageMovable(page)) && !PageIsolated(page)) { - if (locked) { - unlock_page_lruvec_irqrestore(locked, flags); - locked = NULL; + if (lruvec) { + unlock_page_lruvec_irqrestore(lruvec, flags); + lruvec = NULL; } if (!isolate_movable_page(page, isolate_mode)) @@ -992,16 +991,13 @@ static bool too_many_isolated(pg_data_t *pgdat) if (!TestClearPageLRU(page)) goto isolate_fail_put; - rcu_read_lock(); - lruvec = mem_cgroup_page_lruvec(page, pgdat); - /* If we already hold the lock, we can skip some rechecking */ - if (lruvec != locked) { - if (locked) - unlock_page_lruvec_irqrestore(locked, flags); + if (!lruvec || !lruvec_holds_page_lru_lock(page, lruvec)) { + if (lruvec) + unlock_page_lruvec_irqrestore(lruvec, flags); + lruvec = mem_cgroup_page_lruvec(page, pgdat); compact_lock_irqsave(&lruvec->lru_lock, &flags, cc); - locked = lruvec; rcu_read_unlock(); lruvec_memcg_debug(lruvec, page); @@ -1023,8 +1019,7 @@ static bool too_many_isolated(pg_data_t *pgdat) SetPageLRU(page); goto isolate_fail_put; } - } else - rcu_read_unlock(); + } /* The whole page is taken off the LRU; skip the tail pages. */ if (PageCompound(page)) @@ -1057,9 +1052,9 @@ static bool too_many_isolated(pg_data_t *pgdat) isolate_fail_put: /* Avoid potential deadlock in freeing page under lru_lock */ - if (locked) { - unlock_page_lruvec_irqrestore(locked, flags); - locked = NULL; + if (lruvec) { + unlock_page_lruvec_irqrestore(lruvec, flags); + lruvec = NULL; } put_page(page); @@ -1073,9 +1068,9 @@ static bool too_many_isolated(pg_data_t *pgdat) * page anyway. */ if (nr_isolated) { - if (locked) { - unlock_page_lruvec_irqrestore(locked, flags); - locked = NULL; + if (lruvec) { + unlock_page_lruvec_irqrestore(lruvec, flags); + lruvec = NULL; } putback_movable_pages(&cc->migratepages); cc->nr_migratepages = 0; @@ -1102,8 +1097,8 @@ static bool too_many_isolated(pg_data_t *pgdat) page = NULL; isolate_abort: - if (locked) - unlock_page_lruvec_irqrestore(locked, flags); + if (lruvec) + unlock_page_lruvec_irqrestore(lruvec, flags); if (page) { SetPageLRU(page); put_page(page);