Skip to content

Conversation

@aparcar
Copy link
Member

@aparcar aparcar commented May 29, 2022

This is a proof of concept to use EROFS for OpenWrt.

Based on little research it seems to outperform SquashFS regarding speed and storage.

The MicroLZMA (incomplete backport) may allow to save some extra space.

Tested and works with x86/64 QEMU:

/dev/root on / type erofs (ro,noatime,user_xattr,acl,cache_strategy=readaround)

Image filenames still contain squashfs however run an EROFS filesystem.

@aparcar aparcar force-pushed the erofs branch 2 times, most recently from af568b2 to ce8baca Compare May 30, 2022 13:32
@nbd168
Copy link
Member

nbd168 commented May 30, 2022

I just ran a quick test comparing the size of erofs and squashfs. For the same rootfs directory, the erofs file was 14 MB, the squashfs file only 11 MB.
I think we should stick with squashfs...

@aparcar
Copy link
Member Author

aparcar commented May 30, 2022

Could you please elaborate on the test you performed? I'm wondering if the default EROFS LZMA compression is simply not as high as what we use for squashfs.

@nbd168
Copy link
Member

nbd168 commented May 30, 2022

I configured erofs to use lzma at maximum compression level by using -zlzma,9

@mtippmann
Copy link

mtippmann commented May 30, 2022

there are quite a few options, just tested some block-sizes and a single timestamp for all files and no xattr

host/bin - [master] » for size in 4096 8192 16384 32768 65536 131072 262144 524288 1048576; do ./mkfs.erofs \
  -C$size -d1 -zlzma,9 -x-1 -T$(date +%s) \ 
  test.$size.erofs \
  /home/mt/Projects/weimarnetz/openwrt/bin/targets/ath79/generic/rootfs; done

host/bin - [master] » ls -1vl test*
-rw-r--r-- 1 mt mt 5169152 31. Mai 01:02 test.erofs
-rw-r--r-- 1 mt mt 5169152 31. Mai 01:18 test.4096.erofs
-rw-r--r-- 1 mt mt 4919296 31. Mai 01:19 test.8192.erofs
-rw-r--r-- 1 mt mt 4763648 31. Mai 01:19 test.16384.erofs
-rw-r--r-- 1 mt mt 4644864 31. Mai 01:19 test.32768.erofs
-rw-r--r-- 1 mt mt 4583424 31. Mai 01:19 test.65536.erofs
-rw-r--r-- 1 mt mt 4526080 31. Mai 01:19 test.131072.erofs
-rw-r--r-- 1 mt mt 4497408 31. Mai 01:19 test.262144.erofs
-rw-r--r-- 1 mt mt 4485120 31. Mai 01:19 test.524288.erofs
-rw-r--r-- 1 mt mt 4485120 31. Mai 01:19 test.1048576.erofs

host/bin - [master] » du -sh /home/mt/Projects/weimarnetz/openwrt/bin/targets/ath79/generic/rootfs
16M     /home/mt/Projects/weimarnetz/openwrt/bin/targets/ath79/generic/rootfs



https://www.kernel.org/doc/html/latest/filesystems/erofs.html has some interesting things like cache_strategy=disabled which might help with 32mb ram devices.

@mtippmann
Copy link

generic/_openwrt-ath79-generic-tplink_archer-c60-v3-squashfs-factory.bin.extracted - [remotes/github/master] » ls -l
insgesamt 17397
drwxr-xr-x 16 mt mt      18 29. Mai 22:37 squashfs-root
drwxr-xr-x 16 mt mt      18 29. Mai 22:37 squashfs-root-0
-rw-r--r--  1 mt mt 7598807 31. Mai 02:22 2147
-rw-r--r--  1 mt mt 6099566 31. Mai 02:22 2147.7z
-rw-r--r--  1 mt mt 3831660 31. Mai 02:22 2233A6.squashfs

still quite a difference - so 3831660 for squashfs vs. 4497408 with clustersize 256k and 5169152 for defaults

@aparcar
Copy link
Member Author

aparcar commented May 31, 2022

Thank you for testing, could you please append the following parameters and test again?

-zlzma -C 65536 -Eztailpacking

I got some email feedback from the developer and he recommended squashfs for now. I'll keep erofs in mind for the future.

EDIT: I just did, now the storage difference for x86/64 rootfs is 3.6MB (erofs) vs 3.3MB (squashfs).

@mtippmann
Copy link

mtippmann commented May 31, 2022

with -Eztailpacking

-rw-r--r-- 1 mt mt  4132864 31. Mai 11:14 test.1048576.9eztailpacking.erofs
-rw-r--r-- 1 mt mt  4132864 31. Mai 11:14 test.524288.9eztailpacking.erofs
-rw-r--r-- 1 mt mt  4141056 31. Mai 11:14 test.262144.9eztailpacking.erofs
-rw-r--r-- 1 mt mt  4177920 31. Mai 11:14 test.131072.9eztailpacking.erofs
-rw-r--r-- 1 mt mt  4218880 31. Mai 11:14 test.65536.9eztailpacking.erofs
-rw-r--r-- 1 mt mt  4284416 31. Mai 11:14 test.32768.9eztailpacking.erofs
-rw-r--r-- 1 mt mt  4386816 31. Mai 11:14 test.16384.9eztailpacking.erofs
-rw-r--r-- 1 mt mt  4534272 31. Mai 11:14 test.8192.9eztailpacking.erofs
-rw-r--r-- 1 mt mt  4726784 31. Mai 11:13 test.4096.9eztailpacking.erofs
-rw-r--r-- 1 mt mt  4485120 31. Mai 11:13 test.1048576.9.erofs
-rw-r--r-- 1 mt mt  4485120 31. Mai 11:13 test.524288.9.erofs
-rw-r--r-- 1 mt mt  4497408 31. Mai 11:13 test.262144.9.erofs
-rw-r--r-- 1 mt mt  4526080 31. Mai 11:13 test.131072.9.erofs
-rw-r--r-- 1 mt mt  4583424 31. Mai 11:13 test.65536.9.erofs
-rw-r--r-- 1 mt mt  4644864 31. Mai 11:13 test.32768.9.erofs
-rw-r--r-- 1 mt mt  4763648 31. Mai 11:13 test.16384.9.erofs
-rw-r--r-- 1 mt mt  4919296 31. Mai 11:13 test.8192.9.erofs
-rw-r--r-- 1 mt mt  5169152 31. Mai 11:12 test.4096.9.erofs

@txt-file
Copy link
Contributor

txt-file commented Jun 1, 2022

Is there a way to check how much RAM {squashfs4,erofs} kernel module needs?

If RAM usage of erofs is much lower than squashfs4 it might still be good for limited RAM/plenty ROM devices.

@mtippmann
Copy link

Is there a way to check how much RAM {squashfs4,erofs} kernel module needs?

not sure but cat /proc/meminfo -> MemAvailable might be useful - it's also possible to add cat /proc/slabinfo with CONFIG_KERNEL_SLABINFO=y in the openwrt config. There should be allocations from squashfs visible or at least more data than just /proc/meminfo.

I Attempted to boot openwrt with this patch on a wdr4300 but it didn't boot, have to take a look again - poc works in qemu so this should be enough to get an idea and some data.

The EROFS paper talks about improvements vs. squashfs: https://www.usenix.org/system/files/atc19-gao.pdf (section 2.2) but not sure how much of this applies to openwrt.

@aparcar
Copy link
Member Author

aparcar commented Jun 2, 2022

I asked on the erofs mailing list and they're working on improvements regarding size. I'd just leave this PR open and update it from time to time, this way people can run tests without duplicating the work.

It surely takes another year or so to become the default, if ever :)

not sure but cat /proc/meminfo -> MemAvailable might be useful - it's also possible to add cat /proc/slabinfo with CONFIG_KERNEL_SLABINFO=y in the openwrt config. There should be allocations from squashfs visible or at least more data than just /proc/meminfo.

Please report all finding in this PR

I Attempted to boot openwrt with this patch on a wdr4300 but it didn't boot

Sorry for the inconvenience!

@mtippmann
Copy link

Sorry for the inconvenience!

no worries! super cool that we have something to experiment and if it's not a good fit at least we tried :)
It's probably still lot's of work until this someday land in the repo either as default or option but it's more like a marathon than a sprint :)

thanks for your time working on this - I try to gather more data when I have some time again.

@hsiangkao
Copy link
Contributor

Is there a way to check how much RAM {squashfs4,erofs} kernel module needs?

not sure but cat /proc/meminfo -> MemAvailable might be useful - it's also possible to add cat /proc/slabinfo with CONFIG_KERNEL_SLABINFO=y in the openwrt config. There should be allocations from squashfs visible or at least more data than just /proc/meminfo.

Just notice this topic, but that is not simple. EROFS strategy is to reuse page cache rather than allocate bounced compressed buffers if suitable, so the whole benefit is reduced runtime temp buffers, the final MemAvailable isn't helpful to measure such data.

Instead, EROFS will cache some compressed data if needed if available memory is abundant since no need to trigger I/O anymore (if you use readaround or readahead cache_strategy). But in low memory scenarios, it will disable such cache and use inplace I/O only.

I guess it can be observed by allocstall_ in /proc/vmstat if under memory pressure or you could just test some boot speed, app lagging under memory pressure etc instead, anyway I guess MemAvailable is not helpful to this topic.

Also, MicroLZMA is still an experimental feature compared to LZ4, partially due to no stable XZ utils released yet, partially since I still have some remaining runtime tuning work to do for such slow algorithms. I didn't prioritize that also due to no new stable XZ utils till now.

@Ansuel
Copy link
Member

Ansuel commented Jun 4, 2022

I wonder if, aside from size increase problem, this fs would give us other benefits... Improvement to the boot time?

@neheb
Copy link
Contributor

neheb commented Jun 11, 2022

I’ll make a note that @stintel was wondering about reworking the whole thing using btrfs and subvolumes. Never got anywhere.

@timocapa
Copy link

timocapa commented Jun 23, 2022

I'm very interested in moving to EROFS as well but unfortunately this didn't not on mt7621 either :(

I think with the right settings you could probably get very close to squashfs in size and I'd welcome it if this became a FS to choose from

@Ansuel
Copy link
Member

Ansuel commented Jul 7, 2022

-rw-r--r-- 1 ansuel ansuel  6236968 Jul  7 14:59 openwrt-ipq806x-generic-netgear_r7800-initramfs-uImage_erofs
-rw-r--r-- 1 ansuel ansuel  6207768 Jul  7 15:06 openwrt-ipq806x-generic-netgear_r7800-initramfs-uImage_squashfs

-rw-r--r-- 1 ansuel ansuel  8913025 Jul  7 14:59 openwrt-ipq806x-generic-netgear_r7800-squashfs-factory.img_erofs
-rw-r--r-- 1 ansuel ansuel  7733377 Jul  7 15:06 openwrt-ipq806x-generic-netgear_r7800-squashfs-factory.img_squashfs

-rw-r--r-- 1 ansuel ansuel  6912798 Jul  7 14:59 openwrt-ipq806x-generic-netgear_r7800-squashfs-sysupgrade.bin_erofs
-rw-r--r-- 1 ansuel ansuel  5724958 Jul  7 15:06 openwrt-ipq806x-generic-netgear_r7800-squashfs-sysupgrade.bin_squashfs

So yhea compression still needs some love

@timocapa
Copy link

It'd probably be worth giving the option to use it since EROFS is supposed to be noticeably quicker and there's plenty of devices that do have enough storage.

My proposal would be to keep squashfs as default but give an EROFS option while configuring the build.
Alternatively let the device maintainer decide on what should be used as default? Probably a better idea after long-term testing

https://github.com/erofs/erofs-openbenchmark/wiki/linux_5.10_rc4-compression-FSes-benchmark

@Ansuel
Copy link
Member

Ansuel commented Jul 17, 2022

@timocapa i agree... if there are real benefits and someone doesn't care about the extra space than it seems a nice idea to me making erofs an alternative fs

@timocapa
Copy link

Certainly good enough for me :p

4.2M	erofsc128kpclusterlzma.root
3.8M	squashfs.root

That said that'll be impossible for me to make work since I'm not a dev :(

@aparcar
Copy link
Member Author

aparcar commented Jul 18, 2022

I'll work on that

@aparcar
Copy link
Member Author

aparcar commented Jul 18, 2022

@Ansuel could you please help me backport the outstanding Kernel patches that add tailpacking?

@Ansuel
Copy link
Member

Ansuel commented Jul 18, 2022

@aparcar mhhh sure just tell me what you need :D Where can i find the patches?

@aparcar aparcar force-pushed the erofs branch 2 times, most recently from 5f8ed58 to e82e369 Compare July 18, 2022 21:55
aparcar added 4 commits July 18, 2022 23:56
This allows the usage of MicroLZMA usable by erofs.

Signed-off-by: Paul Spooren <mail@aparcar.org>
needed for mkfs.erofs

Signed-off-by: Paul Spooren <mail@aparcar.org>
Signed-off-by: Paul Spooren <mail@aparcar.org>
Signed-off-by: Paul Spooren <mail@aparcar.org>
It is now possible to select erofs as rootfs if Kernel 5.15 is selected.

Signed-off-by: Paul Spooren <mail@aparcar.org>
@aparcar
Copy link
Member Author

aparcar commented Jul 18, 2022

@Ansuel I think it needs everything erofs related up until 5.17.

@Ansuel
Copy link
Member

Ansuel commented Jul 18, 2022

@aparcar oh so we need to backport each patch made to erofs? tedious work!

@aparcar
Copy link
Member Author

aparcar commented Jul 18, 2022

@Ansuel honestly I don't know, I can ask upstream devs what's really needed, I thought you may have a nice script which simplifies backports

@Ansuel
Copy link
Member

Ansuel commented Jul 18, 2022

@aparcar unfortunately no script :(

@timocapa
Copy link

timocapa commented Jul 18, 2022

If lzma is a hard requirement (which to be fair does save ~1 MB) backports are needed - lz4(hc) should work OK with 5.15

I don't know if this would be allowed, but otherwise I would just do the whole EROFS kernel backporting in a single patch

Other than that you do need xz updates as well if lzma

@Ansuel
Copy link
Member

Ansuel commented Sep 5, 2022

@timocapa mhhh single patch backport are scary and a mess to handle with kernel bump. I prefer a well split patchset

@timocapa
Copy link

timocapa commented Sep 5, 2022

@Ansuel We can also wait for the next Linux LTS release to be supported on OpenWrt, already includes lzma

(Sorry for the previous comment that i deleted, i thought 5.19 was LTS)

@Ansuel
Copy link
Member

Ansuel commented Sep 5, 2022

@timocapa are you sure 6.0 will be LTS? I expect a 6.1 version till December at least. We are at rc4, can't take that long for a stable release.

I mean if we really want I can experiment with adding 6.0 support to openwrt ehehehehhe

@timocapa
Copy link

timocapa commented Sep 5, 2022

jesus my github app mad freaked out

@Ansuel Nah I'm not sure however it would fit the release cycle of what i know (every .5), but I've edited the post to say "Next LTS" instead

We can also just skip lzma for now and make LZ4(HC) work, lzma should be a drop in replacement for it (and if not we would still have the basic setup to use)

@timocapa
Copy link

timocapa commented Oct 8, 2022

So 6.0 has been out for a week now, what's the plan? :p

@Ansuel
Copy link
Member

Ansuel commented Oct 8, 2022

@timocapa none for now? openwrt supports only LTS version and the next LTS is 6.1... anyway i have added support for 6.0 on openwrt but currently i only ported ipq806x

@timocapa
Copy link

timocapa commented Oct 8, 2022

You had mentioned "I can experiment with adding 6.0 support to openwrt", so I was curious :)

@Ansuel
Copy link
Member

Ansuel commented Oct 8, 2022

@Djfe
Copy link
Contributor

Djfe commented Feb 19, 2023

This might be helpful in understanding why squashfs might always be smaller but perform slower:
https://blog.sigma-star.at/post/2022/07/squashfs-erofs/

Squashfs has larger chunksizes like 128KiB which increases compression but since they are variable your read speed suffers. EROFS limits itself to one chunk size only: 4KiB block size.
The article explains this way better than me though (especially why 4KiB improves read performance).

Limiting Squashfs to 4KiB appears to produce smaller output than erofs still so there is likely room for improvement. (the article tested outlandishly larger partitions in the gigabytes, so this might not apply to 6MiB images)
It would be cool to see them surpass squashfs in compression but I don't see that happening.

EROFS definitely has a few advantages over squashfs but I'm not sure it justifies running two types of filesystems in parallel on a release. (Squashfs will likely remain the default for low flash devices, I think)
I'm looking forward to further results once openwrt runs 6.1 LTS in testing :) (or earlier since there is that 6.0 test branch)

@Ansuel
Copy link
Member

Ansuel commented Feb 19, 2023

@Djfe the 6.0 testing branch got updated to 6.1... and 6.1 will be introduced when we will branch for a new release

@hsiangkao
Copy link
Contributor

erofs-utils 1.6 is released, could you check this with Linux 6.1/6.2 [1]?
-zlzma -E[all-]fragments[,dedupe] -C xxxxx is preferred if image sizes is the most important stuff.

[1] https://github.com/hsiangkao/erofs-utils/blob/dev/docs/PERFORMANCE.md

@aparcar
Copy link
Member Author

aparcar commented Mar 13, 2023

@Ansuel would you mind helping me with some backporting ;)?

@Ansuel
Copy link
Member

Ansuel commented Mar 14, 2023

@aparcar sure! what can we use to coordinate?

@aparcar
Copy link
Member Author

aparcar commented Jan 8, 2024

Is someone else excited to take care of this? Kernel 6.6 is around the corner so less back porting is needed anyway.

@Ansuel
Copy link
Member

Ansuel commented Jan 8, 2024

@aparcar did we understood if we should target 6.1 or 6.6?

@aparcar
Copy link
Member Author

aparcar commented Jan 8, 2024

Whatever you think is best :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants