From patchwork Tue Jul 12 13:39:37 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: 12915006 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 6FBE3C43334 for ; Tue, 12 Jul 2022 13:40:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0BD5394007C; Tue, 12 Jul 2022 09:40:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 06DC5940063; Tue, 12 Jul 2022 09:40:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E9F1594007C; Tue, 12 Jul 2022 09:40:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id DB206940063 for ; Tue, 12 Jul 2022 09:40:17 -0400 (EDT) Received: from smtpin31.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id B3CCC1204C1 for ; Tue, 12 Jul 2022 13:40:17 +0000 (UTC) X-FDA: 79678556874.31.311A2C2 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by imf06.hostedemail.com (Postfix) with ESMTP id 66A34180027 for ; Tue, 12 Jul 2022 13:40:17 +0000 (UTC) Received: by mail-pl1-f175.google.com with SMTP id l12so7258321plk.13 for ; Tue, 12 Jul 2022 06:40:17 -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=5zXey38vmjUFb+GfMhB6B68P1VCpS6kNFrksbY6msJM=; b=IUUUzFdICndGH31XMdqciHNS9TD8lB55IEPCUzQuALBEjHxdz1FTzdzsTu2vzzp3Vg VK5l7grM5ZJsDCS7/gwbtCmeD4NXHTJHcbfOQgVPjxNqS3Kh6Fhev+0pY//YNvStMXl9 CkCb0f9PjSeW/e8nEkGo+4LkwfziN6UZYtXOOADKQHknRZZU1N3Z1FIral8v/0F6B1Wd 5Zpv6NzPgFq9dl49L2UabaepUujksbXbFMOt4uM9znrUDwMUdOOeZ7uKCRoUaLtneEDD rRh9PFfuWGsTafq6oZdXoDuKCXsAW4c9J/cvAQTlX3goprFNtltR8SZE7Io7i2mLtRwK pRdQ== 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=5zXey38vmjUFb+GfMhB6B68P1VCpS6kNFrksbY6msJM=; b=qD+7TEd6wH2a5Qe5lIbVSXaPf4ZB+Iiz4GxMC8Nhyty63Avdf8Y/w7c/mg0FxnnFst X2eVzLn6nhbpNMcXc5EXdZuJeCAtGtkVB/lhH2ARuuDWhUcwwjEi6hdfezLgBFFbBHio zUBB6RI/8LwptcPSWrXoR48dX8mgepN8haINLXf2xSkWJAwMZG6rLV6njBCo8FF9Txk2 /gofUBCwmON57rQkj742A3gRpAKkcgDZy3vKte9fXyv8mJOFcirRx9hxY7bQ1Zj4k7fa fo7NyFN7YLxr7Q1JCxRGZMIiE9qkh8gd8KZITzYD3vp4UKaVlVUsj0AjmmuSP2kU91BW uxLQ== X-Gm-Message-State: AJIora/R6A4m39WvLDrLlFpLj9MOr1bKj3vO9IMtMgRWr5LIcddDpgez nGsjvMMFpzdgXpgJ8RVvBek= X-Google-Smtp-Source: AGRyM1vtmYPKNJBp2rYSh/8vXIvdTgbEVgesyhLxMtq2Di+VDK83fYVktlc+wENFfd7ZfYqw2CJS+g== X-Received: by 2002:a17:902:eccf:b0:16b:f555:d42e with SMTP id a15-20020a170902eccf00b0016bf555d42emr23624458plh.75.1657633216463; Tue, 12 Jul 2022 06:40:16 -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.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Jul 2022 06:40:15 -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 07/15] mm/slub: move kmalloc_large_node() to slab_common.c Date: Tue, 12 Jul 2022 13:39:37 +0000 Message-Id: <20220712133946.307181-8-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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1657633217; a=rsa-sha256; cv=none; b=y6JyvXPMDRyA1MISQbLGk6DZE14TKgkjaHrvYeBeGo6KBZu3A849pqknFeQfp+6MSc3V/0 sUrZ1R84xL0uS7TOvCMLgNeYzEwgzX4LhIlw6ptWnRaJOI6SBthycoQc6DNl9EpN4TSMP3 8kcD8IHwrJU7THPlhQgNI665dX8iJNE= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=IUUUzFdI; spf=pass (imf06.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.214.175 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1657633217; 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=5zXey38vmjUFb+GfMhB6B68P1VCpS6kNFrksbY6msJM=; b=yTMQ09VCRQQsrek3zijSjUQIGfOABOIAjibI3KrYirVMh1oTiYFMgQic49u65BDCUY+rgP VyPjCYhq22hQJsOWmWRgOJW1ItmYtsbV4YdQ0oaCz5iSz26vxH2TxNT+n5rAAtovlmnOuT ePwdNtMtlN9CmEsVfY6A+WQqdTgFUSY= X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 66A34180027 X-Rspam-User: Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=IUUUzFdI; spf=pass (imf06.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.214.175 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Stat-Signature: eg9iac9xtxti5duaqm6dc66t7th4ema8 X-HE-Tag: 1657633217-463099 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: In later patch SLAB will also pass requests larger than order-1 page to page allocator. Move kmalloc_large_node() to slab_common.c. Fold kmalloc_large_node_hook() into kmalloc_large_node() as there is no other caller. Signed-off-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> Reviewed-by: Vlastimil Babka --- include/linux/slab.h | 4 ++++ mm/slab_common.c | 22 ++++++++++++++++++++++ mm/slub.c | 25 ------------------------- 3 files changed, 26 insertions(+), 25 deletions(-) diff --git a/include/linux/slab.h b/include/linux/slab.h index 15a4c59da59e..082499306098 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -491,6 +491,10 @@ static __always_inline void *kmem_cache_alloc_node_trace(struct kmem_cache *s, g void *kmalloc_large(size_t size, gfp_t flags) __assume_page_alignment __alloc_size(1); + +void *kmalloc_large_node(size_t size, gfp_t flags, int node) __assume_page_alignment + __alloc_size(1); + /** * kmalloc - allocate memory * @size: how many bytes of memory are required. diff --git a/mm/slab_common.c b/mm/slab_common.c index 1f8af2106df0..6f855587b635 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -956,6 +956,28 @@ void *kmalloc_large(size_t size, gfp_t flags) } EXPORT_SYMBOL(kmalloc_large); +void *kmalloc_large_node(size_t size, gfp_t flags, int node) +{ + struct page *page; + void *ptr = NULL; + unsigned int order = get_order(size); + + flags |= __GFP_COMP; + page = alloc_pages_node(node, flags, order); + if (page) { + ptr = page_address(page); + mod_lruvec_page_state(page, NR_SLAB_UNRECLAIMABLE_B, + PAGE_SIZE << order); + } + + ptr = kasan_kmalloc_large(ptr, size, flags); + /* As ptr might get tagged, call kmemleak hook after KASAN. */ + kmemleak_alloc(ptr, size, 1, flags); + + return ptr; +} +EXPORT_SYMBOL(kmalloc_large_node); + #ifdef CONFIG_SLAB_FREELIST_RANDOM /* Randomize a generic freelist */ static void freelist_randomize(struct rnd_state *state, unsigned int *list, diff --git a/mm/slub.c b/mm/slub.c index 2ccc473e0ae7..f22a84dd27de 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -1704,14 +1704,6 @@ static bool freelist_corrupted(struct kmem_cache *s, struct slab *slab, * Hooks for other subsystems that check memory allocations. In a typical * production configuration these hooks all should produce no code at all. */ -static inline void *kmalloc_large_node_hook(void *ptr, size_t size, gfp_t flags) -{ - ptr = kasan_kmalloc_large(ptr, size, flags); - /* As ptr might get tagged, call kmemleak hook after KASAN. */ - kmemleak_alloc(ptr, size, 1, flags); - return ptr; -} - static __always_inline void kfree_hook(void *x) { kmemleak_free(x); @@ -4402,23 +4394,6 @@ static int __init setup_slub_min_objects(char *str) __setup("slub_min_objects=", setup_slub_min_objects); -static void *kmalloc_large_node(size_t size, gfp_t flags, int node) -{ - struct page *page; - void *ptr = NULL; - unsigned int order = get_order(size); - - flags |= __GFP_COMP; - page = alloc_pages_node(node, flags, order); - if (page) { - ptr = page_address(page); - mod_lruvec_page_state(page, NR_SLAB_UNRECLAIMABLE_B, - PAGE_SIZE << order); - } - - return kmalloc_large_node_hook(ptr, size, flags); -} - static __always_inline void *__do_kmalloc_node(size_t size, gfp_t flags, int node, unsigned long caller) {