Re: [PATCH/RFCv4 2/6] mm: cma: Contiguous Memory Allocator added

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Hans Verkuil
Date: Saturday, August 28, 2010 - 5:37 am

On Friday, August 20, 2010 11:50:42 Michal Nazarewicz wrote:

Just wondering: is alignment really needed since we already align to the
PAGE_SIZE? Do you know of hardware with alignment requirements > PAGE_SIZE?


I would make this field internal only. At least for now.


This really should not be optional but compulsory. 'type' has the same function
as the GFP flags with kmalloc. They tell the kernel where the memory should be
allocated. Only if you do not care at all can you pass in NULL. But in almost
all cases the memory should be at least DMA-able (and yes, for a lot of SoCs that
is the same as any memory -- for now).

Memory types should be defined in the platform code. Some can be generic
like 'dma' (i.e. any DMAable memory), 'dma32' (32-bit DMA) and 'common' (any
memory). Others are platform specific like 'banka' and 'bankb'.

A memory type definition can either be a start address/size pair but it can
perhaps also be a GFP type (e.g. .name = "dma32", .gfp = GFP_DMA32).

Regions should be of a single memory type. So when you define the region it
should have a memory type field.

Drivers request memory of whatever type they require. The mapping just maps
one or more regions to the driver and the cma allocator will pick only those
regions with the required type and ignore those that do not match.


So this would become something like this:

         static struct cma_memtype types[] = {
                 { .name = "a", .size = 32 << 20 },
                 { .name = "b", .size = 32 << 20, .start = 512 << 20 },
                 // For example:
                 { .name = "dma", .gfp = GFP_DMA },
                 { }
         }
         static struct cma_region regions[] = {
                 // size may of course be smaller than the memtype size.
                 { .name = "a", type = "a", .size = 32 << 20 },
                 { .name = "b", type = "b", .size = 32 << 20 },
                 { }
         }
         static const char map[] __initconst = "*=a,b";

No need to do anything special for driver foo here: cma_alloc will pick the
correct region based on the memory type requested by the driver.

It is probably no longer needed to specify the memory type in the mapping when
this is in place.


This would be something for the driver to decide. If the driver can handle
this, then the driver should just try memtype "a" first, and then "b".


The only change needed here is that the region gets a '.type = "dma"' specifier
as well.

I think I am otherwise quite happy with this code (as least from the PoV of
v4l). But that 'memory kind' handling never felt like it was handled at the
right level.

Regards,

	Hans

-- 
Hans Verkuil - video4linux developer - sponsored by TANDBERG, part of Cisco
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH/RFCv4 0/6] The Contiguous Memory Allocator framework, Michal Nazarewicz, (Fri Aug 20, 2:50 am)
[PATCH/RFCv4 1/6] lib: rbtree: rb_root_init() function added, Michal Nazarewicz, (Fri Aug 20, 2:50 am)
[PATCH/RFCv4 2/6] mm: cma: Contiguous Memory Allocator added, Michal Nazarewicz, (Fri Aug 20, 2:50 am)
[PATCH/RFCv4 3/6] mm: cma: Added SysFS support, Michal Nazarewicz, (Fri Aug 20, 2:50 am)
[PATCH/RFCv4 4/6] mm: cma: Added command line parameters s ..., Michal Nazarewicz, (Fri Aug 20, 2:50 am)
[PATCH/RFCv4 5/6] mm: cma: Test device and application added, Michal Nazarewicz, (Fri Aug 20, 2:50 am)
[PATCH/RFCv4 6/6] arm: Added CMA to Aquila and Goni, Michal Nazarewicz, (Fri Aug 20, 2:50 am)
Re: [PATCH/RFCv4 2/6] mm: cma: Contiguous Memory Allocator ..., Konrad Rzeszutek Wilk, (Wed Aug 25, 1:32 pm)
Re: [PATCH/RFCv4 3/6] mm: cma: Added SysFS support, Konrad Rzeszutek Wilk, (Wed Aug 25, 1:37 pm)
Re: [PATCH/RFCv4 0/6] The Contiguous Memory Allocator fram ..., KAMEZAWA Hiroyuki, (Wed Aug 25, 5:58 pm)
Re: [PATCH/RFCv4 3/6] mm: cma: Added SysFS support, Michał Nazarewicz, (Wed Aug 25, 6:20 pm)
Re: [PATCH/RFCv4 2/6] mm: cma: Contiguous Memory Allocator ..., Michał Nazarewicz, (Wed Aug 25, 6:22 pm)
Re: [PATCH/RFCv4 0/6] The Contiguous Memory Allocator fram ..., Michał Nazarewicz, (Wed Aug 25, 6:28 pm)
Re: [PATCH/RFCv4 0/6] The Contiguous Memory Allocator fram ..., Michał Nazarewicz, (Wed Aug 25, 6:38 pm)
Re: [PATCH/RFCv4 0/6] The Contiguous Memory Allocator fram ..., Michał Nazarewicz, (Wed Aug 25, 6:49 pm)
Re: [PATCH/RFCv4 0/6] The Contiguous Memory Allocator fram ..., Michał Nazarewicz, (Wed Aug 25, 7:12 pm)
Re: [PATCH/RFCv4 0/6] The Contiguous Memory Allocator fram ..., Michał Nazarewicz, (Wed Aug 25, 7:40 pm)
Re: [PATCH/RFCv4 0/6] The Contiguous Memory Allocator fram ..., KAMEZAWA Hiroyuki, (Wed Aug 25, 7:50 pm)
Re: [PATCH/RFCv4 0/6] The Contiguous Memory Allocator fram ..., KAMEZAWA Hiroyuki, (Wed Aug 25, 8:44 pm)
Re: [PATCH/RFCv4 0/6] The Contiguous Memory Allocator fram ..., Michał Nazarewicz, (Wed Aug 25, 9:01 pm)
Re: [PATCH/RFCv4 0/6] The Contiguous Memory Allocator fram ..., KAMEZAWA Hiroyuki, (Wed Aug 25, 9:30 pm)
Re: [PATCH/RFCv4 0/6] The Contiguous Memory Allocator fram ..., KAMEZAWA Hiroyuki, (Wed Aug 25, 9:39 pm)
[PATCH/RFCv4.1 2/6] mm: cma: Contiguous Memory Allocator added, Michal Nazarewicz, (Wed Aug 25, 11:25 pm)
Re: [PATCH/RFCv4 2/6] mm: cma: Contiguous Memory Allocator ..., Michał Nazarewicz, (Thu Aug 26, 7:09 pm)
Re: [PATCH/RFCv4 0/6] The Contiguous Memory Allocator fram ..., Michał Nazarewicz, (Thu Aug 26, 7:41 pm)
Re: [PATCH/RFCv4 0/6] The Contiguous Memory Allocator fram ..., KAMEZAWA Hiroyuki, (Fri Aug 27, 1:16 am)
Re: [PATCH/RFCv4 2/6] mm: cma: Contiguous Memory Allocator ..., Hans Verkuil, (Sat Aug 28, 5:37 am)
Re: [PATCH/RFCv4 2/6] mm: cma: Contiguous Memory Allocator ..., Michał Nazarewicz, (Sat Aug 28, 6:48 pm)