From patchwork Wed Feb 3 17:20:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12064899 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 38EE0C433DB for ; Wed, 3 Feb 2021 17:21:34 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D56AD64DDB for ; Wed, 3 Feb 2021 17:21:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D56AD64DDB 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 6443A6B007B; Wed, 3 Feb 2021 12:21:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5D0836B007D; Wed, 3 Feb 2021 12:21:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 46EDB6B007E; Wed, 3 Feb 2021 12:21:33 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0226.hostedemail.com [216.40.44.226]) by kanga.kvack.org (Postfix) with ESMTP id 309786B007B for ; Wed, 3 Feb 2021 12:21:33 -0500 (EST) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id E93E1180AD81F for ; Wed, 3 Feb 2021 17:21:32 +0000 (UTC) X-FDA: 77777623224.18.fly80_3912560275d5 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin18.hostedemail.com (Postfix) with ESMTP id BA6D3100ED3B2 for ; Wed, 3 Feb 2021 17:21:32 +0000 (UTC) X-HE-Tag: fly80_3912560275d5 X-Filterd-Recvd-Size: 5675 Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) by imf02.hostedemail.com (Postfix) with ESMTP for ; Wed, 3 Feb 2021 17:21:32 +0000 (UTC) Received: by mail-pg1-f169.google.com with SMTP id s23so162083pgh.11 for ; Wed, 03 Feb 2021 09:21:32 -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=nUMzA/3BdE993wfDsCQXdvkjPYfyPVaNNJORKwDz80c=; b=LfePu6UejxvQdOh2GoD/fAj3ONicQbkZc2mxXNU+hyyYQdjy+n01l4dwHIL3TDJNHO AdoGTQBnvO8yWixQGBdGasySYE0ZZ3RDXxzE7Mej7z0noxcd+JARknsNgIQnql7xvO85 VH6SJ/HLz90ywXZizbp/ooQSNn+GF27tDVTEhVwcPnwp6a3CuVS8QdSPFULH10IXLefO BxNVxluFNk8His5xm6J3gzqJQ9Uw+kheGFOarhrreg5auDg37mVW2H7ahS4n5W8J8N/E mspkFr/a4UqQxVP+K2DmWtfNLKcri14wm/mD+aAZPFOZDWMO28TObbEeRckub47dLOJF W2Ag== 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=nUMzA/3BdE993wfDsCQXdvkjPYfyPVaNNJORKwDz80c=; b=LtOnEFXjpiTmM1xDLAi4sSd66G38j6UeMIQydV720FpKraLCjcTP0izZN0yLQEVpS7 rRg7flevBQs2l92tDxE0rwCNO16OPAAozIgIMzrwjrpVkJbw7ND6AxcuGiP9iTS1nqhk 9RhTgKAvlWRTGGjjoR+M3xxi7dmDu4mCDe49BflvS1x2h9I68KG48kainEb+a/0jRmPK WyJiEv8NF5Jd+lEwjbPRzWZAk/gBTK1CrcgHBOSFGPWS4jZmKK4YA0D+aH62XYdpsMvq 5LaGq4s2YI3Qfjdn8gKCzIy6ttuVgWrB5LmZcnjR/Vjm652VNubCiCHNN1smnWqD5aaF ZoTw== X-Gm-Message-State: AOAM532uWFP2My9xr2vDXi/5432bgcIkkyugdekNRzBU03zNS0HVrB/7 yqVaereAv4j9CTriRV47yLc= X-Google-Smtp-Source: ABdhPJxZ85kIgUNuaFI1hCRoW+MvELqUQ5WPGXjcXFhMMHfHj4lg+FZdDFrWcWpXQWIVRJnKqH+SuQ== X-Received: by 2002:aa7:8881:0:b029:1b4:5b52:b00b with SMTP id z1-20020aa788810000b02901b45b52b00bmr4015162pfe.47.1612372891539; Wed, 03 Feb 2021 09:21:31 -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 x21sm2368636pfn.100.2021.02.03.09.21.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Feb 2021 09:21:30 -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: [v6 PATCH 10/11] mm: memcontrol: reparent nr_deferred when memcg offline Date: Wed, 3 Feb 2021 09:20:41 -0800 Message-Id: <20210203172042.800474-11-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210203172042.800474-1-shy828301@gmail.com> References: <20210203172042.800474-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 Signed-off-by: Yang Shi Acked-by: Kirill Tkhai --- 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 20a35d26ae12..574d920c4cab 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -386,6 +386,30 @@ static long set_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;