linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Li Chen <me@linux.beauty>
To: "Arnd Bergmann" <arnd@arndb.de>
Cc: "Catalin Marinas" <catalin.marinas@arm.com>,
	"Will Deacon" <will@kernel.org>,
	"Rob Herring" <robh+dt@kernel.org>,
	"Frank Rowand" <frowand.list@gmail.com>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Li Chen" <lchen@ambarella.com>,
	"Linux ARM" <linux-arm-kernel@lists.infradead.org>,
	"Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>,
	"DTML" <devicetree@vger.kernel.org>,
	"Linux-MM" <linux-mm@kvack.org>
Subject: Re: [PATCH 4/4] sample/reserved_mem: Introduce a sample of struct page and dio support to no-map rmem
Date: Thu, 04 Aug 2022 19:07:20 +0900	[thread overview]
Message-ID: <1826852ea3a.10a917cc826728.6077661125986568031@linux.beauty> (raw)
In-Reply-To: <CAK8P3a0zSGqj3YEi+i9yfSLk8-aJtyiY6Bj069cxCdErk81+cw@mail.gmail.com>


 ---- On Thu, 04 Aug 2022 17:24:20 +0900  Arnd Bergmann  wrote --- 
 > On Thu, Aug 4, 2022 at 9:17 AM Li Chen me@linux.beauty> wrote:
 > > ---- On Tue, 12 Jul 2022 16:50:46 +0900  Arnd Bergmann  wrote ---
 > >  > Does your hardware require a fixed address for the buffer? If it can be
 > >  > anywhere in memory (or at least within a certain range) but just has to
 > >  > be physically contiguous, the normal way would be to use a CMA area
 > >  > to allocate from, which gives you 'struct page' backed pages.
 > >
 > > CMA does support Direct I/O, but it has its own issue:
 > > It does not guarantee that the memory previously borrowed by the OS will be returned to the device.
 > >
 > > We've been plagued by examples like this in the past:
 > > Many other kernel modules/subsystems have already allocated much memory from both non-CMA and CMA memory,
 > > When our DSP driver got probed then, cma_alloc will fail in that non-CMA system memory is not enough
 > > for CMA memory to migrate.
 > 
 > This part should at least be possible to solve by declaring the amount
 > and location of
 > CMA areas in the right way. It's not great to fine-tune the DT for a
 > particular kernel's
 > use, but if you know which other drivers require CMA type allocations
 > you can find a lower
 > bound that should suffice.

That's the problem, haha. End users(customers) may modprobe many other modules and modprobe our
driver in the end. We cannot decide the probe order for end users.

Apart from our cases, I heard there are some other cases where cma_alloc failed even non-cma system memory has
enough memory because pages in CMA memory are pinned and cannot move out of CMA. There are some fixes like
1. move these memory out of CMA before pinned
2. only allow non-long-time pinned memory allocation from CMA.

But these two solutions are not merged into the mainline yet.

 > 
 > Most coherent allocations tend to be long-lived and only for very
 > small memory regions.
 > If you have another driver that uses large or periodic
 > dma_alloc_coherent() type allocations,
 > you can consider either giving that device its own CMA area, or fixing
 > it to use streaming
 > mappings.

Device-wise CMA also suffers from the problems I mentioned, other modules/subsystems may have already
alloc from this CMA area and refuse to return it back.

Regards,
Li

  reply	other threads:[~2022-08-04 10:07 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-11 12:24 [PATCH 0/4] add struct page and Direct I/O support to reserved memory Li Chen
2022-07-11 12:24 ` [PATCH 1/4] of: add struct page support to rmem Li Chen
2022-07-11 13:36   ` Arnd Bergmann
2022-07-11 14:51     ` Li Chen
2022-07-11 15:06       ` Arnd Bergmann
2022-07-12  3:13         ` Li Chen
2022-07-16  0:38   ` kernel test robot
2022-07-18 13:21   ` Dan Carpenter
2022-07-11 12:24 ` [PATCH 2/4] mm/sparse: skip no-map memblock check when fill_subsection_map Li Chen
2022-07-11 14:53   ` David Hildenbrand
2022-07-12  4:23     ` Li Chen
2022-07-12  7:31       ` David Hildenbrand
2022-07-12  9:31         ` Li Chen
2022-07-14 18:45   ` kernel test robot
2022-07-11 12:24 ` [PATCH 3/4] arm64: mm: move memblock_clear_nomap after __add_pages Li Chen
2022-07-11 12:24 ` [PATCH 4/4] sample/reserved_mem: Introduce a sample of struct page and dio support to no-map rmem Li Chen
2022-07-11 13:28   ` Arnd Bergmann
2022-07-12  0:26     ` Li Chen
2022-07-12  7:50       ` Arnd Bergmann
2022-07-12  9:58         ` Li Chen
2022-07-12 10:08           ` Arnd Bergmann
2022-07-12 10:20             ` Arnd Bergmann
2022-07-12 10:55             ` Li Chen
2022-07-12 12:10               ` Arnd Bergmann
2022-08-04  7:17         ` Li Chen
2022-08-04  8:24           ` Arnd Bergmann
2022-08-04 10:07             ` Li Chen [this message]
2022-08-05 14:09               ` Arnd Bergmann
2022-08-05 15:28                 ` David Hildenbrand
2022-07-11 15:01 ` [PATCH 0/4] add struct page and Direct I/O support to reserved memory Christoph Hellwig
2022-07-11 16:05   ` Li Chen
2022-07-11 16:09     ` Christoph Hellwig
2022-07-12  0:14       ` Li Chen

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=1826852ea3a.10a917cc826728.6077661125986568031@linux.beauty \
    --to=me@linux.beauty \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=catalin.marinas@arm.com \
    --cc=devicetree@vger.kernel.org \
    --cc=frowand.list@gmail.com \
    --cc=lchen@ambarella.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=robh+dt@kernel.org \
    --cc=will@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).