From patchwork Thu Apr 14 08:57:05 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: 12813131 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 D3C36C433EF for ; Thu, 14 Apr 2022 08:57:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 69EFB6B0074; Thu, 14 Apr 2022 04:57:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 64CE06B0075; Thu, 14 Apr 2022 04:57:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 515426B0078; Thu, 14 Apr 2022 04:57:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.25]) by kanga.kvack.org (Postfix) with ESMTP id 42B816B0074 for ; Thu, 14 Apr 2022 04:57:46 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id 11E8F604F6 for ; Thu, 14 Apr 2022 08:57:46 +0000 (UTC) X-FDA: 79354881732.04.3D71DF1 Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) by imf26.hostedemail.com (Postfix) with ESMTP id 82FE414000A for ; Thu, 14 Apr 2022 08:57:45 +0000 (UTC) Received: by mail-pj1-f52.google.com with SMTP id bg24so4532913pjb.1 for ; Thu, 14 Apr 2022 01:57:45 -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=BH7DV9U/vu2jtDErAITdUqLyoGxX/jkJAwwizEZv+Js=; b=JJCBD1YAeoPMhuIjVfylzRv0NxsFdBPMH+kZzmPcRUHMX5TQEv+wea9a8orZanf8p/ iQBR9sZAT+j7gUSeUw5x+S3c7HxDHcxVHwjYCdK64Ubqco6qU/RZDbVHtMfKFNqWUVmP O3nytkKNxVblG0o8Nm0u+CZV0R5UyGqV/FOYrYzfKFjL4Bnc7sOFMZdfj6D4b2M0/r+b TqmA3PW8ykLEUpurPiQU+4bjY8J77+tYoh5W+qyYIXtfWC3/zHTrhaDEEx0IXBPcZFgh jzHWoU+t+KbP9vrRpNLtvi96RB8dbsJo5Oj8NiPQCGf25lX0J3QbY8w05i/odEi4GOc7 WqsA== 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=BH7DV9U/vu2jtDErAITdUqLyoGxX/jkJAwwizEZv+Js=; b=elrReEAfKQATEQrftdAiH8lhzbfZWB0F0kupo+HWZgwdwpYOL0XX4+6OavJQlbqlly O9qkYBT42y4mnfCuxn5voQI50L9adAKP4odl40tz9MhyrZRUJI2Cd0UczPwpAhHnv0uc 1jYnRXQx8rx6HMlZKECow0mMsNBZhyURURMPZ5LimrlzavDMs5eiQD6IlHu9+qAWecG5 0ltFvfVBkwp2N9PG+h9fO0WzE6dLXJLNBBhKRs/y5Auk3jzn6qTDb58VYz/Z0UjUfNRK d9rVkiwqAEZJEQ61tK8lu6EAzgC7862O54Mv8v95dNUVb4jJh0lYO4aEZ2cME8cZs26t LEGg== X-Gm-Message-State: AOAM5322whwyPCFd7liaemExSrxvVbj88fhHb0xJlVyYfTIobONmmH+6 BvjaXeIKjbEret7yI6O/yw8= X-Google-Smtp-Source: ABdhPJxsUXct5U3lD2WN+lLx+SB2iXDsebklAp6DajrSrorvr3K71YGlQGb2/NbFbsSvuQLhCUWLBg== X-Received: by 2002:a17:90a:e7d2:b0:1c7:b410:ccfc with SMTP id kb18-20020a17090ae7d200b001c7b410ccfcmr2567374pjb.209.1649926664449; Thu, 14 Apr 2022 01:57:44 -0700 (PDT) Received: from hyeyoo.. ([114.29.24.243]) by smtp.gmail.com with ESMTPSA id p9-20020aa79e89000000b00505fada20dfsm1403537pfq.117.2022.04.14.01.57.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Apr 2022 01:57:42 -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 01/23] mm/slab: move NUMA-related code to __do_cache_alloc() Date: Thu, 14 Apr 2022 17:57:05 +0900 Message-Id: <20220414085727.643099-2-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-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 82FE414000A X-Stat-Signature: cmny33kedmk5rqyqqxzmui6hs8jepq9k Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=JJCBD1YA; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf26.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.216.52 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com X-Rspam-User: X-HE-Tag: 1649926665-561149 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 --- Changes from v1: - Undo removing path to alternate_node_alloc code when node id is not specified (which was mistake.) mm/slab.c | 68 +++++++++++++++++++++++++------------------------------ 1 file changed, 31 insertions(+), 37 deletions(-) diff --git a/mm/slab.c b/mm/slab.c index e882657c1494..d854c24d5f5a 100644 --- a/mm/slab.c +++ b/mm/slab.c @@ -3187,13 +3187,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; @@ -3208,30 +3209,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); @@ -3242,31 +3220,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; + 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()); - - out: + 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); } @@ -3293,7 +3286,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); @@ -3532,7 +3525,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;