From patchwork Tue Jan 5 22:58:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12000475 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 34D63C433DB for ; Tue, 5 Jan 2021 22:59:09 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D809622EBE for ; Tue, 5 Jan 2021 22:59:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D809622EBE 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 F07488D00C3; Tue, 5 Jan 2021 17:59:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DEC658D006E; Tue, 5 Jan 2021 17:59:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C3DB68D00C3; Tue, 5 Jan 2021 17:59:07 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0020.hostedemail.com [216.40.44.20]) by kanga.kvack.org (Postfix) with ESMTP id A6BCF8D006E for ; Tue, 5 Jan 2021 17:59:07 -0500 (EST) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 7274B180AD817 for ; Tue, 5 Jan 2021 22:59:07 +0000 (UTC) X-FDA: 77673238734.02.side89_1d14ed8274dc Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin02.hostedemail.com (Postfix) with ESMTP id 5A7FB10097AA0 for ; Tue, 5 Jan 2021 22:59:07 +0000 (UTC) X-HE-Tag: side89_1d14ed8274dc X-Filterd-Recvd-Size: 5672 Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) by imf17.hostedemail.com (Postfix) with ESMTP for ; Tue, 5 Jan 2021 22:59:06 +0000 (UTC) Received: by mail-pj1-f43.google.com with SMTP id iq13so548580pjb.3 for ; Tue, 05 Jan 2021 14:59:06 -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=c17ObrP6pIXejl0tN7A+aopaXDPRL2YppDlbMJ0mvSE=; b=tDqzSggaO61nrhp/sqcOfm7bU0V0LMNT0ZsN95jZJivUd9EtqeGXy38BvfNMee/7+l nKG0Y6mRHlVRht0nRcZtH0p5NN9X3Np0GWfBaXkVXG48ooF+N7m4YaTO4AgPbzkQb5vI hOZIaFwnttNdnZhEmmmcfjDXbwmosSgqMdIm6SqYaCTcsDFgcbPD6dR0yvSAwvirVlSm XZJW67Xv3f54G0Vswq+K8BcTjQgKDoo352vC1mVrmkAkeOO90u5dNOW23YkrF1SRd3dO baXzIpqFBhdBU9sqfoP+5dX/5bQPFqy2WxYwMAPN4VepGDH5kzs15Tnq9Jn+P2FPkBj1 GSLQ== 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=c17ObrP6pIXejl0tN7A+aopaXDPRL2YppDlbMJ0mvSE=; b=UbHwRxQUbYvssQ4AY0snVcXKNfbk/5mDZJKMqGdC27AFc7hoiudS6Mtn6mVdIykUKF EDtLW0G5pzEkO/VG5lH27MyBG864y0Go4zuE7Wy/8eURdlIKmls6l7ELjWEI8buo1O3g 4GobOmADBTXrIv1HcaaKNG/8t8BA7wdiZA1vkAkMfMY/DW6lj+o9SIfb/PsP+RvvE/YV CdWruczddGA7bINouKPG+vAzJi2vOjIW38PceO1Cg/30gO9lWF3The1tew+lnN7Mkn1f Imjhg1bmA2/No8jA+Cl4mylX3SH6Qdt8OBJQzloL23WNOS8as72PtfRvmFwXGRWz9iER 35HA== X-Gm-Message-State: AOAM532x6CPkys8S58wzD5x+45TIEa++tXsCE9htlTNs6/md+GXxosKj YPvNua4uVNfa4EM5jNgh1TU= X-Google-Smtp-Source: ABdhPJwM3GKSl7VBuju8WlWtsE8xcxy/o5z2sT9Npe08X1CCSRXQkSoLyg1SdaZVWXQ4a9AcaPU2dA== X-Received: by 2002:a17:90a:454e:: with SMTP id r14mr1377354pjm.194.1609887546032; Tue, 05 Jan 2021 14:59:06 -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 fw12sm244233pjb.43.2021.01.05.14.59.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Jan 2021 14:59:04 -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: [v3 PATCH 10/11] mm: memcontrol: reparent nr_deferred when memcg offline Date: Tue, 5 Jan 2021 14:58:16 -0800 Message-Id: <20210105225817.1036378-11-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210105225817.1036378-1-shy828301@gmail.com> References: <20210105225817.1036378-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 --- include/linux/memcontrol.h | 1 + mm/memcontrol.c | 1 + mm/vmscan.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 5599082df623..d1e52e916cc2 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -1586,6 +1586,7 @@ extern int memcg_alloc_shrinker_info(struct mem_cgroup *memcg); extern void memcg_free_shrinker_info(struct mem_cgroup *memcg); extern void memcg_set_shrinker_bit(struct mem_cgroup *memcg, int nid, int shrinker_id); +extern void memcg_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 126f1fd550c8..19e555675582 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -5284,6 +5284,7 @@ static void mem_cgroup_css_offline(struct cgroup_subsys_state *css) page_counter_set_low(&memcg->memory, 0); memcg_offline_kmem(memcg); + memcg_reparent_shrinker_deferred(memcg); wb_memcg_offline(memcg); drain_all_stock(memcg); diff --git a/mm/vmscan.c b/mm/vmscan.c index d9795fb0f1c5..71056057d26d 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -396,6 +396,35 @@ 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 memcg_reparent_shrinker_deferred(struct mem_cgroup *memcg) +{ + int i, nid; + long nr; + struct mem_cgroup *parent; + struct memcg_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 = rcu_dereference_protected( + memcg->nodeinfo[nid]->shrinker_info, + true); + parent_info = rcu_dereference_protected( + parent->nodeinfo[nid]->shrinker_info, + true); + 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;