From: Christoph Hellwig <hch@lst.de>
To: Barry Song <song.bao.hua@hisilicon.com>
Cc: catalin.marinas@arm.com, Mike Rapoport <rppt@linux.ibm.com>,
Steve Capper <steve.capper@arm.com>,
robin.murphy@arm.com,
Jonathan Cameron <Jonathan.Cameron@huawei.com>,
linuxarm@huawei.com, linux-kernel@vger.kernel.org,
iommu@lists.linux-foundation.org,
Nicolas Saenz Julienne <nsaenzjulienne@suse.de>,
prime.zeng@hisilicon.com, ganapatrao.kulkarni@cavium.com,
Andrew Morton <akpm@linux-foundation.org>,
huangdaode@huawei.com, will@kernel.org, hch@lst.de,
linux-arm-kernel@lists.infradead.org, m.szyprowski@samsung.com
Subject: Re: [PATCH v4 1/2] dma-direct: provide the ability to reserve per-numa CMA
Date: Tue, 28 Jul 2020 13:52:31 +0200 [thread overview]
Message-ID: <20200728115231.GA793@lst.de> (raw)
In-Reply-To: <20200723131344.41472-2-song.bao.hua@hisilicon.com>
On Fri, Jul 24, 2020 at 01:13:43AM +1200, Barry Song wrote:
> +config CMA_PERNUMA_SIZE_MBYTES
> + int "Size in Mega Bytes for per-numa CMA areas"
> + depends on NUMA
> + default 16 if ARM64
> + default 0
> + help
> + Defines the size (in MiB) of the per-numa memory area for Contiguous
> + Memory Allocator. Every numa node will get a separate CMA with this
> + size. If the size of 0 is selected, per-numa CMA is disabled.
I'm still not a fan of the config option. You can just hardcode the
value in CONFIG_CMDLINE based on the kernel parameter. Also I wonder
if a way to expose this in the device tree might be useful, but people
more familiar with the device tree and the arm code will have to chime
in on that.
> struct cma *dma_contiguous_default_area;
> +static struct cma *dma_contiguous_pernuma_area[MAX_NUMNODES];
>
> /*
> * Default global CMA area size can be defined in kernel's .config.
> @@ -44,6 +51,8 @@ struct cma *dma_contiguous_default_area;
> */
> static const phys_addr_t size_bytes __initconst =
> (phys_addr_t)CMA_SIZE_MBYTES * SZ_1M;
> +static phys_addr_t pernuma_size_bytes __initdata =
> + (phys_addr_t)CMA_SIZE_PERNUMA_MBYTES * SZ_1M;
> static phys_addr_t size_cmdline __initdata = -1;
> static phys_addr_t base_cmdline __initdata;
> static phys_addr_t limit_cmdline __initdata;
> @@ -69,6 +78,13 @@ static int __init early_cma(char *p)
> }
> early_param("cma", early_cma);
>
> +static int __init early_pernuma_cma(char *p)
> +{
> + pernuma_size_bytes = memparse(p, &p);
> + return 0;
> +}
> +early_param("pernuma_cma", early_pernuma_cma);
> +
> #ifdef CONFIG_CMA_SIZE_PERCENTAGE
>
> static phys_addr_t __init __maybe_unused cma_early_percent_memory(void)
> @@ -96,6 +112,33 @@ static inline __maybe_unused phys_addr_t cma_early_percent_memory(void)
>
> #endif
>
> +void __init dma_pernuma_cma_reserve(void)
> +{
> + int nid;
> +
> + if (!pernuma_size_bytes)
> + return;
> +
> + for_each_node_state(nid, N_MEMORY) {
> + int ret;
> + char name[20];
> +
> + snprintf(name, sizeof(name), "pernuma%d", nid);
> + ret = cma_declare_contiguous_nid(0, pernuma_size_bytes, 0, 0,
> + 0, false, name,
> + &dma_contiguous_pernuma_area[nid],
> + nid);
This adds a > 80 char line.
> struct page *dma_alloc_contiguous(struct device *dev, size_t size, gfp_t gfp)
> {
> + int nid = dev_to_node(dev);
> +
> /* CMA can be used only in the context which permits sleeping */
> if (!gfpflags_allow_blocking(gfp))
> return NULL;
> if (dev->cma_area)
> return cma_alloc_aligned(dev->cma_area, size, gfp);
> - if (size <= PAGE_SIZE || !dma_contiguous_default_area)
> + if (size <= PAGE_SIZE)
> return NULL;
> +
> + if ((nid != NUMA_NO_NODE) && !(gfp & (GFP_DMA | GFP_DMA32))) {
No need for the braces around the nid check.
> + struct cma *cma = dma_contiguous_pernuma_area[nid];
> + struct page *page;
> +
> + if (cma) {
> + page = cma_alloc_aligned(cma, size, gfp);
> + if (page)
> + return page;
> + }
> + }
> +
> return cma_alloc_aligned(dma_contiguous_default_area, size, gfp);
This seems to have lost the dma_contiguous_default_area NULL check.
> + /* if dev has its own cma, free page from there */
> + if (dev->cma_area) {
> + if (cma_release(dev->cma_area, page, PAGE_ALIGN(size) >> PAGE_SHIFT))
> + return;
Another overly long line.
> + } else {
> + /*
> + * otherwise, page is from either per-numa cma or default cma
> + */
> + if (cma_release(dma_contiguous_pernuma_area[page_to_nid(page)],
> + page, PAGE_ALIGN(size) >> PAGE_SHIFT))
> + return;
> +
> + if (cma_release(dma_contiguous_default_area, page,
> + PAGE_ALIGN(size) >> PAGE_SHIFT))
> + return;
> + }
I'd introduce a count variable for the value of "PAGE_ALIGN(size) >>
PAGE_SHIFT" to clean al lthis up a bit.
Also please add a CONFIG_PERCPU_DMA_CMA config variable so that we
don't build this code for the vast majority of users that don't need it.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2020-07-28 11:54 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-23 13:13 [PATCH v4 0/2] make dma_alloc_coherent NUMA-aware by per-NUMA CMA Barry Song
2020-07-23 13:13 ` [PATCH v4 1/2] dma-direct: provide the ability to reserve per-numa CMA Barry Song
2020-07-28 11:52 ` Christoph Hellwig [this message]
2020-07-28 12:19 ` Song Bao Hua (Barry Song)
2020-07-28 12:22 ` Christoph Hellwig
2020-07-29 11:21 ` Song Bao Hua (Barry Song)
2020-07-23 13:13 ` [PATCH v4 2/2] arm64: mm: reserve per-numa CMA to localize coherent dma buffers Barry Song
2020-07-28 11:53 ` 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=20200728115231.GA793@lst.de \
--to=hch@lst.de \
--cc=Jonathan.Cameron@huawei.com \
--cc=akpm@linux-foundation.org \
--cc=catalin.marinas@arm.com \
--cc=ganapatrao.kulkarni@cavium.com \
--cc=huangdaode@huawei.com \
--cc=iommu@lists.linux-foundation.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxarm@huawei.com \
--cc=m.szyprowski@samsung.com \
--cc=nsaenzjulienne@suse.de \
--cc=prime.zeng@hisilicon.com \
--cc=robin.murphy@arm.com \
--cc=rppt@linux.ibm.com \
--cc=song.bao.hua@hisilicon.com \
--cc=steve.capper@arm.com \
--cc=will@kernel.org \
/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).