linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: Hyesoo Yu <hyesoo.yu@samsung.com>, sumit.semwal@linaro.org
Cc: minchan@kernel.org, akpm@linux-foundation.org,
	iamjoonsoo.kim@lge.com, joaodias@google.com, linux-mm@kvack.org,
	pullip.cho@samsung.com, surenb@google.com, vbabka@suse.cz,
	afd@ti.com, benjamin.gaignard@linaro.org, lmark@codeaurora.org,
	labbott@redhat.com, Brian.Starkey@arm.com,
	john.stultz@linaro.org, christian.koenig@amd.com,
	linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org,
	linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org,
	robh+dt@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH 2/3] dma-buf: heaps: add chunk heap to dmabuf heaps
Date: Tue, 18 Aug 2020 12:11:03 +0200	[thread overview]
Message-ID: <e6a50ebb-3299-77da-757a-3380e9d0ef87@redhat.com> (raw)
In-Reply-To: <20200818080415.7531-3-hyesoo.yu@samsung.com>

On 18.08.20 10:04, Hyesoo Yu wrote:
> This patch adds support for a chunk heap that allows for buffers
> that are made up of a list of fixed size chunks taken from a CMA.
> Chunk sizes are configuratd when the heaps are created.
> 
> Signed-off-by: Hyesoo Yu <hyesoo.yu@samsung.com>
> ---
>  drivers/dma-buf/heaps/Kconfig      |   9 ++
>  drivers/dma-buf/heaps/Makefile     |   1 +
>  drivers/dma-buf/heaps/chunk_heap.c | 222 +++++++++++++++++++++++++++++++++++++
>  3 files changed, 232 insertions(+)
>  create mode 100644 drivers/dma-buf/heaps/chunk_heap.c
> 
> diff --git a/drivers/dma-buf/heaps/Kconfig b/drivers/dma-buf/heaps/Kconfig
> index a5eef06..98552fa 100644
> --- a/drivers/dma-buf/heaps/Kconfig
> +++ b/drivers/dma-buf/heaps/Kconfig
> @@ -12,3 +12,12 @@ config DMABUF_HEAPS_CMA
>  	  Choose this option to enable dma-buf CMA heap. This heap is backed
>  	  by the Contiguous Memory Allocator (CMA). If your system has these
>  	  regions, you should say Y here.
> +
> +config DMABUF_HEAPS_CHUNK
> +	tristate "DMA-BUF CHUNK Heap"
> +	depends on DMABUF_HEAPS && DMA_CMA
> +	help
> +	  Choose this option to enable dma-buf CHUNK heap. This heap is backed
> +	  by the Contiguous Memory Allocator (CMA) and allocate the buffers that
> +	  are made up to a list of fixed size chunks tasken from CMA. Chunk sizes
> +	  are configurated when the heaps are created.
> diff --git a/drivers/dma-buf/heaps/Makefile b/drivers/dma-buf/heaps/Makefile
> index 6e54cde..3b2a0986 100644
> --- a/drivers/dma-buf/heaps/Makefile
> +++ b/drivers/dma-buf/heaps/Makefile
> @@ -2,3 +2,4 @@
>  obj-y					+= heap-helpers.o
>  obj-$(CONFIG_DMABUF_HEAPS_SYSTEM)	+= system_heap.o
>  obj-$(CONFIG_DMABUF_HEAPS_CMA)		+= cma_heap.o
> +obj-$(CONFIG_DMABUF_HEAPS_CHUNK)	+= chunk_heap.o
> diff --git a/drivers/dma-buf/heaps/chunk_heap.c b/drivers/dma-buf/heaps/chunk_heap.c
> new file mode 100644
> index 0000000..1eefaec
> --- /dev/null
> +++ b/drivers/dma-buf/heaps/chunk_heap.c
> @@ -0,0 +1,222 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * ION Memory Allocator chunk heap exporter
> + *
> + * Copyright (c) 2020 Samsung Electronics Co., Ltd.
> + * Author: <hyesoo.yu@samsung.com> for Samsung Electronics.
> + */
> +
> +#include <linux/platform_device.h>
> +#include <linux/cma.h>
> +#include <linux/device.h>
> +#include <linux/dma-buf.h>
> +#include <linux/dma-heap.h>
> +#include <linux/dma-contiguous.h>
> +#include <linux/err.h>
> +#include <linux/errno.h>
> +#include <linux/highmem.h>
> +#include <linux/module.h>
> +#include <linux/slab.h>
> +#include <linux/scatterlist.h>
> +#include <linux/sched/signal.h>
> +#include <linux/of_reserved_mem.h>
> +#include <linux/of.h>
> +
> +#include "heap-helpers.h"
> +
> +struct chunk_heap {
> +	struct dma_heap *heap;
> +	phys_addr_t base;
> +	phys_addr_t size;
> +	atomic_t cur_pageblock_idx;
> +	unsigned int max_num_pageblocks;
> +	unsigned int order;
> +};
> +
> +static void chunk_heap_free(struct heap_helper_buffer *buffer)
> +{
> +	struct chunk_heap *chunk_heap = dma_heap_get_drvdata(buffer->heap);
> +	pgoff_t pg;
> +
> +	for (pg = 0; pg < buffer->pagecount; pg++)
> +		__free_pages(buffer->pages[pg], chunk_heap->order);
> +	kvfree(buffer->pages);
> +	kfree(buffer);
> +}
> +
> +static inline unsigned long chunk_get_next_pfn(struct chunk_heap *chunk_heap)
> +{
> +	unsigned long i = atomic_inc_return(&chunk_heap->cur_pageblock_idx) %
> +		chunk_heap->max_num_pageblocks;
> +
> +	return PHYS_PFN(chunk_heap->base) + i * pageblock_nr_pages;
> +}
> +
> +static int chunk_alloc_pages(struct chunk_heap *chunk_heap, struct page **pages,
> +			     unsigned int order, unsigned int count)
> +{
> +	unsigned long base;
> +	unsigned int i = 0, nr_block = 0, nr_elem, ret;
> +
> +	while (count) {
> +		/*
> +		 * If the number of scanned page block is the same as max block,
> +		 * the tries of allocation fails.
> +		 */
> +		if (nr_block++ == chunk_heap->max_num_pageblocks) {
> +			ret = -ENOMEM;
> +			goto err_bulk;
> +		}
> +		base = chunk_get_next_pfn(chunk_heap);
> +		nr_elem = min_t(unsigned int, count, pageblock_nr_pages >> order);
> +		ret = alloc_pages_bulk(base, base + pageblock_nr_pages, MIGRATE_CMA,
> +				       GFP_KERNEL, order, nr_elem, pages + i);

So you are bypassing the complete cma allocator here. This all smells
like a complete hack to me. No, I don't think this is the right way to
support (or rather speed up allocations for) special, weird hardware.

-- 
Thanks,

David / dhildenb



  reply	other threads:[~2020-08-18 10:11 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20200818074547epcas2p21e0c2442873d03800c7bc2c3e76405d6@epcas2p2.samsung.com>
2020-08-18  8:04 ` [PATCH 0/3] Chunk Heap Support on DMA-HEAP Hyesoo Yu
     [not found]   ` <CGME20200818074550epcas2p1e12121bc6e38086277766f08a59767ff@epcas2p1.samsung.com>
2020-08-18  8:04     ` [PATCH 1/3] dma-buf: add missing EXPORT_SYMBOL_GPL() for dma heaps Hyesoo Yu
     [not found]   ` <CGME20200818074553epcas2p240c2129fb8186f53e03abb0a0725461c@epcas2p2.samsung.com>
2020-08-18  8:04     ` [PATCH 2/3] dma-buf: heaps: add chunk heap to dmabuf heaps Hyesoo Yu
2020-08-18 10:11       ` David Hildenbrand [this message]
2020-08-18 10:17       ` kernel test robot
     [not found]   ` <CGME20200818074554epcas2p2702e648ba975ea6fbe33c84396b152a9@epcas2p2.samsung.com>
2020-08-18  8:04     ` [PATCH 3/3] dma-heap: Devicetree binding for chunk heap Hyesoo Yu
2020-08-18 16:48       ` Rob Herring
2020-08-21  8:21         ` Hyesoo Yu
2020-08-18 10:55   ` [PATCH 0/3] Chunk Heap Support on DMA-HEAP Brian Starkey
2020-08-19  3:46     ` Cho KyongHo
2020-08-19 13:22       ` Brian Starkey
2020-08-21  7:38         ` Cho KyongHo
2020-08-18 20:55   ` John Stultz

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=e6a50ebb-3299-77da-757a-3380e9d0ef87@redhat.com \
    --to=david@redhat.com \
    --cc=Brian.Starkey@arm.com \
    --cc=afd@ti.com \
    --cc=akpm@linux-foundation.org \
    --cc=benjamin.gaignard@linaro.org \
    --cc=christian.koenig@amd.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=hyesoo.yu@samsung.com \
    --cc=iamjoonsoo.kim@lge.com \
    --cc=joaodias@google.com \
    --cc=john.stultz@linaro.org \
    --cc=labbott@redhat.com \
    --cc=linaro-mm-sig@lists.linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lmark@codeaurora.org \
    --cc=minchan@kernel.org \
    --cc=pullip.cho@samsung.com \
    --cc=robh+dt@kernel.org \
    --cc=sumit.semwal@linaro.org \
    --cc=surenb@google.com \
    --cc=vbabka@suse.cz \
    /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).