From patchwork Tue Jul 12 13:39:41 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: 12915010 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 99DC6C433EF for ; Tue, 12 Jul 2022 13:40:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3070E940080; Tue, 12 Jul 2022 09:40:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2B846940063; Tue, 12 Jul 2022 09:40:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 13099940080; Tue, 12 Jul 2022 09:40:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 02A19940063 for ; Tue, 12 Jul 2022 09:40:32 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id D5D7D12072C for ; Tue, 12 Jul 2022 13:40:31 +0000 (UTC) X-FDA: 79678557462.11.D574F52 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by imf26.hostedemail.com (Postfix) with ESMTP id 399FB140064 for ; Tue, 12 Jul 2022 13:40:31 +0000 (UTC) Received: by mail-pl1-f182.google.com with SMTP id v21so4773251plo.0 for ; Tue, 12 Jul 2022 06:40:30 -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=M9trx0bduPD2gKBrMHDX1mfzZZXG+Gw7lYAsCvpVcLo=; b=KGPEqotBNFGeitsFyFdQnj/ioV4T9439Ug3SDyKROEBkz8PCFdHO4XPZdNcc0TOFhd cjrj2c+PJYv0Eb8EqTY+O0hq4bZ/ZpLBNoDasWmtGEqAxn8bxcuxL6cSL8nlOjh6uLGT ic0l7sxWROpTXOPuLmlUszqvdqnZ5LwRZdO954bnV8Xct+3ADkq6OWoE9qgq4/kpiN/s SuSEdfpgplC8O+KIiLgRMy69oKTPxq2dWkDbl0KoiNrKal74bWT6e0FqARZXZaYXiAH5 Aj/wtGTpxxi7lxqCecIdiH6Bc52lbLmZCIg/Iae+9BXhnGMICzn9SFoPBZB4I5G6Q9TC Vedg== 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=M9trx0bduPD2gKBrMHDX1mfzZZXG+Gw7lYAsCvpVcLo=; b=hsJ763AG0E2F5MlL/5lETqozQoqRMgta3Y+vKw5pH6eOa9CdBhAc569Eh9o6ZFcHW/ ZmnSKJcnZQfRBdB5nctg1HhrImlkTysTSai3NzCnJoLL8PFJ5sS16OazmHgZAYdvAp5M E+3E51GFDodYot/V2pOfckDPajtrltfENd3fMIYPOHyL4llKVGW8c1rms+QRZUz0eqPM QPG96NNVX3NyN80zmKz+T7hvfsLqSNRAnlx8fv32mA3IH5qcB8Or8o/V5AYLCHBU4nPj 6SCprtBueOgVGU/R8x542hpQstAnvvfnEuKANVfaEVU1QPklJ5op+U0uU3AGGXFbLLME Thmg== X-Gm-Message-State: AJIora/Em/lw3RPUyWlNO4oH3XQyYqyjdV2cVQK/fpQiroW6kE5mrXgn A2a0BOphYUg0HbKhqjZMVzg= X-Google-Smtp-Source: AGRyM1sMglOT9Btb/nAvMbQYf3DF9hAHMsrKiLzAo+9qCzA5jMlaMSXF/SyIG17UAHaDWKYeJ28Mtw== X-Received: by 2002:a17:902:f792:b0:168:e97b:3c05 with SMTP id q18-20020a170902f79200b00168e97b3c05mr23581351pln.94.1657633230347; Tue, 12 Jul 2022 06:40:30 -0700 (PDT) Received: from ip-172-31-24-42.ap-northeast-1.compute.internal (ec2-35-75-15-180.ap-northeast-1.compute.amazonaws.com. [35.75.15.180]) by smtp.gmail.com with ESMTPSA id r6-20020aa79886000000b0052ae3bcb807sm1947178pfl.188.2022.07.12.06.40.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Jul 2022 06:40:29 -0700 (PDT) From: Hyeonggon Yoo <42.hyeyoo@gmail.com> To: Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Vlastimil Babka , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Joe Perches , Vasily Averin , Matthew WilCox Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 11/15] mm/sl[au]b: introduce common alloc/free functions without tracepoint Date: Tue, 12 Jul 2022 13:39:41 +0000 Message-Id: <20220712133946.307181-12-42.hyeyoo@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220712133946.307181-1-42.hyeyoo@gmail.com> References: <20220712133946.307181-1-42.hyeyoo@gmail.com> MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=KGPEqotB; spf=pass (imf26.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.214.182 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1657633231; a=rsa-sha256; cv=none; b=qNbTezjkeImbtQ31HDvXLk0RXhi/o5RRYQkKiiOQoM/IbipIZJrfZVHZvN83bYbprxcCJk obex0U1UZH5Q79bmmz65RaZFglKDOUIiIfly/T4LRmSN8H74Cqg1yuVim/n1VJHv1h708W jKZrm0lPgtsmT3juSOsqYTHoOTScEcA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1657633231; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=M9trx0bduPD2gKBrMHDX1mfzZZXG+Gw7lYAsCvpVcLo=; b=h/SsdiXZAsyNLCmpC7nz5YxuhxUbPYOytHF/f88w6s3Pz3v0wJYpw4S2qeJEJbdpXCmsKh 2jDC118xX3crx6z2P7Mo3wukQ+I4qdZFFT/j8lGBOmbsFxYXVlZnpWOafCGHeY8l6wZLa3 mXI34qmDgiDn/zsDvH9aZFM7BUPObOM= X-Rspamd-Queue-Id: 399FB140064 Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=KGPEqotB; spf=pass (imf26.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.214.182 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: e6yo9h4wc7o6gju963hr4p7b6df3a8o7 X-HE-Tag: 1657633231-303586 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: To unify kmalloc functions in later patch, introduce common alloc/free functions that does not have tracepoint. Signed-off-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> Reviewed-by: Vlastimil Babka --- v3: Tried to avoid affecting existing functions. mm/slab.c | 36 +++++++++++++++++++++++++++++------- mm/slab.h | 4 ++++ mm/slub.c | 13 +++++++++++++ 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/mm/slab.c b/mm/slab.c index a2f43425a0ae..375e35c14430 100644 --- a/mm/slab.c +++ b/mm/slab.c @@ -3560,6 +3560,14 @@ void *kmem_cache_alloc_node(struct kmem_cache *cachep, gfp_t flags, int nodeid) } EXPORT_SYMBOL(kmem_cache_alloc_node); +void *__kmem_cache_alloc_node(struct kmem_cache *cachep, gfp_t flags, + int nodeid, size_t orig_size, + unsigned long caller) +{ + return slab_alloc_node(cachep, NULL, flags, nodeid, + orig_size, caller); +} + #ifdef CONFIG_TRACING void *kmem_cache_alloc_node_trace(struct kmem_cache *cachep, gfp_t flags, @@ -3645,6 +3653,26 @@ void *__kmalloc(size_t size, gfp_t flags) } EXPORT_SYMBOL(__kmalloc); +static __always_inline +void __do_kmem_cache_free(struct kmem_cache *cachep, void *objp, + unsigned long caller) +{ + unsigned long flags; + + local_irq_save(flags); + debug_check_no_locks_freed(objp, cachep->object_size); + if (!(cachep->flags & SLAB_DEBUG_OBJECTS)) + debug_check_no_obj_freed(objp, cachep->object_size); + __cache_free(cachep, objp, caller); + local_irq_restore(flags); +} + +void __kmem_cache_free(struct kmem_cache *cachep, void *objp, + unsigned long caller) +{ + __do_kmem_cache_free(cachep, objp, caller); +} + /** * kmem_cache_free - Deallocate an object * @cachep: The cache the allocation was from. @@ -3655,18 +3683,12 @@ EXPORT_SYMBOL(__kmalloc); */ void kmem_cache_free(struct kmem_cache *cachep, void *objp) { - unsigned long flags; cachep = cache_from_obj(cachep, objp); if (!cachep) return; trace_kmem_cache_free(_RET_IP_, objp, cachep->name); - local_irq_save(flags); - debug_check_no_locks_freed(objp, cachep->object_size); - if (!(cachep->flags & SLAB_DEBUG_OBJECTS)) - debug_check_no_obj_freed(objp, cachep->object_size); - __cache_free(cachep, objp, _RET_IP_); - local_irq_restore(flags); + __do_kmem_cache_free(cachep, objp, _RET_IP_); } EXPORT_SYMBOL(kmem_cache_free); diff --git a/mm/slab.h b/mm/slab.h index c81c92d421f1..9193e9c1f040 100644 --- a/mm/slab.h +++ b/mm/slab.h @@ -275,6 +275,10 @@ void create_kmalloc_caches(slab_flags_t); struct kmem_cache *kmalloc_slab(size_t, gfp_t); void *kmalloc_large_node_notrace(size_t size, gfp_t flags, int node); +void *__kmem_cache_alloc_node(struct kmem_cache *s, gfp_t gfpflags, + int node, size_t orig_size, + unsigned long caller); +void __kmem_cache_free(struct kmem_cache *s, void *x, unsigned long caller); #endif gfp_t kmalloc_fix_flags(gfp_t flags); diff --git a/mm/slub.c b/mm/slub.c index 6cb7ca27f3b7..74eb78678c98 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -3262,6 +3262,14 @@ void *kmem_cache_alloc_lru(struct kmem_cache *s, struct list_lru *lru, } EXPORT_SYMBOL(kmem_cache_alloc_lru); +void *__kmem_cache_alloc_node(struct kmem_cache *s, gfp_t gfpflags, + int node, size_t orig_size, + unsigned long caller) +{ + return slab_alloc_node(s, NULL, gfpflags, node, + caller, orig_size); +} + #ifdef CONFIG_TRACING void *kmem_cache_alloc_trace(struct kmem_cache *s, gfp_t gfpflags, size_t size) { @@ -3526,6 +3534,11 @@ void ___cache_free(struct kmem_cache *cache, void *x, unsigned long addr) } #endif +void __kmem_cache_free(struct kmem_cache *s, void *x, unsigned long caller) +{ + slab_free(s, virt_to_slab(x), x, NULL, &x, 1, caller); +} + void kmem_cache_free(struct kmem_cache *s, void *x) { s = cache_from_obj(s, x);