Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp329836pxx; Thu, 29 Oct 2020 03:50:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxtUNG0dmHN0U47opCaNQTL6ReMqrTslSAGd47rAoZjnMEEyI2wuBsbt7izsYoNNV8dNVck X-Received: by 2002:a17:906:c407:: with SMTP id u7mr3393508ejz.206.1603968600696; Thu, 29 Oct 2020 03:50:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603968600; cv=none; d=google.com; s=arc-20160816; b=CTacaz70+i9+0hS18vx2zdaRj/W6PP0yUL5ESEFc2dpPseKk3mQXSH0US4FoNZSk+Z +xUKtr0OCP+Wi9O6ImrYJ+6DDWrJ8X14yd5Pi7K/P5Uu1GeWShYyfN/kI1P8mpj7Eg4e 6W9KUYqrefbYFYe8j3gUpln/Uyz2TpzuzSlMucGu07RY5PK9XbCE3ycFFuBfjcAhjzbk ufcn0ai7cOIKcLemCLwtUmtp7v4FJITLaTHtjW1ac95ZXpl5J59wHiR1fti6ueQFGcJx X2IHBnpaP+e39C8fXTuhGHcn7XGzFhKtvI3kyzA5uEs3lJevdMyorv81TYnhGXkR4Z8e qiCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :to:from; bh=QvLtS+thir0hNH5N2aas6cg552afKzromWwTkuOWiaA=; b=uJkeqQZSK+C0FwvyJj76R9HEKT1YbHMaqQg2lbVhQKTrKGMuECE8SzCw93aPvhFZh0 OSEW0IqU2dFFnswyZbqiYxnTlD7ArJIRwB/RcWMtXC50ZVbpyibnoHtr27cK+gfwelwR OBzk/QOQ4kA8SvOluHhJHfJHfratC9Xst0AiS/ZimsBq6BT2TElZ6IXrg9XqUDR4Z1Y3 hU9SrujzLKwdy4H8e9n01WoMvPfhxtn1iK2+zPkkGJ/FW+vbOfSBBIX9ft0wlzm5G7WF gRkJ5RBzjZOXjhXoETiHs+l/gys3CM0hORMAJQ4Dl+OZoV3R3dJdc44vuYhnYk9/WI5w cnWw== 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 e14si1554567ejj.573.2020.10.29.03.49.38; Thu, 29 Oct 2020 03:50:00 -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 S1727110AbgJ2Kqh (ORCPT + 99 others); Thu, 29 Oct 2020 06:46:37 -0400 Received: from out30-131.freemail.mail.aliyun.com ([115.124.30.131]:55556 "EHLO out30-131.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726823AbgJ2Kpk (ORCPT ); Thu, 29 Oct 2020 06:45:40 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R131e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=alimailimapcm10staff010182156082;MF=alex.shi@linux.alibaba.com;NM=1;PH=DS;RN=21;SR=0;TI=SMTPD_---0UDXwDyN_1603968328; Received: from aliy80.localdomain(mailfrom:alex.shi@linux.alibaba.com fp:SMTPD_---0UDXwDyN_1603968328) by smtp.aliyun-inc.com(127.0.0.1); Thu, 29 Oct 2020 18:45:33 +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 v20 11/20] mm/lru: move lock into lru_note_cost Date: Thu, 29 Oct 2020 18:44:56 +0800 Message-Id: <1603968305-8026-12-git-send-email-alex.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1603968305-8026-1-git-send-email-alex.shi@linux.alibaba.com> References: <1603968305-8026-1-git-send-email-alex.shi@linux.alibaba.com> 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 Acked-by: Hugh Dickins Cc: Johannes Weiner Cc: Andrew Morton Cc: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org --- mm/swap.c | 3 +++ mm/vmscan.c | 4 +--- mm/workingset.c | 2 -- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/mm/swap.c b/mm/swap.c index 31fc3ebc1079..8798bd899db0 100644 --- a/mm/swap.c +++ b/mm/swap.c @@ -268,7 +268,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; @@ -292,6 +294,7 @@ 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))); } diff --git a/mm/vmscan.c b/mm/vmscan.c index 6c6965cbbdef..42bac12aacb4 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1973,19 +1973,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); diff --git a/mm/workingset.c b/mm/workingset.c index 975a4d2dd02e..d8d2fdf70c24 100644 --- a/mm/workingset.c +++ b/mm/workingset.c @@ -381,9 +381,7 @@ void workingset_refault(struct page *page, void *shadow) if (workingset) { SetPageWorkingset(page); /* XXX: Move to lru_cache_add() when it supports new vs putback */ - spin_lock_irq(&page_pgdat(page)->lru_lock); lru_note_cost_page(page); - spin_unlock_irq(&page_pgdat(page)->lru_lock); inc_lruvec_state(lruvec, WORKINGSET_RESTORE_BASE + file); } out: -- 1.8.3.1