From patchwork Wed Feb 17 00:13:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12090791 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,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 A2609C433E0 for ; Wed, 17 Feb 2021 00:13:57 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 59ED164EB1 for ; Wed, 17 Feb 2021 00:13:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 59ED164EB1 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 F06378D0014; Tue, 16 Feb 2021 19:13:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E93AC8D000D; Tue, 16 Feb 2021 19:13:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D08908D0014; Tue, 16 Feb 2021 19:13:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id B1DCD8D000D for ; Tue, 16 Feb 2021 19:13:56 -0500 (EST) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 797C318024A62 for ; Wed, 17 Feb 2021 00:13:56 +0000 (UTC) X-FDA: 77825836872.16.neck10_5f181a927648 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin16.hostedemail.com (Postfix) with ESMTP id 5ACBA100E6903 for ; Wed, 17 Feb 2021 00:13:56 +0000 (UTC) X-HE-Tag: neck10_5f181a927648 X-Filterd-Recvd-Size: 5765 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) by imf31.hostedemail.com (Postfix) with ESMTP for ; Wed, 17 Feb 2021 00:13:55 +0000 (UTC) Received: by mail-pl1-f171.google.com with SMTP id a24so6403435plm.11 for ; Tue, 16 Feb 2021 16:13:55 -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=GTXH9pU4UKvAeIiKlIuVYFEP3dOyBTmqLQ92jrFsTbY=; b=mhHHzKvtD90ogbwP0/K8kvPhFu2KAfiTc5QtEhGBbxt+Mb7fSTrStvGppXl9QXOypN SazTKsi8EowW96OwiEgtWaPT7e5yo4OKVvZDPgWwdJGdP1nF54Pc3hyQE3Z2J+StOCiV DpwBPNEoeirEHEdNsQdeRdQK2gTbVCCfMfacsfLPU5sT+RKu9nfzi0KUyruFIYrpvTku oYvfRJsDPRILjSZ2xuRO98HNvDdaA45MP5A8mnCt6rvsi56MMfPv3qhkrgQ4qQ2vv5zB QQ9b56NjjLtscCrZeme0cZprSZkmtqXE371xPBETREEtDSwfCwyJaJU72ytMZTJoK6ZI xzgw== 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=GTXH9pU4UKvAeIiKlIuVYFEP3dOyBTmqLQ92jrFsTbY=; b=RBbWjJMiBmNClQoF/itQ3FThDYAtkPNQO8nD+e2CowCuft7m3vf88Dii8G11DuYXrd 0JAzi/6pe1KMXxjd1GaiV0nmDH0Uf4AJm62x1XlP5Ghk5tBIb9YPqjxurNnu5rCYVd9A g5Me3XByIq/cRhMW2kcK1gQOa0q36O34VIvP9Vu6t7nNcey3Jr6NeMc0Eh/qm9FeMRBx fB0Cdic4nLw20MuycjKalbIyZBn9vgvX+0RyVTNEVui87Gc6sYoohl6v4WYdxV6Zuef5 c0oGKOmPFl1y4guFA2/bzhWqJLgsLj/OQNViKHdFaFFc8/JszKp2/eNnvWHhE8rwN04B IE6w== X-Gm-Message-State: AOAM533VkWUclywV/WjabkcdfxMlQ7IHi5Hqw+7NtFSLGY12lbz837JM vtARmDpDGCepWVuGUm3p2Hs= X-Google-Smtp-Source: ABdhPJzjx38X/6z2lktUcBE2x/989ultR6wYHYlPOfUHfDB0TvkaLepuyhOH/fcjg2aO8iUuqVhjUg== X-Received: by 2002:a17:902:ed0d:b029:e3:76d8:79de with SMTP id b13-20020a170902ed0db02900e376d879demr4980227pld.36.1613520835093; Tue, 16 Feb 2021 16:13:55 -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 y12sm99220pjc.56.2021.02.16.16.13.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Feb 2021 16:13:54 -0800 (PST) From: Yang Shi To: guro@fb.com, ktkhai@virtuozzo.com, vbabka@suse.cz, 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: [v8 PATCH 12/13] mm: memcontrol: reparent nr_deferred when memcg offline Date: Tue, 16 Feb 2021 16:13:21 -0800 Message-Id: <20210217001322.2226796-13-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210217001322.2226796-1-shy828301@gmail.com> References: <20210217001322.2226796-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. Acked-by: Vlastimil Babka Acked-by: Kirill Tkhai Acked-by: Roman Gushchin Signed-off-by: Yang Shi Reviewed-by: Shakeel Butt --- include/linux/memcontrol.h | 1 + mm/memcontrol.c | 1 + mm/vmscan.c | 24 ++++++++++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index c457fc7bc631..e1c4b93889ad 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -1585,6 +1585,7 @@ static inline bool mem_cgroup_under_socket_pressure(struct mem_cgroup *memcg) int alloc_shrinker_info(struct mem_cgroup *memcg); void free_shrinker_info(struct mem_cgroup *memcg); void set_shrinker_bit(struct mem_cgroup *memcg, int nid, int shrinker_id); +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 d8800e4da67d..4247a3568585 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -395,6 +395,30 @@ static long add_nr_deferred_memcg(long nr, int nid, struct shrinker *shrinker, return atomic_long_add_return(nr, &info->nr_deferred[shrinker->id]); } +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;