Skip to contentSkip to conversation

Question about mkfs.jffs2 "-s" option

DISCUSSION Grant Edwards 4 participants 9 messages May 2, 2012 – May 4, 2012 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

[apologies if this isn't the right forum for mkfs.jffs2 questions]

According the the mkfs.jffs2 man page (from mtd-utils 1.4.8):

  -s, --pagesize=SIZE

Use page size SIZE. The default is 4 KiB. This size is the maximum size of a data node.

I'm using NAND flash with an erase size of 128K.

I've got a directory tree with 68 files. A few are largish (100KB), but most of them small (a few hundred bytes or less). They contain a total of 680K bytes of data and take up 900K of space on an ext2 filesystem.

When I do a "mkfs.jffs2 -e128 -l -n" I get a jffs2 image with a size of 300K. That seems reasonable.

If I specify a page size of 4K (which according to the man page is the default) by doing "mkfs.jffs2 -e128 -s4KiB -n -l", I get a jffs2 image with a size of 12MB.

According to the man page the default page size is 4K, so specifying a page size of 4K shouldn't change anything, right?

Why does specifying a page size of 4K make the jffs2 image 40X larger?

The NAND flash I'm using has to be written in 4K blocks -- isn't that the "page size"?

Signature · 3 lines
Grant Edwards               grant.b.edwards        Yow! Either CONFESS now or
                                  at               we go to "PEOPLE'S COURT"!!
                              gmail.com            
#1 lore raw

Hi Grant,

Quoted 23 lines · On Wed, 2 May 2012 16:08:38 +0000 (UTC) Grant Edwards…

[apologies if this isn't the right forum for mkfs.jffs2 questions]

According the the mkfs.jffs2 man page (from mtd-utils 1.4.8):

  -s, --pagesize=SIZE

Use page size SIZE. The default is 4 KiB. This size is the maximum size of a data node.

I'm using NAND flash with an erase size of 128K.

I've got a directory tree with 68 files. A few are largish (100KB), but most of them small (a few hundred bytes or less). They contain a total of 680K bytes of data and take up 900K of space on an ext2 filesystem.

When I do a "mkfs.jffs2 -e128 -l -n" I get a jffs2 image with a size of 300K. That seems reasonable.

If I specify a page size of 4K (which according to the man page is the default) by doing "mkfs.jffs2 -e128 -s4KiB -n -l", I get a jffs2 image with a size of 12MB.

Quoted 7 lines

According to the man page the default page size is 4K, so specifying a page size of 4K shouldn't change anything, right?

Why does specifying a page size of 4K make the jffs2 image 40X larger?

The NAND flash I'm using has to be written in 4K blocks -- isn't that the "page size"?

Looks like mkfs.jffs2 sets

	case 's':
		page_size = strtol(optarg, NULL, 0);

and does not further parse KiB/MiB tokens.

So my buest guess, try to specify '-s 4096' instead of '4KiB'.

Regards,
Shmulik

#2 lore raw
Quoted 7 lines · Shmulik Ladkani

Looks like mkfs.jffs2 sets

	case 's':
		page_size = strtol(optarg, NULL, 0);

and does not further parse KiB/MiB tokens.

So my buest guess, try to specify '-s 4096' instead of '4KiB'.

I should have tried that. Using -s4096 indeed produces the same result as without the -s option. I read the description of how the erase block size was parsed, and assumed that applied to the the page size as well.

Signature · 4 lines
Grant Edwards               grant.b.edwards        Yow! Gee, I feel kind of
                                  at               LIGHT in the head now,
                              gmail.com            knowing I can't make my
                                                   satellite dish PAYMENTS!
#3 lore raw
In reply to Grant Edwards
Quoted 2 lines · Grant Edwards

The NAND flash I'm using has to be written in 4K blocks -- isn't that the "page size"?

The smallest writable unit in a NAND flash is called a 'page', but AFAIK this is not what the -s option in mkfs.jffs2 is for. Instead, it is related for the kernel memory managament page size, which is 4k for most architectures. I think the jffs2 driver determines the smallest writable unit runtime; it is not a parameter during the file system creation. However the erase block size must be specified to mkfs.jffs2 as it affects the structure of the file system image.

/Ricard

Signature · 3 lines
Ricard Wolf Wanderlöf                           ricardw(at)axis.com
Axis Communications AB, Lund, Sweden            www.axis.com
Phone +46 46 272 2016                           Fax +46 46 13 61 30
#4 lore raw
Quoted 6 lines · Ricard Wanderlof
Quoted 2 lines · Grant Edwards

The NAND flash I'm using has to be written in 4K blocks -- isn't that the "page size"?

Quoted 7 lines

The smallest writable unit in a NAND flash is called a 'page', but AFAIK this is not what the -s option in mkfs.jffs2 is for. Instead, it is related for the kernel memory managament page size, which is 4k for most architectures. I think the jffs2 driver determines the smallest writable unit runtime; it is not a parameter during the file system creation. However the erase block size must be specified to mkfs.jffs2 as it affects the structure of the file system image.

So the '-s' option should always be set to the kernel page size for the target?

Signature · 3 lines
Grant Edwards               grant.b.edwards        Yow! Hello?  Enema Bondage?
                                  at               I'm calling because I want
                              gmail.com            to be happy, I guess ...
#5 lore raw
In reply to Ricard Wanderlof

Hi Ricard,

Quoted 10 lines · On Thu, 3 May 2012 09:35:14 +0200 (CEST) Ricard Wanderlof…
Quoted 2 lines · Grant Edwards

The NAND flash I'm using has to be written in 4K blocks -- isn't that the "page size"?

The smallest writable unit in a NAND flash is called a 'page', but AFAIK this is not what the -s option in mkfs.jffs2 is for. Instead, it is related for the kernel memory managament page size, which is 4k for most architectures.

According to MKFS.JFFS2(1),

-s, --pagesize=SIZE
Use page size SIZE. The default is 4 KiB. This size is the maximum size of a data node.

And according to http://linux-mtd.infradead.org/~dwmw2/jffs2.pdf

In order to facilitate rapid decompression of data upon readpage() requests, nodes contain no more than a single page of data, according to the hardware page size on the target platform.

Wow.
I always assumed I had to set it according to NAND's page size, not according to target system's mm page size.

Can you tell what's the effect of incorrectly setting it to values such
as: 512 or 2048 bytes (instead of 4KiB)?

Well, I guess as data is written during runtime by the jffs2 itself, and as the GC gets working, new inodes will be correctly created, and their sizes will be up to system's page size.

However what happens with these small inodes initially created by mkfs.jffs2? "Only" a performance penalty or something worse?

Thanks,
Shmulik

#6 lore raw
Quoted 12 lines · Shmulik Ladkani

Hi Ricard,

Quoted 9 lines · On Thu, 3 May 2012 09:35:14 +0200 (CEST) Ricard Wanderlof…
Quoted 2 lines · Grant Edwards

The NAND flash I'm using has to be written in 4K blocks -- isn't that the "page size"?

The smallest writable unit in a NAND flash is called a 'page', but AFAIK this is not what the -s option in mkfs.jffs2 is for. Instead, it is related for the kernel memory managament page size,

It would be cool if that's what the man page actually said. :)

Quoted 11 lines
Quoted 2 lines

which is 4k
for most architectures.

According to MKFS.JFFS2(1),

-s, --pagesize=SIZE
Use page size SIZE. The default is 4 KiB. This size is the maximum size of a data node.

And according to http://linux-mtd.infradead.org/~dwmw2/jffs2.pdf

Quoted 8 lines

In order to facilitate rapid decompression of data upon readpage() requests, nodes contain no more than a single page of data, according to the hardware page size on the target platform.

Wow.
I always assumed I had to set it according to NAND's page size, not according to target system's mm page size.

To me, that's the obvious interpretation of the man page, and I swear I've read "howto" pages at other sites (probably ARM SoC and eval-board vendors), that explictly told you to set the -s option to be the flash device's page size.

Quoted 9 lines

Can you tell what's the effect of incorrectly setting it to values such as: 512 or 2048 bytes (instead of 4KiB)?

Well, I guess as data is written during runtime by the jffs2 itself, and as the GC gets working, new inodes will be correctly created, and their sizes will be up to system's page size.

However what happens with these small inodes initially created by mkfs.jffs2? "Only" a performance penalty or something worse?

When I created them with 4 byte nodes, the filesystem seemd to work fine. It was just shockingly large. :)

Signature · 3 lines
Grant Edwards               grant.b.edwards        Yow! TAILFINS!! ... click
                                  at               ...
                              gmail.com            
#7 lore raw
In reply to Shmulik Ladkani
Quoted 22 lines · Shmulik Ladkani

Hi Ricard,

Quoted 10 lines · On Thu, 3 May 2012 09:35:14 +0200 (CEST) Ricard Wanderlof…
Quoted 2 lines · Grant Edwards

The NAND flash I'm using has to be written in 4K blocks -- isn't that the "page size"?

The smallest writable unit in a NAND flash is called a 'page', but AFAIK this is not what the -s option in mkfs.jffs2 is for. Instead, it is related for the kernel memory managament page size, which is 4k for most architectures.

According to MKFS.JFFS2(1),

-s, --pagesize=SIZE
Use page size SIZE. The default is 4 KiB. This size is the maximum size of a data node.

And according to http://linux-mtd.infradead.org/~dwmw2/jffs2.pdf

Quoted 8 lines

In order to facilitate rapid decompression of data upon readpage() requests, nodes contain no more than a single page of data, according to the hardware page size on the target platform.

Wow.
I always assumed I had to set it according to NAND's page size, not according to target system's mm page size.

Shmulik, I can give some info about this. First of all because of compression and very different node sizes (UBIFS and JFFS2) and because JFFS2 was designed for NOR flash originally - NAND page size is not something which affects the design of file-systems, or their on-flash layout. We use write-buffers on I/O level to make it appear like the eraseblock is byte-writable.

The RAM page size comes from the general linux design - the VFS writes in RAM page size units, and it is much simpler to make max node size = PAGE_CACHE_SIZE rather than trying to split it when the PAGE_CACHE_SIZE is something like 16KiB. This is where this -s stuff comes from. I think it was a mistake to introduce this parameter because it is very unlikely JFFS2 is/was used on systems with a different PAGE_CACHE_SIZE.

Signature · 2 lines
Best Regards,
Artem Bityutskiy
#8 lore raw

Hi Artem, Ricard,

Quoted 32 lines · On Fri, 04 May 2012 10:15:37 +0300 Artem Bityutskiy <[email protected]> wrote:
Quoted 15 lines · Shmulik Ladkani
Quoted 5 lines · On Thu, 3 May 2012 09:35:14 +0200 (CEST) Ricard Wanderlof…

The smallest writable unit in a NAND flash is called a 'page', but AFAIK this is not what the -s option in mkfs.jffs2 is for. Instead, it is related for the kernel memory managament page size, which is 4k for most architectures.

According to MKFS.JFFS2(1),

-s, --pagesize=SIZE
Use page size SIZE. The default is 4 KiB. This size is the maximum size of a data node.

And according to http://linux-mtd.infradead.org/~dwmw2/jffs2.pdf

Quoted 8 lines

In order to facilitate rapid decompression of data upon readpage() requests, nodes contain no more than a single page of data, according to the hardware page size on the target platform.

Wow.
I always assumed I had to set it according to NAND's page size, not according to target system's mm page size.

Shmulik, I can give some info about this. First of all because of compression and very different node sizes (UBIFS and JFFS2) and because JFFS2 was designed for NOR flash originally - NAND page size is not something which affects the design of file-systems, or their on-flash layout. We use write-buffers on I/O level to make it appear like the eraseblock is byte-writable.

Quoted 6 lines

The RAM page size comes from the general linux design - the VFS writes in RAM page size units, and it is much simpler to make max node size = PAGE_CACHE_SIZE rather than trying to split it when the PAGE_CACHE_SIZE is something like 16KiB. This is where this -s stuff comes from. I think it was a mistake to introduce this parameter because it is very unlikely JFFS2 is/was used on systems with a different PAGE_CACHE_SIZE.

Thanks for the explanations.
I pretty much realized this after reading [1]...

BTW, googling [mkfs.jffs2 and "-s 0x200"] or [mkfs.jffs2 and "-s 0x800"] yielded few howtos, faqs, and alike....
Guess I wasn't the only one fooled by the argument's name :-))

[1] http://linux-mtd.infradead.org/~dwmw2/jffs2.pdf

Regards
Shmulik