Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp6132382ybi; Tue, 4 Jun 2019 19:47:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqwxFFnzcS82jBZ9ll2OZ1i+MCxZack3/qQnvxZkejQt3qaPH7yE6EH2WK7vLoaoPSuWsX+s X-Received: by 2002:a17:902:42e2:: with SMTP id h89mr38929790pld.271.1559702864706; Tue, 04 Jun 2019 19:47:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559702864; cv=none; d=google.com; s=arc-20160816; b=UWylzuc4FkKiFbXOWiqP3DwvJx064a+yFHSvMLQhW7+Ch2ZFyPtfz7KNrQYr5ez28u bgLMV3vCPA614ggqYsffOOgbmfLocR/q9C5x2LCziNqWVHm2IvoJbvvJDPf/c5pzYLfb Y4NZfHLaLdLR3ND/PRKklRzEsXvaLxgmjvlXLDLAvSC+ZgDE1lJjZ+8JaZHzVtUvQsfy /HOvxG2MSNY851RLCI8FrSvU/anQPTqNfMYcfV4pv0+Q+j1J2xKOsoCROIkQYekShRUj k6ziS/aCsVIHMhc3fJS4r874SCC8NTmmMctXYaiIqYtWnRlT/oanU09YowmNXLa9xLbp 3ssw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:smtp-origin-cluster:cc:to :smtp-origin-hostname:from:smtp-origin-hostprefix:dkim-signature; bh=53XDDT3c53a/gFK121iyd3PvVTI7RPL9leWIgYOSFQQ=; b=YhBDM1cKvqT4jwMechnRh7DgRRM/TSyETIqlgSk6uEa20jAecVvAeG/H2ikIsa9rI+ NTOTnJrQ2r3BJyiUnSxgtD/ksMXsr0Gvz2aEmwq5pZiSrCZ3ZiBIlivUIQxFU6PJYThy XLQC7paDroBUSVb+mRYlWAqQnZlrYAavsQNiaLT3ZqdWXdNAYc5d3ki6FMDJWupX/9Xs 7b8nZzVJZXhN2jUNfLrz9efI+XAMPKuAPMoZ0lL3K6Kt0FGMUd/ciJGk5uB6xfnYYd85 dI370Nh70zdfnazMUkQw+3ys4UE3bt91Mru4Atbag394RnwNnthGCS0lkmDH8HzxNWXS ZZgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=d61Hm7uf; 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=NONE dis=NONE) header.from=fb.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p14si24064610plr.29.2019.06.04.19.47.29; Tue, 04 Jun 2019 19:47:44 -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=@fb.com header.s=facebook header.b=d61Hm7uf; 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=NONE dis=NONE) header.from=fb.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726843AbfFECpl (ORCPT + 99 others); Tue, 4 Jun 2019 22:45:41 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:52836 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726463AbfFECpC (ORCPT ); Tue, 4 Jun 2019 22:45:02 -0400 Received: from pps.filterd (m0001303.ppops.net [127.0.0.1]) by m0001303.ppops.net (8.16.0.27/8.16.0.27) with SMTP id x552ghdL021549 for ; Tue, 4 Jun 2019 19:45:00 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=facebook; bh=53XDDT3c53a/gFK121iyd3PvVTI7RPL9leWIgYOSFQQ=; b=d61Hm7ufr0aAMhFrupy0vRGQZna0IgnPrswvu9MJSbyokT+710j+Ey5+hyHsLCv4RITQ 1vnoO0jPWyaKMilPry7ZQvuhlEOsJ7MzeqtWubdb1RecTe/cLJ/08+dfnvwEBSdxJxzy 5WKIsXeyeQMWhYxhX8IXYs+i5zhhSbsYUlk= Received: from mail.thefacebook.com (mailout.thefacebook.com [199.201.64.23]) by m0001303.ppops.net with ESMTP id 2swycb92fv-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Tue, 04 Jun 2019 19:45:00 -0700 Received: from mx-out.facebook.com (2620:10d:c081:10::13) by mail.thefacebook.com (2620:10d:c081:35::129) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA) id 15.1.1713.5; Tue, 4 Jun 2019 19:44:59 -0700 Received: by devvm2643.prn2.facebook.com (Postfix, from userid 111017) id 7B24512C7FDC4; Tue, 4 Jun 2019 19:44:58 -0700 (PDT) Smtp-Origin-Hostprefix: devvm From: Roman Gushchin Smtp-Origin-Hostname: devvm2643.prn2.facebook.com To: Andrew Morton CC: , , , Johannes Weiner , Shakeel Butt , Vladimir Davydov , Waiman Long , Roman Gushchin Smtp-Origin-Cluster: prn2c23 Subject: [PATCH v6 02/10] mm: postpone kmem_cache memcg pointer initialization to memcg_link_cache() Date: Tue, 4 Jun 2019 19:44:46 -0700 Message-ID: <20190605024454.1393507-3-guro@fb.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190605024454.1393507-1-guro@fb.com> References: <20190605024454.1393507-1-guro@fb.com> X-FB-Internal: Safe MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-06-05_02:,, signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1906050015 X-FB-Internal: deliver 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 Reviewed-by: Shakeel Butt Acked-by: Vladimir Davydov Acked-by: Johannes Weiner --- 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 9e3eee5568b6..a4091f8b3655 100644 --- a/mm/slab.c +++ b/mm/slab.c @@ -1239,7 +1239,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 1176b61bb8fc..c16e5af0fb59 100644 --- a/mm/slab.h +++ b/mm/slab.h @@ -290,7 +290,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 *)); @@ -345,7 +345,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 8092bdfc05d5..77df6029de8e 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); @@ -998,7 +998,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 1802c87799ff..9cb2eef62a37 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -4213,7 +4213,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