The Contiguous Memory Allocator framework
Subsystems (9)
PATCH 1/6 lib: rbtree: rb_root_init() function added
In reply to Michal NazarewiczAdded a rb_root_init() function which initialises a rb_root structure as a red-black tree with at most one element. The rationale is that using rb_root_init(root, node) is more straightforward and cleaner then first initialising and empty tree followed by an insert operation.
--- include/linux/rbtree.h | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-)
include/linux/rbtree.h +11 -0
@@ -130,6 +130,17 @@ static inline void rb_set_color(struct rb_node *rb, int color) }#define RB_ROOT (struct rb_root) { NULL, } + +static inline void rb_root_init (struct rb_root *root,struct rb_node *node) +{ + root->rb_node = node; +if (node) { + node->rb_parent_color =RB_BLACK ;/* black, no parent */ + node->rb_left =NULL ; + node->rb_right =NULL ; + } +} +#define rb_entry (ptr, type, member) container_of(ptr, type, member)#define RB_EMPTY_ROOT (root) ((root)->rb_node == NULL)
Signature · 1 line
1.7.1
PATCH 3/6 mm: cma: Added SysFS support
In reply to Michal NazarewiczThe SysFS development interface lets one change the map attribute at run time as well as observe what regions have been reserved.
--- .../ABI/testing/sysfs-kernel-mm-contiguous | 58 ++++ Documentation/contiguous-memory.txt | 4 + mm/Kconfig | 18 +- mm/cma.c | 349 +++++++++++++++++++- 4 files changed, 425 insertions(+), 4 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-kernel-mm-contiguous
Documentation/ABI/testing/sysfs-kernel-mm-contiguous new file +58 -0
@@ -0,0 +1,58 @@ +What: /sys/kernel/mm/contiguous/ +Date: August 2010 +Contact: Michal Nazarewicz <[email protected]> +Description: + If CMA has been built with SysFS support, + /sys/kernel/mm/contiguous/ contains a file called + "map", a file called "allocators" and a directory + called "regions". + + The "map" file lets one change the CMA's map attribute + at run-time. + + The "allocators" file list all registered allocators. + Allocators with no name are listed as a single minus + sign. + + The "regions" directory list all reserved regions. + + For more details see + Documentation/contiguous-memory.txt. + +What: /sys/kernel/mm/contiguous/regions/ +Date: August 201 +Contact: Michal Nazarewicz <[email protected]> +Description: + The /sys/kernel/mm/contiguous/regions/ directory + contain directories for each registered CMA region. + The name of the directory is the same as the start + address of the region. + + If region is named there is also a symbolic link named + like the region pointing to the region's directory. + + Such directory contains the following files: + + * "name" -- the name of the region or an empty file + * "start" -- starting address of the region (formatted + with %p, ie. hex). + * "size" -- size of the region (in bytes). + * "free" -- free space in the region (in bytes). + * "users" -- number of chunks allocated in the region. + * "asterisk" -- whether it is an asterisk region (0 or 1). + * "alloc" -- name of the allocator. + + The "asterisk" file is writable and region's status + can be changed. + + If allocator is not attached to the region, "alloc" is + either the name of desired allocator in square + brackets (ie. "[foo]") or an empty file if region is + to be attached to default allocator. If an allocator + is attached to the region. "alloc" is either its name + or "-" if attached allocator has no name. + + If there are no chunks allocated in given region + ("users" is "0") then a name of desired allocator can + be written to "alloc". +
Documentation/contiguous-memory.txt +4 -0
@@ -288,6 +288,10 @@ attribute is used as well (ie. a "*/*=*" rule is assumed at the end). + If SysFS support is enabled, this attribute is accessible via + SysFS and can be changed at run-time by writing to + /sys/kernel/mm/contiguous/map. + Some examples (whitespace added for better readability): cma_map = foo = r1;
mm/Kconfig +16 -2
@@ -319,12 +319,26 @@ config CMA To make use of CMA you need to specify the regions and driver->region mapping on command line when booting the kernel. -config CMA_DEBUG - bool "CMA debug messages (DEVELOPEMENT)" +config CMA_DEVELOPEMENT + bool "Include CMA developement features" depends on CMA help + This lets you enable some developement features of the CMA + freamework. + +config CMA_DEBUG + bool "CMA debug messages" + depends on CMA_DEVELOPEMENT + help Enable debug messages in CMA code. +config CMA_SYSFS + bool "CMA SysFS interface support" + depends on CMA_DEVELOPEMENT + help + Enable support for SysFS interface. + +config CMA_CMDLINE config CMA_BEST_FIT bool "CMA best-fit allocator" depends on CMA
mm/cma.c +347 -2
373 lines not on this page · raw message
Signature · 7 lines
1.7.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 4/6 mm: cma: Added command line parameters support
This patch adds a pair of early parameters ("cma" and "cma.map") which let one override the CMA configuration given by platform without the need to recompile the kernel.
--- Documentation/contiguous-memory.txt | 82 ++++++++++++++++++++-- Documentation/kernel-parameters.txt | 4 + mm/Kconfig | 6 ++ mm/cma.c | 131 +++++++++++++++++++++++++++++++++++ 4 files changed, 218 insertions(+), 5 deletions(-)
Documentation/contiguous-memory.txt +77 -5
@@ -86,6 +86,20 @@ early region and the framework will handle the rest including choosing the right early allocator. + 4. CMA allows a run-time configuration of the memory regions it + will use to allocate chunks of memory from. The set of memory + regions is given on command line so it can be easily changed + without the need for recompiling the kernel. + + Each region has it's own size, alignment demand, a start + address (physical address where it should be placed) and an + allocator algorithm assigned to the region. + + This means that there can be different algorithms running at + the same time, if different devices on the platform have + distinct memory usage characteristics and different algorithm + match those the best way. + ** Use cases Lets analyse some imaginary system that uses the CMA to see how
@@ -179,7 +193,6 @@ This solution also shows how with CMA you can assign private pools of memory to each device if that is required. - Allocation mechanisms can be replaced dynamically in a similar manner as well. Let's say that during testing, it has been discovered that, for a given shared region of 40 MiB,
@@ -236,6 +249,46 @@ it will be set to a PAGE_SIZE. start will be aligned to alignment. + If command line parameter support is enabled, this attribute can + also be overriden by a command line "cma" parameter. When given + on command line its forrmat is as follows: + + regions-attr ::= [ regions [ ';' ] ] + regions ::= region [ ';' regions ] + + region ::= [ '-' ] REG-NAME + '=' size + [ '@' start ] + [ '/' alignment ] + [ ':' ALLOC-NAME ] + + size ::= MEMSIZE // size of the region + start ::= MEMSIZE // desired start address of + // the region + alignment ::= MEMSIZE // alignment of the start + // address of the region + + REG-NAME specifies the name of the region. All regions given at + via the regions attribute need to have a name. Moreover, all + regions need to have a unique name. If two regions have the same + name it is unspecified which will be used when requesting to + allocate memory from region with given name. + + Optional minus sign in front of region name means that the region + sholud not be an "asterisk" region. All regions given via "cma" + command line parameter are "asterisk" regions by default. + + ALLOC-NAME specifies the name of allocator to be used with the + region. If no allocator name is provided, the "default" + allocator will be used with the region. The "default" allocator + is, of course, the first allocator that has been registered. ;) + + size, start and alignment are specified in bytes with suffixes + that memparse() accept. If start is given, the region will be + reserved on given starting address (or at close to it as + possible). If alignment is specified, the region will be aligned + to given value. + **** Map The format of the "map" attribute is as follows:
@@ -292,8 +345,26 @@ SysFS and can be changed at run-time by writing to /sys/kernel/mm/contiguous/map. + If command line parameter support is enabled, this attribute can + also be overriden by a command line "cma.map" parameter. + +**** Examples + Some examples (whitespace added for better readability): + cma = r1 = 64M // 64M region + @512M // starting at address 512M + // (or at least as near as possible) + /1M // make sure it's aligned to 1M + :foo(bar); // uses allocator "foo" with "bar" + // as parameters for it + r2 = 64M // 64M region + /1M; // make sure it's aligned to 1M + // uses the first available allocator + r3 = 64M // 64M region + @512M // starting at address 512M + :foo; // uses allocator "foo" with no parameters + cma_map = foo = r1; // device foo with kind==NULL uses region r1
@@ -560,10 +631,11 @@ int __init cma_set_defaults(struct cma_region *regions, const char *map) - It needs to be called prior to reserving regions. It let one - specify the list of regions defined by platform and the map - attribute. The map may point to a string in __initdata. See - above in this document for example usage of this function. + It needs to be called after early params have been parsed but + prior to reserving regions. It let one specify the list of + regions defined by platform and the map attribute. The map may + point to a string in __initdata. See above in this document for + example usage of this function. ** Future work
Documentation/kernel-parameters.txt +4 -0
@@ -43,6 +43,7 @@ parameter is applicable: AVR32 AVR32 architecture is enabled. AX25 Appropriate AX.25 support is enabled. BLACKFIN Blackfin architecture is enabled. + CMA Contiguous Memory Allocator is enabled. DRM Direct Rendering Management support is enabled. EDD BIOS Enhanced Disk Drive Services (EDD) is enabled EFI EFI Partitioning (GPT) is enabled
@@ -476,6 +477,9 @@ and is between 256 and 4096 characters. It is defined in the file Also note the kernel might malfunction if you disable some critical bits. + cma= [CMA] List of CMA regions. + See Documentation/contiguous-memory.txt for details. + cmo_free_hint= [PPC] Format: { yes | no } Specify whether pages are marked as being inactive when they are freed. This is used in CMO environments
mm/Kconfig +6 -0
@@ -339,6 +339,12 @@ config CMA_SYSFS Enable support for SysFS interface. config CMA_CMDLINE + bool "CMA command line parameters support" + depends on CMA_DEVELOPEMENT + help + Enable support for cma, cma.map and cma.asterisk command line + parameters. + config CMA_BEST_FIT bool "CMA best-fit allocator" depends on CMA
mm/cma.c +131 -0
143 lines not on this page · raw message
Signature · 1 line
1.7.1
cover The Contiguous Memory Allocator framework
Hello everyone,
The following patchset implements a Contiguous Memory Allocator. For those who have not yet stumbled across CMA an excerpt from documentation:
The Contiguous Memory Allocator (CMA) is a framework, which allows setting up a machine-specific configuration for physically-contiguous memory management. Memory for devices is then allocated according to that configuration.
The main role of the framework is not to allocate memory, but to parse and manage memory configurations, as well as to act as an in-between between device drivers and pluggable allocators. It is thus not tied to any memory allocation method or strategy.
For more information please refer to the second patch from the patchset which contains the documentation.
Links to the previous versions of the patchsets:
v2: <http://article.gmane.org/gmane.linux.kernel.mm/50986/>
v1: <http://article.gmane.org/gmane.linux.kernel.mm/50669/>
This is the third version of the patchset. All of the changes are concentrated in the second, the third and the fourth patch -- the other patches are almost identical.
Major observable changes between the second (the previous) and the third (this) versions are:
1. The command line parameters have been removed (and moved to a separate patch, the fourth one). As a consequence, the cma_set_defaults() function has been changed -- it no longer accepts a string with list of regions but an array of regions.
2. The "asterisk" attribute has been removed. Now, each region has an "asterisk" flag which lets one specify whether this region should by considered "asterisk" region.
3. SysFS support has been moved to a separate patch (the third one in the series) and now also includes list of regions.
Major observable changes between the first and the second versions are:
1. The "cma_map" command line have been removed. In exchange, a SysFS entry has been created under kernel/mm/contiguous.
The intended way of specifying the attributes is
a cma_set_defaults() function called by platform initialisation code. "regions" attribute (the string specified by "cma" command line parameter) can be overwritten with command line parameter; the other attributes can be changed during run-time using the SysFS entries.
2. The behaviour of the "map" attribute has been modified slightly. Currently, if no rule matches given device it is assigned regions specified by the "asterisk" attribute. It is by default built from the region names given in "regions" attribute.
3. Devices can register private regions as well as regions that can be shared but are not reserved using standard CMA mechanisms. A private region has no name and can be accessed only by devices that have the pointer to it.
4. The way allocators are registered has changed. Currently, a cma_allocator_register() function is used for that purpose. Moreover, allocators are attached to regions the first time memory is registered from the region or when allocator is registered which means that allocators can be dynamic modules that are loaded after the kernel booted (of course, it won't be possible to allocate a chunk of memory from a region if allocator is not loaded).
5. Index of new functions:
+static inline dma_addr_t __must_check
+cma_alloc_from(const char *regions, size_t size, dma_addr_t alignment)
+static inline int
+cma_info_about(struct cma_info *info, const const char *regions)
+int __must_check cma_region_register(struct cma_region *reg);
+dma_addr_t __must_check
+cma_alloc_from_region(struct cma_region *reg,
+ size_t size, dma_addr_t alignment);
+static inline dma_addr_t __must_check
+cma_alloc_from(const char *regions,
+ size_t size, dma_addr_t alignment);
+int cma_allocator_register(struct cma_allocator *alloc);
Michal Nazarewicz (6):
lib: rbtree: rb_root_init() function added
mm: cma: Contiguous Memory Allocator added
mm: cma: Added SysFS support
mm: cma: Added command line parameters support
mm: cma: Test device and application added
arm: Added CMA to Aquila and Goni
Documentation/00-INDEX | 2 + .../ABI/testing/sysfs-kernel-mm-contiguous | 58 + Documentation/contiguous-memory.txt | 651 +++++++++ Documentation/kernel-parameters.txt | 4 + arch/arm/mach-s5pv210/mach-aquila.c | 31 + arch/arm/mach-s5pv210/mach-goni.c | 31 + drivers/misc/Kconfig | 8 + drivers/misc/Makefile | 1 + drivers/misc/cma-dev.c | 184 +++ include/linux/cma.h | 475 +++++++ include/linux/rbtree.h | 11 + mm/Kconfig | 54 + mm/Makefile | 2 + mm/cma-best-fit.c | 407 ++++++ mm/cma.c | 1446 ++++++++++++++++++++ tools/cma/cma-test.c | 373 +++++ 16 files changed, 3738 insertions(+), 0 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-kernel-mm-contiguous create mode 100644 Documentation/contiguous-memory.txt create mode 100644 drivers/misc/cma-dev.c create mode 100644 include/linux/cma.h create mode 100644 mm/cma-best-fit.c create mode 100644 mm/cma.c create mode 100644 tools/cma/cma-test.c
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 2/6 mm: cma: Contiguous Memory Allocator added
In reply to Michal NazarewiczThe Contiguous Memory Allocator framework is a set of APIs for allocating physically contiguous chunks of memory.
Various chips require contiguous blocks of memory to operate. Those chips include devices such as cameras, hardware video decoders and encoders, etc.
The code is highly modular and customisable to suit the needs of various users. Set of regions reserved for CMA can be configured per-platform and it is easy to add custom allocator algorithms if one has such need.
--- Documentation/00-INDEX | 2 + Documentation/contiguous-memory.txt | 575 +++++++++++++++++++++ include/linux/cma.h | 445 ++++++++++++++++ mm/Kconfig | 34 ++ mm/Makefile | 2 + mm/cma-best-fit.c | 407 +++++++++++++++ mm/cma.c | 970 +++++++++++++++++++++++++++++++++++ 7 files changed, 2435 insertions(+), 0 deletions(-) create mode 100644 Documentation/contiguous-memory.txt create mode 100644 include/linux/cma.h create mode 100644 mm/cma-best-fit.c create mode 100644 mm/cma.c
Documentation/00-INDEX +2 -0
@@ -94,6 +94,8 @@ connector/ - docs on the netlink based userspace<->kernel space communication mod. console/ - documentation on Linux console drivers. +contiguous-memory.txt + - documentation on physically-contiguous memory allocation framework. cpu-freq/ - info on CPU frequency and voltage scaling. cpu-hotplug.txt
Documentation/contiguous-memory.txt new file +575 -0
575 lines not on this page · raw message
include/linux/cma.h new file +445 -0
445 lines not on this page · raw message
mm/Kconfig +34 -0
@@ -301,3 +301,37 @@ config NOMMU_INITIAL_TRIM_EXCESS of 1 says that all excess pages should be trimmed. See Documentation/nommu-mmap.txt for more information. + + +config CMA + bool "Contiguous Memory Allocator framework" + # Currently there is only one allocator so force it on + select CMA_BEST_FIT + help + This enables the Contiguous Memory Allocator framework which + allows drivers to allocate big physically-contiguous blocks of + memory for use with hardware components that do not support I/O + map nor scatter-gather. + + If you select this option you will also have to select at least + one allocator algorithm below. + + To make use of CMA you need to specify the regions and + driver->region mapping on command line when booting the kernel. + +config CMA_DEBUG + bool "CMA debug messages (DEVELOPEMENT)" + depends on CMA + help + Enable debug messages in CMA code. + +config CMA_BEST_FIT + bool "CMA best-fit allocator" + depends on CMA + default y + help + This is a best-fit algorithm running in O(n log n) time where + n is the number of existing holes (which is never greater then + the number of allocated regions and usually much smaller). It + allocates area from the smallest hole that is big enough for + allocation in question.
mm/Makefile +2 -0
@@ -47,3 +47,5 @@ obj-$(CONFIG_MEMORY_FAILURE) += memory-failure.o obj-$(CONFIG_HWPOISON_INJECT) += hwpoison-inject.o obj-$(CONFIG_DEBUG_KMEMLEAK) += kmemleak.o obj-$(CONFIG_DEBUG_KMEMLEAK_TEST) += kmemleak-test.o +obj-$(CONFIG_CMA) += cma.o +obj-$(CONFIG_CMA_BEST_FIT) += cma-best-fit.o
mm/cma-best-fit.c new file +407 -0
407 lines not on this page · raw message
mm/cma.c new file +970 -0
970 lines not on this page · raw message
Signature · 7 lines
1.7.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 6/6 arm: Added CMA to Aquila and Goni
In reply to Michal NazarewiczAdded the CMA initialisation code to two Samsung platforms.
--- arch/arm/mach-s5pv210/mach-aquila.c | 31 +++++++++++++++++++++++++++++++ arch/arm/mach-s5pv210/mach-goni.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 0 deletions(-)
arch/arm/mach-s5pv210/mach-aquila.c +31 -0
@@ -19,6 +19,7 @@#include <linux/gpio_keys.h> #include <linux/input.h> #include <linux/gpio.h> +#include <linux/cma.h> #include <asm/mach/arch.h> #include <asm/mach/map.h>
@@ -454,6 +455,35 @@ static void __init aquila_map_io(void)s3c24xx_init_uarts (aquila_uartcfgs,ARRAY_SIZE (aquila_uartcfgs)); } +static void __init aquila_reserve (void ) +{ +static struct cma_region regions[] = { + { + .name ="fw" , + .size =1 <<20 , + { .alignment =128 <<10 }, + }, + { + .name ="b1" , + .size =32 <<20 , + .asterisk =1 , + }, + { + .name ="b2" , + .size =16 <<20 , + .start =0x40000000 , + .asterisk =1 , + }, + { } + }; + +static const char map[]__initconst = +"s3c-mfc5/f=fw;s3c-mfc5/a=b1;s3c-mfc5/b=b2" ; + +cma_set_defaults (regions, map); +cma_early_regions_reserve (NULL ); +} +static void __init aquila_machine_init (void ) {/* PMIC */
@@ -478,4 +508,5 @@ MACHINE_START(AQUILA, "Aquila") .map_io = aquila_map_io, .init_machine = aquila_machine_init, .timer = &s3c24xx_timer, + .reserve = aquila_reserve,MACHINE_END
arch/arm/mach-s5pv210/mach-goni.c +31 -0
@@ -19,6 +19,7 @@#include <linux/gpio_keys.h> #include <linux/input.h> #include <linux/gpio.h> +#include <linux/cma.h> #include <asm/mach/arch.h> #include <asm/mach/map.h>
@@ -435,6 +436,35 @@ static void __init goni_map_io(void)s3c24xx_init_uarts (goni_uartcfgs,ARRAY_SIZE (goni_uartcfgs)); } +static void __init goni_reserve (void ) +{ +static struct cma_region regions[] = { + { + .name ="fw" , + .size =1 <<20 , + { .alignment =128 <<10 }, + }, + { + .name ="b1" , + .size =32 <<20 , + .asterisk =1 , + }, + { + .name ="b2" , + .size =16 <<20 , + .start =0x40000000 , + .asterisk =1 , + }, + { } + }; + +static const char map[]__initconst = +"s3c-mfc5/f=fw;s3c-mfc5/a=b1;s3c-mfc5/b=b2" ; + +cma_set_defaults (regions, map); +cma_early_regions_reserve (NULL ); +} +static void __init goni_machine_init (void ) {/* PMIC */
@@ -456,4 +486,5 @@ MACHINE_START(GONI, "GONI") .map_io = goni_map_io, .init_machine = goni_machine_init, .timer = &s3c24xx_timer, + .reserve = goni_reserve,MACHINE_END
Signature · 1 line
1.7.1
PATCH 5/6 mm: cma: Test device and application added
In reply to Michal NazarewiczThis patch adds a "cma" misc device which lets user space use the CMA API. This device is meant for testing. A testing application is also provided.
--- drivers/misc/Kconfig | 8 + drivers/misc/Makefile | 1 + drivers/misc/cma-dev.c | 184 ++++++++++++++++++++++++ include/linux/cma.h | 30 ++++ tools/cma/cma-test.c | 373 ++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 596 insertions(+), 0 deletions(-) create mode 100644 drivers/misc/cma-dev.c create mode 100644 tools/cma/cma-test.c
drivers/misc/Kconfig +8 -0
@@ -368,4 +368,12 @@ source "drivers/misc/eeprom/Kconfig" source "drivers/misc/cb710/Kconfig" source "drivers/misc/iwmc3200top/Kconfig" +config CMA_DEVICE + tristate "CMA misc device (DEVELOPEMENT)" + depends on CMA_DEVELOPEMENT + help + The CMA misc device allows allocating contiguous memory areas + from user space. This is mostly for testing of the CMA + framework. + endif # MISC_DEVICES
drivers/misc/Makefile +1 -0
@@ -32,3 +32,4 @@ obj-y += eeprom/ obj-y += cb710/ obj-$(CONFIG_VMWARE_BALLOON) += vmware_balloon.o obj-$(CONFIG_ARM_CHARLCD) += arm-charlcd.o +obj-$(CONFIG_CMA_DEVICE) += cma-dev.o
drivers/misc/cma-dev.c new file +184 -0
184 lines not on this page · raw message
include/linux/cma.h +30 -0
@@ -11,6 +11,36 @@* See Documentation/contiguous-memory.txt for details. */ +#include <linux/ioctl.h> +#include <linux/types.h> + + +#define CMA_MAGIC (('c' << 24) | ('M' << 16) | ('a' << 8) | 0x42) + +/** +* An information about area exportable to user space. +* @magic: must always be CMA_MAGIC. +* @name: name of the device to allocate as. +* @kind: kind of the memory. +* @_pad: reserved. +* @size: size of the chunk to allocate. +* @alignment: desired alignment of the chunk (must be power of two or zero). +* @start: when ioctl() finishes this stores physical address of the chunk. +*/ +struct cma_alloc_request { +__u32 magic; +char name[17 ]; +char kind[17 ]; +__u16 pad; +/* __u64 to be compatible accross 32 and 64 bit systems. */ +__u64 size; +__u64 alignment; +__u64 start; +}; + +#define IOCTL_CMA_ALLOC _IOWR('p', 0, struct cma_alloc_request) + +/***************************** Kernel lever API *****************************/ #ifdef __KERNEL__
tools/cma/cma-test.c new file +373 -0
373 lines not on this page · raw message
Signature · 7 lines
1.7.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Are there any comments or ack?
We hope this method included at mainline kernel if possible. It's really needed feature for our multimedia frameworks.
Thank you,
Kyungmin Park
Quoted 137 lines · Michal Nazarewicz
Hello everyone,
The following patchset implements a Contiguous Memory Allocator. ?For those who have not yet stumbled across CMA an excerpt from documentation:
? The Contiguous Memory Allocator (CMA) is a framework, which allows ? setting up a machine-specific configuration for physically-contiguous ? memory management. Memory for devices is then allocated according ? to that configuration.
? The main role of the framework is not to allocate memory, but to ? parse and manage memory configurations, as well as to act as an ? in-between between device drivers and pluggable allocators. It is ? thus not tied to any memory allocation method or strategy.
For more information please refer to the second patch from the patchset which contains the documentation.
Links to the previous versions of the patchsets:
v2: <http://article.gmane.org/gmane.linux.kernel.mm/50986/>
v1: <http://article.gmane.org/gmane.linux.kernel.mm/50669/>This is the third version of the patchset. ?All of the changes are concentrated in the second, the third and the fourth patch -- the other patches are almost identical.
Major observable changes between the second (the previous) and the third (this) versions are:
1. The command line parameters have been removed (and moved to ? a separate patch, the fourth one). ?As a consequence, the ?
cma_set_defaults()function has been changed -- it no longer ? accepts a string with list of regions but an array of regions.2. The "asterisk" attribute has been removed. ?Now, each region has an ? "asterisk" flag which lets one specify whether this region should ? by considered "asterisk" region.
3. SysFS support has been moved to a separate patch (the third one in ? the series) and now also includes list of regions.
Major observable changes between the first and the second versions are:
1. The "
cma_map" command line have been removed. ?In exchange, a SysFS ? entry has been created underkernel/mm/contiguous.? The intended way of specifying the attributes is
? acma_set_defaults()function called by platform initialisation ? code. ?"regions" attribute (the string specified by "cma" command ? line parameter) can be overwritten with command line parameter; the ? other attributes can be changed during run-time using the SysFS ? entries.2. The behaviour of the "map" attribute has been modified slightly. ? Currently, if no rule matches given device it is assigned regions ? specified by the "asterisk" attribute. ?It is by default built from ? the region names given in "regions" attribute.
3. Devices can register private regions as well as regions that can be ? shared but are not reserved using standard CMA mechanisms. ? A private region has no name and can be accessed only by devices ? that have the pointer to it.
4. The way allocators are registered has changed. ?Currently, ? a
cma_allocator_register()function is used for that purpose. ? Moreover, allocators are attached to regions the first time memory ? is registered from the region or when allocator is registered which ? means that allocators can be dynamic modules that are loaded after ? the kernel booted (of course, it won't be possible to allocate ? a chunk of memory from a region if allocator is not loaded).5. Index of new functions:
(quoted diff) +12
-0+static inline dma_addr_t __must_check +cma_alloc_from(const char *regions, size_t size, dma_addr_t alignment) +static inline int +cma_info_about(struct cma_info *info, const const char *regions) +int __must_check cma_region_register(struct cma_region *reg); +dma_addr_t __must_check +cma_alloc_from_region(struct cma_region *reg, + ? ? ? ? ? ? ? ? ? ? size_t size, dma_addr_t alignment); +static inline dma_addr_t __must_check +cma_alloc_from(const char *regions, + ? ? ? ? ? ? ? size_t size, dma_addr_t alignment); +int cma_allocator_register(struct cma_allocator *alloc);Michal Nazarewicz (6):
?lib: rbtree:rb_root_init()function added
?mm: cma: Contiguous Memory Allocator added
?mm: cma: Added SysFS support
?mm: cma: Added command line parameters support
?mm: cma: Test device and application added
?arm: Added CMA to Aquila and Goni?Documentation/00-INDEX ? ? ? ? ? ? ? ? ? ? ? ? ? ? | ? ?2 + ?.../ABI/testing/sysfs-kernel-mm-contiguous ? ? ? ? | ? 58 + ?Documentation/contiguous-memory.txt ? ? ? ? ? ? ? ?| ?651 +++++++++ ?Documentation/kernel-parameters.txt ? ? ? ? ? ? ? ?| ? ?4 + ?arch/arm/mach-s5pv210/mach-aquila.c ? ? ? ? ? ? ? ?| ? 31 + ?arch/arm/mach-s5pv210/mach-goni.c ? ? ? ? ? ? ? ? ?| ? 31 + ?drivers/misc/Kconfig ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | ? ?8 + ?drivers/misc/Makefile ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?| ? ?1 + ?drivers/misc/cma-dev.c ? ? ? ? ? ? ? ? ? ? ? ? ? ? | ?184 +++ ?include/linux/cma.h ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?| ?475 +++++++ ?include/linux/rbtree.h ? ? ? ? ? ? ? ? ? ? ? ? ? ? | ? 11 + ?mm/Kconfig ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | ? 54 + ?mm/Makefile ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?| ? ?2 + ?mm/cma-best-fit.c ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?| ?407 ++++++ ?mm/cma.c ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | 1446 ++++++++++++++++++++ ?tools/cma/cma-test.c ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | ?373 +++++?16 files changed, 3738 insertions(+), 0 deletions(-) ?create mode 100644
Documentation/ABI/testing/sysfs-kernel-mm-contiguous?create mode 100644Documentation/contiguous-memory.txt?create mode 100644drivers/misc/cma-dev.c
?create mode 100644include/linux/cma.h
?create mode 100644mm/cma-best-fit.c
?create mode 100644mm/cma.c
?create mode 100644tools/cma/cma-test.c_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 2 lines · Kyungmin Park
Are there any comments or ack?
Is there a git tree and/or link to the latest version that is based on top 2.6.36-rc1?? I somehow seem to have lost the v3 of these patches.
Quoted 4 lines · On Wed, 18 Aug 2010 12:01:35 +0900 Kyungmin Park <[email protected]>…
Are there any comments or ack?
We hope this method included at mainline kernel if possible. It's really needed feature for our multimedia frameworks.
You got any comments from mm people?
Virtually, this adds a new memory allocator implementation that steals some memory from memory allocator during boot process. Its API looks completely different from the API for memory allocator. That doesn't sound appealing to me much. This stuff couldn't be integrated well into memory allocator?
Quoted 2 lines · Konrad Rzeszutek Wilk
Is there a git tree and/or link to the latest version that is based on top 2.6.36-rc1?? I somehow seem to have lost the v3 of these patches.
I'm currently working on a v4 of the patchset after some comments from Hans Verkuil on the #v4l. I should manage to post it today (Korean time).
Signature · 4 lines
Best regards, _ _ | Humble Liege of Serenely Enlightened Majesty of o' \,=./ `o | Computer Science, Micha? "mina86" Nazarewicz (o o) +----[mina86*mina86.com]---[mina86*jabber.org]----ooO--(_)--Ooo--
Quoted 8 lines · FUJITA Tomonori
Quoted 4 lines · On Wed, 18 Aug 2010 12:01:35 +0900 Kyungmin Park <[email protected]>…
Are there any comments or ack?
We hope this method included at mainline kernel if possible. It's really needed feature for our multimedia frameworks.
Quoted 7 lines
You got any comments from mm people?
Virtually, this adds a new memory allocator implementation that steals some memory from memory allocator during boot process. Its API looks completely different from the API for memory allocator. That doesn't sound appealing to me much. This stuff couldn't be integrated well into memory allocator?
What kind of integration do you mean? I see three levels:
1. Integration on API level meaning that some kind of existing API is used instead of new cma_*() calls. CMA adds notion of devices and memory types which is new to all the other APIs (coherent has notion of devices but that's not enough). This basically means that no existing API can be used for CMA. On the other hand, removing notion of devices and memory types would defeat the whole purpose of CMA thus destroying the solution that CMA provides.
2. Reuse of memory pools meaning that memory reserved by CMA can then be used by other allocation mechanisms. This is of course possible. For instance coherent could easily be implemented as a wrapper to CMA. This is doable and can be done in the future after CMA gets more recognition.
3. Reuse of algorithms meaning that allocation algorithms used by other allocators will be used with CMA regions. This is doable as well and can be done in the future.
Signature · 4 lines
Best regards, _ _ | Humble Liege of Serenely Enlightened Majesty of o' \,=./ `o | Computer Science, Micha? "mina86" Nazarewicz (o o) +----[mina86*mina86.com]---[mina86*jabber.org]----ooO--(_)--Ooo--
Quoted 13 lines
Quoted 10 lines
Quoted 2 lines
We hope this method included at mainline kernel if possible. It's really needed feature for our multimedia frameworks.
You got any comments from mm people?
Virtually, this adds a new memory allocator implementation that steals some memory from memory allocator during boot process. Its API looks completely different from the API for memory allocator. That doesn't sound appealing to me much. This stuff couldn't be integrated well into memory allocator?
What kind of integration do you mean? I see three levels:
Quoted 7 lines
1. Integration on API level meaning that some kind of existing API is used instead of new cma_*() calls. CMA adds notion of devices and memory types which is new to all the other APIs (coherent has notion of devices but that's not enough). This basically means that no existing API can be used for CMA. On the other hand, removing notion of devices and memory types would defeat the whole purpose of CMA thus destroying the solution that CMA provides.
You can create something similar to the existing API for memory allocator.
For example, blk_kmalloc/blk_alloc_pages was proposed as memory allocator API with notion of an address range for allocated memory. It wasn't merged for other reasons though.
I don't mean that this is necessary for the inclusion (I'm not the person to ack or nack this). I just expect the similarity of memory allocator API.
Quoted 9 lines
2. Reuse of memory pools meaning that memory reserved by CMA can then be used by other allocation mechanisms. This is of course possible. For instance coherent could easily be implemented as a wrapper to CMA. This is doable and can be done in the future after CMA gets more recognition.
3. Reuse of algorithms meaning that allocation algorithms used by other allocators will be used with CMA regions. This is doable as well and can be done in the future.
Well, why can't we do the above before the inclusion?
Anyway, I think that comments from mm people would be helpful to merge this.
Quoted 10 lines · FUJITA Tomonori
Quoted 7 lines
1. Integration on API level meaning that some kind of existing API is used instead of new cma_*() calls. CMA adds notion of devices and memory types which is new to all the other APIs (coherent has notion of devices but that's not enough). This basically means that no existing API can be used for CMA. On the other hand, removing notion of devices and memory types would defeat the whole purpose of CMA thus destroying the solution that CMA provides.
You can create something similar to the existing API for memory allocator.
That may be tricky. cma_alloc() takes four parameters each of which is required for CMA. No other existing set of API uses all those arguments. This means, CMA needs it's own, somehow unique API. I don't quite see how the APIs may be unified or "made similar". Of course, I'm gladly accepting suggestions.
Quoted 11 lines
Quoted 9 lines
2. Reuse of memory pools meaning that memory reserved by CMA can then be used by other allocation mechanisms. This is of course possible. For instance coherent could easily be implemented as a wrapper to CMA. This is doable and can be done in the future after CMA gets more recognition.
3. Reuse of algorithms meaning that allocation algorithms used by other allocators will be used with CMA regions. This is doable as well and can be done in the future.
Well, why can't we do the above before the inclusion?
Because it's quite a bit of work and instead of diverting my attention I'd prefer to make CMA as good as possible and then integrate it with other subsystems. Also, adding the integration would change the patch from being 4k lines to being like 40k lines.
What I'm trying to say is that I don't consider that a work for now but rather a further enchantments.
Quoted 2 lines
Anyway, I think that comments from mm people would be helpful to merge this.
Yes, I agree.
Signature · 4 lines
Best regards, _ _ | Humble Liege of Serenely Enlightened Majesty of o' \,=./ `o | Computer Science, Micha? "mina86" Nazarewicz (o o) +----[mina86*mina86.com]---[mina86*jabber.org]----ooO--(_)--Ooo--
Quoted 9 lines · On Fri, 20 Aug 2010 08:38:10 +0200 **UNKNOWN CHARSET**…
Quoted 8 lines · FUJITA Tomonori
Quoted 7 lines
1. Integration on API level meaning that some kind of existing API is used instead of new cma_*() calls. CMA adds notion of devices and memory types which is new to all the other APIs (coherent has notion of devices but that's not enough). This basically means that no existing API can be used for CMA. On the other hand, removing notion of devices and memory types would defeat the whole purpose of CMA thus destroying the solution that CMA provides.
Quoted 8 lines
Quoted 2 lines
You can create something similar to the existing API for memory allocator.
That may be tricky.
cma_alloc()takes four parameters each of which is required for CMA. No other existing set of API uses all those arguments. This means, CMA needs it's own, somehow unique API. I don't quite see how the APIs may be unified or "made similar". Of course, I'm gladly accepting suggestions.
Have you even tried to search 'blk_kmalloc' on google? I wrote "similar to the existing API', not "reuse the existing API".
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
2. Reuse of memory pools meaning that memory reserved by CMA can then be used by other allocation mechanisms. This is of course possible. For instance coherent could easily be implemented as a wrapper to CMA. This is doable and can be done in the future after CMA gets more recognition.
3. Reuse of algorithms meaning that allocation algorithms used by other allocators will be used with CMA regions. This is doable as well and can be done in the future.
Quoted 6 lines
Quoted 1 line
Well, why can't we do the above before the inclusion?
Because it's quite a bit of work and instead of diverting my attention I'd prefer to make CMA as good as possible and then integrate it with other subsystems. Also, adding the integration would change the patch from being 4k lines to being like 40k lines.
4k to 40k? I'm not sure. But If I see something like the following, I suspect that there is a better way to integrate this into the existing infrastructure.
mm/cma-best-fit.c | 407 +++++++++++++++
Quoted 15 lines · FUJITA Tomonori
Quoted 12 lines · On Fri, 20 Aug 2010 08:38:10 +0200 **UNKNOWN CHARSET**…
Quoted 10 lines · FUJITA Tomonori
Quoted 7 lines
1. Integration on API level meaning that some kind of existing API is used instead of new cma_*() calls. CMA adds notion of devices and memory types which is new to all the other APIs (coherent has notion of devices but that's not enough). This basically means that no existing API can be used for CMA. On the other hand, removing notion of devices and memory types would defeat the whole purpose of CMA thus destroying the solution that CMA provides.
You can create something similar to the existing API for memory allocator.
Quoted 7 lines
Quoted 5 lines
That may be tricky.
cma_alloc()takes four parameters each of which is required for CMA. No other existing set of API uses all those arguments. This means, CMA needs it's own, somehow unique API. I don't quite see how the APIs may be unified or "made similar". Of course, I'm gladly accepting suggestions.Have you even tried to search '
blk_kmalloc' on google?
I have and I haven't seen any way how
void *()(struct request_queue *q, unsigned size, gfp_t gfp);
prototype could be applied to CMA. I admit that I haven't read the whole discussion of the patch and maybe I'm missing something about Andi's patches but I don't see how CMA could but from what I've understood blk_kmalloc() is dissimilar to CMA. I'll be glad if you could show me where I'm wrong.
Quoted 1 line
I wrote "similar to the existing API', not "reuse the existing API".
Yes, but I don't really know what you have in mind. CMA is similar to various APIs in various ways: it's similar to any allocator since it takes size in bytes, it's similar to coherent since it takes device, it's similar to bootmem/memblock/etc since it takes alignment. I would appreciate if you could give some examples of what you mean by similar and ideas haw CMA's API may be improved.
Quoted 17 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
2. Reuse of memory pools meaning that memory reserved by CMA can then be used by other allocation mechanisms. This is of course possible. For instance coherent could easily be implemented as a wrapper to CMA. This is doable and can be done in the future after CMA gets more recognition.
3. Reuse of algorithms meaning that allocation algorithms used by other allocators will be used with CMA regions. This is doable as well and can be done in the future.
Quoted 6 lines
Quoted 1 line
Well, why can't we do the above before the inclusion?
Because it's quite a bit of work and instead of diverting my attention I'd prefer to make CMA as good as possible and then integrate it with other subsystems. Also, adding the integration would change the patch from being 4k lines to being like 40k lines.
Quoted 5 lines
4k to 40k? I'm not sure. But If I see something like the following, I suspect that there is a better way to integrate this into the existing infrastructure.
mm/cma-best-fit.c| 407 +++++++++++++++
Ah, sorry. I misunderstood you. I thought you were replying to both 2. and 3. above.
If we only take allocating algorithm then you're right. Reusing existing one should not increase the patch size plus it would be probably a better solution.
No matter, I would rather first work and core CMA without worrying about reusing kmalloc()/coherent/etc. code especially since providing a plugable allocator API integration with existing allocating algorithms can be made later on. To put it short I want first to make it work and then improve it.
Signature · 4 lines
Best regards, _ _ | Humble Liege of Serenely Enlightened Majesty of o' \,=./ `o | Computer Science, Micha? "mina86" Nazarewicz (o o) +----[mina86*mina86.com]---[mina86*jabber.org]----ooO--(_)--Ooo--
Quoted 5 lines · On Fri, 20 Aug 2010 10:10:45 +0200 **UNKNOWN CHARSET**…
Quoted 1 line
I wrote "similar to the existing API', not "reuse the existing API".
Yes, but I don't really know what you have in mind. CMA is similar to various APIs in various ways: it's similar to any allocator since it takes size in bytes,
why don't take gfp_t flags?
Something like dev_alloc_page is more appropriate name?
Or something similar to dmapool API (mm/dmapool.c) might work better. The purpose of dmapool API is creating a pool for consistent memory per device. It's similar to yours, creating a pool for contiguous memory per device(s)?
Quoted 2 lines
it's similar to coherent since it takes device, it's similar to bootmem/memblock/etc since it takes alignment.
I don't think that bootmem/memblock matters here since it's not the API for drivers.
Quoted 9 lines
Quoted 5 lines
4k to 40k? I'm not sure. But If I see something like the following, I suspect that there is a better way to integrate this into the existing infrastructure.
mm/cma-best-fit.c| 407 +++++++++++++++Ah, sorry. I misunderstood you. I thought you were replying to both 2. and 3. above.
Quoted 7 lines
If we only take allocating algorithm then you're right. Reusing existing one should not increase the patch size plus it would be probably a better solution.
No matter, I would rather first work and core CMA without worrying about reusing kmalloc()/coherent/etc. code especially since providing a plugable allocator API integration with existing allocating algorithms can be made later on. To put it short I want first to make it work and then improve it.
I'm not sure that's how a new feature is merged.
Quoted 10 lines · FUJITA Tomonori
Quoted 5 lines · On Fri, 20 Aug 2010 10:10:45 +0200 **UNKNOWN CHARSET**…
Quoted 1 line
I wrote "similar to the existing API', not "reuse the existing API".
Yes, but I don't really know what you have in mind. CMA is similar to various APIs in various ways: it's similar to any allocator since it takes size in bytes,
why don't take
gfp_tflags?
Because they are insufficient. Either that or I don't understand gfp_t.
With CMA, platform can define many memory types. For instance, if there are two memory bans there can be two memory types for the two banks. For at least one of the device I'm in contact with, another type for it's firmware is also needed. Bottom line is that there may be possibly many types which won't map to gfp_t.
Quoted 1 line
Something like
dev_alloc_pageis more appropriate name?
Two things: I'd prefer a "cma" prefix rather then "dev" and I think it should be "pages", right? Then, size should be given in pages rather then bytes.
Nonetheless, I don't really see at the moment why this should be better.
Quoted 4 lines
Or something similar to dmapool API (
mm/dmapool.c) might work better. The purpose of dmapool API is creating a pool for consistent memory per device. It's similar to yours, creating a pool for contiguous memory per device(s)?
I'll try to look at it later on and think about it. I'm still somehow reluctant to change the names but still, thank you for suggestions.
Signature · 4 lines
Best regards, _ _ | Humble Liege of Serenely Enlightened Majesty of o' \,=./ `o | Computer Science, Micha? "mina86" Nazarewicz (o o) +----[mina86*mina86.com]---[mina86*jabber.org]----ooO--(_)--Ooo--