From patchwork Thu Jan 21 23:06:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12037947 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 E17FCC433E6 for ; Thu, 21 Jan 2021 23:07:00 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8A2462389F for ; Thu, 21 Jan 2021 23:07:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8A2462389F 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 28CDF6B0024; Thu, 21 Jan 2021 18:07:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1FB046B0025; Thu, 21 Jan 2021 18:07:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0B8B06B0026; Thu, 21 Jan 2021 18:07:00 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0150.hostedemail.com [216.40.44.150]) by kanga.kvack.org (Postfix) with ESMTP id EB2D26B0024 for ; Thu, 21 Jan 2021 18:06:59 -0500 (EST) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id B6A88180ACF75 for ; Thu, 21 Jan 2021 23:06:59 +0000 (UTC) X-FDA: 77731319358.08.team85_5806e4e27567 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin08.hostedemail.com (Postfix) with ESMTP id 95EDE1819E772 for ; Thu, 21 Jan 2021 23:06:59 +0000 (UTC) X-HE-Tag: team85_5806e4e27567 X-Filterd-Recvd-Size: 5809 Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) by imf16.hostedemail.com (Postfix) with ESMTP for ; Thu, 21 Jan 2021 23:06:59 +0000 (UTC) Received: by mail-pg1-f175.google.com with SMTP id v19so2353008pgj.12 for ; Thu, 21 Jan 2021 15:06:58 -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=ej4Rc46w5k8kBipb90Kqo5kCs6g2nAP16XzJEvULq1o=; b=Wqh1uFbzzPDacscNDMRfxpCDbzIF1XQwIiBMlgS+cV9sRWgHFqXIY9qtEWihLhQ0UB rqh4MQ0yYBJpe//Cml1XSs28/ErMUnnsBpuVAz+B5C6d/hbozV2a8Ktt/oq/hzCPaLlR /la3I+slLzw6pqS7/2XuIna/9MdSxor9BPj6rbidquQPAFtekFSoTkTSLY8L5wscXEIa Kndrh/n/GYE5V9O5aglQOH2T/CPtOGfbNb2wNelQke55C81U/mVos+fGI9rCRVBJDpT2 RbR1iGoRmB+HdfSoTNaKiAOBRiC55td7OKx01KCVRDBEgwhMVH2FxEaO4DWLRJUP+fZ5 lVNA== 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=ej4Rc46w5k8kBipb90Kqo5kCs6g2nAP16XzJEvULq1o=; b=NvrTJ9x+KVbxct3WjK88p/mwFaOc1bQ7XCACa5rJJPd/GBSi73bJ/aMxbObszMmMj4 tEQznncABLsBZeHOiWeRpq/Y9GWAR0uel0YYhBG8/kxsOrIqX9dwvifdIvLje1Ir8+Ed sW3iB8NMb5mlzWnSEZ0rxsTW0itO8Q4nNVPdW1S7kQS7EmZuAMdFNxVjxsSq2gbpmLvb iSLBulsfdzQc+PZPgk67CzZ77cBTuut7Zb2qIH6jfhB0qr2DJd7+A7BSPhiqWSPguHFO jWpT2F0Mjum9YXwk5Zhlx7ApapbtAZDkZQNPlRubmlwqBSYpOlrnfXPiZzaoeP2NFHZ8 lRxQ== X-Gm-Message-State: AOAM530coZZiphYB89NGdJBvUjHNsV0nFcsCOzTVgJ12yIp9/acj8ASq xPA+0qMXUUAADemJQHaykxw= X-Google-Smtp-Source: ABdhPJyNaukOZwbxtacagm3HKlPqsr9jW52mpjA/ls4Ymzr4VY6IHzD1KCGZIgN7gJ/FL+9MOX43Zw== X-Received: by 2002:aa7:8ad0:0:b029:1a9:3a46:78d1 with SMTP id b16-20020aa78ad00000b02901a93a4678d1mr1709495pfd.77.1611270418325; Thu, 21 Jan 2021 15:06:58 -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 y16sm6722921pfb.83.2021.01.21.15.06.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jan 2021 15:06:57 -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: [v4 PATCH 10/11] mm: memcontrol: reparent nr_deferred when memcg offline Date: Thu, 21 Jan 2021 15:06:20 -0800 Message-Id: <20210121230621.654304-11-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210121230621.654304-1-shy828301@gmail.com> References: <20210121230621.654304-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 | 31 +++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index e0384367e07d..fe1375f08881 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -1586,6 +1586,7 @@ extern int alloc_shrinker_info(struct mem_cgroup *memcg); extern void free_shrinker_info(struct mem_cgroup *memcg); extern void set_shrinker_bit(struct mem_cgroup *memcg, int nid, int shrinker_id); +extern 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 65d9eb0215b5..cccf2bacb147 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); + reparent_shrinker_deferred(memcg); wb_memcg_offline(memcg); drain_all_stock(memcg); diff --git a/mm/vmscan.c b/mm/vmscan.c index ea1402e7b968..e73f200ffd2d 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -383,6 +383,37 @@ static long set_nr_deferred_memcg(long nr, int nid, struct shrinker *shrinker, return atomic_long_add_return(nr, &info->nr_deferred[shrinker->id]); } +static struct shrinker_info *shrinker_info_protected(struct mem_cgroup *memcg, + int nid) +{ + return rcu_dereference_protected(memcg->nodeinfo[nid]->shrinker_info, + lockdep_is_held(&shrinker_rwsem)); +} + +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;