* [PATCH 1/2] jffs2: check the data CRC of a node in RAM, not through point()
@ 2026-11-18 21:40 Orgad Shaneh
2026-11-18 21:40 ` [PATCH 2/2] jffs2: reschedule between the data CRC checks of an inode Orgad Shaneh
0 siblings, 1 reply; 3+ messages in thread
From: Orgad Shaneh @ 2026-11-18 21:40 UTC (permalink / raw)
To: dwmw2, richard; +Cc: miquel.raynal, linux-mtd, linux-kernel
check_node_data() points at the node data when the MTD supports it
and runs crc32() over the flash, which saves a kmalloc() and a copy.
That paid off while the generic crc32() read words (slice-by-8). Since
commit 5e3c1c48fac3 ("lib/crc32: remove other generic implementations")
it reads a byte at a time, and on a CPU without an arch CRC32 and an
uncached map, such as a NOR flash on a boot bus, every byte is a bus
access of its own, while jffs2_flash_read() copies a word per load.
The MTDs that can be pointed at today are cfi_cmdset_0001 (Intel NOR),
lpddr, map_ram and map_rom.
On an Octeon board with an 8-bit AMD NOR, with point() added to
cfi_cmdset_0002 (under review [1]), the first lookup of a 46.6 MB
file checks the data at 2.77 MB/s through point() and at 3.37 MB/s
from a buffer (16.8 s against 13.8 s), the rate of a plain read of
the partition.
Always read the data into a buffer. MTDs that can be pointed at now
pay a kmalloc() and a copy per node, as all others already do.
[1] https://lore.kernel.org/all/20261117214141.3826637-1-orgads@gmail.com/
Signed-off-by: Orgad Shaneh <orgads@gmail.com>
---
fs/jffs2/readinode.c | 65 +++++++++++++++-----------------------------
1 file changed, 22 insertions(+), 43 deletions(-)
diff --git a/fs/jffs2/readinode.c b/fs/jffs2/readinode.c
index 1caabff9d..18a47b432 100644
--- a/fs/jffs2/readinode.c
+++ b/fs/jffs2/readinode.c
@@ -31,7 +31,7 @@
static int check_node_data(struct jffs2_sb_info *c, struct jffs2_tmp_dnode_info *tn)
{
struct jffs2_raw_node_ref *ref = tn->fn->raw;
- int err = 0, pointed = 0;
+ int err = 0;
struct jffs2_eraseblock *jeb;
unsigned char *buffer;
uint32_t crc, ofs, len;
@@ -61,48 +61,32 @@ static int check_node_data(struct jffs2_sb_info *c, struct jffs2_tmp_dnode_info
dbg_readinode("check node at %#08x, data length %u, partial CRC %#08x, correct CRC %#08x, data starts at %#08x, start checking from %#08x - %u bytes.\n",
ref_offset(ref), tn->csize, tn->partial_crc, tn->data_crc, ofs - len, ofs, len);
-#ifndef __ECOS
- /* TODO: instead, incapsulate point() stuff to jffs2_flash_read(),
- * adding and jffs2_flash_read_end() interface. */
- err = mtd_point(c->mtd, ofs, len, &retlen, (void **)&buffer, NULL);
- if (!err && retlen < len) {
- JFFS2_WARNING("MTD point returned len too short: %zu instead of %u.\n", retlen, tn->csize);
- mtd_unpoint(c->mtd, ofs, retlen);
- } else if (err) {
- if (err != -EOPNOTSUPP)
- JFFS2_WARNING("MTD point failed: error code %d.\n", err);
- } else
- pointed = 1; /* successfully pointed to device */
-#endif
-
- if (!pointed) {
- buffer = kmalloc(len, GFP_KERNEL);
- if (unlikely(!buffer))
- return -ENOMEM;
+ /*
+ * Read the data into RAM even when the flash can be pointed at:
+ * the generic crc32() goes through it a byte at a time, and on an
+ * uncached map each byte is a bus access of its own, while the
+ * read copies a word per load.
+ */
+ buffer = kmalloc(len, GFP_KERNEL);
+ if (unlikely(!buffer))
+ return -ENOMEM;
- /* TODO: this is very frequent pattern, make it a separate
- * routine */
- err = jffs2_flash_read(c, ofs, len, &retlen, buffer);
- if (err) {
- JFFS2_ERROR("can not read %d bytes from 0x%08x, error code: %d.\n", len, ofs, err);
- goto free_out;
- }
+ /* TODO: this is very frequent pattern, make it a separate routine */
+ err = jffs2_flash_read(c, ofs, len, &retlen, buffer);
+ if (err) {
+ JFFS2_ERROR("can not read %d bytes from 0x%08x, error code: %d.\n", len, ofs, err);
+ goto free_out;
+ }
- if (retlen != len) {
- JFFS2_ERROR("short read at %#08x: %zd instead of %d.\n", ofs, retlen, len);
- err = -EIO;
- goto free_out;
- }
+ if (retlen != len) {
+ JFFS2_ERROR("short read at %#08x: %zd instead of %d.\n", ofs, retlen, len);
+ err = -EIO;
+ goto free_out;
}
/* Continue calculating CRC */
crc = crc32(tn->partial_crc, buffer, len);
- if(!pointed)
- kfree(buffer);
-#ifndef __ECOS
- else
- mtd_unpoint(c->mtd, ofs, len);
-#endif
+ kfree(buffer);
if (crc != tn->data_crc) {
JFFS2_NOTICE("wrong data CRC in data node at 0x%08x: read %#08x, calculated %#08x.\n",
@@ -133,12 +117,7 @@ static int check_node_data(struct jffs2_sb_info *c, struct jffs2_tmp_dnode_info
return 0;
free_out:
- if(!pointed)
- kfree(buffer);
-#ifndef __ECOS
- else
- mtd_unpoint(c->mtd, ofs, len);
-#endif
+ kfree(buffer);
return err;
}
--
2.53.0
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] jffs2: reschedule between the data CRC checks of an inode
2026-11-18 21:40 [PATCH 1/2] jffs2: check the data CRC of a node in RAM, not through point() Orgad Shaneh
@ 2026-11-18 21:40 ` Orgad Shaneh
2026-11-18 21:44 ` sashiko-bot
0 siblings, 1 reply; 3+ messages in thread
From: Orgad Shaneh @ 2026-11-18 21:40 UTC (permalink / raw)
To: dwmw2, richard; +Cc: miquel.raynal, linux-mtd, linux-kernel
The first read of an inode checks the data CRC of each of its unchecked
nodes, all in one call. On an Octeon board with an 8-bit NOR, a
46.6 MB file takes 13.8 s of kernel time there. Without kernel
preemption, nothing else ran on that CPU in the meantime: an RT
watchdog thread missed its deadline and the board rebooted. With
this, the lookup takes as long, but the watchdog, the per-CPU
workqueue and the other tasks of that CPU keep running.
jffs2_get_inode_nodes() already reschedules per node while it reads
the headers; do the same before each data check.
Signed-off-by: Orgad Shaneh <orgads@gmail.com>
---
fs/jffs2/readinode.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/fs/jffs2/readinode.c b/fs/jffs2/readinode.c
index 18a47b432..bfee9e57f 100644
--- a/fs/jffs2/readinode.c
+++ b/fs/jffs2/readinode.c
@@ -39,6 +39,13 @@ static int check_node_data(struct jffs2_sb_info *c, struct jffs2_tmp_dnode_info
BUG_ON(tn->csize == 0);
+ /*
+ * A large inode has thousands of data nodes to check on its first
+ * read, and a slow flash takes seconds over them; give the CPU
+ * away between nodes.
+ */
+ cond_resched();
+
/* Calculate how many bytes were already checked */
ofs = ref_offset(ref) + sizeof(struct jffs2_raw_inode);
len = tn->csize;
--
2.53.0
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 2/2] jffs2: reschedule between the data CRC checks of an inode
2026-11-18 21:40 ` [PATCH 2/2] jffs2: reschedule between the data CRC checks of an inode Orgad Shaneh
@ 2026-11-18 21:44 ` sashiko-bot
0 siblings, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-11-18 21:44 UTC (permalink / raw)
To: Orgad Shaneh, dwmw2, richard; +Cc: miquel.raynal, linux-mtd
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] jffs2: missing Fixes: trailer for lost cond_resched() in
readinode
--
commit dc68a5ef42faf811ab61bd897a8b35c11291c24e
Author: Orgad Shaneh <orgads@gmail.com>
> jffs2: reschedule between the data CRC checks of an inode
>
> The first read of an inode checks the data CRC of each of its unchecked
> nodes, all in one call. On an Octeon board with an 8-bit NOR, a
> 46.6 MB file takes 13.8 s of kernel time there. Without kernel
> preemption, nothing else ran on that CPU in the meantime: an RT
> watchdog thread missed its deadline and the board rebooted. With
> this, the lookup takes as long, but the watchdog, the per-CPU
> workqueue and the other tasks of that CPU keep running.
>
> jffs2_get_inode_nodes() already reschedules per node while it reads
> the headers; do the same before each data check.
>
> Signed-off-by: Orgad Shaneh <orgads@gmail.com>
[Severity: Low]
Prior to commit df8e96f39103 ("[JFFS2] Improve read_inode memory usage,
v2."), jffs2_do_read_inode_internal() called cond_resched() on each node
while checking data CRCs and building the fragtree, which was dropped when
that loop moved into jffs2_build_inode_fragtree(). Should this include:
Fixes: df8e96f39103 ("[JFFS2] Improve read_inode memory usage, v2.")
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118214045.107562-1-orgads@gmail.com?part=2
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-18 21:44 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 21:40 [PATCH 1/2] jffs2: check the data CRC of a node in RAM, not through point() Orgad Shaneh
2026-11-18 21:40 ` [PATCH 2/2] jffs2: reschedule between the data CRC checks of an inode Orgad Shaneh
2026-11-18 21:44 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox