From patchwork Tue Jul 12 13:39:31 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: 12915000 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 7B848C433EF for ; Tue, 12 Jul 2022 13:39:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E2B9B940076; Tue, 12 Jul 2022 09:39:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DDACE940063; Tue, 12 Jul 2022 09:39:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C7C9E940076; Tue, 12 Jul 2022 09:39:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id B7F1B940063 for ; Tue, 12 Jul 2022 09:39:57 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 7F0DE20F03 for ; Tue, 12 Jul 2022 13:39:57 +0000 (UTC) X-FDA: 79678556034.19.5273712 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by imf26.hostedemail.com (Postfix) with ESMTP id 26CE6140067 for ; Tue, 12 Jul 2022 13:39:56 +0000 (UTC) Received: by mail-pl1-f179.google.com with SMTP id v21so4772027plo.0 for ; Tue, 12 Jul 2022 06:39:56 -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=6rRFJ0xVh5ABORNo5ssv3zp+HF72hGoY2m+vDB2j/5A=; b=j66iaT+jljhuBXI/FcmS1Ljzo3XHqUsiIheAG10WlV1Ku/9yi7MlhWLmsZuiXwEgSG IykzHuntgUkrgpiVpOi1lVYG8PvbQm2BQToVyI2vVE8xX9Z8UA6ZDZItF582+QgVXWgm OnStF0hYaRWgwBEJSvVjboluOqwfEyMEly8ggpKj7K1Hlt/7qZ9VUTdoLl3GD6+8WI8g SnN8GJg+HJjwXeV5XzOcFNrQzxrhrE7HP38XNHCEnzJ9zYqVXikCDU4bJylBcdFOcUzm F/cCcELaJceKC8dJVpfhxXdQzH/5DGuzzRNmlaWF7Ygj/VgQfuAWWuFLlmH2evYtbSgR k6RQ== 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=6rRFJ0xVh5ABORNo5ssv3zp+HF72hGoY2m+vDB2j/5A=; b=hW2qlg5Geu3jQErlk4UpMV2cHSUeXF3wZa1/c6mnme3Fe1D4/s026qW8Uw7Cq4Xnx0 npFHUH+ycKi2cdU0PNoZ7EMeICqXdcWGC+NY3Aj076ZgV282K7M1I4G82wvPrtNwQUwD dCD8qBi+kEGEcHkHexKsgVCPsnC2nghOnSp8kDJOimIxhArizCp5Z7N4n8aVjdq8v/to PXqvw+6X57uQbW9SR/UhohbSX113b1N4h1ia0XCvJxXgzQVEogBNFtnz0s6WTULewM8f Thvz73cCY8X4Dnt4UV7TA8raKmE4IbjeyWUAUTXRBYFYjCfzwRIM6UjNxtgFrsSzqiHA Brsg== X-Gm-Message-State: AJIora9IOLY2jEyAYHthBsZkZFAfAK/cQHgyecnCkMFh8zsHm77XIRai rsjIUDN5fih73lKPN1ggVCU= X-Google-Smtp-Source: AGRyM1v1TLiXCxd2XqyR+KXoLhBqLyQ1wHNby5FzNlOmnNN+pMCAzAHTJilkftrp2vgWo3ANSltsKg== X-Received: by 2002:a17:902:eec2:b0:16b:e389:7efe with SMTP id h2-20020a170902eec200b0016be3897efemr24530998plb.84.1657633196101; Tue, 12 Jul 2022 06:39:56 -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.39.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Jul 2022 06:39:55 -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 1/15] mm/slab: move NUMA-related code to __do_cache_alloc() Date: Tue, 12 Jul 2022 13:39:31 +0000 Message-Id: <20220712133946.307181-2-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-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1657633197; 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=6rRFJ0xVh5ABORNo5ssv3zp+HF72hGoY2m+vDB2j/5A=; b=DHH2j/NCM/3grjIJVciBo4kHgVzY4Y4CJaT0lIdbqVdcbXXeKnbXtE49YrHs7WllNDnRza FycmNBnGKDoDvYV1K1boKIQpe+6XjOy8BeEaymbmdclcR3UkxHNky0FTGMne0DBlZUsmWr i/AORO25FvmhFG66Mfe1ATXxFHDAxj0= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=j66iaT+j; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf26.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.214.179 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1657633197; a=rsa-sha256; cv=none; b=A1fzv1M+nTooh12eeDDSRvoIz8BbdIylB2efIDK0S5FtOuBqz+Kcbk8pzCmAovzf4Jp73K KY4Blbbtb/DUsda8mLrLaiHl4RlsOezehS5k4mQWItHCy/3KForFehAZEgjxnOXA4cATR5 EAtq7kBfGDbsgtlIS8b+alyRYJDdvrY= X-Stat-Signature: bop4daeg7ite19z5kieiwnjtxsb4a1wg X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 26CE6140067 Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=j66iaT+j; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf26.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.214.179 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com X-Rspam-User: X-HE-Tag: 1657633196-610164 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 implement slab_alloc_node() independent of NUMA configuration, move NUMA fallback/alternate allocation code into __do_cache_alloc(). One functional change here is not to check availability of node when allocating from local node. Signed-off-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> Reviewed-by: Vlastimil Babka --- v3: Fixed uninitialized variable bug due to missing NULL-initialization of variable objp. mm/slab.c | 68 +++++++++++++++++++++++++------------------------------ 1 file changed, 31 insertions(+), 37 deletions(-) diff --git a/mm/slab.c b/mm/slab.c index 764cbadba69c..3d83d17ff3b3 100644 --- a/mm/slab.c +++ b/mm/slab.c @@ -3186,13 +3186,14 @@ static void *____cache_alloc_node(struct kmem_cache *cachep, gfp_t flags, return obj ? obj : fallback_alloc(cachep, flags); } +static void *__do_cache_alloc(struct kmem_cache *cachep, gfp_t flags, int nodeid); + 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; @@ -3207,30 +3208,7 @@ slab_alloc_node(struct kmem_cache *cachep, gfp_t flags, int nodeid, size_t orig_ 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: + ptr = __do_cache_alloc(cachep, flags, nodeid); local_irq_restore(save_flags); ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller); init = slab_want_init_on_alloc(flags, cachep); @@ -3241,31 +3219,46 @@ slab_alloc_node(struct kmem_cache *cachep, gfp_t flags, int nodeid, size_t orig_ } static __always_inline void * -__do_cache_alloc(struct kmem_cache *cache, gfp_t flags) +__do_cache_alloc(struct kmem_cache *cachep, gfp_t flags, int nodeid) { - void *objp; + void *objp = NULL; + int slab_node = numa_mem_id(); - if (current->mempolicy || cpuset_do_slab_mem_spread()) { - objp = alternate_node_alloc(cache, flags); - if (objp) - goto out; + if (nodeid == NUMA_NO_NODE) { + if (current->mempolicy || cpuset_do_slab_mem_spread()) { + objp = alternate_node_alloc(cachep, flags); + if (objp) + goto out; + } + /* + * 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. + */ + objp = ____cache_alloc(cachep, flags); + nodeid = slab_node; + } else if (nodeid == slab_node) { + objp = ____cache_alloc(cachep, flags); + } else if (!get_node(cachep, nodeid)) { + /* Node not bootstrapped yet */ + objp = fallback_alloc(cachep, flags); + goto out; } - objp = ____cache_alloc(cache, flags); /* * We may just have run out of memory on the local node. * ____cache_alloc_node() knows how to locate memory on other nodes */ if (!objp) - objp = ____cache_alloc_node(cache, flags, numa_mem_id()); - + objp = ____cache_alloc_node(cachep, flags, nodeid); out: return objp; } #else static __always_inline void * -__do_cache_alloc(struct kmem_cache *cachep, gfp_t flags) +__do_cache_alloc(struct kmem_cache *cachep, gfp_t flags, int nodeid __maybe_unused) { return ____cache_alloc(cachep, flags); } @@ -3292,7 +3285,7 @@ slab_alloc(struct kmem_cache *cachep, struct list_lru *lru, gfp_t flags, cache_alloc_debugcheck_before(cachep, flags); local_irq_save(save_flags); - objp = __do_cache_alloc(cachep, flags); + objp = __do_cache_alloc(cachep, flags, NUMA_NO_NODE); local_irq_restore(save_flags); objp = cache_alloc_debugcheck_after(cachep, flags, objp, caller); prefetchw(objp); @@ -3531,7 +3524,8 @@ int kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, size_t size, local_irq_disable(); for (i = 0; i < size; i++) { - void *objp = kfence_alloc(s, s->object_size, flags) ?: __do_cache_alloc(s, flags); + void *objp = kfence_alloc(s, s->object_size, flags) ?: + __do_cache_alloc(s, flags, NUMA_NO_NODE); if (unlikely(!objp)) goto error;