From patchwork Thu Mar 11 19:08:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12132539 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 6A782C433DB for ; Thu, 11 Mar 2021 19:09:31 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0288D64EC0 for ; Thu, 11 Mar 2021 19:09:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0288D64EC0 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 6F0988D02F0; Thu, 11 Mar 2021 14:09:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 677BC8D02B2; Thu, 11 Mar 2021 14:09:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4A4EF8D02F0; Thu, 11 Mar 2021 14:09:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0241.hostedemail.com [216.40.44.241]) by kanga.kvack.org (Postfix) with ESMTP id 20F108D02B2 for ; Thu, 11 Mar 2021 14:09:27 -0500 (EST) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id C682B181AF5CC for ; Thu, 11 Mar 2021 19:09:26 +0000 (UTC) X-FDA: 77908531932.25.EA5BF36 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by imf08.hostedemail.com (Postfix) with ESMTP id D8BC78019140 for ; Thu, 11 Mar 2021 19:09:18 +0000 (UTC) Received: by mail-pl1-f174.google.com with SMTP id n17so7135703plc.7 for ; Thu, 11 Mar 2021 11:09:26 -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=387U6EUXBh7mLus/UDVh51X6DyrD4kEMfbx59TkIzlA=; b=ckPBzV+wjhR0jD6bD3xGl+wIqtfYTy22s8zEq9ESXN0mhXp9+zcVvvHlw3gxtFQPKT HRMXK7vIOLygJ54Uifyobx+ZVSjYyKNy3EUYp7N5A10/cn2ZlqM0x+OH6NI47iSMV4Gk 4oOY5NFCM5rH6st4OXi5JWySRl05hCS+SFhxmvxx5l8B4JLWzDBzbIIbNXgy3SHcEtEE cq7hJO5htnHv3DWlJ4wTfFnmUCijyxR70rjXUGMmOLGtWrctfVpkI9sxv25xJGWaF7O8 gpY+b5g+vtqaSyUqWYe3TJ8T90RfZZDRKBWkwBB3zzBgYF9r0WMGR5MI5AP4mEGB6cxk 03jQ== 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=387U6EUXBh7mLus/UDVh51X6DyrD4kEMfbx59TkIzlA=; b=nDsPtr3fq/VaYX5RtrzPLHQpxSodDlbpsg6k9kOowCxfXxgyUynw9NScxxbgn9Aizj HRvNf6LkoyR5Y0orDTISLAWFXqG7YNGBT+8U7VJ0luj0kE7eFqDG8EAU5lXa4LsGBhjy DiuOFp8TzTLIJH2+jKmlTWnQuhvdq3AL7oizicxYeqfrQkHcnVhUgVk5RYfqqC5PEu6q grSc5GP6EA7LNiRz4dYtG+OKmFuITHhQVzxPzDSDOp/WL5u2vTLXDtxRJYTP+1Fj5aYR sTXAfw34oOlBAHRxQWghTHVKoo99+i+IKEMmW14CkaqIkYCKaZVODMHH/BzeJ5ZJwUoC WmQQ== X-Gm-Message-State: AOAM530PPoRPrK4gSuWGS9KBs6famK5RfUiTje+YknEkBYaAKJQCgj4L sMDs3a7S1h7/opx2IX+u1a0= X-Google-Smtp-Source: ABdhPJyQw3LropgZkq0gCBA33nFDKXoIlKKNSZisQrGtPL1ucO8aoBJm/2M9nRLHLxAcIIw7eGjC5g== X-Received: by 2002:a17:902:d64a:b029:e6:30a6:64e3 with SMTP id y10-20020a170902d64ab02900e630a664e3mr9933203plh.28.1615489765521; Thu, 11 Mar 2021 11:09:25 -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 t12sm2999111pfe.203.2021.03.11.11.09.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Mar 2021 11:09:24 -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: [v10 PATCH 12/13] mm: memcontrol: reparent nr_deferred when memcg offline Date: Thu, 11 Mar 2021 11:08:44 -0800 Message-Id: <20210311190845.9708-13-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210311190845.9708-1-shy828301@gmail.com> References: <20210311190845.9708-1-shy828301@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: D8BC78019140 X-Stat-Signature: yr8zceqa7d1qcjy83oc4soicrt4tpgjf Received-SPF: none (gmail.com>: No applicable sender policy available) receiver=imf08; identity=mailfrom; envelope-from=""; helo=mail-pl1-f174.google.com; client-ip=209.85.214.174 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1615489758-380398 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 Acked-by: Roman Gushchin Reviewed-by: Shakeel Butt 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 24e735434a46..4064c9dda534 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -1537,6 +1537,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 35d44afdd9fc..a945dfc85156 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -5167,6 +5167,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 324c34c6e5cf..d0791ebd6761 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -397,6 +397,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;