Linux-mtd Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Miquel Raynal <miquel.raynal@bootlin.com>
To: Ping Li <leeonion.muyu@gmail.com>
Cc: richard@nod.at,  vigneshr@ti.com,  linux-mtd@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH 0/1] mtdchar: kvmalloc() for large read/write buffers?
Date: Mon, 23 Nov 2026 09:35:26 +0100	[thread overview]
Message-ID: <87y0akuer5.fsf@bootlin.com> (raw)
In-Reply-To: <20261123033212.1660477-1-leeonion.muyu@gmail.com> (Ping Li's message of "Mon, 23 Nov 2026 11:32:12 +0800")

On 23/11/2026 at 11:32:12 +08, Ping Li <leeonion.muyu@gmail.com> wrote:

> From: leeonion.muyu@gmail.com
>
> Hi Miquel,
>
> Thanks for the review!
>
>> I would be curious to know how this gets faster and why?
>> Because the preferred path is obviously via DMA ...
>
> The motivation on our platform is not per-byte CPU cost but
> per-transaction cost: the low-level driver forwards the whole
> transfer to a controller over a bus, so the latency of each
> mtd_read()/mtd_write() call dominates.  With the current
> halving, a fragmented 2 MiB read silently turns into dozens
> of small transactions, each paying a full round trip.
>
> You are right that this argument does not hold for DMA-bound
> drivers: for those a smaller kmalloc'd buffer given to the
> DMA engine beats a vmalloc'd one bouncing through the CPU.
> That is exactly why I like your suggestion: a per-device
> policy avoids both failure modes -- DMA devices keep
> contiguous buffers and their graceful halving degradation,
> transaction-bound devices keep a large buffer regardless of
> fragmentation.
>
> While auditing I noticed that the fsmc/intel/r852 exposure
> predates this RFC: since the MEMREAD/MEMWRITE conversion
> (83208e106a8e8), a vmalloc'd ioctl buffer can already reach
> their dma_map_single() under fragmentation, because none of
> them declares NAND_USES_DMA, which is what activates
> nand_base's virt_addr_valid() bounce.  I would like to send
> these three one-line fixes as an independent series right
> away, as they fix a pre-existing issue regardless of the
> direction taken here.  Only powernv_flash (which implements
> plain _read/_write and is unreachable from the ioctls) is
> newly exposed by the proposed conversion, so it would come
> as a prerequisite of the series.
>
> The plan I would then follow:
>
> 1. Audit all mtd->_read/_write implementations for direct
>    __pa()/dma_map_single() use of the data buffer.
> 2. Introduce mtd->expects_dma_bufs and the allocation
>    helper, with powernv_flash declaring it.
> 3. Convert mtdchar_read()/mtdchar_write() to the helper.
> 4. Provide numbers from our platform, including the
>    DMA-bound counter-example.

Fine.

> Three questions before I start:
>
> - Shall I wait for Richard's opinion first, or does this
>   plan already look reasonable enough to draft a series?

I guess you can proceed, but Richard's opinion is indeed very welcome.

> - For expects_dma_bufs=false devices, is plain kvmalloc()
>   acceptable (single kmalloc attempt, then vmalloc), or
>   should the halving stay for those too?  Sashiko's
>   NOMMU/low-memory point suggests keeping it as a
>   last-resort fallback.

We should keep today's default, if there is one. I don't like kvmalloc
in this case because it may hide bugs.

> - One more question on the flag polarity.  With a false
>   default (DMA drivers declare true), a forgetful DMA
>   driver would silently receive vmalloc'd buffers -- the
>   exact fsmc class of bug at the MTD layer.  A true
>   default (vmalloc-safe drivers declare false) keeps the
>   failure mode benign at the cost of having no in-tree
>   "false" users initially.  I slightly lean toward the
>   safe default, but I can see the dead-code concern.
>   Which polarity would you prefer?

We would not have 0 users, because there are plenty drivers already
doing bounce buffering which would therefore need to be converted to
expects_dma_bufs = true.

I think the default today is that the drivers may expect DMA-able
buffers and the subsystems enforce this by bouncing the data,
no?

Miquèl

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

      reply	other threads:[~2026-11-23  8:35 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19  9:00 [RFC PATCH 0/1] mtdchar: kvmalloc() for large read/write buffers? ping.li
2026-11-19  9:08 ` [RFC PATCH 1/1] mtd: mtdchar: use kvmalloc() for large read/write buffers Ping Li
2026-11-19  9:30   ` sashiko-bot
2026-11-19  9:37     ` Ping Li
2026-11-19  9:38     ` Ping Li
2026-11-19  9:39       ` Ping Li
2026-11-19  9:50 ` [RFC PATCH 0/1] mtdchar: kvmalloc() for large read/write buffers? Miquel Raynal
2026-11-23  3:32   ` Ping Li
2026-11-23  8:35     ` Miquel Raynal [this message]

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=87y0akuer5.fsf@bootlin.com \
    --to=miquel.raynal@bootlin.com \
    --cc=leeonion.muyu@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=richard@nod.at \
    --cc=vigneshr@ti.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