From patchwork Tue Apr 5 13:57:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Catalin Marinas X-Patchwork-Id: 12801551 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9B865C433F5 for ; Tue, 5 Apr 2022 13:59:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=Ax6y34jInjxRNhMO0lRycR9Re8tMZLDMJMjQAMqZnMM=; b=hmyJUo8lMwvWTd XbeI+1aLdoH+ZDCChwyllo0YvCsJLiGBnz/pURg79NjzMYTvxSop6Nmi0D4PJoQOBvVWBtmnHtVRU +cIREIc6h3DBGuedZt05WamP3w4192E4QpuU7gakpISANfNzwQdWKFbwcRRainuY+1fn+3t4YehL3 BjrLxc3K3cAcsB+os+fMmSFx8lM+a+6KbD3YbZ6CQtbysAbOQr3KeR4Mtfl5rTFEd/IyLjdvWM3EZ O+jqGGN6OABa4SPU/nzVzzTZ4P8JUR3oEVXfcu59W8+gGhacvE7PN+5mJ7HWCKsY5gib+p6OjDbEZ W9BShBZXb4WU3yVSBgNA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nbjhk-001GAJ-OG; Tue, 05 Apr 2022 13:58:45 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nbjh7-001FnU-JA for linux-arm-kernel@lists.infradead.org; Tue, 05 Apr 2022 13:58:07 +0000 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 91E6961881; Tue, 5 Apr 2022 13:58:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E608EC385A4; Tue, 5 Apr 2022 13:58:00 +0000 (UTC) From: Catalin Marinas To: Will Deacon , Marc Zyngier , Arnd Bergmann , Greg Kroah-Hartman , Andrew Morton , Linus Torvalds Cc: linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Herbert Xu , "David S. Miller" , Mark Brown , Alasdair Kergon , Mike Snitzer , Daniel Vetter , "Rafael J. Wysocki" Subject: [PATCH 00/10] mm, arm64: Reduce ARCH_KMALLOC_MINALIGN below the cache line size Date: Tue, 5 Apr 2022 14:57:48 +0100 Message-Id: <20220405135758.774016-1-catalin.marinas@arm.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220405_065805_749620_5115C00D X-CRM114-Status: GOOD ( 19.67 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi, On arm64 ARCH_DMA_MINALIGN (and therefore ARCH_KMALLOC_MINALIGN) is 128. While the majority of arm64 SoCs have a 64-byte cache line size (or rather CWG - cache writeback granule), we chose a less than optimal value in order to support all SoCs in a single kernel image. The aim of this series is to allow smaller default ARCH_KMALLOC_MINALIGN with kmalloc() caches configured at boot time to be safe when an SoC has a larger DMA alignment requirement. The first patch decouples ARCH_KMALLOC_MINALIGN from ARCH_DMA_MINALIGN with the aim to only use the latter in DMA-specific compile-time annotations. ARCH_KMALLOC_MINALIGN becomes the minimum (static) guaranteed kmalloc() alignment but not necessarily safe for non-coherent DMA. Patches 2-7 change some drivers/ code to use ARCH_DMA_MINALIGN instead of ARCH_KMALLOC_MINALIGN. Patch 8 introduces the dynamic arch_kmalloc_minalign() and the slab code changes to set the corresponding minimum alignment on the newly created kmalloc() caches. Patch 10 defines arch_kmalloc_minalign() for arm64 returning cache_line_size() together with reducing ARCH_KMALLOC_MINALIGN to 64. ARCH_DMA_MINALIGN remains 128 on arm64. I don't have access to it but there's the Fujitsu A64FX with a CWG of 256 (the arm64 cache_line_size() returns 256). This series will bump the smallest kmalloc cache to kmalloc-256. The platform is known to be fully cache coherent (or so I think) and we decided long ago not to bump ARCH_DMA_MINALIGN to 256. If problematic, we could make the dynamic kmalloc() alignment on arm64 min(ARCH_DMA_MINALIGN, cache_line_size()). This series is beneficial to arm64 even if it's only reducing the kmalloc() minimum alignment to 64. While it would be nice to reduce this further to 8 (or 16) on SoCs known to be fully DMA coherent, detecting this is via arch_setup_dma_ops() is problematic, especially with late probed devices. I'd leave it for an additional RFC series on top of this (there are ideas like bounce buffering for non-coherent devices if the SoC was deemed coherent). Thanks. Catalin Marinas (10): mm/slab: Decouple ARCH_KMALLOC_MINALIGN from ARCH_DMA_MINALIGN drivers/base: Use ARCH_DMA_MINALIGN instead of ARCH_KMALLOC_MINALIGN drivers/gpu: Use ARCH_DMA_MINALIGN instead of ARCH_KMALLOC_MINALIGN drivers/md: Use ARCH_DMA_MINALIGN instead of ARCH_KMALLOC_MINALIGN drivers/spi: Use ARCH_DMA_MINALIGN instead of ARCH_KMALLOC_MINALIGN drivers/usb: Use ARCH_DMA_MINALIGN instead of ARCH_KMALLOC_MINALIGN crypto: Use ARCH_DMA_MINALIGN instead of ARCH_KMALLOC_MINALIGN mm/slab: Allow dynamic kmalloc() minimum alignment mm/slab: Simplify create_kmalloc_cache() args and make it static arm64: Enable dynamic kmalloc() minimum alignment arch/arm64/include/asm/cache.h | 1 + arch/arm64/kernel/cacheinfo.c | 7 ++++++ drivers/base/devres.c | 4 ++-- drivers/gpu/drm/drm_managed.c | 4 ++-- drivers/md/dm-crypt.c | 2 +- drivers/spi/spidev.c | 2 +- drivers/usb/core/buffer.c | 8 +++---- drivers/usb/misc/usbtest.c | 2 +- include/linux/crypto.h | 2 +- include/linux/slab.h | 25 ++++++++++++++++----- mm/slab.c | 6 +---- mm/slab.h | 5 ++--- mm/slab_common.c | 40 ++++++++++++++++++++++------------ 13 files changed, 69 insertions(+), 39 deletions(-)