From mboxrd@z Thu Jan 1 00:00:00 1970 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=-13.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 8D202C433DB for ; Tue, 2 Feb 2021 08:05:33 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id F41FB64EE4 for ; Tue, 2 Feb 2021 08:05:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F41FB64EE4 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=icloud.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 3DB8C6B006C; Tue, 2 Feb 2021 03:05:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 38A516B0070; Tue, 2 Feb 2021 03:05:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2C7E86B0071; Tue, 2 Feb 2021 03:05:32 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0177.hostedemail.com [216.40.44.177]) by kanga.kvack.org (Postfix) with ESMTP id 16E466B006C for ; Tue, 2 Feb 2021 03:05:32 -0500 (EST) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id D97FE181AEF15 for ; Tue, 2 Feb 2021 08:05:31 +0000 (UTC) X-FDA: 77772593262.24.home09_2d10b98275c9 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin24.hostedemail.com (Postfix) with ESMTP id B6E161A4A0 for ; Tue, 2 Feb 2021 08:05:31 +0000 (UTC) X-HE-Tag: home09_2d10b98275c9 X-Filterd-Recvd-Size: 5710 Received: from pv50p00im-ztbu10021601.me.com (pv50p00im-ztbu10021601.me.com [17.58.6.57]) by imf13.hostedemail.com (Postfix) with ESMTP for ; Tue, 2 Feb 2021 08:05:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1612253129; bh=8NEp9zklRJUsl/PGNITMgJ3PKhwgHZVdrYPjebI/fgY=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=V3ZNeYbWrC+4zHwFHy4bq0cnl1W3OOtHu+4/7o1t9oWtur2KXT19mlh3VZVC/pcYl XW0kKii9CHlYepHFS2esV/G5q3Xwgh6IpS2w+x6bxRSqc11zn9a9ztfa/roOgjv+/E S7J5sai+D+icLeGoVxRSKQFR5QPFWALfTVR8kgxiWATr56rc3lqsx1IAQqDKPbBzAy 19UQ/LCa7L7KWimufwLS60lzJHK6FWFFyOVV+rkzfM6iBCeqvq8Ok8BGh94OhRVcAh RfCsBPRB2PGpI1bklaxg7mlenJodvYhWmsh6U0RzUHgFx2lFL6VXTOiOqK50hnJhgP isn2nVReQOeOg== Received: from localhost.localdomain (unknown [119.3.119.19]) by pv50p00im-ztbu10021601.me.com (Postfix) with ESMTPSA id 3E0BD6E034F; Tue, 2 Feb 2021 08:05:25 +0000 (UTC) From: Abel Wu To: Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Vlastimil Babka Cc: hewenliang4@huawei.com, wuyun.wu@huawei.com, Abel Wu , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH] mm/slub: embed __slab_alloc to its caller Date: Tue, 2 Feb 2021 03:05:14 -0500 Message-Id: <20210202080515.2689-1-abel.w@icloud.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.369,18.0.737 definitions=2021-02-02_04:2021-01-29,2021-02-02 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-2006250000 definitions=main-2102020055 Content-Transfer-Encoding: quoted-printable 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: Since slab_alloc_node() is the only caller of __slab_alloc(), embed __slab_alloc() to its caller to save function call overhead. This will also expand the caller's code block size a bit, but hackbench tests on both host and guest didn't show a difference w/ or w/o this patch. Also rename ___slab_alloc() to __slab_alloc(). Signed-off-by: Abel Wu --- mm/slub.c | 46 ++++++++++++++++------------------------------ 1 file changed, 16 insertions(+), 30 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index 7ecbbbe5bc0c..0f69d2d0471a 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -2654,10 +2654,9 @@ static inline void *get_freelist(struct kmem_cache= *s, struct page *page) * we need to allocate a new slab. This is the slowest path since it inv= olves * a call to the page allocator and the setup of a new slab. * - * Version of __slab_alloc to use when we know that interrupts are - * already disabled (which is the case for bulk allocation). + * Must be called with interrupts disabled. */ -static void *___slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int nod= e, +static void *__slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node= , unsigned long addr, struct kmem_cache_cpu *c) { void *freelist; @@ -2758,31 +2757,6 @@ static void *___slab_alloc(struct kmem_cache *s, g= fp_t gfpflags, int node, return freelist; } =20 -/* - * Another one that disabled interrupt and compensates for possible - * cpu changes by refetching the per cpu area pointer. - */ -static void *__slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node= , - unsigned long addr, struct kmem_cache_cpu *c) -{ - void *p; - unsigned long flags; - - local_irq_save(flags); -#ifdef CONFIG_PREEMPTION - /* - * We may have been preempted and rescheduled on a different - * cpu before disabling interrupts. Need to reload cpu area - * pointer. - */ - c =3D this_cpu_ptr(s->cpu_slab); -#endif - - p =3D ___slab_alloc(s, gfpflags, node, addr, c); - local_irq_restore(flags); - return p; -} - /* * If the object has been wiped upon free, make sure it's fully initiali= zed by * zeroing out freelist pointer. @@ -2854,7 +2828,19 @@ static __always_inline void *slab_alloc_node(struc= t kmem_cache *s, object =3D c->freelist; page =3D c->page; if (unlikely(!object || !page || !node_match(page, node))) { + unsigned long flags; + + local_irq_save(flags); +#ifdef CONFIG_PREEMPTION + /* + * We may have been preempted and rescheduled on a different + * cpu before disabling interrupts. Need to reload cpu area + * pointer. + */ + c =3D this_cpu_ptr(s->cpu_slab); +#endif object =3D __slab_alloc(s, gfpflags, node, addr, c); + local_irq_restore(flags); } else { void *next_object =3D get_freepointer_safe(s, object); =20 @@ -3299,7 +3285,7 @@ int kmem_cache_alloc_bulk(struct kmem_cache *s, gfp= _t flags, size_t size, * We may have removed an object from c->freelist using * the fastpath in the previous iteration; in that case, * c->tid has not been bumped yet. - * Since ___slab_alloc() may reenable interrupts while + * Since __slab_alloc() may reenable interrupts while * allocating memory, we should bump c->tid now. */ c->tid =3D next_tid(c->tid); @@ -3308,7 +3294,7 @@ int kmem_cache_alloc_bulk(struct kmem_cache *s, gfp= _t flags, size_t size, * Invoking slow path likely have side-effect * of re-populating per CPU c->freelist */ - p[i] =3D ___slab_alloc(s, flags, NUMA_NO_NODE, + p[i] =3D __slab_alloc(s, flags, NUMA_NO_NODE, _RET_IP_, c); if (unlikely(!p[i])) goto error; --=20 2.27.0