JFFS2: accelerate scanning.
PATCH 1/1 JFFS2: accelerate scanning.
This patch make the JFFS2 scanning faster in U-Boot.
1). if we find 1KB 0xFF data from the beginning of the erase block,skip it. 2). if the 1KB data is 0xFF after the cleanmarker, ship this erase block.
For the 16MB nor flash, the scanning time is changed from about 9s to 1s.
--- fs/jffs2/jffs2_1pass.c | 31 +++++++++++++++++++++---------- fs/jffs2/jffs2_nand_1pass.c | 2 +- 2 files changed, 22 insertions(+), 11 deletions(-)
fs/jffs2/jffs2_1pass.c +19 -10
@@ -1441,7 +1441,7 @@ dump_dirents(struct b_lists *pL) }#endif -#define DEFAULT_EMPTY_SCAN_SIZE 4096 +#define DEFAULT_EMPTY_SCAN_SIZE 1024static inline uint32_t EMPTY_SCAN_SIZE (uint32_t sector_size) {
@@ -1461,7 +1461,7 @@ jffs2_1pass_build_lists(struct part_info * part)u32 counter4 =0 ;u32 counterF =0 ;u32 counterN =0 ; -u32 buf_size =DEFAULT_EMPTY_SCAN_SIZE ; +u32 buf_size =128 *1024 ;;char *buf;/* turn off the lcd. Refreshing the lcd adds 50% overhead to the */
@@ -1559,14 +1559,17 @@ jffs2_1pass_build_lists(struct part_info * part)/* We temporarily use 'ofs' as a pointer into the buffer/jeb */ ofs =0 ; -/* Scan only 4KiB of 0xFF before declaring it's empty */ +/* Scan only 1KiB of 0xFF before declaring it's empty */ while (ofs <EMPTY_SCAN_SIZE (part->sector_size) && *(uint32_t *)(&buf[ofs]) ==0xFFFFFFFF ) ofs +=4 ; -if (ofs ==EMPTY_SCAN_SIZE (part->sector_size)) +if (ofs ==EMPTY_SCAN_SIZE (part->sector_size)) { +printf ("Block at 0x%08x is empty (erased)\n" , sector_ofs);continue ; + } +/* Now ofs is a complete physical flash offset as it always was... */ ofs += sector_ofs; prevofs = ofs -1 ;
@@ -1594,16 +1597,14 @@ jffs2_1pass_build_lists(struct part_info * part)if (*(uint32_t *)(&buf[ofs-buf_ofs]) ==0xffffffff ) {uint32_t inbuf_ofs; -uint32_t empty_start, scan_end; +uint32_t empty_start; empty_start = ofs; ofs +=4 ; - scan_end =min_t (uint32_t,EMPTY_SCAN_SIZE ( - part->sector_size)/8 , - buf_len); + more_empty: inbuf_ofs = ofs - buf_ofs; -while (inbuf_ofs < scan_end) { +while (inbuf_ofs < buf_len) {if (*(uint32_t *)(&buf[inbuf_ofs]) !=0xffffffff ) goto scan_more;
@@ -1613,6 +1614,12 @@ jffs2_1pass_build_lists(struct part_info * part) }/* Ran off end. */ +/* If we're only checking the beginning of a block with a cleanmarker, +bail now */ +if ((buf_ofs == sector_ofs) && + (node ==(struct jffs2_unknown_node *)&buf[ofs-buf_ofs])) +break ; +/* See how much more there is to read in this * eraseblock... */
@@ -1627,12 +1634,12 @@ jffs2_1pass_build_lists(struct part_info * part)*/ break ; } - scan_end = buf_len;get_fl_mem ((u32 )part->offset + ofs, buf_len, buf); buf_ofs = ofs; goto more_empty; } +if (node->magic !=JFFS2_MAGIC_BITMASK || !hdr_crc (node)) { ofs +=4 ;
@@ -1650,6 +1657,8 @@ jffs2_1pass_build_lists(struct part_info * part)case JFFS2_NODETYPE_INODE :if (buf_ofs + buf_len < ofs +sizeof (struct jffs2_raw_inode )) { + buf_len =min_t (uint32_t, buf_size, sector_ofs + + part->sector_size - ofs);get_fl_mem ((u32 )part->offset + ofs, buf_len, buf);
buf_ofs = ofs;
@@ -1671,6 +1680,8 @@ jffs2_1pass_build_lists(struct part_info * part)
((struct
jffs2_raw_dirent *)
node)->nsize) {
+ buf_len = min_t(uint32_t, buf_size, sector_ofs
+ + part->sector_size - ofs);
get_fl_mem((u32)part->offset + ofs,
buf_len, buf);
buf_ofs = ofs;
fs/jffs2/jffs2_nand_1pass.c +1 -1
@@ -833,7 +833,7 @@ jffs2_1pass_build_lists(struct part_info * part)return 0 ; ofs =0 ; -/* Scan only 4KiB of 0xFF before declaring it's empty */ +/* Scan only 1KiB of 0xFF before declaring it's empty */ while (ofs <EMPTY_SCAN_SIZE && *(uint32_t *)(&buf[ofs]) ==0xFFFFFFFF ) ofs +=4 ;if (ofs ==EMPTY_SCAN_SIZE )
Signature · 1 line
1.7.3.1.msysgit.0
PATCH 1/1 JFFS2: accelerate scanning.
Hi Leo,
Quoted 3 lines
This patch make the JFFS2 scanning faster in U-Boot.
1). if we find 1KB0xFFdata from the beginning of the erase block,skip it. 2). if the 1KB data is0xFFafter the cleanmarker, ship this erase block.
Ship it to where? ;) Typo, should be skip.
Quoted 3 lines
For the 16MB nor flash, the scanning time is changed from about 9s to 1s.
Signed-off-by Leo Liu <[email protected]>
checkpatch says:
total: 7 errors, 9 warnings, 103 lines checked
NOTE: whitespace errors detected, you may wish to use scripts/cleanpatch or
scripts/cleanfile
Is there a corresponding thing in the Linux kernel?
Quoted 10 lines
--- fs/jffs2/jffs2_1pass.c | 31 +++++++++++++++++++++---------- fs/jffs2/jffs2_nand_1pass.c | 2 +- 2 files changed, 22 insertions(+), 11 deletions(-)fs/jffs2/jffs2_1pass.c +0
-0
fs/jffs2/jffs2_1pass.c dump_dirents(struct b_lists *pL) · line 1444
Quoted 5 lines
fs/jffs2/jffs2_1pass.c +1
-1@@ -1441,7 +1441,7 @@ dump_dirents(struct b_lists *pL) }#endif -#define DEFAULT_EMPTY_SCAN_SIZE 4096 +#define DEFAULT_EMPTY_SCAN_SIZE 1024
Hm, this is not mentioned in the commit log. So is this detection already there and you simply decrease the amount of empty space you are looking for?
fs/jffs2/jffs2_1pass.c jffs2_1pass_build_lists(struct part_info * part) · line 1464
Quoted 9 lines
fs/jffs2/jffs2_1pass.c +1
-1static inline uint32_t EMPTY_SCAN_SIZE (uint32_t sector_size) {@@ -1461,7 +1461,7 @@ jffs2_1pass_build_lists(struct part_info * part)u32 counter4 =0 ;u32 counterF =0 ;u32 counterN =0 ; -u32 buf_size =DEFAULT_EMPTY_SCAN_SIZE ; +u32 buf_size =128 *1024 ;;
This is a 128k buffer size which previously was a 4k buffer. Why is this change needed? Where does the size come from?
fs/jffs2/jffs2_1pass.c jffs2_1pass_build_lists(struct part_info * part) · line 1562
Quoted 9 lines
fs/jffs2/jffs2_1pass.c +1
-1char *buf;/* turn off the lcd. Refreshing the lcd adds 50% overhead to the */ @@ -1559,14 +1559,17 @@ jffs2_1pass_build_lists(struct part_info * part)/* We temporarily use 'ofs' as a pointer into the buffer/jeb */ ofs =0 ; -/* Scan only 4KiB of 0xFF before declaring it's empty */ +/* Scan only 1KiB of 0xFF before declaring it's empty */
Change the comment to refer to the macro so we don't need to change it every time the macro changes.
fs/jffs2/jffs2_1pass.c jffs2_1pass_build_lists(struct part_info * part) · line 1568
Quoted 7 lines
fs/jffs2/jffs2_1pass.c +2
-1while (ofs <EMPTY_SCAN_SIZE (part->sector_size) && *(uint32_t *)(&buf[ofs]) ==0xFFFFFFFF ) ofs +=4 ; -if (ofs ==EMPTY_SCAN_SIZE (part->sector_size)) +if (ofs ==EMPTY_SCAN_SIZE (part->sector_size)) { +printf ("Block at 0x%08x is empty (erased)\n" , sector_ofs);
Hm, you add this output so lets consider what it says - wouldn't it be better to say "is considered to be empty"? After all, we only infer the emptiness in the code.
Quoted 79 lines
fs/jffs2/jffs2_1pass.c +14
-6continue ; + } +/* Now ofs is a complete physical flash offset as it always was... */ ofs += sector_ofs; prevofs = ofs -1 ;@@ -1594,16 +1597,14 @@ jffs2_1pass_build_lists(struct part_info * part)if (*(uint32_t *)(&buf[ofs-buf_ofs]) ==0xffffffff ) {uint32_t inbuf_ofs; -uint32_t empty_start, scan_end; +uint32_t empty_start; empty_start = ofs; ofs +=4 ; - scan_end =min_t (uint32_t,EMPTY_SCAN_SIZE ( - part->sector_size)/8 , - buf_len); + more_empty: inbuf_ofs = ofs - buf_ofs; -while (inbuf_ofs < scan_end) { +while (inbuf_ofs < buf_len) {if (*(uint32_t *)(&buf[inbuf_ofs]) !=0xffffffff ) goto scan_more;@@ -1613,6 +1614,12 @@ jffs2_1pass_build_lists(struct part_info * part) }/* Ran off end. */ +/* If we're only checking the beginning of a block with a cleanmarker, +bail now */ +if ((buf_ofs == sector_ofs) && + (node ==(struct jffs2_unknown_node *)&buf[ofs-buf_ofs])) +break ; +/* See how much more there is to read in this * eraseblock... */ @@ -1627,12 +1634,12 @@ jffs2_1pass_build_lists(struct part_info * part)*/ break ; } - scan_end = buf_len;get_fl_mem ((u32 )part->offset + ofs, buf_len, buf); buf_ofs = ofs; goto more_empty; } +if (node->magic !=JFFS2_MAGIC_BITMASK || !hdr_crc (node)) { ofs +=4 ;@@ -1650,6 +1657,8 @@ jffs2_1pass_build_lists(struct part_info * part)case JFFS2_NODETYPE_INODE :if (buf_ofs + buf_len < ofs +sizeof (struct jffs2_raw_inode )) { + buf_len =min_t (uint32_t, buf_size, sector_ofs + + part->sector_size - ofs);get_fl_mem ((u32 )part->offset + ofs, buf_len, buf);fs/jffs2/jffs2_1pass.c +2
-0buf_ofs = ofs;@@ -1671,6 +1680,8 @@ jffs2_1pass_build_lists(struct part_info * part) ((struct jffs2_raw_dirent *) node)->nsize) { + buf_len =min_t (uint32_t, buf_size, sector_ofs + + part->sector_size - ofs);get_fl_mem ((u32 )part->offset + ofs, buf_len, buf);fs/jffs2/jffs2_1pass.c +0
-0buf_ofs = ofs;fs/jffs2/jffs2_nand_1pass.c +0
-0
fs/jffs2/jffs2_nand_1pass.c jffs2_1pass_build_lists(struct part_info * part) · line 839
Quoted 8 lines
fs/jffs2/jffs2_nand_1pass.c +1
-1@@ -833,7 +833,7 @@ jffs2_1pass_build_lists(struct part_info * part)return 0 ; ofs =0 ; -/* Scan only 4KiB of 0xFF before declaring it's empty */ +/* Scan only 1KiB of 0xFF before declaring it's empty */ while (ofs <EMPTY_SCAN_SIZE && *(uint32_t *)(&buf[ofs]) ==0xFFFFFFFF ) ofs +=4 ;if (ofs ==EMPTY_SCAN_SIZE )
On a whole - is this optimization safe with regard to uncompressed files containing only 0xFFs?
Cheers
Detlev
Signature · 6 lines
"One of my most productive days was throwing away 1000 lines of code." - Ken Thompson. -- DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-40 Fax: (+49)-8142-66989-80 Email: dzu at denx.de