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 0/1] mtdchar: kvmalloc() for large read/write buffers?
Date: Thu, 19 Nov 2026 17:00:54 +0800 [thread overview]
Message-ID: <20261119090055.1255028-1-ping.li@horizon.auto> (raw)
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
next reply other threads:[~2026-11-19 9:01 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 9:00 ping.li [this message]
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
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=20261119090055.1255028-1-ping.li@horizon.auto \
--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®