Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3044973pxp; Tue, 8 Mar 2022 06:48:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJxVcaq//+ky/yII4jNV09AhjUFjDB5tfM1NE3NWQbl73yurKWhkpJaBqSOQBKmDE+58Ujvh X-Received: by 2002:a63:7502:0:b0:37f:f089:7d56 with SMTP id q2-20020a637502000000b0037ff0897d56mr14314521pgc.531.1646750918241; Tue, 08 Mar 2022 06:48:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646750918; cv=none; d=google.com; s=arc-20160816; b=H1GtCiI6tFy9eulffFBVG0EAmXzWufseb3r3ZjpnH1leVwiLkqc6SUtr9RxXV7EaNR pBdUt2NoPirT8J5u4Yx3jT7w0mUffVU8Va04gEiasS0yHSLBgyx1SQdIAySVkZ3l9jCd w0XJLC8f5EgTIU+GF0sQexQVeQX0UuwwNXQe4/lYxW1oz+gglRVjgLMQHcybiTLoDGWO sJQV2ek65vbuHiaFBPpz2ZGLOjGFyW+n5whw+5NXIhgMwDoER7SnaNbixzHB736cDsVg PBuugFnvoDxLIJW1Dz//tChW3uZKFtKweS42Jn9p+RXWVU3vKImQuZss5fzWVrlhUKrB tlTQ== 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=WyJUzAbm9yHjJ4QKSKKsRPqOaZ/q3Aw9wGC8avt4y3A=; b=xj2OghttX5SYOalGn06thdRiz2OUZi5pkPnTH50/2R69G84TrxxK6Qi/S6qa8AoB92 WISBOR2S3mnfmxfloOFgek01c+Z6qBAv6nyVWHzXRGmREuROztu18Gbu0XHJtHmSTozn XN2zPy/RBIz9zKfX79dz2L8JYEDYB8lfyF1rSCE7tyCZ3hM2MnG1jobIAqMkTQ+HB0nq JX1R2Ca7+FTGJIGV3je8NeXUmr+oRKbJdOMkuwp8MyDJJpn+Rn821eTLeXm0LZQSNn4M S1u9md5wx0WOWFaDf9DB21qjckmLcd3RBbDfyijOF0kUF7ArHb+A3cqGIruS3iaIwrbw 4jcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=SPOB2Is9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b21-20020a170902d41500b00151838059adsi13819157ple.480.2022.03.08.06.48.14; Tue, 08 Mar 2022 06:48:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=SPOB2Is9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S1346560AbiCHLoE (ORCPT + 99 others); Tue, 8 Mar 2022 06:44:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346583AbiCHLnv (ORCPT ); Tue, 8 Mar 2022 06:43:51 -0500 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6DC4CDF06 for ; Tue, 8 Mar 2022 03:42:43 -0800 (PST) Received: by mail-pj1-x1036.google.com with SMTP id k92so7800582pjh.5 for ; Tue, 08 Mar 2022 03:42:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WyJUzAbm9yHjJ4QKSKKsRPqOaZ/q3Aw9wGC8avt4y3A=; b=SPOB2Is9v5XHsx3KQKzQnq3I+g7W8LG2kR7QM7TXpvg7Yy/WQuHZEsBvJVobSOf7TL S0Y5M5vqJcfdS51VXiGAzQe5WwhM5NXOmkw5bdY5Q5WSxRN4ffqzxXZnkMpWzqC0nsGC pQKd/G9pyhqk62HNgFxlL3PPLu7a4u7RKHj6qguBWeNrl81xQHwFBaXc4YcGDx74fQ6H /EQeI77O1+2AC+zZFbojMcQ+ZmaVDV00jrpTjS7YIaHHMzUUkSb1zVu9+gaXwFZ2+jW0 ZYZooIb73Psyq0sG1WsaQl+lPMt4gf+lSMEp5zDZXy+VfkO2Jr+iNY9O2vezybOEWf6O wwtQ== 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=WyJUzAbm9yHjJ4QKSKKsRPqOaZ/q3Aw9wGC8avt4y3A=; b=j28bD6tILI+DBjS1g7TQfKc8UbWZ/3qYckA7q7ouzVvsFhkG0/QWgTSHvH+5tytaei o1oWGq0JyckD0D54zaH02qDt8qFr+cZEPfzK2ppvON4v+AWlLFJ9T3/1GuBxmY3bFGeD 40yhxWinP4HBmrbrq8Oz34bbHb/7BZgZUX87l27gSjDP5RcfFsq8jsZW1U8nKguTGLZn re3DUSSsrOt8ipD16v9mrrwMPovqNtT6J9IGjoKnmMbMRgJoZWUcPCKBxDgbcdXsoINS yJugPtTnzyfALfw9XpifBj89+g3qERJIcysP2LoEImny2N7HTLRxHl5Cd7icpyA+/lUH pcWQ== X-Gm-Message-State: AOAM532+oqU+BJJytVLa2ucItceAFOEfDuFP09gtnd3AGLDpTCq5jLCb VWX60YVILaueEcC4E8baV0k= X-Received: by 2002:a17:902:7298:b0:151:842b:a241 with SMTP id d24-20020a170902729800b00151842ba241mr16959617pll.115.1646739762983; Tue, 08 Mar 2022 03:42:42 -0800 (PST) Received: from ip-172-31-19-208.ap-northeast-1.compute.internal (ec2-18-181-137-102.ap-northeast-1.compute.amazonaws.com. [18.181.137.102]) by smtp.gmail.com with ESMTPSA id i2-20020a17090ac40200b001bd0e552d27sm2578285pjt.11.2022.03.08.03.42.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 03:42:42 -0800 (PST) From: Hyeonggon Yoo <42.hyeyoo@gmail.com> To: linux-mm@kvack.org Cc: Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Vlastimil Babka , Marco Elver , Matthew WilCox , Roman Gushchin , linux-kernel@vger.kernel.org, 42.hyeyoo@gmail.com Subject: [RFC PATCH v1 08/15] mm/sl[auo]b: cleanup kmalloc() Date: Tue, 8 Mar 2022 11:41:35 +0000 Message-Id: <20220308114142.1744229-9-42.hyeyoo@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220308114142.1744229-1-42.hyeyoo@gmail.com> References: <20220308114142.1744229-1-42.hyeyoo@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HK_RANDOM_ENVFROM, HK_RANDOM_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Now that kmalloc() and kmalloc_node() do same job, make kmalloc() wrapper of kmalloc_node(). Remove kmalloc_trace() that is now unused. This patch makes slab allocator use kmalloc_node tracepoints in kmalloc(). Signed-off-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> --- include/linux/slab.h | 82 +++++++++++++++++--------------------------- mm/slab.c | 14 -------- mm/slub.c | 9 ----- 3 files changed, 31 insertions(+), 74 deletions(-) diff --git a/include/linux/slab.h b/include/linux/slab.h index 33d4260bce8b..dfcc8301d969 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -460,9 +460,6 @@ static __always_inline void kfree_bulk(size_t size, void **p) kmem_cache_free_bulk(NULL, size, p); } -extern void *kmem_cache_alloc_trace(struct kmem_cache *s, gfp_t flags, size_t size) - __assume_slab_alignment __alloc_size(3); - extern void *kmem_cache_alloc_node_trace(struct kmem_cache *s, gfp_t gfpflags, int node, size_t size) __assume_slab_alignment __alloc_size(4); @@ -475,6 +472,36 @@ static __always_inline void *kmalloc_large(size_t size, gfp_t flags) return kmalloc_large_node(size, flags, NUMA_NO_NODE); } +#ifndef CONFIG_SLOB +static __always_inline __alloc_size(1) void *kmalloc_node(size_t size, gfp_t flags, int node) +{ + if (__builtin_constant_p(size)) { + unsigned int index; + + if (size > KMALLOC_MAX_CACHE_SIZE) + return kmalloc_large(size, flags); + + index = kmalloc_index(size); + + if (!index) + return ZERO_SIZE_PTR; + + return kmem_cache_alloc_node_trace( + kmalloc_caches[kmalloc_type(flags)][index], + flags, node, size); + } + return __kmalloc_node(size, flags, node); +} +#else +static __always_inline __alloc_size(1) void *kmalloc_node(size_t size, gfp_t flags, int node) +{ + if (__builtin_constant_p(size) && size > KMALLOC_MAX_CACHE_SIZE) + return kmalloc_large(size, flags); + + return __kmalloc_node(size, flags, node); +} +#endif + /** * kmalloc - allocate memory * @size: how many bytes of memory are required. @@ -531,55 +558,8 @@ static __always_inline void *kmalloc_large(size_t size, gfp_t flags) */ static __always_inline __alloc_size(1) void *kmalloc(size_t size, gfp_t flags) { - if (__builtin_constant_p(size)) { -#ifndef CONFIG_SLOB - unsigned int index; -#endif - if (size > KMALLOC_MAX_CACHE_SIZE) - return kmalloc_large(size, flags); -#ifndef CONFIG_SLOB - index = kmalloc_index(size); - - if (!index) - return ZERO_SIZE_PTR; - - return kmem_cache_alloc_trace( - kmalloc_caches[kmalloc_type(flags)][index], - flags, size); -#endif - } - return __kmalloc(size, flags); -} - -#ifndef CONFIG_SLOB -static __always_inline __alloc_size(1) void *kmalloc_node(size_t size, gfp_t flags, int node) -{ - if (__builtin_constant_p(size)) { - unsigned int index; - - if (size > KMALLOC_MAX_CACHE_SIZE) - return kmalloc_large_node(size, flags, node); - - index = kmalloc_index(size); - - if (!index) - return ZERO_SIZE_PTR; - - return kmem_cache_alloc_node_trace( - kmalloc_caches[kmalloc_type(flags)][i], - flags, node, size); - } - return __kmalloc_node(size, flags, node); -} -#else -static __always_inline __alloc_size(1) void *kmalloc_node(size_t size, gfp_t flags, int node) -{ - if (__builtin_constant_p(size) && size > KMALLOC_MAX_CACHE_SIZE) - return kmalloc_large_node(size, flags, node); - - return __kmalloc_node(size, flags, node); + return kmalloc_node(size, flags, NUMA_NO_NODE); } -#endif /** * kmalloc_array - allocate memory for an array. diff --git a/mm/slab.c b/mm/slab.c index 1f3195344bdf..6ebf509bf2de 100644 --- a/mm/slab.c +++ b/mm/slab.c @@ -3519,20 +3519,6 @@ int kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, size_t size, } EXPORT_SYMBOL(kmem_cache_alloc_bulk); -void * -kmem_cache_alloc_trace(struct kmem_cache *cachep, gfp_t flags, size_t size) -{ - void *ret; - - ret = slab_alloc(cachep, flags, size, _RET_IP_); - - ret = kasan_kmalloc(cachep, ret, size, flags); - trace_kmalloc(_RET_IP_, ret, - size, cachep->size, flags); - return ret; -} -EXPORT_SYMBOL(kmem_cache_alloc_trace); - /** * kmem_cache_alloc_node - Allocate an object on the specified node * @cachep: The cache to allocate from. diff --git a/mm/slub.c b/mm/slub.c index cdbbf0e97637..d8fb987ff7e0 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -3230,15 +3230,6 @@ static __always_inline void *slab_alloc(struct kmem_cache *s, return slab_alloc_node(s, gfpflags, NUMA_NO_NODE, addr, orig_size); } -void *kmem_cache_alloc_trace(struct kmem_cache *s, gfp_t gfpflags, size_t size) -{ - void *ret = slab_alloc(s, gfpflags, _RET_IP_, size); - trace_kmalloc(_RET_IP_, ret, size, s->size, gfpflags); - ret = kasan_kmalloc(s, ret, size, gfpflags); - return ret; -} -EXPORT_SYMBOL(kmem_cache_alloc_trace); - void *kmem_cache_alloc_node(struct kmem_cache *s, gfp_t gfpflags, int node) { void *ret = slab_alloc_node(s, gfpflags, node, _RET_IP_, s->object_size); -- 2.33.1