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 5CD27E81E17 for ; Fri, 6 Oct 2023 16:25:39 +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-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:From:References:Cc:To:Subject: MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=42DGuykhAdlUrfIS2ZouIq3AI3ZXpV21bueB3c3kRec=; b=SiqFlX0/+9DVs2 1liKZfj20pc/QBUo5zRaB88p6d+DjdsHkO0sPpajbqQT8udmxV5NGEgwTnmt2UPnt++qFnUwZtMrQ PP8pqcUDNbqUGi6u6AWj6ExoP/3P9zb/uD0Vc94VV5kKFa1AMI+TbBOHpAFqpDS8Hwi45/nb27CKT 0wNFLayJnik1kZv9OcY1Wvgbp4stbMKbAiCasFtUHOVci2WSV8s7YC0zLazRCyDPouL3ZcldEP/l5 mpVPjofloB8VfCdp20BFdonsbnMmpSNhtaQYA+X+pft7pZCAvl3BCSG7bNle2LpT9eEWchdq23W3y l3uXN0anTgBP+OdPyQmQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qondc-006BIU-2g; Fri, 06 Oct 2023 16:25:16 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qondZ-006BHi-31 for linux-arm-kernel@lists.infradead.org; Fri, 06 Oct 2023 16:25:15 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id F241DC15; Fri, 6 Oct 2023 09:25:45 -0700 (PDT) Received: from [10.57.66.230] (unknown [10.57.66.230]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D2C6A3F5A1; Fri, 6 Oct 2023 09:25:05 -0700 (PDT) Message-ID: Date: Fri, 6 Oct 2023 17:25:03 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] arm64: swiotlb: Reduce the default size if no ZONE_DMA bouncing needed Content-Language: en-GB To: Catalin Marinas , linux-arm-kernel@lists.infradead.org Cc: Ross Burton , Will Deacon References: <20231006153252.3162299-1-catalin.marinas@arm.com> From: Robin Murphy In-Reply-To: <20231006153252.3162299-1-catalin.marinas@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231006_092514_025125_6145D979 X-CRM114-Status: GOOD ( 19.41 ) 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: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 2023-10-06 16:32, Catalin Marinas wrote: > 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; Hmm, I wondered if DIV_ROUND_UP(memblock_phys_mem_size(), 1024) might be any easier, but by the time I've typed it out it's still just as long :) Either way then, Reviewed-by Robin Murphy > + swiotlb_adjust_size(min(swiotlb_size_or_default(), size)); > swiotlb = true; > + } > > swiotlb_init(swiotlb, SWIOTLB_VERBOSE); > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel