lkml.org 
[lkml]   [2022]   [Aug]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH 1/3] dma-pool: factor out a calculate_pool_size helper
From
On 2022-08-17 07:06, Christoph Hellwig wrote:
> Add a helper to calculate the pool size from dma_atomic_pool_init,
> and fix up the last max_t to use the proper type.

Hmm, both atomic_pool_size and the argument to __dma_atomic_pool_init()
where this gets directly passed later are size_t, not to mention that
the function name says we're calculating a size, so I'd say size_t *is*
the proper type to return here.

> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
> kernel/dma/pool.c | 17 ++++++++++++-----
> 1 file changed, 12 insertions(+), 5 deletions(-)
>
> diff --git a/kernel/dma/pool.c b/kernel/dma/pool.c
> index 4d40dcce7604b..56f96678934bf 100644
> --- a/kernel/dma/pool.c
> +++ b/kernel/dma/pool.c
> @@ -184,6 +184,15 @@ static __init struct gen_pool *__dma_atomic_pool_init(size_t pool_size,
> return pool;
> }
>
> +static unsigned long calculate_pool_size(unsigned long zone_pages)
> +{
> + unsigned long nr_pages = min_t(unsigned long,
> + zone_pages / (SZ_1G / SZ_128K),
> + MAX_ORDER_NR_PAGES);

Nit: this is arguably less readable, and objectively one line longer,
than the original two statements.

Other that those nits though,

Reviewed-by: Robin Murphy <robin.murphy@arm.com>

> +
> + return max_t(unsigned long, nr_pages << PAGE_SHIFT, SZ_128K);
> +}
> +
> static int __init dma_atomic_pool_init(void)
> {
> int ret = 0;
> @@ -192,11 +201,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,

\
 
 \ /
  Last update: 2022-08-17 14:33    [W:1.173 / U:0.100 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site