From: Christoph Hellwig <hch@lst.de>
To: iommu@lists.linux.dev,
Marek Szyprowski <m.szyprowski@samsung.com>,
Robin Murphy <robin.murphy@arm.com>
Cc: Michal Hocko <mhocko@suse.com>,
David Rientjes <rientjes@google.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH 1/3] dma-pool: factor out a calculate_pool_size helper
Date: Mon, 22 Aug 2022 08:12:53 +0200 [thread overview]
Message-ID: <20220822061255.151688-2-hch@lst.de> (raw)
In-Reply-To: <20220822061255.151688-1-hch@lst.de>
Add a helper to calculate the pool size from dma_atomic_pool_init.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Robin Murphy <robin.murphy@arm.com>
---
kernel/dma/pool.c | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/kernel/dma/pool.c b/kernel/dma/pool.c
index 4d40dcce7604b..37008d4f6d7af 100644
--- a/kernel/dma/pool.c
+++ b/kernel/dma/pool.c
@@ -184,6 +184,14 @@ static __init struct gen_pool *__dma_atomic_pool_init(size_t pool_size,
return pool;
}
+static size_t calculate_pool_size(unsigned long zone_pages)
+{
+ unsigned long pages = zone_pages / (SZ_1G / SZ_128K);
+
+ pages = min_t(unsigned long, pages, MAX_ORDER_NR_PAGES);
+ return max_t(size_t, pages << PAGE_SHIFT, SZ_128K);
+}
+
static int __init dma_atomic_pool_init(void)
{
int ret = 0;
@@ -192,11 +200,9 @@ static int __init dma_atomic_pool_init(void)
* If coherent_pool was not used on the command line, default the pool
* sizes to 128KB per 1GB of memory, min 128KB, max MAX_ORDER-1.
*/
- if (!atomic_pool_size) {
- 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);
- }
+ if (!atomic_pool_size)
+ atomic_pool_size = calculate_pool_size(totalram_pages());
+
INIT_WORK(&atomic_pool_work, atomic_pool_work_fn);
atomic_pool_kernel = __dma_atomic_pool_init(atomic_pool_size,
--
2.30.2
next prev parent reply other threads:[~2022-08-22 6:13 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-22 6:12 fix dma coherent pool sizing Christoph Hellwig
2022-08-22 6:12 ` Christoph Hellwig [this message]
2022-08-22 6:12 ` [PATCH 2/3] dma-pool: don't return errors from dma_atomic_pool_init Christoph Hellwig
2022-08-22 6:12 ` [PATCH 3/3] dma-pool: limit DMA and DMA32 zone size pools Christoph Hellwig
-- strict thread matches above, loose matches on Subject: below --
2022-08-17 6:06 fix dma coherent pool sizing Christoph Hellwig
2022-08-17 6:06 ` [PATCH 1/3] dma-pool: factor out a calculate_pool_size helper Christoph Hellwig
2022-08-17 12:32 ` Robin Murphy
2022-08-21 10:41 ` Christoph Hellwig
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=20220822061255.151688-2-hch@lst.de \
--to=hch@lst.de \
--cc=iommu@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=mhocko@suse.com \
--cc=rientjes@google.com \
--cc=robin.murphy@arm.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