From: Robin Murphy <robin.murphy@arm.com>
To: Geert Uytterhoeven <geert@linux-m68k.org>,
Christoph Hellwig <hch@lst.de>,
Marek Szyprowski <m.szyprowski@samsung.com>,
David Rientjes <rientjes@google.com>
Cc: iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] dma-pool: Fix too large DMA pools on medium systems
Date: Mon, 8 Jun 2020 13:03:54 +0100 [thread overview]
Message-ID: <92b53a24-2f1f-2add-6bea-eeda7317520f@arm.com> (raw)
In-Reply-To: <20200608085231.8924-1-geert@linux-m68k.org>
On 2020-06-08 09:52, Geert Uytterhoeven wrote:
> 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.
>
> Fixes: 1d659236fb43c4d2 ("dma-pool: scale the default DMA coherent pool size with memory capacity")
> Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
> ---
> kernel/dma/pool.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/dma/pool.c b/kernel/dma/pool.c
> index 35bb51c31fff370f..1c7eab2cc0498003 100644
> --- a/kernel/dma/pool.c
> +++ b/kernel/dma/pool.c
> @@ -175,8 +175,8 @@ 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;
> + unsigned long gigs = totalram_pages() >> (30 - PAGE_SHIFT);
> + atomic_pool_size = max(gigs, 1UL) * SZ_128K;
> atomic_pool_size = min_t(size_t, atomic_pool_size,
> 1 << (PAGE_SHIFT + MAX_ORDER-1));
> }
Nit: although this probably is right, it seems even less readable than
the broken version (where at least some at-a-glance 'dimensional
analysis' flags up "(number of pages) >> PAGE_SHIFT" as rather
suspicious). How about a something a little more self-explanatory, e.g.:
unsigned long pages = totalram_pages() * SZ_128K / SZ_1GB;
atomic_pool_size = min(pages, MAX_ORDER_NR_PAGES) << PAGE_SHIFT;
atomic_pool_size = max_t(size_t, atomic_pool_size, SZ_128K);
?
Robin.
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
next prev parent reply other threads:[~2020-06-08 12:04 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-08 8:52 [PATCH] dma-pool: Fix too large DMA pools on medium systems Geert Uytterhoeven
2020-06-08 12:03 ` Robin Murphy [this message]
2020-06-08 12:25 ` Geert Uytterhoeven
2020-06-08 12:53 ` Robin Murphy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=92b53a24-2f1f-2add-6bea-eeda7317520f@arm.com \
--to=robin.murphy@arm.com \
--cc=geert@linux-m68k.org \
--cc=hch@lst.de \
--cc=iommu@lists.linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=rientjes@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).