dma/pool: distinguish between missing and exhausted atomic pools
PATCH v3 1/1 dma/pool: distinguish between missing and exhausted atomic pools
Currently, dma_alloc_from_pool() unconditionally warns and dumps a stack trace when an allocation fails, with the message "Failed to get suitable pool".
This conflates two distinct failure modes:
1. Configuration error: No atomic pool is available for the requested DMA mask (a fundamental system setup issue)
2. Resource Exhaustion: A suitable pool exists but is currently full (a recoverable runtime state)
This lack of distinction prevents drivers from using __GFP_NOWARN to suppress error messages during temporary pressure spikes, such as when awaiting synchronous reclaim of descriptors.
Refactor the error handling to distinguish these cases:
- If no suitable pool is found, keep the unconditional WARN regarding the missing pool.
- If a pool was found but is exhausted, respect __GFP_NOWARN and update the warning message to explicitly state "DMA pool exhausted".
---
Changes from v2 to v3:
- Distinguish between "no suitable pool is found" and "pool is exhausted" cases.
kernel/dma/pool.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
kernel/dma/pool.c +6 -1
@@ -277,15 +277,20 @@ struct page *dma_alloc_from_pool(struct device *dev, size_t size, {struct gen_pool *pool =NULL ;struct page *page; +bool pool_found = false;while ((pool =dma_guess_pool (pool, gfp))) { + pool_found = true; page =__dma_alloc_from_pool (dev, size, pool, cpu_addr, phys_addr_ok);if (page)return page; } -WARN (1 ,"Failed to get suitable pool for %s\n" ,dev_name (dev)); +if (pool_found) +WARN (!(gfp & __GFP_NOWARN),"DMA pool exhausted for %s\n" ,dev_name (dev)); +else +WARN (1 ,"Failed to get suitable pool for %s\n" ,dev_name (dev));return NULL ; }
Signature · 1 line
2.34.1
Quoted 14 lines · Sai Sree Kartheek Adivi
Currently,
dma_alloc_from_pool()unconditionally warns and dumps a stack trace when an allocation fails, with the message "Failed to get suitable pool".This conflates two distinct failure modes:
1. Configuration error: No atomic pool is available for the requested DMA mask (a fundamental system setup issue)
2. Resource Exhaustion: A suitable pool exists but is currently full (a recoverable runtime state)This lack of distinction prevents drivers from using
__GFP_NOWARNto suppress error messages during temporary pressure spikes, such as when awaiting synchronous reclaim of descriptors.
Quoted 5 lines
Refactor the error handling to distinguish these cases:
- If no suitable pool is found, keep the unconditional WARN regarding the missing pool.
- If a pool was found but is exhausted, respect__GFP_NOWARNand update the warning message to explicitly state "DMA pool exhausted".
Great writeup!
Quoted 38 lines
Fixes 9420139f516d ("dma-pool: fix coherent pool allocations for IOMMU mappings")Signed-off-by Sai Sree Kartheek Adivi <[email protected]>---
Changes from v2 to v3:
- Distinguish between "no suitable pool is found" and "pool is exhausted" cases.kernel/dma/pool.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)kernel/dma/pool.c +6
-1@@ -277,15 +277,20 @@ struct page *dma_alloc_from_pool(struct device *dev, size_t size, {struct gen_pool *pool =NULL ;struct page *page; +bool pool_found = false;while ((pool =dma_guess_pool (pool, gfp))) { + pool_found = true; page =__dma_alloc_from_pool (dev, size, pool, cpu_addr, phys_addr_ok);if (page)return page; } -WARN (1 ,"Failed to get suitable pool for %s\n" ,dev_name (dev)); +if (pool_found) +WARN (!(gfp & __GFP_NOWARN),"DMA pool exhausted for %s\n" ,dev_name (dev)); +else +WARN (1 ,"Failed to get suitable pool for %s\n" ,dev_name (dev));return NULL ; }
Quoted 14 lines · Sai Sree Kartheek Adivi
Currently,
dma_alloc_from_pool()unconditionally warns and dumps a stack trace when an allocation fails, with the message "Failed to get suitable pool".This conflates two distinct failure modes:
1. Configuration error: No atomic pool is available for the requested DMA mask (a fundamental system setup issue)
2. Resource Exhaustion: A suitable pool exists but is currently full (a recoverable runtime state)This lack of distinction prevents drivers from using
__GFP_NOWARNto suppress error messages during temporary pressure spikes, such as when awaiting synchronous reclaim of descriptors.
Quoted 8 lines
Refactor the error handling to distinguish these cases:
- If no suitable pool is found, keep the unconditional WARN regarding the missing pool.
- If a pool was found but is exhausted, respect__GFP_NOWARNand update the warning message to explicitly state "DMA pool exhausted".Fixes 9420139f516d ("dma-pool: fix coherent pool allocations for IOMMU mappings")Signed-off-by Sai Sree Kartheek Adivi <[email protected]>
Applied to dma-mapping-fixes. Thanks!
Best regards
Signature · 2 lines
Marek Szyprowski, PhD Samsung R&D Institute Poland