Skip to contentSkip to conversation

Clean up document and small improvement of atomic pool

PATCH In review Baoquan He 2 participants 5 messages Dec 17, 2021 – Dec 21, 2021

Subsystems (3)
lore
Share & tools
lore

Baoquan He

author
#0 lore raw

cover Clean up document and small improvement of atomic pool

This patchset contains two small patches. Identified this when I tried to fix a kdump bug that page allocation failure is always warned out during kdump kernel on x86_64. Since dma atomic pool is initialized very early during bootup, that allocation failure is always triggered in dma_atomic_pool_init() firstly. I originally planned to add an kernel option to disable each of the three dma atomic pool. Finally I realized it's not only dma atomic pool getting the issue, any later requsting page from DMA zone will fail. So I changed solution to fix the kdump bug. While the document clean up and the small fix which allows user to disable atomic pool makes sense to improve. The small fix which makes 'coherent_pool=0' disable dma atomic pool like 'cma=0', looks more reasonable than the old behavioud which will take the default atomic size.

[PATCH RESEND v2 0/5] Avoid requesting page from DMA zone when no managed pages
https://lore.kernel.org/all/[email protected]/T/#u

Baoquan He (2):
docs: kernel-parameters: Update to reflect the current default size of
atomic pool
dma-pool: allow user to disable atomic pool

 Documentation/admin-guide/kernel-parameters.txt | 5 ++++-
 kernel/dma/pool.c                               | 7 +++++--
 2 files changed, 9 insertions(+), 3 deletions(-)
Signature · 1 line
2.26.0
author
#1 lore raw

PATCH 1/2 docs: kernel-parameters: Update to reflect the current default size of atomic pool

Since commit 1d659236fb43("dma-pool: scale the default DMA coherent pool size with memory capacity"), the default size of atomic pool has been changed to take by scaling with system memory capacity. So update the document in kerenl-parameter.txt accordingly.

---
 Documentation/admin-guide/kernel-parameters.txt | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Documentation/admin-guide/kernel-parameters.txt +3 -1
index 9725c546a0d4..ec4d25e854a8 100644
@@ -664,7 +664,9 @@
 
 	coherent_pool=nn[KMG]	[ARM,KNL]
 			Sets the size of memory pool for coherent, atomic dma
-			allocations, by default set to 256K.
+			allocations. Otherwise the default size will be scaled
+			with memory capacity, while clamped between 128K and
+			1 << (PAGE_SHIFT + MAX_ORDER-1).
 
 	com20020=	[HW,NET] ARCnet - COM20020 chipset
 			Format:
Signature · 1 line
2.26.0
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] docs: kernel-parameters: Update to reflect the current default size of atomic pool

Quoted 4 lines · Baoquan He

Since commit 1d659236fb43("dma-pool: scale the default DMA coherent pool size with memory capacity"), the default size of atomic pool has been changed to take by scaling with system memory capacity. So update the document in kerenl-parameter.txt accordingly.

Looks good,

author
#3 lore raw

PATCH 2/2 dma-pool: allow user to disable atomic pool

In reply to Baoquan He

In the current code, three atomic memory pools are always created, atomic_pool_kernel|dma|dma32, even though 'coherent_pool=0' is specified in kernel command line. In fact, atomic pool is only necessary when CONFIG_DMA_DIRECT_REMAP=y or mem_encrypt_active=y which are needed on few ARCHes.

So change code to allow user to disable atomic pool by specifying 'coherent_pool=0'.

Meanwhile, update the relevant document in kernel-parameter.txt.

---
 Documentation/admin-guide/kernel-parameters.txt | 3 ++-
 kernel/dma/pool.c                               | 7 +++++--
 2 files changed, 7 insertions(+), 3 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +2 -1
index ec4d25e854a8..d7015309614b 100644
@@ -664,7 +664,8 @@
 
 	coherent_pool=nn[KMG]	[ARM,KNL]
 			Sets the size of memory pool for coherent, atomic dma
-			allocations. Otherwise the default size will be scaled
+			allocations. A value of 0 disables the three atomic
+			memory pool. Otherwise the default size will be scaled
 			with memory capacity, while clamped between 128K and
 			1 << (PAGE_SHIFT + MAX_ORDER-1).
 
kernel/dma/pool.c +5 -2
index 5f84e6cdb78e..5a85804b5beb 100644
@@ -21,7 +21,7 @@ static struct gen_pool *atomic_pool_kernel __ro_after_init;
 static unsigned long pool_size_kernel;
 
 /* Size can be defined by the coherent_pool command line */
-static size_t atomic_pool_size;
+static unsigned long atomic_pool_size = -1;
 
 /* Dynamic background expansion when the atomic pool is near capacity */
 static struct work_struct atomic_pool_work;
@@ -188,11 +188,14 @@ static int __init dma_atomic_pool_init(void)
 {
 	int ret = 0;
 
+	if (!atomic_pool_size)
+		return 0;
+
 	/*
 	 * If coherent_pool was not used on the command line, default the pool
 	 * sizes to 128KB per 1GB of memory, min 128KB, max MAX_ORDER-1.
 	 */
-	if (!atomic_pool_size) {
+	if (atomic_pool_size == -1) {
 		unsigned long pages = totalram_pages() / (SZ_1G / SZ_128K);
 		pages = min_t(unsigned long, pages, MAX_ORDER_NR_PAGES);
 		atomic_pool_size = max_t(size_t, pages << PAGE_SHIFT, SZ_128K);
Signature · 1 line
2.26.0
Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] dma-pool: allow user to disable atomic pool

Quoted 36 lines · Baoquan He

In the current code, three atomic memory pools are always created, atomic_pool_kernel|dma|dma32, even though 'coherent_pool=0' is specified in kernel command line. In fact, atomic pool is only necessary when CONFIG_DMA_DIRECT_REMAP=y or mem_encrypt_active=y which are needed on few ARCHes.

So change code to allow user to disable atomic pool by specifying 'coherent_pool=0'.

Meanwhile, update the relevant document in kernel-parameter.txt.

---
 Documentation/admin-guide/kernel-parameters.txt | 3 ++-
 kernel/dma/pool.c                               | 7 +++++--
 2 files changed, 7 insertions(+), 3 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +2 -1
index ec4d25e854a8..d7015309614b 100644
@@ -664,7 +664,8 @@
 
 	coherent_pool=nn[KMG]	[ARM,KNL]
 			Sets the size of memory pool for coherent, atomic dma
-			allocations. Otherwise the default size will be scaled
+			allocations. A value of 0 disables the three atomic
+			memory pool. Otherwise the default size will be scaled
 			with memory capacity, while clamped between 128K and
 			1 << (PAGE_SHIFT + MAX_ORDER-1).
 
kernel/dma/pool.c +0 -0
index 5f84e6cdb78e..5a85804b5beb 100644

kernel/dma/pool.c static struct gen_pool *atomic_pool_kernel __ro_after_init; · line 24

Quoted 5 lines
kernel/dma/pool.c +1 -1
@@ -21,7 +21,7 @@ static struct gen_pool *atomic_pool_kernel __ro_after_init;
 static unsigned long pool_size_kernel;
 
 /* Size can be defined by the coherent_pool command line */
-static size_t atomic_pool_size;
+static unsigned long atomic_pool_size = -1;

Using UINT_MAX instead of -1 here and below would probably be more descriptive.

Otherwise looks good: