From patchwork Thu Apr 14 08:57:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hyeonggon Yoo <42.hyeyoo@gmail.com> X-Patchwork-Id: 12813158 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 04D3DC433F5 for ; Thu, 14 Apr 2022 08:58:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9839A6B007B; Thu, 14 Apr 2022 04:58:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9332C6B007D; Thu, 14 Apr 2022 04:58:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7FAE36B007E; Thu, 14 Apr 2022 04:58:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.27]) by kanga.kvack.org (Postfix) with ESMTP id 7298D6B007B for ; Thu, 14 Apr 2022 04:58:11 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 3D0CF25211 for ; Thu, 14 Apr 2022 08:58:11 +0000 (UTC) X-FDA: 79354882782.06.A177E61 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by imf23.hostedemail.com (Postfix) with ESMTP id D1A07140006 for ; Thu, 14 Apr 2022 08:58:10 +0000 (UTC) Received: by mail-pf1-f178.google.com with SMTP id n43so276918pfv.10 for ; Thu, 14 Apr 2022 01:58:10 -0700 (PDT) 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=puoTxozYPPe1WBJOeEiOmhEKhJO+f8Zoi/BnyAhKQd8=; b=cdksr7EV49IyEJgLUz1YWDTL9lJ/zdfWCGdXtI9Bh0TKKCe9eNh2TlIy4BlUAgAKC6 pUG2zCtCjSVzx33NAuhCNZLPINqhW5RFCGOTvuSw6R9sdp9BRwMW+slA01wYuSmUIHUJ QOWhpVTp1JVhPuHxZO5FvGsP6u76460r6QxrVOKjXOGFqhLVMPGKuTv0Y5GFDi4JRz1B 0trDBxOgXfgi7wNmvFjM9EbAa+QLrLxC+iXRis/JYgzqurNP6MiMTeQ/pjG4lh21Ymkl ixXRImK43ZXqcpydtsny7uQVxBezw9010hdqZWsIQd1hZgE+ssHU28Cse+Jcs3es+08b Is9w== 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=puoTxozYPPe1WBJOeEiOmhEKhJO+f8Zoi/BnyAhKQd8=; b=QnXO36rHj6kx+kaQwrl6pkmd6Lfn4qEvgqE+UTuzX70rfaOyl2tsCzRzKg8gwcgPtc dHSpvh/5bsgVroeSFRoRJ1fOV+P9iX6ZMBQkUEHTu0TTYm9hCUCrtbviqluw6EhqwyBp LCuMJqVHnePEU5UUT2neQ6c3HKTzTt/NO4uC2uRofLu0K+XU63xbkJa1JuKQBeaFjif0 cRFxQ6C+agjlbFTR9wfhAuKPJMZvb/fOm8GuQQJjZedmQVI5v1wGJo/BaEmj0h905ybm 1SMVfYPYxexmc2R+RbQJIiAkNcVjfdLo0Eqhl4pjmnWZatayisKZSFp1w9Rx0wldX182 MdXQ== X-Gm-Message-State: AOAM5323WO1jwXmRhuyZll/gGTY5oFXrpsNtxBpnM5dT6MHeIReSuukN iftm71VRSH7bvW+HEFOXnHs= X-Google-Smtp-Source: ABdhPJzR2qAtqNLzPfNtBk/cK7xehrYa7p742CXwvRI/dSLx9v1+BABWqj52kjI0Nkv1Qjq5r9dLmw== X-Received: by 2002:a05:6a00:a12:b0:504:e93f:2dd9 with SMTP id p18-20020a056a000a1200b00504e93f2dd9mr2886591pfh.49.1649926689688; Thu, 14 Apr 2022 01:58:09 -0700 (PDT) Received: from hyeyoo.. ([114.29.24.243]) by smtp.gmail.com with ESMTPSA id p9-20020aa79e89000000b00505fada20dfsm1403537pfq.117.2022.04.14.01.58.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Apr 2022 01:58:07 -0700 (PDT) From: Hyeonggon Yoo <42.hyeyoo@gmail.com> To: Vlastimil Babka Cc: Marco Elver , Matthew WilCox , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Roman Gushchin , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 05/23] mm/slab_common: cleanup __kmalloc() Date: Thu, 14 Apr 2022 17:57:09 +0900 Message-Id: <20220414085727.643099-6-42.hyeyoo@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220414085727.643099-1-42.hyeyoo@gmail.com> References: <20220414085727.643099-1-42.hyeyoo@gmail.com> MIME-Version: 1.0 X-Stat-Signature: u8z941394p7b7uxqfi7r3xcrw4uu8h8k Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=cdksr7EV; spf=pass (imf23.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.210.178 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: D1A07140006 X-HE-Tag: 1649926690-973430 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: Make __kmalloc() wrapper of __kmalloc_node(). Signed-off-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> Reviewed-by: Vlastimil Babka --- include/linux/slab.h | 13 ++++++++++--- mm/slab.c | 34 ---------------------------------- mm/slob.c | 6 ------ mm/slub.c | 23 ----------------------- 4 files changed, 10 insertions(+), 66 deletions(-) diff --git a/include/linux/slab.h b/include/linux/slab.h index acdb4b7428f9..4c06d15f731c 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -419,7 +419,16 @@ static __always_inline unsigned int __kmalloc_index(size_t size, #define kmalloc_index(s) __kmalloc_index(s, true) #endif /* !CONFIG_SLOB */ -void *__kmalloc(size_t size, gfp_t flags) __assume_kmalloc_alignment __alloc_size(1); +extern void *__kmalloc_node(size_t size, gfp_t flags, int node) + __assume_kmalloc_alignment + __alloc_size(1); + +static __always_inline __alloc_size(1) __assume_kmalloc_alignment +void *__kmalloc(size_t size, gfp_t flags) +{ + return __kmalloc_node(size, flags, NUMA_NO_NODE); +} + void *kmem_cache_alloc(struct kmem_cache *s, gfp_t flags) __assume_slab_alignment __malloc; void *kmem_cache_alloc_lru(struct kmem_cache *s, struct list_lru *lru, gfp_t gfpflags) __assume_slab_alignment __malloc; @@ -444,8 +453,6 @@ static __always_inline void kfree_bulk(size_t size, void **p) kmem_cache_free_bulk(NULL, size, p); } -void *__kmalloc_node(size_t size, gfp_t flags, int node) __assume_kmalloc_alignment - __alloc_size(1); void *kmem_cache_alloc_node(struct kmem_cache *s, gfp_t flags, int node) __assume_slab_alignment __malloc; diff --git a/mm/slab.c b/mm/slab.c index 5f20efc7a330..db7eab9e2e9f 100644 --- a/mm/slab.c +++ b/mm/slab.c @@ -3641,40 +3641,6 @@ void kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct slab *slab) } #endif -/** - * __do_kmalloc - allocate memory - * @size: how many bytes of memory are required. - * @flags: the type of memory to allocate (see kmalloc). - * @caller: function caller for debug tracking of the caller - * - * Return: pointer to the allocated memory or %NULL in case of error - */ -static __always_inline void *__do_kmalloc(size_t size, gfp_t flags, - unsigned long caller) -{ - struct kmem_cache *cachep; - void *ret; - - if (unlikely(size > KMALLOC_MAX_CACHE_SIZE)) - return NULL; - cachep = kmalloc_slab(size, flags); - if (unlikely(ZERO_OR_NULL_PTR(cachep))) - return cachep; - ret = slab_alloc(cachep, NULL, flags, size, caller); - - ret = kasan_kmalloc(cachep, ret, size, flags); - trace_kmalloc(caller, ret, - size, cachep->size, flags); - - return ret; -} - -void *__kmalloc(size_t size, gfp_t flags) -{ - return __do_kmalloc(size, flags, _RET_IP_); -} -EXPORT_SYMBOL(__kmalloc); - /** * kmem_cache_free - Deallocate an object * @cachep: The cache the allocation was from. diff --git a/mm/slob.c b/mm/slob.c index 6d0fc6ad1413..ab67c8219e8d 100644 --- a/mm/slob.c +++ b/mm/slob.c @@ -522,12 +522,6 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller) return ret; } -void *__kmalloc(size_t size, gfp_t gfp) -{ - return __do_kmalloc_node(size, gfp, NUMA_NO_NODE, _RET_IP_); -} -EXPORT_SYMBOL(__kmalloc); - void *__kmalloc_node_track_caller(size_t size, gfp_t gfp, int node, unsigned long caller) { diff --git a/mm/slub.c b/mm/slub.c index e425c5c372de..44170b4f084b 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -4399,29 +4399,6 @@ static int __init setup_slub_min_objects(char *str) __setup("slub_min_objects=", setup_slub_min_objects); -void *__kmalloc(size_t size, gfp_t flags) -{ - struct kmem_cache *s; - void *ret; - - if (unlikely(size > KMALLOC_MAX_CACHE_SIZE)) - return kmalloc_large(size, flags); - - s = kmalloc_slab(size, flags); - - if (unlikely(ZERO_OR_NULL_PTR(s))) - return s; - - ret = slab_alloc(s, NULL, flags, _RET_IP_, size); - - trace_kmalloc(_RET_IP_, ret, size, s->size, flags); - - ret = kasan_kmalloc(s, ret, size, flags); - - return ret; -} -EXPORT_SYMBOL(__kmalloc); - static void *kmalloc_large_node(size_t size, gfp_t flags, int node) { struct page *page;