From patchwork Fri Oct 6 15:32:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Catalin Marinas X-Patchwork-Id: 13411690 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 E2987E81E0B for ; Fri, 6 Oct 2023 15:33:25 +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=jLOdAbOCCqRSp7NbAQpHvDzudZ5rRP3DyvJvn7onGgc=; b=ddR/Wd82F7Xt85 aqgkZ5lxnXEVDrU8uzDmrvjcOEVw8QZye7dkBrHPtf+gWovco7WuHmgmlNoMpup6zxdm4lULI14Wi Rpj05eZ9gZlucFB5W2clS3gWMtWj+WYHl6KtaDUellfuHExdaNpBe6/JWj4zvRJYGWmJ/quE7P7I9 CKiEmP3mnKNma8iisCjKEPh8o7PYAEoOAcQ4k5IF8zHKgEO2+N4LiNWKdWXvXU2VlKIbHg0Yh2kir NzoxRlcXP/pgw21ThbUZ46DvtOE3vUrPMSo65k3qKMc9TdP+5PSA/OljEFFc4AgEH8/56I9zVB2gf kgyXnVSCP8Ki6dJe5bKw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qomp3-00668K-14; Fri, 06 Oct 2023 15:33:01 +0000 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qomp0-00667e-2n for linux-arm-kernel@lists.infradead.org; Fri, 06 Oct 2023 15:33:00 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by ams.source.kernel.org (Postfix) with ESMTP id 4FE4CB829C6; Fri, 6 Oct 2023 15:32:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AA1AFC433C9; Fri, 6 Oct 2023 15:32:55 +0000 (UTC) From: Catalin Marinas To: linux-arm-kernel@lists.infradead.org Cc: Ross Burton , Robin Murphy , Will Deacon Subject: [PATCH] arm64: swiotlb: Reduce the default size if no ZONE_DMA bouncing needed Date: Fri, 6 Oct 2023 16:32:52 +0100 Message-Id: <20231006153252.3162299-1-catalin.marinas@arm.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231006_083259_062664_5CA37D3E X-CRM114-Status: GOOD ( 12.11 ) 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 With CONFIG_DMA_BOUNCE_UNALIGNED_KMALLOC enabled, the arm64 kernel still allocates the default SWIOTLB buffer (64MB) even if ZONE_DMA is disabled or all the RAM fits into this zone. However, this potentially wastes a non-negligible amount of memory on platforms with little RAM. Reduce the SWIOTLB size to 1MB per 1GB of RAM if only needed for kmalloc() buffer bouncing. Signed-off-by: Catalin Marinas Suggested-by: Ross Burton Cc: Ross Burton Cc: Robin Murphy Cc: Will Deacon --- arch/arm64/mm/init.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index 8a0f8604348b..54ee1a4868c2 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -493,8 +493,16 @@ void __init mem_init(void) { bool swiotlb = max_pfn > PFN_DOWN(arm64_dma_phys_limit); - if (IS_ENABLED(CONFIG_DMA_BOUNCE_UNALIGNED_KMALLOC)) + if (IS_ENABLED(CONFIG_DMA_BOUNCE_UNALIGNED_KMALLOC) && !swiotlb) { + /* + * If no bouncing needed for ZONE_DMA, reduce the swiotlb + * buffer for kmalloc() bouncing to 1MB per 1GB of RAM. + */ + unsigned long size = + ALIGN(memblock_phys_mem_size(), SZ_1G) >> 10; + swiotlb_adjust_size(min(swiotlb_size_or_default(), size)); swiotlb = true; + } swiotlb_init(swiotlb, SWIOTLB_VERBOSE);