Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4587370yba; Wed, 17 Apr 2019 14:56:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqz/RHjurUt2ScsVdGaNUuRfwR5NCR+fgvI/3JgqUhxE1rb1Yp79eNeXwC+MoEacsXh3ohwA X-Received: by 2002:a17:902:aa5:: with SMTP id 34mr2216617plp.326.1555538180405; Wed, 17 Apr 2019 14:56:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555538180; cv=none; d=google.com; s=arc-20160816; b=JC1Nu7AJIQcz/HJAiJFeACanoGrdRRD7GFP9TFeaTqnz/lef9xNUqnHhFVeBvbKhf+ kSPGJ0hegifDd3ln6vAya29DrHvRQd52W8Dc/PGX47sQJIXdcRi5rZL4vfl1MgfVxkl9 GZzjwI7CJhcOH9mgCMdb5/+fHyTmgK4xBRwCa9nA6Z24vEkYZwsCLUFF7Mlz8tnbZ6Ea 2aE4Re4q2OxHmH/FHuWMv8f57JDKX1WWK1eSMj33UaQS2wiRCD4bcc/xsem3xxdHLj4x cj/VrVz0o+9Kv4nsmQlE86Dw3b4Y9/zAXetN+vctLlI4Rk0AqgvMos+SK+c7l0BfxwjN PK9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=76gfXMG+0uRElSBO/APtur6FtcIZXTee5d1iEwxVGMw=; b=vB/v9LNtWhz2k1Eo+EnFLzcfDioXZz3qXpy4a0hmS1jkIPX0tQ7e+fC7y0CrBQMx1r E5TdFIHaqe0FmmTr9HvJEQE+JPzzuXWOK0/QvtV6oE8e6AA0En26khlawfkwxgwXG6xd LZuJRc8zyfWT965Xn0ciXmJ1wbD6hapMjpG974txT34nhR5ri9DEm/c83dk/AMRXUrhL OguM/rRhFk9uFwgDCy+H1BfuiKi6k8cJnMoGpobxp+tNVyjYRqBliOVxkoj0Q/doq2ak hf7V0F8wEVUYoBZoUMj4dRI16DlDkoq4pVwS59XXUwIvlmJrjhwmC2i14VapR4XSxXB6 pIgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=gdI5EkLP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id r9si26055999pgv.504.2019.04.17.14.56.05; Wed, 17 Apr 2019 14:56:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=gdI5EkLP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S2387568AbfDQVy5 (ORCPT + 99 others); Wed, 17 Apr 2019 17:54:57 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:43394 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387545AbfDQVyz (ORCPT ); Wed, 17 Apr 2019 17:54:55 -0400 Received: by mail-pf1-f195.google.com with SMTP id c8so80645pfd.10; Wed, 17 Apr 2019 14:54:54 -0700 (PDT) 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=76gfXMG+0uRElSBO/APtur6FtcIZXTee5d1iEwxVGMw=; b=gdI5EkLPUs5z6EaRfXGw41UkfBRR+UKMoxX+s1rEhoXw64sOhR8jwzVaL3cG3TWfx5 o5aPe4KIU6ePKtPU2Uu5fTifU2uklWuSHVSrCpusHW4Ri0HIF5z2uMg1J/cR7CmROP0w lb6tUoAsX4j4BS6wtsZ5Qz7ICnhWgHnVqC++hCMJVymGGwketGMErK95ltTSPfj0xEE7 hHE3k6GXHf4IHciGhiSWFeogsipTbMCm3FzroabyrNDzl1aQG1rN+lh5lO0Onwy5spfT R/PejDH+aBhLKbhGoS8FqSORqec0RybvC2TFq3PCOPBGsC6MESABES8Q0QdksuPQbHyT h3UA== 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=76gfXMG+0uRElSBO/APtur6FtcIZXTee5d1iEwxVGMw=; b=hSezVBoAfVT2p5k3kT0Glx7fVtIeJp2Z7CQrev5HFRTBPHnQfhyO4oztXL7yghU1CE ySi02//5p9q8OL3iNMMz/TnJ6lkFEw/74nDj2QcqEkxaAIfOg+5BCtFdbigcLJnxWvGB wDLt3s/DcyZIjwKpKoe9ko9uVBIQC7dAV1b5IqyOHsDiPe18lwWLTZQdgJU9u3Hg/Ilx bwdXA+nJ+s5BzrsGZqvtXSEkgjKAOeyfkWhkSYGhlc9kCV0OWnNCR8bE3HutDvPis9FN h0lGL2pzSqLXRabevP8TZ9KuGmBXfysqk0/j7NC6aOIXI3V5fX06HktWECQDBJLWMR7v w/SA== X-Gm-Message-State: APjAAAWuUsfXPRZ4YZnMLukQbuG2g4JpB21NgPDmWHvuxjqERXwHFAro Esz7+md8SzyrabdJ9rXV8mA= X-Received: by 2002:a62:1f92:: with SMTP id l18mr93491326pfj.180.1555538094660; Wed, 17 Apr 2019 14:54:54 -0700 (PDT) Received: from tower.thefacebook.com ([2620:10d:c090:200::5597]) by smtp.gmail.com with ESMTPSA id x6sm209024pfb.171.2019.04.17.14.54.53 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 17 Apr 2019 14:54:53 -0700 (PDT) From: Roman Gushchin X-Google-Original-From: Roman Gushchin To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@fb.com, Johannes Weiner , Michal Hocko , Rik van Riel , david@fromorbit.com, Christoph Lameter , Pekka Enberg , Vladimir Davydov , cgroups@vger.kernel.org, Roman Gushchin Subject: [PATCH 1/5] mm: postpone kmem_cache memcg pointer initialization to memcg_link_cache() Date: Wed, 17 Apr 2019 14:54:30 -0700 Message-Id: <20190417215434.25897-2-guro@fb.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190417215434.25897-1-guro@fb.com> References: <20190417215434.25897-1-guro@fb.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Initialize kmem_cache->memcg_params.memcg pointer in memcg_link_cache() rather than in init_memcg_params(). Once kmem_cache will hold a reference to the memory cgroup, it will simplify the refcounting. For non-root kmem_caches memcg_link_cache() is always called before the kmem_cache becomes visible to a user, so it's safe. Signed-off-by: Roman Gushchin --- mm/slab.c | 2 +- mm/slab.h | 5 +++-- mm/slab_common.c | 14 +++++++------- mm/slub.c | 2 +- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/mm/slab.c b/mm/slab.c index b1eefe751d2a..57a332f524cf 100644 --- a/mm/slab.c +++ b/mm/slab.c @@ -1268,7 +1268,7 @@ void __init kmem_cache_init(void) nr_node_ids * sizeof(struct kmem_cache_node *), SLAB_HWCACHE_ALIGN, 0, 0); list_add(&kmem_cache->list, &slab_caches); - memcg_link_cache(kmem_cache); + memcg_link_cache(kmem_cache, NULL); slab_state = PARTIAL; /* diff --git a/mm/slab.h b/mm/slab.h index 43ac818b8592..6a562ca72bca 100644 --- a/mm/slab.h +++ b/mm/slab.h @@ -289,7 +289,7 @@ static __always_inline void memcg_uncharge_slab(struct page *page, int order, } extern void slab_init_memcg_params(struct kmem_cache *); -extern void memcg_link_cache(struct kmem_cache *s); +extern void memcg_link_cache(struct kmem_cache *s, struct mem_cgroup *memcg); extern void slab_deactivate_memcg_cache_rcu_sched(struct kmem_cache *s, void (*deact_fn)(struct kmem_cache *)); @@ -344,7 +344,8 @@ static inline void slab_init_memcg_params(struct kmem_cache *s) { } -static inline void memcg_link_cache(struct kmem_cache *s) +static inline void memcg_link_cache(struct kmem_cache *s, + struct mem_cgroup *memcg) { } diff --git a/mm/slab_common.c b/mm/slab_common.c index 58251ba63e4a..6e00bdf8618d 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -140,13 +140,12 @@ void slab_init_memcg_params(struct kmem_cache *s) } static int init_memcg_params(struct kmem_cache *s, - struct mem_cgroup *memcg, struct kmem_cache *root_cache) + struct kmem_cache *root_cache) { struct memcg_cache_array *arr; if (root_cache) { s->memcg_params.root_cache = root_cache; - s->memcg_params.memcg = memcg; INIT_LIST_HEAD(&s->memcg_params.children_node); INIT_LIST_HEAD(&s->memcg_params.kmem_caches_node); return 0; @@ -221,11 +220,12 @@ int memcg_update_all_caches(int num_memcgs) return ret; } -void memcg_link_cache(struct kmem_cache *s) +void memcg_link_cache(struct kmem_cache *s, struct mem_cgroup *memcg) { if (is_root_cache(s)) { list_add(&s->root_caches_node, &slab_root_caches); } else { + s->memcg_params.memcg = memcg; list_add(&s->memcg_params.children_node, &s->memcg_params.root_cache->memcg_params.children); list_add(&s->memcg_params.kmem_caches_node, @@ -244,7 +244,7 @@ static void memcg_unlink_cache(struct kmem_cache *s) } #else static inline int init_memcg_params(struct kmem_cache *s, - struct mem_cgroup *memcg, struct kmem_cache *root_cache) + struct kmem_cache *root_cache) { return 0; } @@ -384,7 +384,7 @@ static struct kmem_cache *create_cache(const char *name, s->useroffset = useroffset; s->usersize = usersize; - err = init_memcg_params(s, memcg, root_cache); + err = init_memcg_params(s, root_cache); if (err) goto out_free_cache; @@ -394,7 +394,7 @@ static struct kmem_cache *create_cache(const char *name, s->refcount = 1; list_add(&s->list, &slab_caches); - memcg_link_cache(s); + memcg_link_cache(s, memcg); out: if (err) return ERR_PTR(err); @@ -997,7 +997,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, create_boot_cache(s, name, size, flags, useroffset, usersize); list_add(&s->list, &slab_caches); - memcg_link_cache(s); + memcg_link_cache(s, NULL); s->refcount = 1; return s; } diff --git a/mm/slub.c b/mm/slub.c index a34fbe1f6ede..2b9244529d76 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -4224,7 +4224,7 @@ static struct kmem_cache * __init bootstrap(struct kmem_cache *static_cache) } slab_init_memcg_params(s); list_add(&s->list, &slab_caches); - memcg_link_cache(s); + memcg_link_cache(s, NULL); return s; } -- 2.20.1