2021-12-17 09:08:42

by Baoquan He

[permalink] [raw]
Subject: [PATCH 0/2] 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(-)

--
2.26.0



2021-12-17 09:08:43

by Baoquan He

[permalink] [raw]
Subject: [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.

Signed-off-by: Baoquan He <[email protected]>
---
Documentation/admin-guide/kernel-parameters.txt | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index 9725c546a0d4..ec4d25e854a8 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -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:
--
2.26.0


2021-12-17 09:08:46

by Baoquan He

[permalink] [raw]
Subject: [PATCH 2/2] dma-pool: allow user to disable atomic pool

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.

Signed-off-by: Baoquan He <[email protected]>
---
Documentation/admin-guide/kernel-parameters.txt | 3 ++-
kernel/dma/pool.c | 7 +++++--
2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index ec4d25e854a8..d7015309614b 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -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).

diff --git a/kernel/dma/pool.c b/kernel/dma/pool.c
index 5f84e6cdb78e..5a85804b5beb 100644
--- a/kernel/dma/pool.c
+++ b/kernel/dma/pool.c
@@ -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);
--
2.26.0


2021-12-21 08:51:06

by Christoph Hellwig

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

On Fri, Dec 17, 2021 at 05:08:26PM +0800, Baoquan He wrote:
> 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,

Reviewed-by: Christoph Hellwig <[email protected]>

2021-12-21 08:53:01

by Christoph Hellwig

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

On Fri, Dec 17, 2021 at 05:08:27PM +0800, Baoquan He wrote:
> 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.
>
> Signed-off-by: Baoquan He <[email protected]>
> ---
> Documentation/admin-guide/kernel-parameters.txt | 3 ++-
> kernel/dma/pool.c | 7 +++++--
> 2 files changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
> index ec4d25e854a8..d7015309614b 100644
> --- a/Documentation/admin-guide/kernel-parameters.txt
> +++ b/Documentation/admin-guide/kernel-parameters.txt
> @@ -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).
>
> diff --git a/kernel/dma/pool.c b/kernel/dma/pool.c
> index 5f84e6cdb78e..5a85804b5beb 100644
> --- a/kernel/dma/pool.c
> +++ b/kernel/dma/pool.c
> @@ -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:

Reviewed-by: Christoph Hellwig <[email protected]>