Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp440064pxb; Tue, 14 Sep 2021 00:34:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzFpq96zRGjDTGTIYDHR4ra3/WiHBs+6sqoQ1KcnQqGxqpyAT5t0sGgXJXtvFJsE/EAYKRM X-Received: by 2002:a02:94e4:: with SMTP id x91mr13388971jah.99.1631604853559; Tue, 14 Sep 2021 00:34:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631604853; cv=none; d=google.com; s=arc-20160816; b=emXSCJ5XZFnJzxjLd/2EkLLat/39Exhw87wvLzUoQYXQN1ZKoPDbu5gdtJNiTWageq 6erKAQM1mKZqko2w8lKfO+/kfNGxisGNCJfqeGHl4nVdx28dL0mbC3jdboxYOi6hAG2G E+dNLBjkPZidJmQuw9pAr6i4U07Di3VI8rJqFQRxHH5P84rs1zQzFygg+tGPq5/g8ks4 aChFatZJ8XISfJM8gNkZhgZ9SajTg9l5MFQIE//vMWlSVIlZbMvdHaZKDvMzq+SiOV2E F69g2+2zMCUrvnXEwdcCQxMaDa8bEWURo5q5upsBnRoJ9rjWu1I4/C3UUTXYv1d9+eE4 ojyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=rI7PKACqM/Kwcdk+6AVk4DQ16MheMLZPlQjMEC5n7yk=; b=VneX/fAXWb7HMfvT9Kkytjw+IWXOP4GoQ9yQxRDunPO2rP4VsO4/AljFZkMaRFszEw FMkONSNwBGq2U8vULIyqQ2RH2Rdsb30ozA3dUqH3KmN+8iF9cspyHeQiJvpL9cwGvyCb GkJBUtIzRovXM9ywaj5nYiy8VHDbLOAyU7I/viIEbsR1GhzGbRES9PjbfaYirhQuSEle 7uCBEL3Tn8sCr/Fg2fnlkbu0GOEPNaNH8yddYfowU4SJCexsys+cj7D214x5M/8fshPS EdIEDjH23VuzjQBPwTMIkJLMP7ImnYcYDi9sLY8U4NzkTuk41DfRfwHvLJQzc9yn7sxG jJSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=EdRD6sHz; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n7si9559443ilj.150.2021.09.14.00.34.01; Tue, 14 Sep 2021 00:34:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=EdRD6sHz; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241018AbhINHfH (ORCPT + 99 others); Tue, 14 Sep 2021 03:35:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240963AbhINHey (ORCPT ); Tue, 14 Sep 2021 03:34:54 -0400 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAB6BC061762 for ; Tue, 14 Sep 2021 00:33:37 -0700 (PDT) Received: by mail-pj1-x102e.google.com with SMTP id g13-20020a17090a3c8d00b00196286963b9so1444548pjc.3 for ; Tue, 14 Sep 2021 00:33:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rI7PKACqM/Kwcdk+6AVk4DQ16MheMLZPlQjMEC5n7yk=; b=EdRD6sHziaUM8ZWwxrmJqt7nsJvDxYQmRneqGGkNe4BMlgV93fTvY2OehhPz1IFX1k YZkwM/14bd/X2mxRpcHaMtYegAn4Xp3oZu5WoP1rYKkupk8RUyF4chweIn+rbkx6PI0T 2tzbfNdxm3YDWMnbwTb3lzapiSC+RYDp1PRGKF9ZVYYwMk+tIfuidHTsOb58Nbx8ATZP amG6TR448PN8cJaY2YytWw9yP5YHUl3aLII/2hVQ0/UmP9eiyVwl+G4TVNV/cpizgA8N EEkC7jtYQmemaObOfbSkvNmmSWli8j1ASAjaJe4Ey7y3CNI7wdSRaBChZ8WUoNUxdEYF jG4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rI7PKACqM/Kwcdk+6AVk4DQ16MheMLZPlQjMEC5n7yk=; b=07ciEtm5VRVfzjfBqy0nM0T2MvoXyQ+tiOYY0jjS8wRhF1vUgqTh+K0kzF4GZlAvSR mcB7Zvwekg4HHi/33WMlX7NFbbN3MgWSLTzoxFGO6nMQ3z2RjF+qYEW3pvKJ1KlP/M5o tFIII07bCoEBIM+URzGORKk6+fFk4yIeF46YY4uAdpk4vnVJCVH8y3TSSGRQSqlUAnjT hdL24HsQi1xJDwBoYGG3wuq/9Vd19xrffa6/p4D2/BUTsQdW6cqkC7qJRBLj46r95IMN vL4lchCi2vL8NrSvPfFknSke5Z0RMxpzbdD/rOoc38Msm1TRyRkSkQj9zCCnqPbkAySp YyFQ== X-Gm-Message-State: AOAM530HNoMTVgh5tx6ets4h4zwtc4dEKvTcejvu82XbYejlj88fVOOD FTbBbpY+junq5RLY/asDnsjNdA== X-Received: by 2002:a17:90b:3890:: with SMTP id mu16mr575506pjb.78.1631604817392; Tue, 14 Sep 2021 00:33:37 -0700 (PDT) Received: from localhost.localdomain ([139.177.225.244]) by smtp.gmail.com with ESMTPSA id s3sm9377839pfd.188.2021.09.14.00.33.30 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 Sep 2021 00:33:36 -0700 (PDT) From: Muchun Song To: willy@infradead.org, akpm@linux-foundation.org, hannes@cmpxchg.org, mhocko@kernel.org, vdavydov.dev@gmail.com, shakeelb@google.com, guro@fb.com, shy828301@gmail.com, alexs@kernel.org, richard.weiyang@gmail.com, david@fromorbit.com, trond.myklebust@hammerspace.com, anna.schumaker@netapp.com Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-nfs@vger.kernel.org, zhengqi.arch@bytedance.com, duanxiongchun@bytedance.com, fam.zheng@bytedance.com, smuchun@gmail.com, Muchun Song Subject: [PATCH v3 06/76] mm: list_lru: only add memcg-aware lrus to the global lru list Date: Tue, 14 Sep 2021 15:28:28 +0800 Message-Id: <20210914072938.6440-7-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20210914072938.6440-1-songmuchun@bytedance.com> References: <20210914072938.6440-1-songmuchun@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org The non-memcg-aware lru is always skiped when traversing the global lru list, which is not efficient. We can only add the memcg-aware lru to the global lru list instead to make traversing more efficient. Signed-off-by: Muchun Song --- mm/list_lru.c | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/mm/list_lru.c b/mm/list_lru.c index 6b2f3cbe5f67..39828632631c 100644 --- a/mm/list_lru.c +++ b/mm/list_lru.c @@ -15,18 +15,29 @@ #include "slab.h" #ifdef CONFIG_MEMCG_KMEM -static LIST_HEAD(list_lrus); +static LIST_HEAD(memcg_list_lrus); static DEFINE_MUTEX(list_lrus_mutex); +static inline bool list_lru_memcg_aware(struct list_lru *lru) +{ + return lru->memcg_aware; +} + static void list_lru_register(struct list_lru *lru) { + if (!list_lru_memcg_aware(lru)) + return; + mutex_lock(&list_lrus_mutex); - list_add(&lru->list, &list_lrus); + list_add(&lru->list, &memcg_list_lrus); mutex_unlock(&list_lrus_mutex); } static void list_lru_unregister(struct list_lru *lru) { + if (!list_lru_memcg_aware(lru)) + return; + mutex_lock(&list_lrus_mutex); list_del(&lru->list); mutex_unlock(&list_lrus_mutex); @@ -37,11 +48,6 @@ static int lru_shrinker_id(struct list_lru *lru) return lru->shrinker_id; } -static inline bool list_lru_memcg_aware(struct list_lru *lru) -{ - return lru->memcg_aware; -} - static inline struct list_lru_one * list_lru_from_memcg_idx(struct list_lru_node *nlru, int idx) { @@ -458,9 +464,6 @@ static int memcg_update_list_lru(struct list_lru *lru, { int i; - if (!list_lru_memcg_aware(lru)) - return 0; - for_each_node(i) { if (memcg_update_list_lru_node(&lru->node[i], old_size, new_size)) @@ -483,9 +486,6 @@ static void memcg_cancel_update_list_lru(struct list_lru *lru, { int i; - if (!list_lru_memcg_aware(lru)) - return; - for_each_node(i) memcg_cancel_update_list_lru_node(&lru->node[i], old_size, new_size); @@ -498,7 +498,7 @@ int memcg_update_all_list_lrus(int new_size) int old_size = memcg_nr_cache_ids; mutex_lock(&list_lrus_mutex); - list_for_each_entry(lru, &list_lrus, list) { + list_for_each_entry(lru, &memcg_list_lrus, list) { ret = memcg_update_list_lru(lru, old_size, new_size); if (ret) goto fail; @@ -507,7 +507,7 @@ int memcg_update_all_list_lrus(int new_size) mutex_unlock(&list_lrus_mutex); return ret; fail: - list_for_each_entry_continue_reverse(lru, &list_lrus, list) + list_for_each_entry_continue_reverse(lru, &memcg_list_lrus, list) memcg_cancel_update_list_lru(lru, old_size, new_size); goto out; } @@ -544,9 +544,6 @@ static void memcg_drain_list_lru(struct list_lru *lru, { int i; - if (!list_lru_memcg_aware(lru)) - return; - for_each_node(i) memcg_drain_list_lru_node(lru, i, src_idx, dst_memcg); } @@ -556,7 +553,7 @@ void memcg_drain_all_list_lrus(int src_idx, struct mem_cgroup *dst_memcg) struct list_lru *lru; mutex_lock(&list_lrus_mutex); - list_for_each_entry(lru, &list_lrus, list) + list_for_each_entry(lru, &memcg_list_lrus, list) memcg_drain_list_lru(lru, src_idx, dst_memcg); mutex_unlock(&list_lrus_mutex); } -- 2.11.0