Linux IOMMU Development
 help / color / mirror / Atom feed
From: Robin Murphy <robin.murphy@arm.com>
To: Christoph Hellwig <hch@lst.de>,
	iommu@lists.linux.dev,
	Marek Szyprowski <m.szyprowski@samsung.com>
Cc: Michal Hocko <mhocko@suse.com>,
	David Rientjes <rientjes@google.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/3] dma-pool: limit DMA and DMA32 zone size pools
Date: Wed, 17 Aug 2022 13:50:09 +0100	[thread overview]
Message-ID: <04790bd9-4f20-4d51-b988-ad4b44eeee98@arm.com> (raw)
In-Reply-To: <20220817060647.1032426-4-hch@lst.de>

On 2022-08-17 07:06, Christoph Hellwig wrote:
> Limit the sizing of the atomic pools for allocations from
> ZONE_DMA and ZONE_DMA32 based on the number of pages actually
> present in those zones instead of the total memory.
> 
> Fixes: c84dc6e68a1d ("dma-pool: add additional coherent pools to map to gfp mask")
> Reported-by: Michal Hocko <mhocko@suse.com>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>   kernel/dma/pool.c | 40 +++++++++++++++++++++++++++++-----------
>   1 file changed, 29 insertions(+), 11 deletions(-)
> 
> diff --git a/kernel/dma/pool.c b/kernel/dma/pool.c
> index 5b07b0379a501..f629c6dfd8555 100644
> --- a/kernel/dma/pool.c
> +++ b/kernel/dma/pool.c
> @@ -193,28 +193,46 @@ static unsigned long calculate_pool_size(unsigned long zone_pages)
>   	return max_t(unsigned long, nr_pages << PAGE_SHIFT, SZ_128K);
>   }
>   
> +#if defined(CONFIG_ZONE_DMA) || defined(CONFIG_ZONE_DMA32)

This #ifdeffery seems horribly clunky - I think it would be much nicer 
to mark this __maybe_unused, and preserve the has_managed_dma/IS_ENABLED 
logic below.

> +static unsigned long __init nr_managed_pages(int zone_idx)
> +{
> +	struct pglist_data *pgdat;
> +	unsigned long nr_pages = 0;
> +
> +	for_each_online_pgdat(pgdat)
> +		nr_pages += zone_managed_pages(&pgdat->node_zones[zone_idx]);
> +	return nr_pages;
> +}
> +#endif /* CONFIG_ZONE_DMA || CONFIG_ZONE_DMA32 */
> +
>   static int __init dma_atomic_pool_init(void)
>   {
> +	unsigned long nr_zone_dma_pages, nr_zone_dma32_pages;

...otherwise, I expect the buildbots will be along shortly with unused 
variable warnings for these :)

Cheers,
Robin.

> +
> +#ifdef CONFIG_ZONE_DMA
> +	nr_zone_dma_pages = nr_managed_pages(ZONE_DMA);
> +	if (nr_zone_dma_pages)
> +		atomic_pool_dma = __dma_atomic_pool_init(
> +				calculate_pool_size(nr_zone_dma_pages),
> +				GFP_DMA);
> +#endif
> +#ifdef CONFIG_ZONE_DMA32
> +	nr_zone_dma32_pages = nr_managed_pages(ZONE_DMA32);
> +	if (nr_zone_dma32_pages)
> +		atomic_pool_dma32 = __dma_atomic_pool_init(
> +				calculate_pool_size(nr_zone_dma32_pages),
> +				GFP_DMA32);
> +#endif
>   	/*
>   	 * 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)
>   		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,
>   						    GFP_KERNEL);
> -	if (has_managed_dma()) {
> -		atomic_pool_dma = __dma_atomic_pool_init(atomic_pool_size,
> -						GFP_KERNEL | GFP_DMA);
> -	}
> -	if (IS_ENABLED(CONFIG_ZONE_DMA32)) {
> -		atomic_pool_dma32 = __dma_atomic_pool_init(atomic_pool_size,
> -						GFP_KERNEL | GFP_DMA32);
> -	}
>   
> +	INIT_WORK(&atomic_pool_work, atomic_pool_work_fn);
>   	dma_atomic_pool_debugfs_init();
>   	return 0;
>   }

  reply	other threads:[~2022-08-17 12:50 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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
2022-08-17  6:06 ` [PATCH 2/3] dma-pool: don't return errors from dma_atomic_pool_init Christoph Hellwig
2022-08-17 12:36   ` Robin Murphy
2022-08-17  6:06 ` [PATCH 3/3] dma-pool: limit DMA and DMA32 zone size pools Christoph Hellwig
2022-08-17 12:50   ` Robin Murphy [this message]
2022-08-21 10:43     ` Christoph Hellwig
2022-08-17 12:53   ` Michal Hocko
2022-08-21 10:44     ` Christoph Hellwig
2022-08-22  8:41       ` Michal Hocko
2022-08-22 11:14         ` Christoph Hellwig
2022-08-22 12:09           ` Michal Hocko
2022-08-22 12:27             ` Christoph Hellwig
2022-08-22 14:21               ` Michal Hocko
  -- strict thread matches above, loose matches on Subject: below --
2022-08-22  6:12 fix dma coherent pool sizing Christoph Hellwig
2022-08-22  6:12 ` [PATCH 3/3] dma-pool: limit DMA and DMA32 zone size pools 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=04790bd9-4f20-4d51-b988-ad4b44eeee98@arm.com \
    --to=robin.murphy@arm.com \
    --cc=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 \
    /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