[HOWTO] Optimal ext4 mount options

Search This thread

hardcore

Senior Member
Sep 12, 2006
3,435
7,992
Hi guys,

Now that several lagfixes are using the ext4 filesystem, perhaps we should look at optimizing ext4 for performance and lifespan of the flash memory.

One of the main things we can change is the journaling method to data=writeback. This should reduce writes and improve performance at a slight expense of reliability. Quote:

"In data=writeback mode, ext4 does not journal data at all. This mode provides a similar level of journaling as that of XFS, JFS, and ReiserFS in its default mode - metadata journaling. A crash+recovery can cause incorrect data to appear in files which were written shortly before the crash. This mode will typically provide the best ext4 performance."

One explanation here:
http://blog.smartlogicsolutions.com...ions-to-improve-ext4-file-system-performance/
Reference here:
http://git.kernel.org/?p=linux/kern...02ac5fa36d7f4c07856fe9cf89391e08986f7;hb=HEAD

HOW TO

1. Change the default mount option of the partition using tune2fs. You need to use a version of tune2fs that supports ext4, the one in busybox 1.17 does NOT. A working version is attached to this post.

- Push the tune2fs file to the phone's SD CARD:
adb push tune2fs /sdcard/

- Copy the tune2fs file to /data/
adb shell
su
cp /sdcard/tune2fs /data/

Now change the options:

/data/tune2fs -o journal_data_writeback /dev/block/mmcblk0p2

To verify:
/data/tune2fs -l /dev/block/mmcblk0p2

Look for the line that says:
Default mount options: journal_data_writeback

* Repeat the above for all other ext4 partitions.

It should take effect after a reboot. The next time it will be mounted automatically with data=writeback. You might have to do the tune2fs settings and reboot twice to get it to stick - I'm not sure why, but I had to.

You can verify this using the mount command:

# busybox mount | grep ext4
/dev/block/mmcblk0p2 on /data type ext4 (rw,noatime,barrier=0,nobh,data=writeback,noauto_da_alloc)
/dev/block/stl10 on /dbdata type ext4 (rw,noatime,barrier=0,nobh,data=writeback,noauto_da_alloc)

2. In addition to that, you can also edit the mount options to include the nobh option, which is a further minor optimization for data=writeback mode.

I personally use the options noatime,barrier=0,nobh,data=writeback. Voodoo already uses some of them like noatime and barrier=0.

I do it using a startup script (you need to know how to use/modify a startup script), with the following commands:

for k in $(busybox mount | grep ext4 | cut -d " " -f3)
do
sync
busybox mount -o remount,barrier=0,nobh $k
done

EDIT: Attached tune2fs that supports ext4. Works on Froyo kernels with ext4 support.
 

Attachments

  • tune2fs-ext4.zip
    111 KB · Views: 2,340
Last edited:
  • Like
Reactions: MaXo64

s88

Senior Member
Nov 27, 2009
76
3
I posted the same request in another thread and i though it will be better if i do it here.

I found e2fsprogs-ext4.zip, but not sure if this is the correct zip.

it will be great if you can provide it here.

For others willing to try it, please change the /dev/block/mmcblk0pX to whatever you are using now.
my system is using /dev/block/mmcblk0p4
 
Last edited:

hardcore

Senior Member
Sep 12, 2006
3,435
7,992
I posted the same request in another thread and i though it will be better if i do it here.

I found e2fsprogs-ext4.zip, but not sure if this is the correct zip.

it will be great if you can provide it here.
I've attached it here, it worked for me with the Universal Lagfix Froyo kernel that supports ext4.
 

danzel

Senior Member
May 5, 2004
137
10
busybox 1.17.1 says invalid option -o on tune2fs :(
==
i need the version attached to this thread, busybox version only supports ext2 and ext3
 
Last edited:

chanw4

Senior Member
Oct 8, 2010
134
1
Write back will cause data loses on crashes and it will increase read time on read miss since you need to write the block back to the main mem before reading a new block.
 

danzel

Senior Member
May 5, 2004
137
10
I don't know about performance but my SGS feels like a little bit snappier.

Thanks for this info.
 

hardcore

Senior Member
Sep 12, 2006
3,435
7,992
Write back will cause data loses on crashes and it will increase read time on read miss since you need to write the block back to the main mem before reading a new block.
There is always a risk of slight data loss during crash, even with data=ordered. And we are already using some even more 'risky' options like barrier=0 and noauto_da_alloc anyway.

This setting increases the risk a bit more.
 

hardcore

Senior Member
Sep 12, 2006
3,435
7,992
copy tune2fs into /system/xbin and chmod 755
He's referring to the busybox 1.17.1 version. It doesnt support the ext4 options. For the version attached here, you have to copy it to somewhere else like /data/ before u can execute it. You don't really need to copy it to /system/xbin.
 

RyanZA

Senior Member
Jan 21, 2006
2,023
784
JHB
There is always a risk of slight data loss during crash, even with data=ordered. And we are already using some even more 'risky' options like barrier=0 and noauto_da_alloc anyway.

This setting increases the risk a bit more.

Yeah but I think at some point you're just throwing away the safety of EXT4, and might as well just use EXT2 since it writes faster even with these options on. (Can anybody confirm this? I did a check and EXT2 is still faster even with these mount options... while EXT4 reads faster. But writes are more important than reads on MoviNAND from my usability experience, since the reads are generally fast enough anyway.)
 

hardcore

Senior Member
Sep 12, 2006
3,435
7,992
Yeah but I think at some point you're just throwing away the safety of EXT4, and might as well just use EXT2 since it writes faster even with these options on. (Can anybody confirm this? I did a check and EXT2 is still faster even with these mount options... while EXT4 reads faster. But writes are more important than reads on MoviNAND from my usability experience, since the reads are generally fast enough anyway.)
Hi Ryan, it's different. ext4 with data=writeback still uses journaling but only for metadata, which supposedly "provides a similar level of journaling as that of XFS, JFS, and ReiserFS".

So it's still safer than ext2 but without the speed (and more importantly, battery or flash write lifespan) impact full data+metadata journaling.

More detailed information in the sources here:
http://git.kernel.org/?p=linux/kern...02ac5fa36d7f4c07856fe9cf89391e08986f7;hb=HEAD
 

s88

Senior Member
Nov 27, 2009
76
3
hardcore,

how do you change the mount options? like buffer from 1 to 0 and nobh, etc
 

ashwinds

Senior Member
Aug 10, 2010
807
52
I didn't do any benchmarks, but in theory it should be better - reduced periodic journal writes (better battery life, flash lifespan and performance).

That sounds very promising :D

Followed the procedure - had to do it twice as well to make it stick...dont see any obvious changes in the last 5 minutes. Will update after using it for a while.

PS: how persistent is that setting? what circumstance does it get reset? When a new kernel is installed?
 
Last edited:

bobbel

Member
Apr 7, 2009
24
7
Ulm
yes, it does. I am using JM9, and it feel faster.
take note i only change the data to write_back, haven't figure out a way to do the rest.

for write back, it can be done on the terminal emulator.

Cool, I give it a try.
One Question:
When I enter the mount cmd I have:
/dev/block/mmcblk0p4 /data ext4 rw,noatime,...
So I have to use
/data/tune2fs -o journal_data_writeback /dev/block/mmcblk0p4 (instead mmcblk0p2)

Right?
 

Top Liked Posts

  • There are no posts matching your filters.
  • 1
    Hi guys,

    Now that several lagfixes are using the ext4 filesystem, perhaps we should look at optimizing ext4 for performance and lifespan of the flash memory.

    One of the main things we can change is the journaling method to data=writeback. This should reduce writes and improve performance at a slight expense of reliability. Quote:

    "In data=writeback mode, ext4 does not journal data at all. This mode provides a similar level of journaling as that of XFS, JFS, and ReiserFS in its default mode - metadata journaling. A crash+recovery can cause incorrect data to appear in files which were written shortly before the crash. This mode will typically provide the best ext4 performance."

    One explanation here:
    http://blog.smartlogicsolutions.com...ions-to-improve-ext4-file-system-performance/
    Reference here:
    http://git.kernel.org/?p=linux/kern...02ac5fa36d7f4c07856fe9cf89391e08986f7;hb=HEAD

    HOW TO

    1. Change the default mount option of the partition using tune2fs. You need to use a version of tune2fs that supports ext4, the one in busybox 1.17 does NOT. A working version is attached to this post.

    - Push the tune2fs file to the phone's SD CARD:
    adb push tune2fs /sdcard/

    - Copy the tune2fs file to /data/
    adb shell
    su
    cp /sdcard/tune2fs /data/

    Now change the options:

    /data/tune2fs -o journal_data_writeback /dev/block/mmcblk0p2

    To verify:
    /data/tune2fs -l /dev/block/mmcblk0p2

    Look for the line that says:
    Default mount options: journal_data_writeback

    * Repeat the above for all other ext4 partitions.

    It should take effect after a reboot. The next time it will be mounted automatically with data=writeback. You might have to do the tune2fs settings and reboot twice to get it to stick - I'm not sure why, but I had to.

    You can verify this using the mount command:

    # busybox mount | grep ext4
    /dev/block/mmcblk0p2 on /data type ext4 (rw,noatime,barrier=0,nobh,data=writeback,noauto_da_alloc)
    /dev/block/stl10 on /dbdata type ext4 (rw,noatime,barrier=0,nobh,data=writeback,noauto_da_alloc)

    2. In addition to that, you can also edit the mount options to include the nobh option, which is a further minor optimization for data=writeback mode.

    I personally use the options noatime,barrier=0,nobh,data=writeback. Voodoo already uses some of them like noatime and barrier=0.

    I do it using a startup script (you need to know how to use/modify a startup script), with the following commands:

    for k in $(busybox mount | grep ext4 | cut -d " " -f3)
    do
    sync
    busybox mount -o remount,barrier=0,nobh $k
    done

    EDIT: Attached tune2fs that supports ext4. Works on Froyo kernels with ext4 support.