mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [RFC PATCH 0/1] mtdchar: kvmalloc() for large read/write buffers?
@ 2026-11-19  9:00 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
  0 siblings, 2 replies; 6+ messages in thread
From: ping.li @ 2026-11-19  9:00 UTC (permalink / raw)
  To: miquel.raynal, richard, vigneshr; +Cc: linux-mtd, linux-kernel, Ping Li

From: Ping Li <leeonion.muyu@gmail.com>

While investigating a throughput regression on one of our platforms
(long uptime, fragmented memory, large read()/write() on /dev/mtdX)
I noticed an inconsistency inside mtdchar:

  - the ioctl paths (MEMREAD/MEMWRITE) allocate their bounce
    buffers with kvmalloc() (83208e106a8e8),
  - but the read()/write() paths still use mtd_kmalloc_up_to(),
    which halves the buffer size until kmalloc() succeeds.

The halving behavior is not a correctness problem: the loop in
mtdchar_read()/mtdchar_write() makes progress with whatever chunk
size it gets.  But under fragmentation a multi-megabyte transfer
silently degrades into many small mtd_read()/mtd_write() calls,
which is visible when the low-level driver cost scales with the
number of transactions (e.g. drivers that forward each call to a
remote controller over a bus).

This RFC proposes to align the read()/write() paths with the ioctl
paths by using kvmalloc(), keeping the KMALLOC_MAX_SIZE cap.

The open question I would like to sort out before submitting a
proper patch:

  How concerned should we be about low-level drivers receiving a
  vmalloc'd buffer?

Looking at the tree, most drivers only memcpy() the buffer, and
the controllers that DMA directly into it (brcmnand, gpmi,
cadence, atmel, ...) already check is_vmalloc_addr()/
virt_addr_valid() and fall back to a bounce path.  So vmalloc'd
buffers are supported everywhere today -- just slower on those
controllers.  With mtd_kmalloc_up_to() the same controllers get a
kmalloc'd (smaller) buffer instead, so either way there is a
slowdown; it is mostly a question of which one userspace prefers:
few large transactions through a bounce path, or many small
transactions without one.

If the direction is agreed, I will follow up with a proper patch
and numbers from our platform.

Ping Li (1):
  mtd: mtdchar: use kvmalloc() for large read/write buffers

 drivers/mtd/mtdchar.c | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)


base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
--
2.34.1


^ permalink raw reply	[flat|nested] 6+ messages in thread
[parent not found: <sashiko-outbox-222838@kernel.org>]

end of thread, other threads:[~2026-11-19  9:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
     [not found] <sashiko-outbox-222838@kernel.org>
2026-11-19  9:37 ` [RFC PATCH 1/1] mtd: mtdchar: use kvmalloc() for large read/write buffers Ping Li
2026-11-19  9:38 ` Ping Li
2026-11-19  9:39   ` Ping Li

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®