On Wed, Jul 08, 2026 at 10:59:46AM +0200, David Hildenbrand (Arm) wrote: > On 7/1/26 18:08, Thierry Reding wrote: > > From: Thierry Reding > > > > There is no technical reason why there should be a limited number of CMA > > regions, so extract some code into helpers and use them to create extra > > functions (cma_create() and cma_free()) that allow creating and freeing, > > respectively, CMA regions dynamically at runtime. > > I'm confused. We still allow cma_create() only during __init, right? > > Would we expect callers of cma_free() after __init? Or at which point? The idea is to allow cma_create() at any point. I forgot to properly remove the various __init annotations to make that clear. I've done that for the next revision. Technically cma_free() could happen any time a user no longer needs it. While we currently only do this on error-unwind, the Tegra VPR driver could technically be turned into a module and the entire region be torn down at that point, including calling cma_free() on all the chunks. I don't think we ever want to do that and it'd require a bit of tweaking to the OF reserved-memory code, but generally speaking I don't see why we wouldn't want to allow cma_create() and cma_free() at any time after __init. > > The static array of CMA areas cannot be replaced by dynamically created > > areas because for many of them, allocation must not fail and some cases > > may need to initialize them before the slab allocator is even available. > > We can start with a memblock array of an initial size (like we do today). > > Then, when you need more space, we can double the size (copying content and > exchanging the pointer). Either allocate from memblock or from slab, if > available (slab_is_available). > > memblock does something similar, see memblock_double_array(). After replying to T.J. I think this static array is actually a nice feature in a way. It allows us to more easily make a distinction between the regular CMA regions created from reserved-memory regions that represent classic carveouts, and the more versatile CMA areas that could be used for any purpose. Telling the two types apart could obviously also be solved using some kind of flag stored with the CMA area, but at this point I don't really see a reason why the two lists would need to be unified. Thierry