Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp6094942pxb; Tue, 16 Feb 2021 16:20:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJyTgxvo8GBP7nDDncgwzyB/qw1tSkXn1RdO2PB6kA/Lm0QhghnUfKAvxEGFI1Xt7QzLbqys X-Received: by 2002:a17:907:b08:: with SMTP id h8mr4244995ejl.165.1613521220192; Tue, 16 Feb 2021 16:20:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613521220; cv=none; d=google.com; s=arc-20160816; b=tkdlCKGUAm31CSCaPfGNF+9pGnH3GxuJCoGKiKJNEmKt0nkQ1lbMxoM7MV+bSsb5KU JLASA/PT7N2JdkC1XYCR5V6VYliPVAYZSjiuxT1CkRjx48/INXO8MmR+J+1CeBiOIL5L u4OzAbE8Tqn4Vzplqk//LmYr9SvDOjxPr82migN0dF7sFzhQq/nPK5yTvORwcNGzhXSd P582GCd2WfEwx/RLkZXUAS9uknvgx2EVQuGWd4Ktcel2FytTuCg4HnD+iaDeSKl54tyy LHgAOPgZPEOWieQIHbJbBS5Hd7veAcbVZBu6hR8wut56B2fRiYHDreBxAhL7M7vzS7x9 yPTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=GTXH9pU4UKvAeIiKlIuVYFEP3dOyBTmqLQ92jrFsTbY=; b=YCvZlJ2lgwgMQPEghFUYflCIAI1BvMF6Kort5oMtx3czFZvIkVg7+N5vTBm8RqpFJE OqTmst1jgzKSMYh+o+FZslrhO+Ks1Okgg539JRmX+Tug/OfDeU2FColHNIe9W2/tn6W8 G5YH22zVY5Zgr2+nTxOe2N4haI32XzDrnwcOonGipGf9T1KSs3CjY2JZbsndvNKIQUsW NdABrG8E/FZLO2DOgTgIOqyg3IjYcdfEbDuvk0/KG7jFVx+kMSLH/KDPTRzyY/ZJ5Z7Y yddR6mi7i5UmKMsjIfzosidj1j0hE3uVJY6gieufxDE6J3uZQFuqJPE57Gs5pjH93bPF 3Lfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=mhHHzKvt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q16si376439ejc.424.2021.02.16.16.19.56; Tue, 16 Feb 2021 16:20:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=mhHHzKvt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231476AbhBQAS7 (ORCPT + 99 others); Tue, 16 Feb 2021 19:18:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231406AbhBQAPL (ORCPT ); Tue, 16 Feb 2021 19:15:11 -0500 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 757ABC0617A9; Tue, 16 Feb 2021 16:13:55 -0800 (PST) Received: by mail-pj1-x1034.google.com with SMTP id c19so356510pjq.3; 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=GMHq38fmcAPvjQg4VnWAxXNLjhTBDqdXvAiusXljHzV3wyxE6rE1d1s66aEYG9m/Qm XSshT394xlo8ZQNkxo5/bgbGafnkpVymK8auhPwZSqbyrpV+CrtGZJjXGxRh/P3chLHP PfnAlqmN4q9Lc+P+AdxODpGrwRAvpWDRNedIOTJrbzCLhdgVGKU3bb+MXFrC8XnNk5yc zL7965F5Rn0ciP1HN/FOLoCSF/tpIeCzbUvtynsaBD6M8hcrM6nsWjaIekEoDhYY1M3K qnijVv23DXpuBTSFbdrZl2+qSSawrc/Xk9YSqyU9STgV+Kd7r1qgdgegiH2UmegX2GrT RoLA== X-Gm-Message-State: AOAM531FKd9jlcrd51wj9klqbTvtGBXi6C9w+LTvIgNbNrJ5T+UERL1E aq72DG7/jBGs9WLN7IfpB9Q= 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 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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; -- 2.26.2