[PATCH] mtd: spinand: cache the last read page to avoid redundant SPI operations
1768315307
1768315307 at qq.com
Mon Sep 7 20:34:26 PDT 2026
Hi Miquel,
Thanks for the review. Sent v2 with the fixes.
> why would you use mtdblock on top of a SPI NAND? It sounds like a very
> bad choice. Maybe mtdblock itself could be improved to avoid 512B
> accesses instead?
We use a read-only squashfs rootfs on mtdblock for SPI NAND. This is
a minimal configuration that avoids the complexity of UBI/UBIFS for
a read-only partition, and is commonly used in embedded devices like
routers and IoT systems.
The block layer's 512-byte sector size is not easily configurable per
device, and the driver already holds the full page in its bounce buffer
after each read. Adding a lightweight cache avoids the redundant SPI
reads without any additional hardware cost.
> Pseudonyms are not allowed in the Linux kernel.
Fixed in v2.
> Spurious change.
Fixed in v2.
Thanks,
Zongzhen Feng
原始邮件
发件人:Miquel Raynal <miquel.raynal at bootlin.com>
发件时间:2026年9月7日 20:33
收件人:fzz <1768315307 at qq.com>
抄送:Vignesh Raghavendra <vigneshr at ti.com>, Richard Weinberger <richard at nod.at>, linux-mtd <linux-mtd at lists.infradead.org>, linux-kernel <linux-kernel at vger.kernel.org>
主题:Re: [PATCH] mtd: spinand: cache the last read page to avoid redundant SPI operations
Hello,
On 07/09/2026 at 19:10:40 +08, fzz <1768315307 at qq.com> wrote:
> When squashfs reads files through mtdblock, the mtdblock layer
> splits I/O into 512-byte sectors. For a 4K-page SPI NAND, this
> means reading the same page 8 times (4096 / 512), generating 7x
> redundant SPI read-from-cache operations. Each such operation
> involves a full SPI bus transaction, significantly slowing down
> boot time and file access.
>
> Cache the last successfully read page in spinand_device to avoid
> these redundant operations. When the same {target, eraseblock,
> page} is requested consecutively, the data is served directly
> from the bounce buffer (databuf) via memcpy, skipping the SPI
> transaction entirely.
>
> The cache is invalidated on write and erase operations. RAW reads,
> OOB reads, and continuous reads are excluded from caching to
> maintain correctness.
Why would you use mtdblock on top of a SPI NAND? It sounds like a very
bad choice.
Maybe mtdblock itself could be improved to avoid 512B accesses instead?
> Signed-off-by: fzz <1768315307 at qq.com>
Unfortunately, for licensing and copyright reasons, pseudonyms are not
allowed in the Linux kernel.
> ---
> drivers/mtd/nand/spi/core.c | 36 +++++++++++++++++++++++++++++++++++-
> include/linux/mtd/spinand.h | 9 +++++++++
> 2 files changed, 44 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
> index 8bf9301f25e7..fc082127bda8 100644
> --- a/drivers/mtd/nand/spi/core.c
> +++ b/drivers/mtd/nand/spi/core.c
> @@ -557,7 +557,14 @@ static int spinand_read_from_cache_op(struct spinand_device *spinand,
> req->ooblen);
> else
> memcpy(req->oobbuf.in, spinand->oobbuf + req->ooboffs,
> - req->ooblen);
> + req->ooblen);
Spurious change.
> + }
> +
Thanks,
Miquèl
More information about the linux-mtd
mailing list