Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp440417pxb; Tue, 14 Sep 2021 00:34:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy7v6wbaUd020omh/JkgRK4DHOe/qe0lZMbszrgviQVY2NlKdheoRRe77b+HnXfW2hx07Zq X-Received: by 2002:a92:2a10:: with SMTP id r16mr10892142ile.309.1631604896730; Tue, 14 Sep 2021 00:34:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631604896; cv=none; d=google.com; s=arc-20160816; b=XDt+h0KPNH4IoB/KCf4JhbD+CfwM4MR8rh6kFS3TDsWaALb50f49WXcDxFSRsabtLV nXKV+Cdljp1XtTzWaGEluw7mHy5DH4rDLb2zdalRz+01IFgUNMbO4olYITZb3m/3X/Oj JNGsVWC2M6UZkNR5u2Bc17XQGddqBUd7j/G5jwfV1sa7SrH4xczBaLoBgKDZKzb7OP6i IaqKgxWrijZAClbzoZfQPlI/jUDQ5ghxkWG6W7AJONOE6VfhRr9mN6OOcKXHza1YWieG BqIT8rOXB+4TPW8mnV6Dj7msDUWEixswbTE6DyQqXWlI4g7M8WTELK0PyGddgXijm6FI eWdg== 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=i9dWAQT9MnFNTmopLa7uI8hnCzKur7mFh/tgOEsG0ak=; b=OkwuXLk6hj9fBdGMyLHZD8YR3b8E9h+CMy3UkSUlkRDWZJrU7lHfp2o1wyKiY/+NEA Wr/l2r3RSRTKt1ljlkb5CXz4edXbrNpyoHP1+siDk3GSRq+dLwVcx6I2QCL2stmHN37k OHTffOCWVOYSv/grp8CZp3gFNRL0vv20JWFVYo50juXjrrWyiB4h/YiypPsAOjo+k6aq wzpEnYAIFoqmxLcHxWileIvdkBixjXsgfxy0awqErHwkUTcgrKHr3OLsGIw9bd1pRj+Z jSMPtxfcNvUFH4S6TTyo2S07F5Rn57RdbftcJq+QTmImO/VaAdrclNwZayVIXbvYy8TU xThA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=tvtI2oh7; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t44si9437755jal.14.2021.09.14.00.34.45; Tue, 14 Sep 2021 00:34:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-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=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=tvtI2oh7; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240888AbhINHfF (ORCPT + 99 others); Tue, 14 Sep 2021 03:35:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240881AbhINHen (ORCPT ); Tue, 14 Sep 2021 03:34:43 -0400 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 26398C0613E0 for ; Tue, 14 Sep 2021 00:33:24 -0700 (PDT) Received: by mail-pj1-x1034.google.com with SMTP id me5-20020a17090b17c500b0019af76b7bb4so777846pjb.2 for ; Tue, 14 Sep 2021 00:33:24 -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=i9dWAQT9MnFNTmopLa7uI8hnCzKur7mFh/tgOEsG0ak=; b=tvtI2oh7KRqjHCGIC33vHZ0eTeCepMMOZzXUpOe8B0d52bMkBme0jt/iAIH+WSxPrU bmQxXDU5jsRQtJpLnGyCh7yW3S9qM2hCZqV3O4vqTbI16BR8EagQaj5prtkzuF1OLCgQ rSpGZHDgWCEWqYpkz+G07cHTCU35NTg5bhnq73sgywUxy1uC+y4xFqljbevKplx0vCIF 8ewaaJ6a04UMwXac4zqf+HlKhbM7u5HD+IrzirICPUWi3cVzIFEd1tQcvxmSw3M9EAPW qB4HE29noctkhSzKmIGAKTzrJn/qPJIViF3DVha1y4XA0qZ5Cx2vgipV5a+eR5V6n/N8 WzvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=i9dWAQT9MnFNTmopLa7uI8hnCzKur7mFh/tgOEsG0ak=; b=SF/s9b2tAXDIOT7CZM7JDNODcSh8ZMZ22yfVuQl8WYptsybLb6jxg6D+uXrqx/nCfF uxMOUee5mmQxTabg4jWEVG++ylQr3Guh82gQZmk0MMvPHEvnX5v+j/tSl7si87K3KyEg sqlHnRRhBKwemddnGH8DzgnL4XN/U9BrQEB+g2En3ojIaxmHIDj9yN7CKtMJFwinlA6B tUoi5IiTQnZxG5Wp4R31gD/mdgM9UPpe86S0aKWtRh1D+nZRt14Gc9Tcph2gSsC0OPBE GTmeQENc6wO5qitMn4zvEp25mf9dm6vXZazIu/2ddAHrOid1Rhiu1aPuldTBiwQkVOhW OlUg== X-Gm-Message-State: AOAM531kiDdaSPbzAeJfWa8krZMXD2z7A+eWom+94fRoIfw5A/o84n6c 880FZF8YHKsA0JyB0H/uTU0yvg== X-Received: by 2002:a17:90b:2243:: with SMTP id hk3mr507259pjb.203.1631604803701; Tue, 14 Sep 2021 00:33:23 -0700 (PDT) Received: from localhost.localdomain ([139.177.225.244]) by smtp.gmail.com with ESMTPSA id s3sm9377839pfd.188.2021.09.14.00.33.17 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 Sep 2021 00:33:23 -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, smuchun@gmail.com, Muchun Song Subject: [PATCH v3 04/76] mm: memcontrol: move memcg_online_kmem() to mem_cgroup_css_online() Date: Tue, 14 Sep 2021 15:28:26 +0800 Message-Id: <20210914072938.6440-5-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20210914072938.6440-1-songmuchun@bytedance.com> References: <20210914072938.6440-1-songmuchun@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org It will simplify code if moving work of making kmem online to the place where making memcg online. It is unnecessary to set ->kmemcg_id when the kmem is offline, memcg_free_kmem() can go away as well. 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 6844d8b511d8..a85b52968666 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -3610,7 +3610,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) @@ -3639,6 +3640,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; @@ -3646,20 +3650,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) @@ -3669,9 +3664,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, @@ -5183,7 +5175,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(); @@ -5213,33 +5204,26 @@ 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); @@ -5249,6 +5233,11 @@ static int mem_cgroup_css_online(struct cgroup_subsys_state *css) queue_delayed_work(system_unbound_wq, &stats_flush_dwork, 2UL*HZ); 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) @@ -5306,7 +5295,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); } -- 2.11.0