From patchwork Wed May 8 13:23:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13658768 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 B8964C19F4F for ; Wed, 8 May 2024 13:23:43 +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=kUwdLN98iMU9mUcbCoWSUcAJ3U1NzPhCyl6+Jt3oXSI=; b=mQk0WsClNM9CeQ fNypSC6rRgCRYlhXuRz2W7iubuOep0nwRtQFe0u1c9RFiRbebmMtBvyyTqLFSwq2yQNEXxf4Sju7r TQhQj9Z9OwNpmkn1iW2ZvnhnQom7aLQcUSatJ7Rt3SnELPbuKXmVZM4FT0cYr8xGCbn587EMvLA3C ifgE1VKQtNRHUXwGBlxfNBdzvEwYJ2qby1OUWT68DG0mWTSt1JbBQo2qkicnSEAQf0+iowBGX/1nO svjUEmt/UJM6tmWVrRFch3/E2XJ+DbTPqlYUCLqotlhY704p2aaCfyvmck64q/Yx80KMypCTiqTu4 8oR/CgsPJJrsOiRKVnpA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s4hGZ-0000000Fd5s-0d1o; Wed, 08 May 2024 13:23:27 +0000 Received: from szxga02-in.huawei.com ([45.249.212.188]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s4hGP-0000000Fd2T-0jBk for linux-arm-kernel@lists.infradead.org; Wed, 08 May 2024 13:23:25 +0000 Received: from mail.maildlp.com (unknown [172.19.162.254]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4VZG2D1mW5zYpLv; Wed, 8 May 2024 21:19:16 +0800 (CST) Received: from dggpemm100001.china.huawei.com (unknown [7.185.36.93]) by mail.maildlp.com (Postfix) with ESMTPS id 23E2D1800B8; Wed, 8 May 2024 21:23:07 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemm100001.china.huawei.com (7.185.36.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Wed, 8 May 2024 21:23:06 +0800 From: Kefeng Wang To: Catalin Marinas , Will Deacon CC: , Kefeng Wang Subject: [PATCH] arm64: mm: reduce swiotlb size when dynamic swiotlb enabled Date: Wed, 8 May 2024 21:23:00 +0800 Message-ID: <20240508132300.691518-1-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm100001.china.huawei.com (7.185.36.93) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240508_062317_462079_1E2C7CEF X-CRM114-Status: GOOD ( 10.94 ) 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 After commit a1e50a82256e ("arm64: Increase the swiotlb buffer size 64MB"), the swiotlb buffer size increased to 64M in case of 32-bit only devices require many bounce buffering via swiotlb, but with the CONFIG_SWIOTLB_DYNAMIC enabled, we could reduce swiotlb size from 64M to 4M(MAX_ORDER_NR_PAGES << PAGE_SHIFT) again since swiotlb buffer size could be allocated danamicly, and this should save 60M for most platform which don't require too much swiotlb buffer. Signed-off-by: Kefeng Wang --- arch/arm64/mm/init.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index 9b5ab6818f7f..425222c13d97 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -370,18 +370,23 @@ void __init bootmem_init(void) void __init mem_init(void) { bool swiotlb = max_pfn > PFN_DOWN(arm64_dma_phys_limit); + unsigned long size = 0; 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 = - DIV_ROUND_UP(memblock_phys_mem_size(), 1024); - swiotlb_adjust_size(min(swiotlb_size_or_default(), size)); + size = DIV_ROUND_UP(memblock_phys_mem_size(), 1024); swiotlb = true; } + if (IS_ENABLED(CONFIG_SWIOTLB_DYNAMIC) && !size) + size = MAX_ORDER_NR_PAGES << PAGE_SHIFT; + + if (size) + swiotlb_adjust_size(min(swiotlb_size_or_default(), size)); + swiotlb_init(swiotlb, SWIOTLB_VERBOSE); /* this will put all unused low memory onto the freelists */