Skip to content

Commit 2edc5bb

Browse files
rientjesChristoph Hellwig
authored and
Christoph Hellwig
committed
dma-pool: add pool sizes to debugfs
The atomic DMA pools can dynamically expand based on non-blocking allocations that need to use it. Export the sizes of each of these pools, in bytes, through debugfs for measurement. Suggested-by: Christoph Hellwig <[email protected]> Signed-off-by: David Rientjes <[email protected]> [hch: remove the !CONFIG_DEBUG_FS stubs] Signed-off-by: Christoph Hellwig <[email protected]>
1 parent 76a1994 commit 2edc5bb

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

kernel/dma/pool.c

+30
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright (C) 2012 ARM Ltd.
44
* Copyright (C) 2020 Google LLC
55
*/
6+
#include <linux/debugfs.h>
67
#include <linux/dma-direct.h>
78
#include <linux/dma-noncoherent.h>
89
#include <linux/dma-contiguous.h>
@@ -13,8 +14,11 @@
1314
#include <linux/workqueue.h>
1415

1516
static struct gen_pool *atomic_pool_dma __ro_after_init;
17+
static unsigned long pool_size_dma;
1618
static struct gen_pool *atomic_pool_dma32 __ro_after_init;
19+
static unsigned long pool_size_dma32;
1720
static struct gen_pool *atomic_pool_kernel __ro_after_init;
21+
static unsigned long pool_size_kernel;
1822

1923
#define DEFAULT_DMA_COHERENT_POOL_SIZE SZ_256K
2024
static size_t atomic_pool_size = DEFAULT_DMA_COHERENT_POOL_SIZE;
@@ -29,6 +33,29 @@ static int __init early_coherent_pool(char *p)
2933
}
3034
early_param("coherent_pool", early_coherent_pool);
3135

36+
static void __init dma_atomic_pool_debugfs_init(void)
37+
{
38+
struct dentry *root;
39+
40+
root = debugfs_create_dir("dma_pools", NULL);
41+
if (IS_ERR_OR_NULL(root))
42+
return;
43+
44+
debugfs_create_ulong("pool_size_dma", 0400, root, &pool_size_dma);
45+
debugfs_create_ulong("pool_size_dma32", 0400, root, &pool_size_dma32);
46+
debugfs_create_ulong("pool_size_kernel", 0400, root, &pool_size_kernel);
47+
}
48+
49+
static void dma_atomic_pool_size_add(gfp_t gfp, size_t size)
50+
{
51+
if (gfp & __GFP_DMA)
52+
pool_size_dma += size;
53+
else if (gfp & __GFP_DMA32)
54+
pool_size_dma32 += size;
55+
else
56+
pool_size_kernel += size;
57+
}
58+
3259
static int atomic_pool_expand(struct gen_pool *pool, size_t pool_size,
3360
gfp_t gfp)
3461
{
@@ -76,6 +103,7 @@ static int atomic_pool_expand(struct gen_pool *pool, size_t pool_size,
76103
if (ret)
77104
goto encrypt_mapping;
78105

106+
dma_atomic_pool_size_add(gfp, pool_size);
79107
return 0;
80108

81109
encrypt_mapping:
@@ -160,6 +188,8 @@ static int __init dma_atomic_pool_init(void)
160188
if (!atomic_pool_dma32)
161189
ret = -ENOMEM;
162190
}
191+
192+
dma_atomic_pool_debugfs_init();
163193
return ret;
164194
}
165195
postcore_initcall(dma_atomic_pool_init);

0 commit comments

Comments
 (0)