Re: [PATCH] mtd: spinand: cache the last read page to avoid redundant SPI operations
From: Miquel Raynal
Date: Mon Sep 07 2026 - 08:41:26 EST
Hello,
On 07/09/2026 at 19:10:40 +08, fzz <1768315307@xxxxxx> 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@xxxxxx>
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