From patchwork Tue Feb 9 17:46:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12078687 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 10673C433E6 for ; Tue, 9 Feb 2021 17:47:33 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 94D1864EB8 for ; Tue, 9 Feb 2021 17:47:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 94D1864EB8 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 9E2A86B0073; Tue, 9 Feb 2021 12:47:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 96BC56B0074; Tue, 9 Feb 2021 12:47:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 834408D0001; Tue, 9 Feb 2021 12:47:31 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0035.hostedemail.com [216.40.44.35]) by kanga.kvack.org (Postfix) with ESMTP id 68F4B6B0073 for ; Tue, 9 Feb 2021 12:47:31 -0500 (EST) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 3661A1DF9 for ; Tue, 9 Feb 2021 17:47:31 +0000 (UTC) X-FDA: 77799461502.28.wound49_070f85127609 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin28.hostedemail.com (Postfix) with ESMTP id 10BF5F01D for ; Tue, 9 Feb 2021 17:47:31 +0000 (UTC) X-HE-Tag: wound49_070f85127609 X-Filterd-Recvd-Size: 5726 Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) by imf36.hostedemail.com (Postfix) with ESMTP for ; Tue, 9 Feb 2021 17:47:30 +0000 (UTC) Received: by mail-pg1-f177.google.com with SMTP id z21so12949077pgj.4 for ; Tue, 09 Feb 2021 09:47:30 -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=0vxSQstCm0rFqXMJSzTOrbGMjufuS8TCQJNnJKNC7TU=; b=kWhwJCn2HSplrJKmcFdUT8xE5+TrhsIvBVUakU3FxNw0V+tHRbkhT9QhFviWZpXngw O6YPg2xJbS+4A7+wI4BykkTC/dfls4ro1MyqlcWXEt7q+G83CsFdata9Mmc25DFWYEbi HyIGwQJUnNONeORegAXbOu0pWHI0/jWS0cEEFzSu30Nr0SftX+v2gBHde0oymvzY2Az9 Scfy1oEoB/gGsaxcDcKKiKleTcg1o+YfHeGd2wv/OX/ugFUI9/6xc8cepfppZsLWfj4i 3JsngITGO7n9ZlSdRCLEd6CUuCtvosTId5gZo1cxNtaM82gjTd/dQhC6trwkZerSrsdP 3GWA== 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=0vxSQstCm0rFqXMJSzTOrbGMjufuS8TCQJNnJKNC7TU=; b=supOeA9ygeJ5J4u2PtS7pd59lOB9i4bcoE0iDKXJNEkLjNpWVGAGc1veKquwtoBeBx JxvyV80JStKpeMH1vwAQJhRAtmMMorWWoAQnFPIckzaYRA2tI/pai0Sfy/Esz/NGctpD 7bx7mcJa97eoL+rPu1Daomq7yP4qoXKerOW0p4Gw0bt4e6ogUFnEuBlWBpCG21rkefvs tcw3UL3voURbIYIIuZOTr6V4S0fdnL6HAIdD3RP2DA+zk7Rz6eJ1+Q+xEy1ILS3vrIHh Zuj5ptazzzxWIVawj/B+2EHOOHy6hIDnB8lLDfbng43XO6SkjpY4rzBxoOXwHdgbv/9A vl2w== X-Gm-Message-State: AOAM532RV2UlbRuhImZ0LCRbxqviL2gEelbvVfmUtS/xluKUpGHQUmap zU3Cw8TpxDzuELso737eyaA= X-Google-Smtp-Source: ABdhPJyb1163li3Zilu1BpE4OXhPrvUfIC+orUtZkhePoodhjE4yilOtjb1DQgGcYyBK0qRpqo9ZZw== X-Received: by 2002:a62:b60c:0:b029:1dd:f110:b27d with SMTP id j12-20020a62b60c0000b02901ddf110b27dmr9796973pff.42.1612892849699; Tue, 09 Feb 2021 09:47:29 -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 j1sm22260929pfr.78.2021.02.09.09.47.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Feb 2021 09:47:28 -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: [v7 PATCH 11/12] mm: memcontrol: reparent nr_deferred when memcg offline Date: Tue, 9 Feb 2021 09:46:45 -0800 Message-Id: <20210209174646.1310591-12-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210209174646.1310591-1-shy828301@gmail.com> References: <20210209174646.1310591-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 Signed-off-by: Yang Shi Acked-by: Roman Gushchin --- 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 dfde6e7fd7f5..66163082cc6f 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -389,6 +389,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;