Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3790107ybt; Tue, 23 Jun 2020 10:45:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwu0s3s6HfXUx8eQ9YHtgfCCt+O24pn049SeqXH+4A4qHVuuYWXcC4tr/Vl8A2x3CiFkwoq X-Received: by 2002:a17:906:abca:: with SMTP id kq10mr20735129ejb.242.1592934334299; Tue, 23 Jun 2020 10:45:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592934334; cv=none; d=google.com; s=arc-20160816; b=z0ZpA+qKMAxVYHBLHtjwEbAZpA4oD48CLVZ0cp9j0XA6Um/R6BDM845RLppIQxIJ4n /3iNszE53/V91YGsZgVf7ywcdA8lOwfZOwMAVkBBlduO+IQNbGJv0KTdxre/X6yerFqD y8myTvtWNh0VY4uVy25T31C0V6kaMThZsR8U59cIqN/6/PeyE97C/4kIWDPB30EeXatW dE4xg5GG9Jd+6yz5huT9mQUgGUy4/wOSzeYkNPgoZ5NHeNE+DNTfaps5pGfZyGBjAaS1 Sx6tEqgGV4GoNXSBkylglrQh5Zzp4kGNPCZTAyRgpu9/fgwyOdGJGjSXAoOD9+k35CxB g2dQ== 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:smtp-origin-cluster :cc:to:smtp-origin-hostname:from:smtp-origin-hostprefix :dkim-signature; bh=JXUspudHQGAsG6wbk4FnMPo8oy0xBT01USd2Q25R2f8=; b=uVJSs6XcbEyxDqLaVUVCjbvi2jnNsH+QABnGep7GKftEWX542th+jHTNuc9galZsTY Mf88DbzC9ZSt9V4hOs2kXkYXIufd3fzZOGnsghWt0eX76joxzgcwT5CvoHKHipMtC/pI nMbHiOnqDMxjgvgYjOhoypZjAx8RBbucxz04riXxZlvC/f7Kdd0+dfEvk2dLaAcqJ9SM qAaQ46gxas1bOXBBHJzhflgvgJSkBPBo9xgNxq3QrAPRDxxHuGspkxxNT4AAtMZvdh8T 3HRZRnkAz+fLg1khbqt5FCfp2CnVvDihhlp9/LFnmpU8yZOjGR/lh5dHAlgfuGZ4uUtk mUXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b="EygI/43M"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fb.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b5si11181808ejk.381.2020.06.23.10.45.11; Tue, 23 Jun 2020 10:45:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=@fb.com header.s=facebook header.b="EygI/43M"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fb.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387861AbgFWRl4 (ORCPT + 99 others); Tue, 23 Jun 2020 13:41:56 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:22582 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387924AbgFWRlE (ORCPT ); Tue, 23 Jun 2020 13:41:04 -0400 Received: from pps.filterd (m0044012.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 05NHf0te010526 for ; Tue, 23 Jun 2020 10:41:04 -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-transfer-encoding : content-type; s=facebook; bh=JXUspudHQGAsG6wbk4FnMPo8oy0xBT01USd2Q25R2f8=; b=EygI/43MNI2vZfC73t/E4aKzBS/bd/rJsZ+FzHt4zpuvQz1lt960V7nf+l2dMUlE/Dg1 xGEPEuN/EaYtu2I6EUeJVPignHDyMzGFEgGwDwXgfntatjhacP1slM7CLZvKupKAMYVT ulMW4pfm5Ckmyb0I9C+EnAuTMbE/R4X4964= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com with ESMTP id 31uk3ch4x4-5 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 23 Jun 2020 10:41:03 -0700 Received: from intmgw003.06.prn3.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::c) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Tue, 23 Jun 2020 10:40:46 -0700 Received: by devvm1291.vll0.facebook.com (Postfix, from userid 111017) id D8986273E5F0; Tue, 23 Jun 2020 10:40:41 -0700 (PDT) Smtp-Origin-Hostprefix: devvm From: Roman Gushchin Smtp-Origin-Hostname: devvm1291.vll0.facebook.com To: Andrew Morton , Christoph Lameter CC: Johannes Weiner , Michal Hocko , Shakeel Butt , , Vlastimil Babka , , , Roman Gushchin Smtp-Origin-Cluster: vll0c01 Subject: [PATCH v7 14/19] mm: memcg/slab: remove memcg_kmem_get_cache() Date: Tue, 23 Jun 2020 10:40:32 -0700 Message-ID: <20200623174037.3951353-15-guro@fb.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200623174037.3951353-1-guro@fb.com> References: <20200623174037.3951353-1-guro@fb.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-FB-Internal: Safe Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216,18.0.687 definitions=2020-06-23_11:2020-06-23,2020-06-23 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 clxscore=1015 impostorscore=0 suspectscore=2 phishscore=0 mlxlogscore=658 priorityscore=1501 mlxscore=0 lowpriorityscore=0 adultscore=0 spamscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006120000 definitions=main-2006230124 X-FB-Internal: deliver Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The memcg_kmem_get_cache() function became really trivial, so let's just inline it into the single call point: memcg_slab_pre_alloc_hook(). It will make the code less bulky and can also help the compiler to generate a better code. Signed-off-by: Roman Gushchin Reviewed-by: Vlastimil Babka Reviewed-by: Shakeel Butt --- include/linux/memcontrol.h | 2 -- mm/memcontrol.c | 25 +------------------------ mm/slab.h | 11 +++++++++-- mm/slab_common.c | 2 +- 4 files changed, 11 insertions(+), 29 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 2ac84dcfc9e5..5a8b62d075e6 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -1403,8 +1403,6 @@ static inline void memcg_set_shrinker_bit(struct me= m_cgroup *memcg, } #endif =20 -struct kmem_cache *memcg_kmem_get_cache(struct kmem_cache *cachep); - #ifdef CONFIG_MEMCG_KMEM int __memcg_kmem_charge(struct mem_cgroup *memcg, gfp_t gfp, unsigned int nr_pages); diff --git a/mm/memcontrol.c b/mm/memcontrol.c index d23c2bdeea66..c910fe326ca6 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -393,7 +393,7 @@ void memcg_put_cache_ids(void) =20 /* * A lot of the calls to the cache allocation functions are expected to = be - * inlined by the compiler. Since the calls to memcg_kmem_get_cache are + * inlined by the compiler. Since the calls to memcg_slab_pre_alloc_hook= () are * conditional to this static branch, we'll have to allow modules that d= oes * kmem_cache_alloc and the such to see this symbol as well */ @@ -2900,29 +2900,6 @@ static void memcg_free_cache_id(int id) ida_simple_remove(&memcg_cache_ida, id); } =20 -/** - * memcg_kmem_get_cache: select memcg or root cache for allocation - * @cachep: the original global kmem cache - * - * Return the kmem_cache we're supposed to use for a slab allocation. - * - * If the cache does not exist yet, if we are the first user of it, we - * create it asynchronously in a workqueue and let the current allocatio= n - * go through with the original cache. - */ -struct kmem_cache *memcg_kmem_get_cache(struct kmem_cache *cachep) -{ - struct kmem_cache *memcg_cachep; - - memcg_cachep =3D READ_ONCE(cachep->memcg_params.memcg_cache); - if (unlikely(!memcg_cachep)) { - queue_work(system_wq, &cachep->memcg_params.work); - return cachep; - } - - return memcg_cachep; -} - /** * __memcg_kmem_charge: charge a number of kernel pages to a memcg * @memcg: memory cgroup to charge diff --git a/mm/slab.h b/mm/slab.h index 66482f8467e7..d47430e97ff1 100644 --- a/mm/slab.h +++ b/mm/slab.h @@ -364,9 +364,16 @@ static inline struct kmem_cache *memcg_slab_pre_allo= c_hook(struct kmem_cache *s, if (memcg_kmem_bypass()) return s; =20 - cachep =3D memcg_kmem_get_cache(s); - if (is_root_cache(cachep)) + cachep =3D READ_ONCE(s->memcg_params.memcg_cache); + if (unlikely(!cachep)) { + /* + * If memcg cache does not exist yet, we schedule it's + * asynchronous creation and let the current allocation + * go through with the root cache. + */ + queue_work(system_wq, &s->memcg_params.work); return s; + } =20 objcg =3D get_obj_cgroup_from_current(); if (!objcg) diff --git a/mm/slab_common.c b/mm/slab_common.c index fe4f5be0e51f..e0a2a904fdd9 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -568,7 +568,7 @@ void memcg_create_kmem_cache(struct kmem_cache *root_= cache) } =20 /* - * Since readers won't lock (see memcg_kmem_get_cache()), we need a + * Since readers won't lock (see memcg_slab_pre_alloc_hook()), we need = a * barrier here to ensure nobody will see the kmem_cache partially * initialized. */ --=20 2.26.2