From patchwork Tue Mar 8 11:41:28 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: 12773562 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 72F0AC433F5 for ; Tue, 8 Mar 2022 11:42:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0CB158D0005; Tue, 8 Mar 2022 06:42:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 07A678D0001; Tue, 8 Mar 2022 06:42:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E859F8D0005; Tue, 8 Mar 2022 06:42:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.a.hostedemail.com [64.99.140.24]) by kanga.kvack.org (Postfix) with ESMTP id DA0E28D0001 for ; Tue, 8 Mar 2022 06:42:22 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id B28BE184B for ; Tue, 8 Mar 2022 11:42:22 +0000 (UTC) X-FDA: 79221030924.13.7749EB3 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by imf18.hostedemail.com (Postfix) with ESMTP id 2C1231C0006 for ; Tue, 8 Mar 2022 11:42:22 +0000 (UTC) Received: by mail-pl1-f179.google.com with SMTP id p17so16818801plo.9 for ; Tue, 08 Mar 2022 03:42:21 -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=CvChe1Nx5QM82i5sMEtLWw0W8b5zEMFWykl/RZ7HcKk=; b=lrQARZIbg6zKFpFazaRiPu+2pB6jdM9vBa23U+KrHIi6moyefe5oBwfnXHbcrMGd1u 9FCk//aQX0m0rZmdOe2RsuQp3QKMoFuQsOQfhlt3sYQYVrLy2ttEmGIDELJ8eZ41xTx5 o/4ZOe7LoQjZSZQrTYHmYIhLWLjPsiHDUUXLKsZYnqwsuG4UtHFJleJxm48RmTNzG0KV xE3EBjTQOJsguaBxkzu/qfLA408wOR/EGWDgbNx+Z01+A7nLgWpB2KBXpAH6fPvOKD4n 5rXL5+o/bVWraQjrUz7pNy5csAtWYciNG5NCyVBmnl9K5lu9LK9BdQzd8t1T83QdOvhz M/ew== 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=CvChe1Nx5QM82i5sMEtLWw0W8b5zEMFWykl/RZ7HcKk=; b=RLc721Cdb+JQt6l+L4EupYd66qRHmnGk5aqhV6lSN6noO2Ba9+NkJcb1+UInMlbuAz z47V62rCV/SDxpX2NcCZrVfwRbH0HuBWAusISwaZL6C2mReO06a6VOJ/fQqpSSLX2ew9 stAGgemT70PtywgCCzVk+DnVp3IaGrN8pi42Bv8snrGaeowTt0UuDYrmtNBpCEYQsGum lJ9y6QIvvqPUjV50aWmBfyzA49uu4ROXRwiAZQbrL0ZvbOJ2Di6A25ufsKzwZNm21FzY d8RIjZDZDaUKQ8Jdblbq9Qup4PBaDEaG3l6YSbitoo+I9kZwvPOCZpv1zLfL5QgChp2d 8VvA== X-Gm-Message-State: AOAM530q0/YMOYmNJ+jSrkPbg/58AJjNrILTcCL0X+5aaLQa+PFoljo1 8Y4CxgOkqbzk7+sioJkdw08aXrfn0SyeiA== X-Google-Smtp-Source: ABdhPJxSdPT1uqVF9ZNoFsseoMYuGupVSa9y0mdlo7pCI66JTfN53RgQfS/FDGbDBCK8yrS+hUeKoA== X-Received: by 2002:a17:902:7fc1:b0:151:f80f:494a with SMTP id t1-20020a1709027fc100b00151f80f494amr5769354plb.81.1646739740665; Tue, 08 Mar 2022 03:42:20 -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.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 03:42:20 -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 01/15] mm/slab: cleanup slab_alloc() and slab_alloc_node() Date: Tue, 8 Mar 2022 11:41:28 +0000 Message-Id: <20220308114142.1744229-2-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 X-Rspamd-Queue-Id: 2C1231C0006 X-Stat-Signature: hsswe6a7xy8wtes54g6aszhou3z8q1qt X-Rspam-User: Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=lrQARZIb; spf=pass (imf18.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.214.179 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam07 X-HE-Tag: 1646739742-272079 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 slab_alloc_node() available for non-NUMA configurations and make slab_alloc() wrapper of slab_alloc_node(). This is necessary for further cleanup. Do not check availability of node when allocating from locally cached objects. It's redundant. This patch was tested on both CONFIG_NUMA=y and n. Signed-off-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> --- mm/slab.c | 116 +++++++++++++++++++++++------------------------------- 1 file changed, 50 insertions(+), 66 deletions(-) diff --git a/mm/slab.c b/mm/slab.c index ddf5737c63d9..5d102aaf1629 100644 --- a/mm/slab.c +++ b/mm/slab.c @@ -3200,60 +3200,6 @@ static void *____cache_alloc_node(struct kmem_cache *cachep, gfp_t flags, return obj ? obj : fallback_alloc(cachep, flags); } -static __always_inline void * -slab_alloc_node(struct kmem_cache *cachep, gfp_t flags, int nodeid, size_t orig_size, - unsigned long caller) -{ - unsigned long save_flags; - void *ptr; - int slab_node = numa_mem_id(); - struct obj_cgroup *objcg = NULL; - bool init = false; - - flags &= gfp_allowed_mask; - cachep = slab_pre_alloc_hook(cachep, &objcg, 1, flags); - if (unlikely(!cachep)) - return NULL; - - ptr = kfence_alloc(cachep, orig_size, flags); - if (unlikely(ptr)) - goto out_hooks; - - cache_alloc_debugcheck_before(cachep, flags); - local_irq_save(save_flags); - - if (nodeid == NUMA_NO_NODE) - nodeid = slab_node; - - if (unlikely(!get_node(cachep, nodeid))) { - /* Node not bootstrapped yet */ - ptr = fallback_alloc(cachep, flags); - goto out; - } - - if (nodeid == slab_node) { - /* - * Use the locally cached objects if possible. - * However ____cache_alloc does not allow fallback - * to other nodes. It may fail while we still have - * objects on other nodes available. - */ - ptr = ____cache_alloc(cachep, flags); - if (ptr) - goto out; - } - /* ___cache_alloc_node can fall back to other nodes */ - ptr = ____cache_alloc_node(cachep, flags, nodeid); - out: - local_irq_restore(save_flags); - ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller); - init = slab_want_init_on_alloc(flags, cachep); - -out_hooks: - slab_post_alloc_hook(cachep, objcg, flags, 1, &ptr, init); - return ptr; -} - static __always_inline void * __do_cache_alloc(struct kmem_cache *cache, gfp_t flags) { @@ -3283,14 +3229,24 @@ __do_cache_alloc(struct kmem_cache *cachep, gfp_t flags) { return ____cache_alloc(cachep, flags); } - #endif /* CONFIG_NUMA */ +static __always_inline bool node_match(int nodeid, int slab_node) +{ +#ifdef CONFIG_NUMA + if (nodeid != NUMA_NO_NODE && nodeid != slab_node) + return false; +#endif + return true; +} + static __always_inline void * -slab_alloc(struct kmem_cache *cachep, gfp_t flags, size_t orig_size, unsigned long caller) +slab_alloc_node(struct kmem_cache *cachep, gfp_t flags, int nodeid, size_t orig_size, + unsigned long caller) { unsigned long save_flags; - void *objp; + void *ptr; + int slab_node = numa_mem_id(); struct obj_cgroup *objcg = NULL; bool init = false; @@ -3299,21 +3255,49 @@ slab_alloc(struct kmem_cache *cachep, gfp_t flags, size_t orig_size, unsigned lo if (unlikely(!cachep)) return NULL; - objp = kfence_alloc(cachep, orig_size, flags); - if (unlikely(objp)) - goto out; + ptr = kfence_alloc(cachep, orig_size, flags); + if (unlikely(ptr)) + goto out_hooks; cache_alloc_debugcheck_before(cachep, flags); local_irq_save(save_flags); - objp = __do_cache_alloc(cachep, flags); + + if (node_match(nodeid, slab_node)) { + /* + * Use the locally cached objects if possible. + * However ____cache_alloc does not allow fallback + * to other nodes. It may fail while we still have + * objects on other nodes available. + */ + ptr = ____cache_alloc(cachep, flags); + if (ptr) + goto out; + } +#ifdef CONFIG_NUMA + else if (unlikely(!get_node(cachep, nodeid))) { + /* Node not bootstrapped yet */ + ptr = fallback_alloc(cachep, flags); + goto out; + } + + /* ___cache_alloc_node can fall back to other nodes */ + ptr = ____cache_alloc_node(cachep, flags, nodeid); +#endif +out: local_irq_restore(save_flags); - objp = cache_alloc_debugcheck_after(cachep, flags, objp, caller); - prefetchw(objp); + ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller); + prefetchw(ptr); init = slab_want_init_on_alloc(flags, cachep); -out: - slab_post_alloc_hook(cachep, objcg, flags, 1, &objp, init); - return objp; +out_hooks: + slab_post_alloc_hook(cachep, objcg, flags, 1, &ptr, init); + return ptr; +} + +static __always_inline void * +slab_alloc(struct kmem_cache *cachep, gfp_t flags, size_t orig_size, unsigned long caller) +{ + return slab_alloc_node(cachep, flags, NUMA_NO_NODE, orig_size, caller); } /*