From patchwork Wed Dec 2 18:27:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 11946707 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=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 9D753C71156 for ; Wed, 2 Dec 2020 18:28:05 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2279222249 for ; Wed, 2 Dec 2020 18:28:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2279222249 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 8DA1D6B0072; Wed, 2 Dec 2020 13:28:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 83B226B0073; Wed, 2 Dec 2020 13:28:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 72A4F6B0074; Wed, 2 Dec 2020 13:28:04 -0500 (EST) 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 57FBD6B0072 for ; Wed, 2 Dec 2020 13:28:04 -0500 (EST) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 16C7C181AEF1F for ; Wed, 2 Dec 2020 18:28:04 +0000 (UTC) X-FDA: 77549176488.30.range23_560cede273b5 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin30.hostedemail.com (Postfix) with ESMTP id EF23B180B3C85 for ; Wed, 2 Dec 2020 18:28:03 +0000 (UTC) X-HE-Tag: range23_560cede273b5 X-Filterd-Recvd-Size: 5828 Received: from mail-pf1-f193.google.com (mail-pf1-f193.google.com [209.85.210.193]) by imf05.hostedemail.com (Postfix) with ESMTP for ; Wed, 2 Dec 2020 18:28:03 +0000 (UTC) Received: by mail-pf1-f193.google.com with SMTP id q22so1759841pfk.12 for ; Wed, 02 Dec 2020 10:28:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vKQ+xPb0r9nNI6kfI9ZBDBE9gitSqzBXebPL/8fpVzE=; b=nj/7BqYlZwg8znD81/vfXzs6ArF+M8qXSuJ5a9WuI9e/hfRhm1v4/gYPWalwc/TlM4 6F/rSomsJXUQ4EpDQYFpSAh82V/WqdjDxQ2e8nvwVXN7wBTBOk61H5J76pHR1CCCBP6D nlYjFzW2cVvnSbb1SgCjZYUhc6Buvlkzq0ysPluyZJKMDazAYg5pvKm6HEKabirJdpd0 uznrcMTWGebypvAmrpfEszv8FySwjX9gEMsLuqnOlTc4nluRGe74wVn2CsrAkjtWn0q7 H6fB3X1eUY8eDTWJO1Byk1fTG7f99wZrqKamabm9OrNTJe1U0dkxa51GjjCm53Yu8RsL hh8A== 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=vKQ+xPb0r9nNI6kfI9ZBDBE9gitSqzBXebPL/8fpVzE=; b=eBMWSEZq4+Z+01FOlwh9JCKe9xXnSJjEBRMf5ZGfE9GBgcy1bocrfOUHAYjGHCidzD tMI3Uz36eYgQ2FkQ648s6pz6xj2mb1RxNw94JWNLAzKZjyknxHntJtmoIF8JX83MYagQ kXjf8mZK0j2lv44Uyzed6TWp4jrpHcPVt2YYESmvyAxAdujO7SW9Hp5tHnArieQe2j0I VTfOpoCte5kOQ2h5RVM8ssU1zKRPyXvcyS2Pp8KOGA+RasVx2qULtz3b2Cfeb91YAhDM ZLPSb79wWsx1Dehf8HL7HCTQigusjjrXCjyRLuugxeD/Jwxd6dY854dD8Ko3UH4GPjRi 9GNg== X-Gm-Message-State: AOAM531BFLxNmTudFZULm7ZD34yKRUv0ahwEGGvrYsPXR2yGQH4oIO8H mK6FqWlo03Ql8+8o+OzGFyg= X-Google-Smtp-Source: ABdhPJxQKoIFdMyU/1Ay7uLq3AbzqAGodA79ySyV5eVU7XWUWSccqPYCWM43OGq8/UFqVQgC2Ouo/Q== X-Received: by 2002:a05:6a00:134d:b029:18b:2cde:d747 with SMTP id k13-20020a056a00134db029018b2cded747mr4069247pfu.60.1606933682661; Wed, 02 Dec 2020 10:28:02 -0800 (PST) Received: from localhost.localdomain (c-73-93-239-127.hsd1.ca.comcast.net. [73.93.239.127]) by smtp.gmail.com with ESMTPSA id c6sm396906pgl.38.2020.12.02.10.28.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2020 10:28:01 -0800 (PST) From: Yang Shi To: guro@fb.com, ktkhai@virtuozzo.com, shakeelb@google.com, david@fromorbit.com, hannes@cmpxchg.org, mhocko@suse.com, akpm@linux-foundation.org Cc: shy828301@gmail.com, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 8/9] mm: memcontrol: reparent nr_deferred when memcg offline Date: Wed, 2 Dec 2020 10:27:24 -0800 Message-Id: <20201202182725.265020-9-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201202182725.265020-1-shy828301@gmail.com> References: <20201202182725.265020-1-shy828301@gmail.com> MIME-Version: 1.0 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: Now shrinker's nr_deferred is per memcg for memcg aware shrinkers, add to parent's corresponding nr_deferred when memcg offline. Signed-off-by: Yang Shi --- include/linux/shrinker.h | 4 ++++ mm/memcontrol.c | 24 ++++++++++++++++++++++++ mm/vmscan.c | 2 +- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/include/linux/shrinker.h b/include/linux/shrinker.h index 0bb5be88e41d..8f095e424799 100644 --- a/include/linux/shrinker.h +++ b/include/linux/shrinker.h @@ -82,6 +82,10 @@ struct shrinker { }; #define DEFAULT_SEEKS 2 /* A good number if you don't know better. */ +#ifdef CONFIG_MEMCG +extern int shrinker_nr_max; +#endif + /* Flags */ #define SHRINKER_NUMA_AWARE (1 << 0) #define SHRINKER_MEMCG_AWARE (1 << 1) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index d3d5c88db179..df128cab900f 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -59,6 +59,7 @@ #include #include #include +#include #include "internal.h" #include #include @@ -619,6 +620,28 @@ void memcg_set_shrinker_bit(struct mem_cgroup *memcg, int nid, int shrinker_id) } } +static void memcg_reparent_shrinker_deferred(struct mem_cgroup *memcg) +{ + int i, nid; + long nr; + struct mem_cgroup *parent; + struct memcg_shrinker_deferred *child_deferred, *parent_deferred; + + parent = parent_mem_cgroup(memcg); + if (!parent) + parent = root_mem_cgroup; + + for_each_node(nid) { + child_deferred = memcg->nodeinfo[nid]->shrinker_deferred; + parent_deferred = parent->nodeinfo[nid]->shrinker_deferred; + for (i = 0; i < shrinker_nr_max; i ++) { + nr = atomic_long_read(&child_deferred->nr_deferred[i]); + atomic_long_add(nr, + &parent_deferred->nr_deferred[i]); + } + } +} + /** * mem_cgroup_css_from_page - css of the memcg associated with a page * @page: page of interest @@ -5543,6 +5566,7 @@ static void mem_cgroup_css_offline(struct cgroup_subsys_state *css) page_counter_set_low(&memcg->memory, 0); memcg_offline_kmem(memcg); + memcg_reparent_shrinker_deferred(memcg); wb_memcg_offline(memcg); drain_all_stock(memcg); diff --git a/mm/vmscan.c b/mm/vmscan.c index 5fd57060fafd..7dc8075c371b 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -201,7 +201,7 @@ static DECLARE_RWSEM(shrinker_rwsem); #define SHRINKER_REGISTERING ((struct shrinker *)~0UL) static DEFINE_IDR(shrinker_idr); -static int shrinker_nr_max; +int shrinker_nr_max; static inline bool is_deferred_memcg_aware(struct shrinker *shrinker) {