Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp4402505ybg; Mon, 8 Jun 2020 07:04:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyigfGLJRUn6WF2DfIiqghrMwWLztd/h5ZmMcuDZQ77izGUXxbEkae0yJAwj/+c/UQ8LJT1 X-Received: by 2002:a17:906:c1c4:: with SMTP id bw4mr13435742ejb.452.1591625045548; Mon, 08 Jun 2020 07:04:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591625045; cv=none; d=google.com; s=arc-20160816; b=DiAYwNiobqhcA6tRhLagHxL2cj5E2Ptjmja2PSBkx49aV02qAaL8CatK6VU9Cr1P1M QWvPNBZpsQTDC6t+zc3f2runywz/EBqN1hsNSsnZRe/SPoGSVI9JepJVBwZ44WcKffuw vHdSb4u5sE5ZcYaAF63YQ3+nKarh62itZixcJZH2N5EbEIImd9sr5Y62mQCo6LBs6eL/ HUArFBCekMudN8H+BofJt7kuj7tLHqqiJ3Q2fMAPeawmsEPvnskx4If82RJ9AoV5CpEk Ui/g1qt+Vw0NYnfua3OZ4LEW6/9Y9xq0tSd2iaz95JjDSgB8hsG22hBV5hsqzYU3Ma+J BMOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=C9S7R6xx8HsAOOaCnJ+to/96q1YOO2LmKpMZnVrbDbE=; b=FNYBo6loCS6FE7Q+jwy9cMpak3djHQ3ZaqPZD5Mb8gwnF0clvBrkWk7Ynm+oQTQnWc suvsFwI+gkqsSRoIP/qL2WkvrOr+K1OhMCE39zOsHe6zP9pA/djkKahvbNuiND+7DPGm afKSSNH+FaGK+OBp4j1VcDT45FEXc5qGZhOP9mQxSM/zV2iNyz3beoiCs0RfW4rtw5iE Y8O65UQwEbTohoTmNatLecXgzc8YKRcZ2gw6+V2dLX3hhAp79hxMXwsNJGAC3hwbmEWW poJ2fKJGPuMv5MCOjwbMPQU2MY6Az1Mn0hrdCC/0XFvfwEP/eEWADjQecjZXJGMQoq3C 1D1Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c24si9111193edv.129.2020.06.08.07.03.38; Mon, 08 Jun 2020 07:04:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729550AbgFHNWX (ORCPT + 99 others); Mon, 8 Jun 2020 09:22:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728022AbgFHNWW (ORCPT ); Mon, 8 Jun 2020 09:22:22 -0400 Received: from xavier.telenet-ops.be (xavier.telenet-ops.be [IPv6:2a02:1800:120:4::f00:14]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8CD32C08C5C2 for ; Mon, 8 Jun 2020 06:22:22 -0700 (PDT) Received: from ramsan ([IPv6:2a02:1810:ac12:ed60:c85f:a5bf:b1bd:702b]) by xavier.telenet-ops.be with bizsmtp id odNJ2200D0R8aca01dNJ0S; Mon, 08 Jun 2020 15:22:18 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan with esmtp (Exim 4.90_1) (envelope-from ) id 1jiHjG-00013I-97; Mon, 08 Jun 2020 15:22:18 +0200 Received: from geert by rox.of.borg with local (Exim 4.90_1) (envelope-from ) id 1jiHjG-0007nj-6d; Mon, 08 Jun 2020 15:22:18 +0200 From: Geert Uytterhoeven To: Christoph Hellwig , Marek Szyprowski , Robin Murphy , David Rientjes Cc: iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH v2] dma-pool: Fix too large DMA pools on medium systems Date: Mon, 8 Jun 2020 15:22:17 +0200 Message-Id: <20200608132217.29945-1-geert@linux-m68k.org> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On systems with at least 32 MiB, but less than 32 GiB of RAM, the DMA memory pools are much larger than intended (e.g. 2 MiB instead of 128 KiB on a 256 MiB system). Fix this by correcting the calculation of the number of GiBs of RAM in the system. Invert the order of the min/max operations, to keep on calculating in pages until the last step, which aids readability. Fixes: 1d659236fb43c4d2 ("dma-pool: scale the default DMA coherent pool size with memory capacity") Signed-off-by: Geert Uytterhoeven --- v2: - Improve readability: - Divide by (SZ_1G / SZ_128K) instead of using a shift, - Invert min/max order to keep calculating in pages until the last step. --- kernel/dma/pool.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/kernel/dma/pool.c b/kernel/dma/pool.c index 35bb51c31fff370f..8cfa01243ed27b6f 100644 --- a/kernel/dma/pool.c +++ b/kernel/dma/pool.c @@ -175,10 +175,9 @@ static int __init dma_atomic_pool_init(void) * sizes to 128KB per 1GB of memory, min 128KB, max MAX_ORDER-1. */ if (!atomic_pool_size) { - atomic_pool_size = max(totalram_pages() >> PAGE_SHIFT, 1UL) * - SZ_128K; - atomic_pool_size = min_t(size_t, atomic_pool_size, - 1 << (PAGE_SHIFT + MAX_ORDER-1)); + unsigned long pages = totalram_pages() / (SZ_1G / SZ_128K); + pages = min_t(unsigned long, pages, MAX_ORDER_NR_PAGES); + atomic_pool_size = max_t(size_t, pages << PAGE_SHIFT, SZ_128K); } INIT_WORK(&atomic_pool_work, atomic_pool_work_fn); -- 2.17.1