Skip to content

Commit c6ccd09

Browse files
rmurphy-armmszyprow
authored andcommitted
dma/pool: Avoid allocating redundant pools
On smaller systems, e.g. embedded arm64, it is common for all memory to end up in ZONE_DMA32 or even ZONE_DMA. In such cases it is redundant to allocate a nominal pool for an empty higher zone that just ends up coming from a lower zone that should already have its own pool anyway. We already have logic to skip allocating a ZONE_DMA pool when that is empty, so generalise that to save memory in the case of other zones too. Signed-off-by: Robin Murphy <robin.murphy@arm.com> Tested-by: Vladimir Kondratiev <vladimir.kondratiev@mobileye.com> Reviewed-by: Baoquan He <bhe@redhat.com> Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com> Link: https://lore.kernel.org/r/8ab8d8a620dee0109f33f5cb63d6bfeed35aac37.1768230104.git.robin.murphy@arm.com
1 parent 6626734 commit c6ccd09

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

kernel/dma/pool.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,12 @@ static __init struct gen_pool *__dma_atomic_pool_init(size_t pool_size,
184184
return pool;
185185
}
186186

187+
#ifdef CONFIG_ZONE_DMA32
188+
#define has_managed_dma32 has_managed_zone(ZONE_DMA32)
189+
#else
190+
#define has_managed_dma32 false
191+
#endif
192+
187193
static int __init dma_atomic_pool_init(void)
188194
{
189195
int ret = 0;
@@ -199,17 +205,20 @@ static int __init dma_atomic_pool_init(void)
199205
}
200206
INIT_WORK(&atomic_pool_work, atomic_pool_work_fn);
201207

202-
atomic_pool_kernel = __dma_atomic_pool_init(atomic_pool_size,
208+
/* All memory might be in the DMA zone(s) to begin with */
209+
if (has_managed_zone(ZONE_NORMAL)) {
210+
atomic_pool_kernel = __dma_atomic_pool_init(atomic_pool_size,
203211
GFP_KERNEL);
204-
if (!atomic_pool_kernel)
205-
ret = -ENOMEM;
212+
if (!atomic_pool_kernel)
213+
ret = -ENOMEM;
214+
}
206215
if (has_managed_dma()) {
207216
atomic_pool_dma = __dma_atomic_pool_init(atomic_pool_size,
208217
GFP_KERNEL | GFP_DMA);
209218
if (!atomic_pool_dma)
210219
ret = -ENOMEM;
211220
}
212-
if (IS_ENABLED(CONFIG_ZONE_DMA32)) {
221+
if (has_managed_dma32) {
213222
atomic_pool_dma32 = __dma_atomic_pool_init(atomic_pool_size,
214223
GFP_KERNEL | GFP_DMA32);
215224
if (!atomic_pool_dma32)
@@ -228,7 +237,7 @@ static inline struct gen_pool *dma_guess_pool(struct gen_pool *prev, gfp_t gfp)
228237
return atomic_pool_dma ?: atomic_pool_dma32 ?: atomic_pool_kernel;
229238
if (gfp & GFP_DMA32)
230239
return atomic_pool_dma32 ?: atomic_pool_dma ?: atomic_pool_kernel;
231-
return atomic_pool_kernel;
240+
return atomic_pool_kernel ?: atomic_pool_dma32 ?: atomic_pool_dma;
232241
}
233242
if (prev == atomic_pool_kernel)
234243
return atomic_pool_dma32 ? atomic_pool_dma32 : atomic_pool_dma;

0 commit comments

Comments
 (0)