Re: [PATCH 0/3] Chunk Heap Support on DMA-HEAP

From: Brian Starkey
Date: Tue Aug 18 2020 - 06:56:32 EST


Hi,

On Tue, Aug 18, 2020 at 05:04:12PM +0900, Hyesoo Yu wrote:
> These patch series to introduce a new dma heap, chunk heap.
> That heap is needed for special HW that requires bulk allocation of
> fixed high order pages. For example, 64MB dma-buf pages are made up
> to fixed order-4 pages * 1024.
>
> The chunk heap uses alloc_pages_bulk to allocate high order page.
> https://lore.kernel.org/linux-mm/20200814173131.2803002-1-minchan@xxxxxxxxxx
>
> The chunk heap is registered by device tree with alignment and memory node
> of contiguous memory allocator(CMA). Alignment defines chunk page size.
> For example, alignment 0x1_0000 means chunk page size is 64KB.
> The phandle to memory node indicates contiguous memory allocator(CMA).
> If device node doesn't have cma, the registration of chunk heap fails.

This reminds me of an ion heap developed at Arm several years ago:
https://git.linaro.org/landing-teams/working/arm/kernel.git/tree/drivers/staging/android/ion/ion_compound_page.c

Some more descriptive text here:
https://github.com/ARM-software/CPA

It maintains a pool of high-order pages with a worker thread to
attempt compaction and allocation to keep the pool filled, with high
and low watermarks to trigger freeing/allocating of chunks.
It implements a shrinker to allow the system to reclaim the pool under
high memory pressure.

Is maintaining a pool something you considered? From the
alloc_pages_bulk thread it sounds like you want to allocate 300M at a
time, so I expect if you tuned the pool size to match that it could
work quite well.

That implementation isn't using a CMA region, but a similar approach
could definitely be applied.

Thanks,
-Brian

>
> The patchset includes the following:
> - export dma-heap API to register kernel module dma heap.
> - add chunk heap implementation.
> - document of device tree to register chunk heap
>
> Hyesoo Yu (3):
> dma-buf: add missing EXPORT_SYMBOL_GPL() for dma heaps
> dma-buf: heaps: add chunk heap to dmabuf heaps
> dma-heap: Devicetree binding for chunk heap
>
> .../devicetree/bindings/dma-buf/chunk_heap.yaml | 46 +++++
> drivers/dma-buf/dma-heap.c | 2 +
> drivers/dma-buf/heaps/Kconfig | 9 +
> drivers/dma-buf/heaps/Makefile | 1 +
> drivers/dma-buf/heaps/chunk_heap.c | 222 +++++++++++++++++++++
> drivers/dma-buf/heaps/heap-helpers.c | 2 +
> 6 files changed, 282 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/dma-buf/chunk_heap.yaml
> create mode 100644 drivers/dma-buf/heaps/chunk_heap.c
>
> --
> 2.7.4
>