From patchwork Thu May 27 06:21:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 12283479 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F1CBEC4708A for ; Thu, 27 May 2021 06:25:02 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A7A2A613C9 for ; Thu, 27 May 2021 06:25:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A7A2A613C9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E3DBB6B0074; Thu, 27 May 2021 02:25:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DE9736B0075; Thu, 27 May 2021 02:25:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8B5EF6B0078; Thu, 27 May 2021 02:25:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0102.hostedemail.com [216.40.44.102]) by kanga.kvack.org (Postfix) with ESMTP id 47B2A6B0074 for ; Thu, 27 May 2021 02:25:01 -0400 (EDT) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id CEA80824999B for ; Thu, 27 May 2021 06:25:00 +0000 (UTC) X-FDA: 78186023160.04.26D2859 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) by imf28.hostedemail.com (Postfix) with ESMTP id 4307F2000981 for ; Thu, 27 May 2021 06:24:53 +0000 (UTC) Received: by mail-pf1-f171.google.com with SMTP id p39so2857707pfw.8 for ; Wed, 26 May 2021 23:25:00 -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=HEia8IE8kslbq8l2doyQoIh1s6NP1wi5+X3AcZEFjeo=; b=kvlV9ariGPa/KOzsdvMjL84J7KWbdBZljXXTqzBfy1gdD9aUiqOXYY7jJQcZ6EvphQ g5z1HggN5fovKKWheUdFdNevBNnCo1Y5FChVJM1/DuUAV36d/srrFP8AiZwJCy+M1ATd 3xhBPwrQGJbKj2Kl3PGvzcn+Dg2smkoyiPmIwtsfxEKF6SrN6b04pXobPQjFpXbR6spG lJc/mkpgOWaK5OEFoF0G+i+xICYWPwDNN/lYDf5Mj138CEBpr7jh8ghx1EP+yJo8N+z8 QxZdlGmO13yEIskhtzWSkcu7NE88svZEfcAegqOuCoCVD2QjYW395gNPHg9oHw5ejkrV /ysg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HEia8IE8kslbq8l2doyQoIh1s6NP1wi5+X3AcZEFjeo=; b=RGHBdhOhfHakFpDr7YJ8H82j4/fXCCYuRE6aCuAGcrW1maxZcnXf8XCxlzBTllO63A NufeGgmZ362YlHqQSieLdeyKkoZtrESwywlvroqvTDveZOu7k/wLwMq+JuCDLVcIOTyv xarxIWf8GZ9ODQ5GlAJE1lNEVqqfdgFaCIfdYcppQTLqpizLNoc6RQQEV3eB8cDOvzHC 1wvHaqJMPL1gnJcw+LxjVZe7Rg97NSR8RqdGsh4tUPJ8w7ItbDJn0sef8I/lDCb91ZNh mqDuxioAD0pflSZu6GBVBWYJtSBXNMBpyJKu1tB5ptZ1wLcBzt/ivs/yFmK6YvXTp6QC o4Xg== X-Gm-Message-State: AOAM530SjC9bmYyLtWAExPBX6qrq4nvwwLtIitDzyOSHIp8bqu0J53IE tHbJNXDJgbNoTLDBb1NSGN4ncw== X-Google-Smtp-Source: ABdhPJy8A0vvkxkOQSVawjHK6CAOJlYjigmh+AJP/eE52bt7Q22D37+MA/80ZY8HArWIAUCkU+9QRQ== X-Received: by 2002:a65:64cc:: with SMTP id t12mr2330420pgv.64.1622096699772; Wed, 26 May 2021 23:24:59 -0700 (PDT) Received: from localhost.localdomain ([139.177.225.254]) by smtp.gmail.com with ESMTPSA id m5sm882971pgl.75.2021.05.26.23.24.53 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 26 May 2021 23:24:59 -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, Muchun Song Subject: [PATCH v2 06/21] mm: list_lru: only add the memcg aware lrus to the list_lrus Date: Thu, 27 May 2021 14:21:33 +0800 Message-Id: <20210527062148.9361-7-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20210527062148.9361-1-songmuchun@bytedance.com> References: <20210527062148.9361-1-songmuchun@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4307F2000981 Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=kvlV9ari; spf=pass (imf28.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.210.171 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com; dmarc=pass (policy=none) header.from=bytedance.com X-Rspamd-Server: rspam04 X-Stat-Signature: taj1xkhapfqra13c1ftkt9mhfbs3mp3i X-HE-Tag: 1622096693-263160 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: We need to traverse every lru in the list_lrus in some routines, but skip memcg non-aware lrus. However, we can only add the memcg aware lrus to the list_lrus. This can be efficient to traverse the list. Signed-off-by: Muchun Song --- mm/list_lru.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/mm/list_lru.c b/mm/list_lru.c index e86d4d055d3c..bed699edabe5 100644 --- a/mm/list_lru.c +++ b/mm/list_lru.c @@ -18,8 +18,16 @@ static LIST_HEAD(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); mutex_unlock(&list_lrus_mutex); @@ -27,6 +35,9 @@ static void list_lru_register(struct list_lru *lru) 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) { @@ -460,9 +466,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)) @@ -485,9 +488,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); @@ -546,9 +546,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); }