Skip to contentSkip to conversation

mtd2block should not expand sparse loopback files

DISCUSSION Johannes Niess 3 participants 5 messages May 27, 2006 – Jun 1, 2006 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

Hi list,

Thank you all for providing mtd and jffs2. I'm using it a little bit different than intended and it looks like the crash recovery feature is causing me trouble. I'm trying to save disk space on my gentoo installation for an old notebook. AFAIK jffs2 is the only way to provide transparent read and write access with compression. Other FS can be used with sparse loopback files and do not occupy disk space for unused blocks ("Over commiting disk space" becomes feasible). I want to combine the features, e. g. to
store /usr/portage in a sparse loopback file formated with jffs2.

I tried this:

# make1G sparse loop file, taking 1M real disk space dd if=/dev/null of=sparse.jffs2 bs=1M count=1000 seek=1000

# mount it as loop device
losetup /dev/loop/0 sparse.jffs2
# make a jffs2 file system on it
mkfs.jffs2 -o /dev/loop/0 -d /emptydir
# convert it into a mtd
modprobe block2mtd block2mtd=/dev/loop/0
# mount the mtd device
mount -t jffs2 /dev/mtdblock0 /mnt/somewhere

The jffs2 is readable and writable as expected. BUT upon first mount a couple of pdflush (pseudo kernel) processes become active and completely expand the sparse loopback file. Only after that disk activity has settled, "ls" and "du" give identical numbers of 1GB. Before mounting "ls" gives the maximum size and "du" just counts occupied sectors, e. g. "ls" gives 1 GB and "du" only 1 MB.

"od -h sparse.jffs2|less" gives a repeating pattern after mount:

*
617750000 1985 2003 000c 0000 b0b1 e41e ffff ffff
617750020 ffff ffff ffff ffff ffff ffff ffff ffff
*
617760000 1985 2003 000c 0000 b0b1 e41e ffff ffff
617760020 ffff ffff ffff ffff ffff ffff ffff ffff
*

I guess that the "fill with 1's" flash strategy is taking its toll together with the "Clean" markers. Can I switch that off? Using "mkfs.jffs2 --no-cleanmarkers" does not help, as does --eraseblock=0.

block2mtd should not touch unused blocks at all in this setup. They should only be written to on first use for storing real data.

Please make transparent compression AND loop file expansion on demand possible. Thank you very much for your work!

Johannes Nieß

#1 lore raw
Quoted 9 lines · Johannes Niess

Hi list,

The jffs2 is readable and writable as expected. BUT upon first mount a couple of pdflush (pseudo kernel) processes become active and completely expand the sparse loopback file. Only after that disk activity has settled, "ls" and "du" give identical numbers of 1GB. Before mounting "ls" gives the maximum size and "du" just counts occupied sectors, e. g. "ls" gives 1 GB and "du" only 1 MB.

JFFS2 is going through and adding cleanmarkers to the blocks that don't have them.

Quoted 3 lines

I guess that the "fill with 1's" flash strategy is taking its toll together with the "Clean" markers. Can I switch that off? Using "mkfs.jffs2 --no-cleanmarkers" does not help, as does --eraseblock=0.

No you can't switch it off. The filesystem will add them itself.

Quoted 2 lines

block2mtd should not touch unused blocks at all in this setup. They should only be written to on first use for storing real data.

This has nothing to do with block2mtd. It's a result of using JFFS2.

Quoted 2 lines

Please make transparent compression AND loop file expansion on demand possible. Thank you very much for your work!

Um.. why don't you make it possible and provide a patch? Otherwise you might want to seriously look into e2compr.

josh

#2 lore raw
Quoted 7 lines · Josh Boyer
Quoted 3 lines · Johannes Niess

I guess that the "fill with 1's" flash strategy is taking its toll together with the "Clean" markers. Can I switch that off? Using "mkfs.jffs2 --no-cleanmarkers" does not help, as does --eraseblock=0.

No you can't switch it off. The filesystem will add them itself.

For now. I have a patch pending that removes the cleanmarker generation from jffs2. Still needs some polishing, though.

Basically, if the mtd can do implicit erase, like any RAM, disk or file-based device, there is no point in the cleanmarkers and jffs2 doesn't write them. There might be other cases where they can be omitted at well.

Jörn

Signature · 2 lines
He who knows that enough is enough will always have enough.
-- Lao Tsu
#3 lore raw

Am Dienstag, 30. Mai 2006 13:03 schrieb Jörn Engel:

Quoted 8 lines · Josh Boyer
Quoted 6 lines · Johannes Niess
Quoted 3 lines

I guess that the "fill with 1's" flash strategy is taking its toll together with the "Clean" markers. Can I switch that off? Using "mkfs.jffs2 --no-cleanmarkers" does not help, as does --eraseblock=0.

No you can't switch it off. The filesystem will add them itself.

Quoted 7 lines

For now. I have a patch pending that removes the cleanmarker generation from jffs2. Still needs some polishing, though.

Basically, if the mtd can do implicit erase, like any RAM, disk or file-based device, there is no point in the cleanmarkers and jffs2 doesn't write them. There might be other cases where they can be omitted at well.

Hi Jörn,

That is great news. If your patch is still applicable to a released vanilla kernel (or not requiring too many other patches) I'd volunteer as beta tester. I see potential of wide spread use in "compact" linux distributions. It makes it very easy to use a full scale distribution in reduced space.

I'm quite sure that you have seen the difference of mtd wanting 1's all over the place and a sparse file returning implicit 0's when reading in the holes. I've no idea whether this is relevant.

I had a quick look at the source if I could find the relevant parts and do some very nasty hacking. Given my very limited C programming skills ("C++ very easy", approx. 100 pages) and using Perl if I feel the need for some hobby programming, I had no chance.

Following up on Josh's hint to e2compr I had the feeling that "e2compr.infradead.org" would be an address to describe the current status :-) But that stuff has patches to kernel 2.6.10 . I don't consider it being "alive" enough to be usefull.

Thank you again for developing mtd/jffs2!

Johannes

#4 lore raw
Quoted 8 lines · Johannes Niess
Quoted 3 lines

For now. I have a patch pending that removes the cleanmarker generation from jffs2. Still needs some polishing, though.

That is great news. If your patch is still applicable to a released vanilla kernel (or not requiring too many other patches) I'd volunteer as beta tester. I see potential of wide spread use in "compact" linux distributions. It makes it very easy to use a full scale distribution in reduced space.

"Still needs some polishing" can be read as "I have something half-arsed that noone should ever see before I rewrite it properly". Might still take a while. You shouldn't hold your breath until it happens.

Quoted 3 lines

I'm quite sure that you have seen the difference of mtd wanting 1's all over the place and a sparse file returning implicit 0's when reading in the holes. I've no idea whether this is relevant.

Known problem. If I had a time machine, one of the immediate uses would be to LART whichever genius decided to device "1" as erased and "0" as written. The reverse would have had quite some advantages. Changing it today would break pretty much everything, so without a time machine, the situation remains as is.

Quoted 4 lines

Following up on Josh's hint to e2compr I had the feeling that "e2compr.infradead.org" would be an address to describe the current status :-) But that stuff has patches to kernel 2.6.10 . I don't consider it being "alive" enough to be usefull.

Yup.

Jörn

Signature · 2 lines
A victorious army first wins and then seeks battle.
-- Sun Tzu