From patchwork Wed May 24 17:18:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Catalin Marinas X-Patchwork-Id: 13254343 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 818A6C77B7C for ; Wed, 24 May 2023 17:19:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E4FA7900007; Wed, 24 May 2023 13:19:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DD93F900002; Wed, 24 May 2023 13:19:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CC683900007; Wed, 24 May 2023 13:19:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id BD750900002 for ; Wed, 24 May 2023 13:19:29 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 981321C787B for ; Wed, 24 May 2023 17:19:29 +0000 (UTC) X-FDA: 80825810058.13.89349F0 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf18.hostedemail.com (Postfix) with ESMTP id E60AE1C0007 for ; Wed, 24 May 2023 17:19:27 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=none; spf=pass (imf18.hostedemail.com: domain of cmarinas@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cmarinas@kernel.org; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684948768; 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; bh=0mqLCBdpgkfqDUcqHwwIym+BakJfQ9CLI5FzmbFJWTk=; b=XqcrOvRYFL9GWUgT+fHxRQyCHv38d6YIBVd6K+dALsFEKywjAKPnwCv1KnHIvp5oplRy2N Ftl0rGPzRhsfx9xW1ZgTxbsN/DXQaODN8XCbqB2Jnkmvnwy5f/tIlMefBVowLoYB2JVcni 5ISRUEFlPUbkmjeg4MEIdv9qAWWFqiE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684948768; a=rsa-sha256; cv=none; b=QyiZxa+pesF22U/RAsi9ji7AdoqeEdpqjqpiIMWJocwWiCsxyOTPHnV43u+yhvpjz7xBj/ tOat6ntO99paz9WXAmpkn2IcpbYOXwkxPY/zfIQLvHK5KAf/2MLkXA8NFFHfPw0EjoOZqy WUvff354UwlsCT0tWFl7CYK4EnKcmyg= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=none; spf=pass (imf18.hostedemail.com: domain of cmarinas@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cmarinas@kernel.org; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0CBFB638D6; Wed, 24 May 2023 17:19:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BAAE6C433EF; Wed, 24 May 2023 17:19:22 +0000 (UTC) From: Catalin Marinas To: Linus Torvalds , Christoph Hellwig , Robin Murphy Cc: Arnd Bergmann , Greg Kroah-Hartman , Will Deacon , Marc Zyngier , Andrew Morton , Herbert Xu , Ard Biesheuvel , Isaac Manjarres , Saravana Kannan , Alasdair Kergon , Daniel Vetter , Joerg Roedel , Mark Brown , Mike Snitzer , "Rafael J. Wysocki" , linux-mm@kvack.org, iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org Subject: [PATCH v5 04/15] mm/slab: Limit kmalloc() minimum alignment to dma_get_cache_alignment() Date: Wed, 24 May 2023 18:18:53 +0100 Message-Id: <20230524171904.3967031-5-catalin.marinas@arm.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230524171904.3967031-1-catalin.marinas@arm.com> References: <20230524171904.3967031-1-catalin.marinas@arm.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: E60AE1C0007 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: g7gqm885kr9zyh4p7r8t4yrxn99e3eez X-HE-Tag: 1684948767-795912 X-HE-Meta: U2FsdGVkX1/xftYLrbeauha6Ii5lsk5V3hFQEsfJJnC89JGLFty4kk9qWXJRTfH8xKMF9aKwUuCI6T7Y4Uy+MqW+kIXrPlIEQGnlf4O7PPylkjboJ12KJEUfkA6XsYovjWdKBToyMTR8Jsv6z3kcIroSlgXPDBpSev9vWVj3rugKe/INs5s4U2Y6Hb/a5IJEWjzfsWKOikFZnk/wiP0StHHZP5LZJ1S/1x78yKsCuXQriOajNT/YaW5U7FVThiGAEmqp7W5OwnRpA781R48F+yUuwMEdC7XE8FJ8ycQWx5f+5N457B7IArMbmY5BYL5kpafzrVzE6gCDFK9bMTLLCWKCyV0ubC4Z2RKS2p+yiKpouXx+K2vnvxQduidq2jOuJ7zs5tBQttZAVAz0gEe4Sqev1rA8JfZfmDbXQthExIxSyIuzcgz2ide05THC1yRxMf3kPRyNCygNTW9rvCg3mro677H02lajdTwJVekiKhIyHHfHE8wBD6Ey1r9DtZf6RnErfzrwqrb9uvgSC8Ns7s5jU5Jpf83MXiasLBYkf/wGRE8tHXnglhioED7QrjE5daYfQM/FtDrtZXMss2zBVABJGTWzD33YmS/SgeK67YBtA4sc9dNO4T443KZ/auIQ8is9afdqgW2G44zIFzn1YHcaDPRXa0sauHBL4PNZXo9bAQXoOZcjgxE6s2wpYendXnm7Ho78VFHK+q7i/BWoQnrdaD7354vT+vfichPRdUxgSdlEgXoEykV0vxlR4LV28id6dw2zSUsFZ6V1YaBQ0mPB2K4bQAaaAy3luo4dBS7HnuPPfArzJYdZRn4lSQODu7SsKSqNZKlLQQjFxsm69+mnPfwzhzm0tIUh90mG4h4uFQ2H8hnh13n/D6XNd/yb/tTkQ8wMjIep3/GuY/WxLYADF24S3Rm4U8OYFM+GSBpnxe+HFV0AQLowxSjhRoEsR4QWfX4ZIFaauYJNI5h cr7s/OuD bQzDKmdpcdKi+DBbB1IQATemFzj3HLXhxSGRQ4VDJX7UwfcK1xJ48WPsH+LxDSkO+jRQ6BVB7t9DSXyDTPSpPNul9wqrJ16bWTs2IgRHuBQ6yImq6XlU3Vn7yX4j0dBzvdsoAPVIZYNn9GsYMZZYnqgg8nsJmLxLgD/2tzsRxwt0R6aHvxPQdVXwbDPvCUJ1TD9iKv8Z0lN5RtwMmJqFcpe2fVMBDo/sHp/ijam0LIkkFJDd3piG6tbe4M2RJ+MxVSOT5pN/MgCbkmTrBoIMPEYmkuhHhLMD+QSwLImRISczPajR4kq1bUL+A4AOjn/t0Iya9ekPzEs7unAwpn7DN75G2OSKF+CTBxV0VO8DRXAlqSJ0TrBO0K4nh9+VSw7x+pbXghW+Gc+1x/O/Q6yGW0s7dDekOHCyc3a0niXw48793MM1TIOkYwgYsHMbEOkAGTqLgIZP99RWxY728hfA0T3UtxVVIIEuEgFLakHQ7SmkO8YRYx7LHC5SftU8FRNkka3wT1IKHbjHUK+BiEMJfhMh8eRaB/AkY6wxDJZd+DZA++O6BANshneUpisWt3dqBBdzt 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: Do not create kmalloc() caches which are not aligned to dma_get_cache_alignment(). There is no functional change since for current architectures defining ARCH_DMA_MINALIGN, ARCH_KMALLOC_MINALIGN equals ARCH_DMA_MINALIGN (and dma_get_cache_alignment()). On architectures without a specific ARCH_DMA_MINALIGN, dma_get_cache_alignment() is 1, so no change to the kmalloc() caches. If an architecture selects ARCH_HAS_DMA_CACHE_LINE_SIZE (introduced previously), the kmalloc() caches will be aligned to a cache line size. Signed-off-by: Catalin Marinas Cc: Andrew Morton Cc: Christoph Hellwig Cc: Robin Murphy --- mm/slab_common.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/mm/slab_common.c b/mm/slab_common.c index 7f069159aee2..7c6475847fdf 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -862,9 +863,18 @@ void __init setup_kmalloc_cache_index_table(void) } } +static unsigned int __kmalloc_minalign(void) +{ + return dma_get_cache_alignment(); +} + void __init new_kmalloc_cache(int idx, enum kmalloc_cache_type type, slab_flags_t flags) { + unsigned int minalign = __kmalloc_minalign(); + unsigned int aligned_size = kmalloc_info[idx].size; + int aligned_idx = idx; + if ((KMALLOC_RECLAIM != KMALLOC_NORMAL) && (type == KMALLOC_RECLAIM)) { flags |= SLAB_RECLAIM_ACCOUNT; } else if (IS_ENABLED(CONFIG_MEMCG_KMEM) && (type == KMALLOC_CGROUP)) { @@ -877,9 +887,17 @@ new_kmalloc_cache(int idx, enum kmalloc_cache_type type, slab_flags_t flags) flags |= SLAB_CACHE_DMA; } - kmalloc_caches[type][idx] = create_kmalloc_cache( - kmalloc_info[idx].name[type], - kmalloc_info[idx].size, flags); + if (minalign > ARCH_KMALLOC_MINALIGN) { + aligned_size = ALIGN(aligned_size, minalign); + aligned_idx = __kmalloc_index(aligned_size, false); + } + + if (!kmalloc_caches[type][aligned_idx]) + kmalloc_caches[type][aligned_idx] = create_kmalloc_cache( + kmalloc_info[aligned_idx].name[type], + aligned_size, flags); + if (idx != aligned_idx) + kmalloc_caches[type][idx] = kmalloc_caches[type][aligned_idx]; /* * If CONFIG_MEMCG_KMEM is enabled, disable cache merging for