From: Nicolin Chen <nicoleotsuka@gmail.com> To: hch@lst.de, robin.murphy@arm.com Cc: vdumpa@nvidia.com, linux@armlinux.org.uk, catalin.marinas@arm.com, will.deacon@arm.com, joro@8bytes.org, m.szyprowski@samsung.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org, tony@atomide.com Subject: [PATCH RFC/RFT 5/5] dma-contiguous: Do not allocate a single page from CMA area Date: Tue, 26 Mar 2019 15:49:59 -0700 [thread overview] Message-ID: <20190326224959.9656-6-nicoleotsuka@gmail.com> (raw) In-Reply-To: <20190326224959.9656-1-nicoleotsuka@gmail.com> The addresses within a single page are always contiguous, so it's not so necessary to always allocate one single page from CMA area. Since the CMA area has a limited predefined size of space, it may run out of space in heavy use cases, where there might be quite a lot CMA pages being allocated for single pages. However, there is also a concern that a device might care where a page comes from -- it might expect the page from CMA area and act differently if the page doesn't. This patch tries to skip of one-page size allocations and returns NULL so as to let callers allocate normal pages unless the device has its own CMA area. This would save resources from the CMA area for more CMA allocations. And it'd also reduce CMA fragmentations resulted from trivial allocations. Signed-off-by: Nicolin Chen <nicoleotsuka@gmail.com> --- kernel/dma/contiguous.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/kernel/dma/contiguous.c b/kernel/dma/contiguous.c index b2a87905846d..09074bd04793 100644 --- a/kernel/dma/contiguous.c +++ b/kernel/dma/contiguous.c @@ -186,16 +186,32 @@ int __init dma_contiguous_reserve_area(phys_addr_t size, phys_addr_t base, * * This function allocates memory buffer for specified device. It uses * device specific contiguous memory area if available or the default - * global one. Requires architecture specific dev_get_cma_area() helper - * function. + * global one. + * + * However, it skips one-page size of allocations from the global area. + * As the addresses within one page are always contiguous, so there is + * no need to waste CMA pages for that kind; it also helps reduce the + * fragmentations in the CMA area. So a caller should be the rebounder + * in such case to allocate a normal page upon NULL return value. + * + * Requires architecture specific dev_get_cma_area() helper function. */ struct page *dma_alloc_from_contiguous(struct device *dev, size_t count, unsigned int align, bool no_warn) { + struct cma *cma; + if (align > CONFIG_CMA_ALIGNMENT) align = CONFIG_CMA_ALIGNMENT; - return cma_alloc(dev_get_cma_area(dev), count, align, no_warn); + if (dev && dev->cma_area) + cma = dev->cma_area; + else if (count > 1) + cma = dma_contiguous_default_area; + else + return NULL; + + return cma_alloc(cma, count, align, no_warn); } /** -- 2.17.1
WARNING: multiple messages have this Message-ID (diff)
From: Nicolin Chen <nicoleotsuka@gmail.com> To: hch@lst.de, robin.murphy@arm.com Cc: tony@atomide.com, catalin.marinas@arm.com, joro@8bytes.org, will.deacon@arm.com, linux@armlinux.org.uk, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, m.szyprowski@samsung.com Subject: [PATCH RFC/RFT 5/5] dma-contiguous: Do not allocate a single page from CMA area Date: Tue, 26 Mar 2019 15:49:59 -0700 [thread overview] Message-ID: <20190326224959.9656-6-nicoleotsuka@gmail.com> (raw) In-Reply-To: <20190326224959.9656-1-nicoleotsuka@gmail.com> The addresses within a single page are always contiguous, so it's not so necessary to always allocate one single page from CMA area. Since the CMA area has a limited predefined size of space, it may run out of space in heavy use cases, where there might be quite a lot CMA pages being allocated for single pages. However, there is also a concern that a device might care where a page comes from -- it might expect the page from CMA area and act differently if the page doesn't. This patch tries to skip of one-page size allocations and returns NULL so as to let callers allocate normal pages unless the device has its own CMA area. This would save resources from the CMA area for more CMA allocations. And it'd also reduce CMA fragmentations resulted from trivial allocations. Signed-off-by: Nicolin Chen <nicoleotsuka@gmail.com> --- kernel/dma/contiguous.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/kernel/dma/contiguous.c b/kernel/dma/contiguous.c index b2a87905846d..09074bd04793 100644 --- a/kernel/dma/contiguous.c +++ b/kernel/dma/contiguous.c @@ -186,16 +186,32 @@ int __init dma_contiguous_reserve_area(phys_addr_t size, phys_addr_t base, * * This function allocates memory buffer for specified device. It uses * device specific contiguous memory area if available or the default - * global one. Requires architecture specific dev_get_cma_area() helper - * function. + * global one. + * + * However, it skips one-page size of allocations from the global area. + * As the addresses within one page are always contiguous, so there is + * no need to waste CMA pages for that kind; it also helps reduce the + * fragmentations in the CMA area. So a caller should be the rebounder + * in such case to allocate a normal page upon NULL return value. + * + * Requires architecture specific dev_get_cma_area() helper function. */ struct page *dma_alloc_from_contiguous(struct device *dev, size_t count, unsigned int align, bool no_warn) { + struct cma *cma; + if (align > CONFIG_CMA_ALIGNMENT) align = CONFIG_CMA_ALIGNMENT; - return cma_alloc(dev_get_cma_area(dev), count, align, no_warn); + if (dev && dev->cma_area) + cma = dev->cma_area; + else if (count > 1) + cma = dma_contiguous_default_area; + else + return NULL; + + return cma_alloc(cma, count, align, no_warn); } /** -- 2.17.1 _______________________________________________ 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:[~2019-03-26 22:50 UTC|newest] Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-03-26 22:49 [PATCH RFC/RFT 0/5] Save single pages from CMA area Nicolin Chen 2019-03-26 22:49 ` Nicolin Chen 2019-03-26 22:49 ` [PATCH RFC/RFT 1/5] ARM: dma-mapping: Add fallback normal page allocations Nicolin Chen 2019-03-26 22:49 ` Nicolin Chen 2019-03-26 22:49 ` Nicolin Chen 2019-03-26 22:49 ` [PATCH RFC/RFT 2/5] dma-remap: Run alloc_pages() on failure Nicolin Chen 2019-03-26 22:49 ` Nicolin Chen 2019-03-26 22:49 ` Nicolin Chen 2019-03-26 22:53 ` Nicolin Chen 2019-03-26 22:53 ` Nicolin Chen 2019-03-26 22:49 ` [PATCH RFC/RFT 3/5] iommu: amd_iommu: Add fallback normal page allocations Nicolin Chen 2019-03-26 22:49 ` Nicolin Chen 2019-03-26 22:49 ` [PATCH RFC/RFT 4/5] arm64: dma-mapping: " Nicolin Chen 2019-03-26 22:49 ` Nicolin Chen 2019-03-26 22:49 ` Nicolin Chen [this message] 2019-03-26 22:49 ` [PATCH RFC/RFT 5/5] dma-contiguous: Do not allocate a single page from CMA area Nicolin Chen
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=20190326224959.9656-6-nicoleotsuka@gmail.com \ --to=nicoleotsuka@gmail.com \ --cc=catalin.marinas@arm.com \ --cc=hch@lst.de \ --cc=iommu@lists.linux-foundation.org \ --cc=joro@8bytes.org \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux@armlinux.org.uk \ --cc=m.szyprowski@samsung.com \ --cc=robin.murphy@arm.com \ --cc=tony@atomide.com \ --cc=vdumpa@nvidia.com \ --cc=will.deacon@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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.