public inbox for linux-mm@kvack.org
 help / color / mirror / Atom feed
From: Feng Tang <feng.tang@linux.alibaba.com>
To: "David Hildenbrand (Arm)" <david@kernel.org>
Cc: Marek Szyprowski <m.szyprowski@samsung.com>,
	Robin Murphy <robin.murphy@arm.com>,
	Ying Huang <ying.huang@linux.alibaba.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Lorenzo Stoakes <ljs@kernel.org>,
	Liam.Howlett@oracle.com, Vlastimil Babka <vbabka@kernel.org>,
	Mike Rapoport <rppt@kernel.org>,
	Suren Baghdasaryan <surenb@google.com>,
	Michal Hocko <mhocko@suse.com>,
	linux-mm@kvack.org, Christoph Hellwig <hch@lst.de>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will@kernel.org>,
	iommu@lists.linux.dev, linux-kernel@vger.kernel.org,
	Changrong Chen <chenchangrong.ccr@alibaba-inc.com>
Subject: Re: [PATCH v3] dma-contiguous: setup default numa cma area if not configured explicitly
Date: Tue, 28 Apr 2026 16:37:08 +0800	[thread overview]
Message-ID: <afBxtIdWqv8pD8YE@U-2FWC9VHC-2323.local> (raw)
In-Reply-To: <6dd52f8b-7092-4d02-ba24-f8b55409b7b6@kernel.org>

Hi David,

Thanks for the review!

On Tue, Apr 28, 2026 at 09:52:15AM +0200, David Hildenbrand (Arm) wrote:
> On 4/28/26 08:05, Feng Tang wrote:
> > There was a report on a multi-numa-nodes ARM server that when IOMMU is
> > disabled, the dma_alloc_coherent() function always returns memory from
> > node 0 even for devices attaching to other nodes, while they can get
> > local dma memory when IOMMU is on with the same API.
> > 
> > The reason is, when IOMMU is disabled, the dma_alloc_coherent() will
> > go the direct way and call dma_alloc_contiguous(). The system doesn't
> > have any explicit cma setting (like per-numa cma), and only has a
> > default 64MB cma reserved area (on node 0), where kernel will try
> > first to allocate memory from.
> > 
> > Robin Murphy suggested to setup pernuma cma or disable cma, which did
> > solve the issue. 
> 
> That sounds like the obvious approach to me.

Indeed. We also gave some of them to the reporter once we got the report. 

> > While there is still concern that for customers
> > which don't have much kernel knowledge, they could still suffer from
> > this silently as some architectures enable cma area by default (not
> > an issue for X86 though, which set CONFIG_CMA_SIZE_MBYTES to 0 by
> > default) for most Linux distributions.
> 
> Okay, so on x86 it is not silent, because they don't even have a default CMA area?

Right for default kernel configs.

In kernel/dma/Kconfig:

config CMA_SIZE_MBYTES
	int "Size in Mega Bytes"
	depends on !CMA_SIZE_SEL_PERCENTAGE
	default 0 if X86
	default 16

config CMA_SIZE_PERCENTAGE
	int "Percentage of total memory"
	depends on !CMA_SIZE_SEL_MBYTES
	default 0 if X86
	default 10

> > 
> > One thought is to follow the current cma reserving policy for platform
> > with 'CONFIG_DMA_NUMA_CMA=y', that if the numa cma (either the 'numa cma'
> > or 'cma pernuma' method) is not explicitly configured, set it up
> > according to size of default 'dma_contiguous_default_area', while
> > skipping the numa node where the 'dma_contiguous_default_area' lies
> > in, this way the default behavior of platform with one NUMA node is
> > kept unchanged.
> 
> So, the kernel is configured to have a certain CONFIG_CMA_SIZE_MBYTES size, but
> you go ahead and multiply that by the number of nodes? Sounds wrong.

Yes. I thought about that, and didn't have good solution, and used this
given it's on a multi-numa-node machine, which may not be too bad
regarding memory usage.

Robin did concern about the memory usage for embedded/small devices in
v2 review, and we change to v3 to not affect them.

> 
> The whole proposal here looks rather hacky.

I agree :)

> Wouldn't a default for e.g., pernuma_size_bytes make more sense, that users can
> then overwrite on the cmdline?
 
This sounds good to me, if no objection from others. Maybe default 64MB
or more. One good part is, all these setup is under protection of
CONFIG_DMA_NUMA_CMA. 

> > 
> > To get the node info of cma area, add some helpr funciton and setup
> > in cma code.
> > 
> > Reported-by: Changrong Chen <chenchangrong.ccr@alibaba-inc.com>
> > Suggested-by: Ying Huang <ying.huang@linux.alibaba.com>
> > Suggested-by: Robin Murphy <robin.murphy@arm.com>
> > Signed-off-by: Feng Tang <feng.tang@linux.alibaba.com>
> > ---
> > Changelog:
> > 
> >   since v2:
> >     * setup the numa cma are following default cma, while
> > 	  skipping the node holds the default cma (Robin Murphy)
> > 	* add cma_get_node() help and related code
> > 	* add reporter info 
> > 
> >   since v1:
> > 	* don't use the original way of adding alloc_pages_node()
> > 	  before trying default cma node (Robin Murphy)
> > 	* setup default numa cma area if not configured (Ying Huang)
> > 
> >    v2: https://lore.kernel.org/lkml/20260423095243.14239-1-feng.tang@linux.alibaba.com/
> >    v1: https://lore.kernel.org/lkml/20260414090310.92055-1-feng.tang@linux.alibaba.com/
> > 
> >  include/linux/cma.h     |  1 +
> >  kernel/dma/contiguous.c | 14 ++++++++++++--
> >  mm/cma.c                | 11 ++++++++++-
> >  3 files changed, 23 insertions(+), 3 deletions(-)
[...]
> > +extern int cma_get_nid(const struct cma *cma)
> > +{
> > +	return cma->nid;
> > +}
> 
> Why do you have to store the nid instead of just looking it up from the base_pfn
> in here?

My thought was 'struct cma' already have 'nid' member, and when CONFIG_NUMA=y,
it may be useful to save the 'nid' info instead of NUMA_NO_NODE for the default
cma area (cmdline like cma=XXG@YYG could make it on different node)

> 
> Also, what is the expectation when the ranges would span different NIDs? (is
> that possible?)

Per my understanding, it won't. There is a cma_validate_zones() to prevent it
from crossing zones.

Thanks,
Feng

> 
> -- 
> Cheers,
> 
> David


  reply	other threads:[~2026-04-28  8:37 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-28  6:05 [PATCH v3] dma-contiguous: setup default numa cma area if not configured explicitly Feng Tang
2026-04-28  7:52 ` David Hildenbrand (Arm)
2026-04-28  8:37   ` Feng Tang [this message]
2026-04-28  9:03     ` Feng Tang
2026-05-01 18:51     ` David Hildenbrand (Arm)
2026-05-01  5:57 ` kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=afBxtIdWqv8pD8YE@U-2FWC9VHC-2323.local \
    --to=feng.tang@linux.alibaba.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=catalin.marinas@arm.com \
    --cc=chenchangrong.ccr@alibaba-inc.com \
    --cc=david@kernel.org \
    --cc=hch@lst.de \
    --cc=iommu@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=m.szyprowski@samsung.com \
    --cc=mhocko@suse.com \
    --cc=robin.murphy@arm.com \
    --cc=rppt@kernel.org \
    --cc=surenb@google.com \
    --cc=vbabka@kernel.org \
    --cc=will@kernel.org \
    --cc=ying.huang@linux.alibaba.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox