From patchwork Thu May 27 06:21:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 12283475 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=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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 1D0A7C47089 for ; Thu, 27 May 2021 06:24:46 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A7FBD6135F for ; Thu, 27 May 2021 06:24:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A7FBD6135F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 4DB966B0072; Thu, 27 May 2021 02:24:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4B3B96B0073; Thu, 27 May 2021 02:24:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 353298D0001; Thu, 27 May 2021 02:24:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0163.hostedemail.com [216.40.44.163]) by kanga.kvack.org (Postfix) with ESMTP id 003666B0072 for ; Thu, 27 May 2021 02:24:44 -0400 (EDT) Received: from smtpin33.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 9328F180ACEEB for ; Thu, 27 May 2021 06:24:44 +0000 (UTC) X-FDA: 78186022488.33.D3FDEFC Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) by imf06.hostedemail.com (Postfix) with ESMTP id D8BB7C0007CB for ; Thu, 27 May 2021 06:24:36 +0000 (UTC) Received: by mail-pj1-f54.google.com with SMTP id g24so2145792pji.4 for ; Wed, 26 May 2021 23:24:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=69t5JvkMUpa4S3zHMzIPphToxILDMFyOxSV05k21NRo=; b=HKrLitcBnnklOOWAEzdjePdIbJuUgcw2SjWSInye4lqApH/rU0YcYtdFyq/JhyyFoG Su+eQeNmI0dL5rm6AjU4TNwh7Cg/2BG2fW/54JrJNPMdw0DSbUCF98FyR6DMchWC742O YEbNH8cBvRolyAvZ7fPJm3xEFzSKD6S7nZZ4chf7nnrx5f7Oj4yoKFFVxp2noXxKTiQr 04fVYRoe8f/H88BRNeu84IxYynvj3YflDbnQIR7hks2nJU1fXSZCf7AuwIkfagDooa/9 7JXKTpGfB0m4oKQFs/dL4v6rMwUMkavZlMi5+jXC+PVmOxDWraZ5CiqdbxoSm2TH5bgw YSyA== 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=69t5JvkMUpa4S3zHMzIPphToxILDMFyOxSV05k21NRo=; b=Nm8263XyqO1fluiMiJVtvN5hy6T2gliOcgFn96AOXT0EV1A6fqHKycrsUUn7oURFd6 QKm/zrPR+HFa29AlzmeBJR7DW6md04iaZUUQTGWoUWsNg/P6Zwp7FujALMs+rF+iFZyl X+/oHTtBvNz/MpPN73JZPSnXxlykPuMNFrnhnF3Eqfoln7giqT6edkRVfzIPeHU5W7Qo kOqsu0OtS4qW+xA2rbsipOVHWtuqc50iiBz5aJAqMKtMR2PBBHfOwe2sYR1eVztfwUUr MXkrb+HLxJ9pUboxvuaYYtmu6qPtmLhyn71FtJlowv5v2Dtpxu5xaENEwymAMa3zWdDa hA8w== X-Gm-Message-State: AOAM532P9AU1i/2+doXjChb0ue1cU4Z5YYmoiEXWZjXKSMc1DrGc6B+9 ZR35TmfLqv/TYitctp047wt7sA== X-Google-Smtp-Source: ABdhPJxmvTKJ6I8q166ESGz1b/+UAvPTvctOrfMJF1LBcEehrkaOaWTcdudYGcw9acZPesyY84UDFw== X-Received: by 2002:a17:902:db0f:b029:f3:e5f4:87f1 with SMTP id m15-20020a170902db0fb02900f3e5f487f1mr1856086plx.26.1622096683363; Wed, 26 May 2021 23:24:43 -0700 (PDT) Received: from localhost.localdomain ([139.177.225.254]) by smtp.gmail.com with ESMTPSA id m5sm882971pgl.75.2021.05.26.23.24.36 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 26 May 2021 23:24:43 -0700 (PDT) From: Muchun Song To: willy@infradead.org, akpm@linux-foundation.org, hannes@cmpxchg.org, mhocko@kernel.org, vdavydov.dev@gmail.com, shakeelb@google.com, guro@fb.com, shy828301@gmail.com, alexs@kernel.org, richard.weiyang@gmail.com, david@fromorbit.com, trond.myklebust@hammerspace.com, anna.schumaker@netapp.com Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-nfs@vger.kernel.org, zhengqi.arch@bytedance.com, duanxiongchun@bytedance.com, fam.zheng@bytedance.com, Muchun Song Subject: [PATCH v2 04/21] mm: memcontrol: do it in mem_cgroup_css_online to make the kmem online Date: Thu, 27 May 2021 14:21:31 +0800 Message-Id: <20210527062148.9361-5-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20210527062148.9361-1-songmuchun@bytedance.com> References: <20210527062148.9361-1-songmuchun@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: D8BB7C0007CB Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=HKrLitcB; dmarc=pass (policy=none) header.from=bytedance.com; spf=pass (imf06.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.216.54 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com X-Rspamd-Server: rspam03 X-Stat-Signature: pwyix1wu7crrtqdcsg9ga71nb8xtc5cs X-HE-Tag: 1622096676-337432 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: If we do it in the mem_cgroup_css_online() to make the kmem online, we do not need to set ->kmemcg_id when the kmem is offline. And we also can remove memcg_free_kmem(). So just do that to simplify the code. Signed-off-by: Muchun Song --- mm/memcontrol.c | 42 +++++++++++++++--------------------------- 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 23a9fc8dc143..377ec9847179 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -3629,7 +3629,8 @@ static int memcg_online_kmem(struct mem_cgroup *memcg) if (cgroup_memory_nokmem) return 0; - BUG_ON(memcg->kmemcg_id >= 0); + if (unlikely(mem_cgroup_is_root(memcg))) + return 0; memcg_id = memcg_alloc_cache_id(); if (memcg_id < 0) @@ -3658,6 +3659,9 @@ static void memcg_offline_kmem(struct mem_cgroup *memcg) if (cgroup_memory_nokmem) return; + if (unlikely(mem_cgroup_is_root(memcg))) + return; + parent = parent_mem_cgroup(memcg); if (!parent) parent = root_mem_cgroup; @@ -3665,20 +3669,11 @@ static void memcg_offline_kmem(struct mem_cgroup *memcg) memcg_reparent_objcgs(memcg, parent); kmemcg_id = memcg->kmemcg_id; - BUG_ON(kmemcg_id < 0); /* memcg_reparent_objcgs() must be called before this. */ memcg_drain_all_list_lrus(kmemcg_id, parent); memcg_free_cache_id(kmemcg_id); - memcg->kmemcg_id = -1; -} - -static void memcg_free_kmem(struct mem_cgroup *memcg) -{ - /* css_alloc() failed, offlining didn't happen */ - if (unlikely(memcg->kmemcg_id != -1)) - memcg_offline_kmem(memcg); } #else static int memcg_online_kmem(struct mem_cgroup *memcg) @@ -3688,9 +3683,6 @@ static int memcg_online_kmem(struct mem_cgroup *memcg) static void memcg_offline_kmem(struct mem_cgroup *memcg) { } -static void memcg_free_kmem(struct mem_cgroup *memcg) -{ -} #endif /* CONFIG_MEMCG_KMEM */ static int memcg_update_kmem_max(struct mem_cgroup *memcg, @@ -5219,7 +5211,6 @@ mem_cgroup_css_alloc(struct cgroup_subsys_state *parent_css) { struct mem_cgroup *parent = mem_cgroup_from_css(parent_css); struct mem_cgroup *memcg, *old_memcg; - long error = -ENOMEM; old_memcg = set_active_memcg(parent); memcg = mem_cgroup_alloc(); @@ -5249,38 +5240,36 @@ mem_cgroup_css_alloc(struct cgroup_subsys_state *parent_css) } /* The following stuff does not apply to the root */ - error = memcg_online_kmem(memcg); - if (error) - goto fail; - if (cgroup_subsys_on_dfl(memory_cgrp_subsys) && !cgroup_memory_nosocket) static_branch_inc(&memcg_sockets_enabled_key); return &memcg->css; -fail: - mem_cgroup_id_remove(memcg); - mem_cgroup_free(memcg); - return ERR_PTR(error); } static int mem_cgroup_css_online(struct cgroup_subsys_state *css) { struct mem_cgroup *memcg = mem_cgroup_from_css(css); + if (memcg_online_kmem(memcg)) + goto remove_id; + /* * A memcg must be visible for expand_shrinker_info() * by the time the maps are allocated. So, we allocate maps * here, when for_each_mem_cgroup() can't skip it. */ - if (alloc_shrinker_info(memcg)) { - mem_cgroup_id_remove(memcg); - return -ENOMEM; - } + if (alloc_shrinker_info(memcg)) + goto offline_kmem; /* Online state pins memcg ID, memcg ID pins CSS */ refcount_set(&memcg->id.ref, 1); css_get(css); return 0; +offline_kmem: + memcg_offline_kmem(memcg); +remove_id: + mem_cgroup_id_remove(memcg); + return -ENOMEM; } static void mem_cgroup_css_offline(struct cgroup_subsys_state *css) @@ -5338,7 +5327,6 @@ static void mem_cgroup_css_free(struct cgroup_subsys_state *css) cancel_work_sync(&memcg->high_work); mem_cgroup_remove_from_trees(memcg); free_shrinker_info(memcg); - memcg_free_kmem(memcg); mem_cgroup_free(memcg); }