Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2121645pxa; Mon, 24 Aug 2020 05:58:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwIcPgK9vBqxnIAWmdousrytsjaDTWnbOT6snjjtPI2Vz5nJFTivOvSPSNaTKTcmMVzHR9y X-Received: by 2002:aa7:cccb:: with SMTP id y11mr4933251edt.15.1598273896967; Mon, 24 Aug 2020 05:58:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598273896; cv=none; d=google.com; s=arc-20160816; b=KZPXuvY4DafqhQZ/7HnS7/pEG+UXCLb7xCdpOXuqXxyElL013X5LAuxhWIUMb+uv/4 a0eVmqIsEWoVTKOePDKMrn32k45JJGsw2kMg3EXI+/TaASaoICkJzTRGVv3I76Iao4sn 144VpVFjKRfRlKvGqkgfF4akXDkXwNwWs/cswk2XMbVRI9KH7TrYzLiK32wSdIiRhfjc BQC2exCiNOaWLPnJonpD1YSDLg2d35Kg5kSHK26i/+NdFHvMT7I+9qJ1Z5vODL/N+ALz k6uyQkbps98zpBiTr/oc7Uvawicvx7DB0OFvhhdYh3YYkJ/cj+Zf7JqEmb2f+7p6PjjY 9g5w== 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:to:from; bh=OwheYKqbRdvIKCOu69LgfrWhh4pkkuY9YEt8OD7Jlys=; b=AhmrqrqKuKvfHameQUasDVOfhCD331GAYuUtE4rimA3TfvXh4UZ9MWozEJ8TW7aVlq DpwZHftoxi3ibYCR5/jcFKoU4ENkFg4Wqmw2LTALuJVFrlQ6w6cxkhIMOjIFy0OiT+wz jyL1zTivSit7beaJFC+F+aHjm99Xui1xrmYrwgP746IRRCNDLk1beALfZ8gHceasaRH/ WO2kuBFa4GcSjNyYz4fvhjFPn4wAObGH+yBcehahStLN2RoE2wRy1euJGy4FJTbupvJa 0osneFxwzYrYVMLTV8tyigX3dTGTITJY3PO6DytMfP4oMzFtP8VjLBik1AwwU02mot9w YFJg== 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 q11si6072972ejb.101.2020.08.24.05.57.53; Mon, 24 Aug 2020 05:58:16 -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 S1728007AbgHXM4m (ORCPT + 99 others); Mon, 24 Aug 2020 08:56:42 -0400 Received: from out4436.biz.mail.alibaba.com ([47.88.44.36]:22355 "EHLO out4436.biz.mail.alibaba.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727872AbgHXMzf (ORCPT ); Mon, 24 Aug 2020 08:55:35 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R141e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e07488;MF=alex.shi@linux.alibaba.com;NM=1;PH=DS;RN=21;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:18 +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 Subject: [PATCH v18 15/32] mm/lru: move lock into lru_note_cost Date: Mon, 24 Aug 2020 20:54:48 +0800 Message-Id: <1598273705-69124-16-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 We have to move lru_lock into lru_note_cost, since it cycle up on memcg tree, for future per lruvec lru_lock replace. It's a bit ugly and may cost a bit more locking, but benefit from multiple memcg locking could cover the lost. Signed-off-by: Alex Shi Cc: Johannes Weiner Cc: Andrew Morton Cc: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org --- mm/swap.c | 5 +++-- mm/vmscan.c | 4 +--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/mm/swap.c b/mm/swap.c index 906255db6006..f80ccd6f3cb4 100644 --- a/mm/swap.c +++ b/mm/swap.c @@ -269,7 +269,9 @@ void lru_note_cost(struct lruvec *lruvec, bool file, unsigned int nr_pages) { do { unsigned long lrusize; + struct pglist_data *pgdat = lruvec_pgdat(lruvec); + spin_lock_irq(&pgdat->lru_lock); /* Record cost event */ if (file) lruvec->file_cost += nr_pages; @@ -293,15 +295,14 @@ void lru_note_cost(struct lruvec *lruvec, bool file, unsigned int nr_pages) lruvec->file_cost /= 2; lruvec->anon_cost /= 2; } + spin_unlock_irq(&pgdat->lru_lock); } while ((lruvec = parent_lruvec(lruvec))); } void lru_note_cost_page(struct page *page) { - spin_lock_irq(&page_pgdat(page)->lru_lock); lru_note_cost(mem_cgroup_page_lruvec(page, page_pgdat(page)), page_is_file_lru(page), thp_nr_pages(page)); - spin_unlock_irq(&page_pgdat(page)->lru_lock); } static void __activate_page(struct page *page, struct lruvec *lruvec) diff --git a/mm/vmscan.c b/mm/vmscan.c index ffccb94defaf..7b7b36bd1448 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1971,19 +1971,17 @@ static int current_may_throttle(void) &stat, false); spin_lock_irq(&pgdat->lru_lock); - move_pages_to_lru(lruvec, &page_list); __mod_node_page_state(pgdat, NR_ISOLATED_ANON + file, -nr_taken); - lru_note_cost(lruvec, file, stat.nr_pageout); item = current_is_kswapd() ? PGSTEAL_KSWAPD : PGSTEAL_DIRECT; if (!cgroup_reclaim(sc)) __count_vm_events(item, nr_reclaimed); __count_memcg_events(lruvec_memcg(lruvec), item, nr_reclaimed); __count_vm_events(PGSTEAL_ANON + file, nr_reclaimed); - spin_unlock_irq(&pgdat->lru_lock); + lru_note_cost(lruvec, file, stat.nr_pageout); mem_cgroup_uncharge_list(&page_list); free_unref_page_list(&page_list); -- 1.8.3.1