From: Ping Li <leeonion.muyu@gmail.com>
To: miquel.raynal@bootlin.com, richard@nod.at, vigneshr@ti.com
Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org,
Ping Li <leeonion.muyu@gmail.com>
Subject: [RFC PATCH v2 0/2] mtdchar: per-device bounce buffer policy
Date: Tue, 24 Nov 2026 10:57:20 +0800 [thread overview]
Message-ID: <20261124025722.1476247-1-leeonion.muyu@gmail.com> (raw)
In-Reply-To: <20261119090055.1255028-1-ping.li@horizon.auto>
This is the second revision of the RFC I sent earlier [1], following
the discussion with Miquel [2][3]. It implements the agreed
direction: low-level drivers decide whether they may receive
non-linear-map buffers, and a helper applies the allocation policy
accordingly.
Patch 1 introduces mtd->allows_vmalloc_bufs (defaults to false,
partitions inherit it from their master) and mtd_alloc_buf()/
mtd_free_buf(). By default buffers come from
mtd_kmalloc_up_to(), which gracefully shrinks the size under
fragmentation, so a driver never unexpectedly receives a buffer
which is not DMA-able. Drivers that only memcpy() the buffer,
or which bounce it internally, may set the flag to get
kvmalloc()'s vmalloc fallback and keep the requested size, so a
large read()/write() no longer silently degrades into many
small mtd_read()/mtd_write() calls. The size reduction is
intentionally not kept as a last resort for those devices: an
allocation failure is reported to userspace rather than
silently shrinking the buffer.
Patch 2 converts mtdchar_read()/mtdchar_write() to the helper
and updates the stale comment above mtdchar_read().
Compared to v1, the flag is an explicit opt-in with a conservative
default rather than core-set, the halving fallback after
kvmalloc() is dropped, and the powernv_flash declaration patch is
no longer needed since the conservative default already covers it.
Converting the drivers which already bounce internally
(brcmnand, gpmi, atmel, am654-hbmc, ...) to the new flag is
planned as a follow-up series.
Numbers from our platform (an IPC-backed NOR flash device where each
mtd_read()/mtd_write() is forwarded to a remote controller):
- one transaction costs t ~= 20ms + 0.3ms/KB, i.e. ~620ms for the
2M+2K transfer this platform uses for OTA updates;
- with the opt-in, every 2M+2K read() issued during the tests
(~80 runs across clean, fragmented and severely fragmented
memory states) produced exactly one transaction, in every
single run;
- without the opt-in, the same command was observed to produce
both single full-size and halved (len=1049600, two transactions)
transfers within the same session, depending on transient
allocator state. The split is not reproducible on demand;
- wall-clock throughput is not the benefit: a halved transfer pays
only one extra fixed cost (~3%). The benefit is determinism:
the opt-in makes the transaction count and buffer size
independent of memory state, which is what transaction-bound
backends need.
[1] https://lore.kernel.org/linux-mtd/20261119090055.1255028-1-ping.li@horizon.auto/
[2] https://lore.kernel.org/linux-mtd/875wxtf8uy.fsf@bootlin.com/
[3] https://lore.kernel.org/linux-mtd/87y0akuer5.fsf@bootlin.com/
Ping Li (2):
mtd: core: add per-device bounce buffer allocation helper
mtd: mtdchar: use mtd_alloc_buf() for the read/write bounce buffers
drivers/mtd/mtdchar.c | 24 +++++++++++-----------
drivers/mtd/mtdcore.c | 44 +++++++++++++++++++++++++++++++++++++++++
drivers/mtd/mtdpart.c | 1 +
include/linux/mtd/mtd.h | 16 +++++++++++++++
4 files changed, 74 insertions(+), 11 deletions(-)
base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
--
2.34.1
next prev parent reply other threads:[~2026-11-24 2:57 UTC|newest]
Thread overview: 8+ 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: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
2026-11-24 2:57 ` Ping Li [this message]
2026-11-24 2:57 ` [RFC PATCH v2 1/2] mtd: core: add per-device bounce buffer allocation helper Ping Li
2026-11-24 2:57 ` [RFC PATCH v2 2/2] mtd: mtdchar: use mtd_alloc_buf() for the read/write bounce buffers Ping Li
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=20261124025722.1476247-1-leeonion.muyu@gmail.com \
--to=leeonion.muyu@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=miquel.raynal@bootlin.com \
--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
all inboxes | Powered by JetHome®