From patchwork Wed Jan 27 23:33:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12051227 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 4E5DAC433DB for ; Wed, 27 Jan 2021 23:34:17 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 04E1361601 for ; Wed, 27 Jan 2021 23:34:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 04E1361601 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 A99386B007B; Wed, 27 Jan 2021 18:34:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9D3A16B007D; Wed, 27 Jan 2021 18:34:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 848286B007E; Wed, 27 Jan 2021 18:34:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0244.hostedemail.com [216.40.44.244]) by kanga.kvack.org (Postfix) with ESMTP id 67A7B6B007B for ; Wed, 27 Jan 2021 18:34:15 -0500 (EST) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 302328249980 for ; Wed, 27 Jan 2021 23:34:15 +0000 (UTC) X-FDA: 77753160870.01.spy56_3c066ea2759b Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin01.hostedemail.com (Postfix) with ESMTP id 121C71004D5BA for ; Wed, 27 Jan 2021 23:34:15 +0000 (UTC) X-HE-Tag: spy56_3c066ea2759b X-Filterd-Recvd-Size: 5756 Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) by imf25.hostedemail.com (Postfix) with ESMTP for ; Wed, 27 Jan 2021 23:34:14 +0000 (UTC) Received: by mail-pj1-f49.google.com with SMTP id a20so2434138pjs.1 for ; Wed, 27 Jan 2021 15:34:14 -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=rtMUSqzuW0mmPVrpVmtzg3xeLjYzKxf0vIpZFRWhJNw=; b=IK7YmjHgj3pG2Gx8I4pi5CXEEK/MPNLJUX4VO9Jdoy/OhHpqD4N9Rjybc3tE1VprDL faSkbMaZzSd+bXQJfD4wq3KQ+rS+HR6XRRzQatXUhi3fcnuH786tYm+8LpHKV8oINHnC x3ih9cNljKRSf1cnl7ytq9eMTTqSA14ESeIVH7QMzIXStQxo6pfiI47aUCdph1Trlhc4 udhsPCMwEfjg6Swin7MBa6JurkEsyX3wvV5tlL5oibECFNES/9DjFgfZabm5IWGD8cgp WYU8ECzM6bi9wEzHsAJHbDQ4i9wx/++eUPrBv+6UWIFqhabLqRtMe3seEOYCHAAXBRfr j+Iw== 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=rtMUSqzuW0mmPVrpVmtzg3xeLjYzKxf0vIpZFRWhJNw=; b=DOZ3kDsT1U4EpaWx9NChZMIOhL+6eg3V5wRnbTkiD6gXcwszrT6i4AUsjCDHJQxM71 kPVSVx3vMHQdnx7K476bRa2GXErnNcYct1bJZJ7dvRQcEnvUfSxUL8lwVM4zb00nEbep e5SVF8PZc3+Rj7N/p2T228/O9t3g1/8CE4VsdNp/totuFX42OYpznAZ4GCCN0vMuNlwN 72LftrzghvEA7IflS6FrduG4lBVfwDxyKBvuGYeoQACr773rwl0FF9IK2Q/IeRj9BI4R fAQfV9zn2naCIWe9d1EddkDUcXKpS8a5C4ml7eb3wwaHo6DGVEjOTxmD3pjiV2rV4Hl+ QoNA== X-Gm-Message-State: AOAM5310HllvDIeLxOIlPAx801XiyT48jXTNnzxhSXmGm1fCCeIRkqwk tDEbS8p3TPmS9XulRWQxWzY= X-Google-Smtp-Source: ABdhPJwJbUr7AEV5afH0AkrswES2yI+fQ1dNzepkpXY5WMSGLXOLIFnWa24NcIjMjMn7Ku8CPLOEgA== X-Received: by 2002:a17:90a:7e84:: with SMTP id j4mr2214547pjl.167.1611790453815; Wed, 27 Jan 2021 15:34:13 -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 124sm3498648pfd.59.2021.01.27.15.34.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Jan 2021 15:34:12 -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: [v5 PATCH 10/11] mm: memcontrol: reparent nr_deferred when memcg offline Date: Wed, 27 Jan 2021 15:33:44 -0800 Message-Id: <20210127233345.339910-11-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210127233345.339910-1-shy828301@gmail.com> References: <20210127233345.339910-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 Acked-by: Vlastimil Babka --- include/linux/memcontrol.h | 1 + mm/memcontrol.c | 1 + mm/vmscan.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index e0384367e07d..fe1375f08881 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -1586,6 +1586,7 @@ extern int alloc_shrinker_info(struct mem_cgroup *memcg); extern void free_shrinker_info(struct mem_cgroup *memcg); extern void set_shrinker_bit(struct mem_cgroup *memcg, int nid, int shrinker_id); +extern void reparent_shrinker_deferred(struct mem_cgroup *memcg); #else #define mem_cgroup_sockets_enabled 0 static inline void mem_cgroup_sk_alloc(struct sock *sk) { }; diff --git a/mm/memcontrol.c b/mm/memcontrol.c index f64ad0d044d9..21f36b73f36a 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -5282,6 +5282,7 @@ static void mem_cgroup_css_offline(struct cgroup_subsys_state *css) page_counter_set_low(&memcg->memory, 0); memcg_offline_kmem(memcg); + reparent_shrinker_deferred(memcg); wb_memcg_offline(memcg); drain_all_stock(memcg); diff --git a/mm/vmscan.c b/mm/vmscan.c index 0373d7619d7b..55ad91a26ba3 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -386,6 +386,37 @@ static long set_nr_deferred_memcg(long nr, int nid, struct shrinker *shrinker, return atomic_long_add_return(nr, &info->nr_deferred[shrinker->id]); } +static struct shrinker_info *shrinker_info_protected(struct mem_cgroup *memcg, + int nid) +{ + return rcu_dereference_protected(memcg->nodeinfo[nid]->shrinker_info, + lockdep_is_held(&shrinker_rwsem)); +} + +void reparent_shrinker_deferred(struct mem_cgroup *memcg) +{ + int i, nid; + long nr; + struct mem_cgroup *parent; + struct shrinker_info *child_info, *parent_info; + + parent = parent_mem_cgroup(memcg); + if (!parent) + parent = root_mem_cgroup; + + /* Prevent from concurrent shrinker_info expand */ + down_read(&shrinker_rwsem); + for_each_node(nid) { + child_info = shrinker_info_protected(memcg, nid); + parent_info = shrinker_info_protected(parent, nid); + for (i = 0; i < shrinker_nr_max; i++) { + nr = atomic_long_read(&child_info->nr_deferred[i]); + atomic_long_add(nr, &parent_info->nr_deferred[i]); + } + } + up_read(&shrinker_rwsem); +} + static bool cgroup_reclaim(struct scan_control *sc) { return sc->target_mem_cgroup;