From patchwork Mon Dec 14 22:37:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 11973301 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 CFD61C4361B for ; Mon, 14 Dec 2020 22:38:01 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7322D20731 for ; Mon, 14 Dec 2020 22:38:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7322D20731 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 117D46B0073; Mon, 14 Dec 2020 17:38:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EF7A86B0074; Mon, 14 Dec 2020 17:38:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D218B6B0075; Mon, 14 Dec 2020 17:38:00 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0046.hostedemail.com [216.40.44.46]) by kanga.kvack.org (Postfix) with ESMTP id B157B6B0073 for ; Mon, 14 Dec 2020 17:38:00 -0500 (EST) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 6F004181AEF0B for ; Mon, 14 Dec 2020 22:38:00 +0000 (UTC) X-FDA: 77593351920.29.jail43_02127572741e Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin29.hostedemail.com (Postfix) with ESMTP id 4DE88180868C8 for ; Mon, 14 Dec 2020 22:38:00 +0000 (UTC) X-HE-Tag: jail43_02127572741e X-Filterd-Recvd-Size: 5823 Received: from mail-pg1-f195.google.com (mail-pg1-f195.google.com [209.85.215.195]) by imf28.hostedemail.com (Postfix) with ESMTP for ; Mon, 14 Dec 2020 22:37:59 +0000 (UTC) Received: by mail-pg1-f195.google.com with SMTP id k65so3450995pgk.0 for ; Mon, 14 Dec 2020 14:37:59 -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=w3fRQtpX8VRWJVNuVlihrDSl4Ew2OVDi3uoQ+orHFSM=; b=TUWsLN2EIgkfe9UBwtBIZfE2DYuDAvqDdRMI2Mzue4kMvvvzUiNj6Hple87HPp2G/p m2vn8lIGJ3ccErxvg6+mSJA9OIBTGnlxjN6kAz2Ha+JqXXUyhU6ToD/1s9ggBTx8my9u GDBG3+FZfNKeJlTdz+jGhB9ials3Yak4nSI6MqItr76HUvhNN/v50JsTz7G9COEt0C8Z fRLPSSHRlyYvfdIhxC8cpseF5JQJl/PbjXNlLlCtz45Czf8pup73ukEbKZSEmX/yD+JD NHII5vcveR9S7an5u1MUIetWNpbfHppz2X41tSHAnIv/Y2ezkciJBMStXI6b4xSAf1R0 XaBg== 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=w3fRQtpX8VRWJVNuVlihrDSl4Ew2OVDi3uoQ+orHFSM=; b=twRa0499jkHTqZ2kmZcUhGkG3dG9zyd0/VVNEkEQ07H2S3bzPBaILSL9eC5r4uR8K2 PFE/ssawuCd6on16szvGrEj3hVhIzDbfroil/CjLcD4UTqvwkwmd5oCGeqxcjp97tzw3 va1A7QFy427BOn2q7CTZhJNjL8N2l4rR/IXT0w0n7cMUEBDSZLwFdAbuNARlJ/9qXvBw w2Vm5tvNiwwe/CqroVIATKUB7ai98RUZplOnxN7SbXYSU+2FLnfYCl9Nieq4tzKBByZd /tRNtbfsQcbfWzOooSGALLMd0fj1ziYjEKdb5ijMaUo/+XU7jQ+Qju10DUyxO1OrshnR zbEw== X-Gm-Message-State: AOAM5328sdVluCNeatEvxznPxyRshpVh+TIZwbw0vZf8974OgSkE3urd c2GaTCWeb/05uWvtzmE5i9Q= X-Google-Smtp-Source: ABdhPJy5whBOYsOd14m3qSnV22diJRbUamHDpaAsnC9yQbAgm+Kzx7vaAAYra+01E60AsBNY91361Q== X-Received: by 2002:aa7:85d2:0:b029:1a2:73fe:5c28 with SMTP id z18-20020aa785d20000b02901a273fe5c28mr14313012pfn.40.1607985479060; Mon, 14 Dec 2020 14:37:59 -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 d4sm20610758pfo.127.2020.12.14.14.37.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Dec 2020 14:37:58 -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: [v2 PATCH 8/9] mm: memcontrol: reparent nr_deferred when memcg offline Date: Mon, 14 Dec 2020 14:37:21 -0800 Message-Id: <20201214223722.232537-9-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201214223722.232537-1-shy828301@gmail.com> References: <20201214223722.232537-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 1eac79ce57d4..85cfc910dde4 100644 --- a/include/linux/shrinker.h +++ b/include/linux/shrinker.h @@ -78,6 +78,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_REGISTERED (1 << 0) #define SHRINKER_NUMA_AWARE (1 << 1) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 321d1818ce3d..1f191a15bee1 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -59,6 +59,7 @@ #include #include #include +#include #include "internal.h" #include #include @@ -612,6 +613,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 8d5bfd818acd..693a41e89969 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -201,7 +201,7 @@ 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) {