From patchwork Wed Mar 10 17:46:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12128831 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 4900CC433E0 for ; Wed, 10 Mar 2021 17:46:44 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E934564F48 for ; Wed, 10 Mar 2021 17:46:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E934564F48 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 9171A8D01EB; Wed, 10 Mar 2021 12:46:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8A50B8D01D5; Wed, 10 Mar 2021 12:46:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6F5F48D01EB; Wed, 10 Mar 2021 12:46:41 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0246.hostedemail.com [216.40.44.246]) by kanga.kvack.org (Postfix) with ESMTP id 5677D8D01D5 for ; Wed, 10 Mar 2021 12:46:41 -0500 (EST) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 10A57181AF5C2 for ; Wed, 10 Mar 2021 17:46:41 +0000 (UTC) X-FDA: 77904694602.01.44E77D0 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) by imf12.hostedemail.com (Postfix) with ESMTP id 0D5EA3D6 for ; Wed, 10 Mar 2021 17:46:36 +0000 (UTC) Received: by mail-pf1-f175.google.com with SMTP id x7so9137193pfi.7 for ; Wed, 10 Mar 2021 09:46:40 -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=G7y5azUFXSsyavdHIsaT9AMO5ymd4GoyVzQs6Ax3Mec=; b=s23IbToCEQiW2LfwWgwPLKu/K9irz9puJBxy4pj77zsIN1F4mhp6kFZ0fvAnr8bRW/ nix8GUrtk1m2rNPjffKA5w++RSNotRLG7AMG0xYRpHpPfBFWIUw4cF40Z2oBVIdBfUGA 868+iPgOzhmkwBGjSPjYxsi0LRNDzHWeu72Dqiv+ZVOhlsmhAMYW2MgSvsoUx0am3akz BBQWSKepzU2L5MzrdVv24FZ/ZWf60yQVGJVNFsVXol0aW3SU69apMVL+roJ8a/GFu7A6 rlkKCAnvXOe/sHkc1noaSpLzmzsINLfKBvsYZEASTt4GBr+owzhw8Aj4afFDFZALePnS Qatg== 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=G7y5azUFXSsyavdHIsaT9AMO5ymd4GoyVzQs6Ax3Mec=; b=I6qY0b5ZSq88mfA6sqwitPCTvSFmbInW7cILkyIm3BoiJhE2FndWSHSN5Otq7yixpd NarE1j/s21Losjbr/1FXXNm8biaU71jaIM/ATN6pxF2j5a744EWVdQCn/BwG9QjQkb92 WKf0jCplDJdtPxYp2eIgS14k2+DRPFs+EvLyDOM6wx2WPu4o0cJgnSj7aQhJJHEy756J MlK0uHztcfo0zmcQtHLbSG3C0Gbnc/aBXfRIuc5UkVwL9pZz/jlhCf6qOKgaspYJHMYH 61GdRSCC8WAe+oro+K2yHfEYBpeBIr9FXwIIvq9B/tjz1WQF6T1ZHaa1506bSyfRADCn PM+g== X-Gm-Message-State: AOAM533NLeasja5P4g2YiNnIflHBumMHSimnhbqgzx6DZnM24ihY0Cq/ +mwR+IliDRoe90Gxe33Fc4I= X-Google-Smtp-Source: ABdhPJzvRhb2rWON3l0wObFgGYmePKCSygAJAPGbZZV40nSzwpJc9kOk6TMgIw6aZvx6zbZDlOoUew== X-Received: by 2002:a63:2a16:: with SMTP id q22mr3743667pgq.211.1615398399711; Wed, 10 Mar 2021 09:46:39 -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 d6sm145804pfq.109.2021.03.10.09.46.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 09:46:38 -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: [v9 PATCH 12/13] mm: memcontrol: reparent nr_deferred when memcg offline Date: Wed, 10 Mar 2021 09:46:02 -0800 Message-Id: <20210310174603.5093-13-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210310174603.5093-1-shy828301@gmail.com> References: <20210310174603.5093-1-shy828301@gmail.com> MIME-Version: 1.0 X-Stat-Signature: n4q879u79q6w9icaz9hccwgexip9p4zw X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 0D5EA3D6 Received-SPF: none (gmail.com>: No applicable sender policy available) receiver=imf12; identity=mailfrom; envelope-from=""; helo=mail-pf1-f175.google.com; client-ip=209.85.210.175 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1615398396-135994 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 Reviewed-by: Shakeel Butt Signed-off-by: Yang Shi --- 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 42a4facb5b7c..2c76fe53fb6d 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -1569,6 +1569,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 edd8a06c751f..dacb1c6087ea 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -5262,6 +5262,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 cf25c78661d1..9a2dfeaa79f4 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;