[Mod]Change read ahead values of various partitions

Search This thread

Wooaarr

Senior Member
May 29, 2012
151
139
Changing read ahead values

Hello there,

i was a bit shocked when i checked the diskstats from my Cm 7.2 and saw, that only about 5 - 10% of the readings from the /system /cache partition are actuallly merged.
Now i asked myself why was that?
Linux has a function called read ahead, which tells the system to read further then it actually needs. Not a bad thing, considering it is very likely that you will need object B, once you called object A.
The problem with a too high value for read ahead is once you red object A, the one that you were looking for, the system is going to call for object B, C, D, E, F, G, and so on... Now you might also need object B, maybe even C, but it gets more unlikely that you will need all the following data as well...
This information will just be flushed from the memory, hence only 5 - 10% of the readings are actually merged.

Digging a bit deeper reveals read ahead values of 768kb for the /system and /cache partition, which seems a bit pointless to me, especially on the cache partition. (Bear in mind, linux default is 4kb)

So i called:

Code:
proc/self/mountinfo

to get a detailed info about the partitions. (Importent part in bold)
Code:
C:\adb>adb shell cat /proc/self/mountinfo
1 1 0:1 / / rw,relatime - rootfs rootfs rw
11 1 0:11 / /dev rw,relatime - tmpfs tmpfs rw,mode=755
12 11 0:9 / /dev/pts rw,relatime - devpts devpts rw,mode=600
13 1 0:3 / /proc rw,relatime - proc proc rw
14 1 0:12 / /sys rw,relatime - sysfs sysfs rw
15 1 0:13 / /acct rw,relatime - cgroup none rw,cpuacct
16 1 0:14 / /mnt/asec rw,relatime - tmpfs tmpfs rw,mode=755,gid=1000
17 1 0:15 / /mnt/obb rw,relatime - tmpfs tmpfs rw,mode=755,gid=1000
18 11 0:16 / /dev/cpuctl rw,relatime - cgroup none rw,cpu
[SIZE="4"][B]19 1 138:12 / /system rw,relatime - ext4 /dev/block/stl12 rw,barrier=1,data=ordered
20 1 138:13 / /data rw,nosuid,nodev,relatime - ext4 /dev/block/stl13 rw,barrier=1,data=ordered
21 1 138:14 / /cache rw,nosuid,nodev,relatime - ext4 /dev/block/stl14 rw,barrier=1,data=ordered
22 21 138:13 /local/download /cache/download rw,nosuid,nodev,relatime - ext4 /dev/block/stl13 rw,barrier=1,data=ordered
23 20 179:2 / /data/sdext2 rw,relatime - ext4 /dev/block/mmcblk0p2 rw,barrier=1,data=ordered
24 1 179:1 / /mnt/sdcard rw,nosuid,nodev,noexec,relatime - vfat /dev/block/vold/179:1 rw,dirsync,uid=1000,gid=1015,fmask=0602,dmask=0602,allow_utime=0020,codepage=cp437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro[/B][/SIZE]
25 1 179:1 /.android_secure /mnt/secure/asec rw,nosuid,nodev,noexec,relatime - vfat /dev/block/vold/179:1rw,dirsync,uid=1000,gid=1015,fmask=0602,dmask=0602,allow_utime=0020,codepage=cp437,iocharset=iso88591,shortname=mixed,utf8,errors=remount-ro
26 24 0:17 / /mnt/sdcard/.android_secure ro,relatime - tmpfs tmpfs ro,size=0k,mode=000

Adding the following lines to init.gt-s5570.rc in the kernel ramdisk, changes the default read ahead value (768 :eek:) to smaller ones.

Code:
# Read Ahead
        write /sys/block/mmcblk0/bdi/read_ahead_kb 512
        write /sys/block/mmcblk0p2/bdi/read_ahead_kb 512
    	write /sys/block/stl12/queue/read_ahead_kb 4
	write /sys/block/stl13/queue/read_ahead_kb 4
	write /sys/block/stl14/queue/read_ahead_kb 4
	write /sys/devices/virtual/block/stl12/queue/read_ahead_kb 4
	write /sys/devices/virtual/block/stl13/queue/read_ahead_kb 4
	write /sys/devices/virtual/block/stl14/queue/read_ahead_kb 4

/sdcard (including sdext) 512kb (Maybe not optimal if you use a swap file)
/system 4kb
/cache 4kb
/data 4kb

I now have about 30% of my readings actually merged and i guess that is way better.

If you want to confirm, that you have done everything right, browse to:
sys/devices/virtual/bdi/x:x

where x:x should be replaced by:
Code:
[I]179:1 / 179:2 / 179:0 for the [B]sdcard[/B]
138:12 for the [B]/system[/B] partition
138:13 for the [B]/data[/B] partition
138:14 for the [B]/cache[/B] partition[/I]

Now look for the read_ahead_kb file, open it and confirm the value.


I do have the feeling, that my phone is a lot snappier then before... Also my battery seems to last longer... All this might of course be a placebo, also it does make sense (Less readings should result in less battery consumption and of course free up some ressources).

If someone knows a bit more on that topic (And why the values were 768kb in the first place anyway...) i would be happy to learn more about it.

Take care

Wooaarr

Edit: I included this in the Badass Kernel for Gingerbread from alin.p (Just the Kernel, not the keylayout!)

This is not my work, but alin.p's!
 
Last edited:

Masrepus

Senior Member
Feb 12, 2013
767
99
If i use sd with sd-ext and swap, which readahead value would u set?

---------------------------------
Phone : Samsung Galaxy Mini S5570
OS:
•AOSP ICS Touchwiz V5 by A_U
•Android 4.0.4
•Baseband XWKS2
•Kernel: 2.6.37.6 Badass v1.9 by alin.p
•Recovery CWM v4.0.0.5
Mods:
PureAudio, Mounts2SD, ODEX through Universal ODEX script, AdBlock by AdAway
---------------------------------

Gesendet von Tapatalk
 

Wooaarr

Senior Member
May 29, 2012
151
139
If i use sd with sd-ext and swap, which readahead value would u set?

I have to be honest with you, that is a bit tricky.
For the sd-ext i would set it to 512kb.

Do have a a swap file, or do you use a swap partition? If you use a swap partition you should be able to give it a seperate read_ahead value.

Anyway i wouldn't know which value would be good, as swap is kind of a Ram exchange, so i don't know what data lies in there (Probably similiar to /data?). From my guts i would say 512, but just experiment a little bit=)

Maybe someone else could help out.
 
  • Like
Reactions: Masrepus

Masrepus

Senior Member
Feb 12, 2013
767
99
Ya, i have a partition
Ok, i will try that with 512 :)

---------------------------------
Phone : Samsung Galaxy Mini S5570
OS:
•AOSP ICS Touchwiz V5 by A_U
•Android 4.0.4
•Baseband XWKS2
•Kernel: 2.6.37.6 Badass v1.9 by alin.p
•Recovery CWM v4.0.0.5
Mods:
PureAudio, Mounts2SD, ODEX through Universal ODEX script, AdBlock by AdAway
---------------------------------

Gesendet von Tapatalk
 

Wooaarr

Senior Member
May 29, 2012
151
139
For those who are interested in the topic, it seems I'm not the only one who thinks that high values are not always a good idea. This thread is from 2011.

Click...

A nice quote from this thread:
....the reason the mainline kernel tree doesn't have a higher readahead value isn't because some kernel "developers" here are smarter than Linus and everyone else, but because it is generally a bad idea...

I'm a bit sad, that no one else knows something about this. Are the values just as high in Cm 9.2 and Cm 10.1?

Take care
 

alin.p

Senior Member
Mar 2, 2012
739
1,795
Iasi
For those who are interested in the topic, it seems I'm not the only one who thinks that high values are not always a good idea. This thread is from 2011.

Click...

A nice quote from this thread:


I'm a bit sad, that no one else knows something about this. Are the values just as high in Cm 9.2 and Cm 10.1?

Take care

Nice work. :d I'll be including these in all my kernels from now on.
 

Wooaarr

Senior Member
May 29, 2012
151
139
Nice work. :d I'll be including these in all my kernels from now on.
I suppose that means the values are just as high in Cm 9.2 & 10.1?

U can use these int.d scripts made by me using google
I did not even think about making a init.d script. That is of course the easier option :)

But all your scripts do is set
/data
/sdcard

to 512kb read ahead.

You still leave /system & /cache at 768kb and don't set it to 4kb.
 
Last edited:

arpitkh96

Senior Member
Feb 17, 2012
1,156
645
27
panipat
They were initially at 4 kb in cm9.2.but it is easy to make.just to change the path.

Sent from my GT-S5570 using XDA Premium 4 mobile app
 

Wooaarr

Senior Member
May 29, 2012
151
139
Just to make it a bit easier I made a script that sets

/cache to 4 kb
/system to 4 kb
/data to 512 kb
/sdcard to 512 kb
/sdcard android.secure to 512 kb
/sd ext to 512 kb


Just download the script:

1. Rename it from 99readahead.txt to 99readahead
2. Push 99readahead to /system/etc/init.d
3. Set the permissions to -rwxr-x----

Take care
 

Attachments

  • 99readahead.txt
    937 bytes · Views: 248
  • Like
Reactions: damiensmyth

arpitkh96

Senior Member
Feb 17, 2012
1,156
645
27
panipat
Just to make it a bit easier I made a script that sets

/cache to 4 kb
/system to 4 kb
/data to 512 kb
/sdcard to 512 kb
/sdcard android.secure to 512 kb
/sd ext to 512 kb


Just download the script:

1. Rename it from 99readahead.txt to 99readahead
2. Push 99readahead to /system/etc/init.d
3. Set the permissions to -rwxr-x----

Take care

What if sdext is mounted as data partition?

Sent from my GT-S5570 using XDA Premium 4 mobile app
 

dead soul

Senior Member
May 4, 2011
252
29
Just to make it a bit easier I made a script that sets

/cache to 4 kb
/system to 4 kb
/data to 512 kb
/sdcard to 512 kb
/sdcard android.secure to 512 kb
/sd ext to 512 kb


Just download the script:

1. Rename it from 99readahead.txt to 99readahead
2. Push 99readahead to /system/etc/init.d
3. Set the permissions to -rwxr-x----

Take care

what if im using another version of android like cm9 or 10?? is this tweak/script still applicable ???

thanx
 

Wooaarr

Senior Member
May 29, 2012
151
139
what if im using another version of android like cm9 or 10?? is this tweak/script still applicable ???

It should not make a difference, as /data and /sdcard should have a read ahead value of 512kb.
Anyway type
Code:
cat proc/self/mountinfo

and post the output here.

What if sdext is mounted as data partition?

Browse to:
sys/devices/virtual/bdi/x:x

where x:x should be replaced by:
Code:
[I]179:1 / 179:2 / 179:0 for the [B]sdcard[/B]
138:12 for the [B]/system[/B] partition
138:13 for the [B]/data[/B] partition
138:14 for the [B]/cache[/B] partition[/I]

Now look for the read_ahead_kb file, open it and see what values are in there. If it it 768, it is very likely that Cm 9.2 & 10.1 have the same default values as 7.2.
 

Wooaarr

Senior Member
May 29, 2012
151
139
First post revised to the following values:

Code:
# Read Ahead
        write /sys/block/mmcblk0/bdi/read_ahead_kb 512
        write /sys/block/mmcblk0p2/bdi/read_ahead_kb 512
    	write /sys/block/stl12/queue/read_ahead_kb 4
	write /sys/block/stl13/queue/read_ahead_kb 4
	write /sys/block/stl14/queue/read_ahead_kb 4
	write /sys/devices/virtual/block/stl12/queue/read_ahead_kb 4
	write /sys/devices/virtual/block/stl13/queue/read_ahead_kb 4
	write /sys/devices/virtual/block/stl14/queue/read_ahead_kb 4

I took these from the main kernel tree. It seems that even 512kb on data was a silly idea...
 

gerstavros

Senior Member
May 30, 2012
771
118
Athens
hi, meminfo on my Android 4.4.2 device gives following:
1 1 0:1 / / ro,relatime - rootfs rootfs ro,seclabel
11 1 0:11 / /dev rw,nosuid,relatime - tmpfs tmpfs rw,seclabel,mode=755
12 11 0:9 / /dev/pts rw,relatime - devpts devpts rw,seclabel,mode=600
13 1 0:3 / /proc rw,relatime - proc proc rw
14 1 0:12 / /sys rw,relatime - sysfs sysfs rw,seclabel
15 14 0:10 / /sys/fs/selinux rw,relatime - selinuxfs selinuxfs rw
16 1 0:13 / /acct rw,relatime - cgroup none rw,cpuacct
17 14 0:14 / /sys/fs/cgroup rw,relatime - tmpfs none rw,seclabel,mode=750,gid=1000
18 1 0:15 / /mnt/secure rw,relatime - tmpfs tmpfs rw,seclabel,mode=700
19 1 0:16 / /mnt/asec rw,relatime - tmpfs tmpfs rw,seclabel,mode=755,gid=1000
20 1 0:17 / /mnt/obb rw,relatime - tmpfs tmpfs rw,seclabel,mode=755,gid=1000
21 11 0:18 / /dev/cpuctl rw,relatime - cgroup none rw,cpu
22 1 179:5 / /system ro,noatime - ext4 /emmc@android ro,seclabel,noauto_da_alloc,commit=1,data=ordered
23 1 179:7 / /data rw,nosuid,nodev,noatime - ext4 /emmc@usrdata rw,seclabel,discard,noauto_da_alloc,data=ordered
24 1 179:6 / /cache rw,nosuid,nodev,noatime - ext4 /emmc@cache rw,seclabel,discard,noauto_da_alloc,data=ordered
25 1 179:2 / /protect_f rw,nosuid,nodev,noatime - ext4 /emmc@protect_f rw,seclabel,nodelalloc,noauto_da_alloc,commit=1,data=ordered
26 1 179:3 / /protect_s rw,nosuid,nodev,noatime - ext4 /emmc@protect_s rw,seclabel,nodelalloc,noauto_da_alloc,commit=1,data=ordered
27 1 7:0 / /mnt/cd-rom ro,relatime - iso9660 /dev/block/loop0 ro
28 1 179:8 / /mnt/media_rw/sdcard0 rw,nosuid,nodev,noexec,relatime - vfat /dev/block/vold/179:8 rw,dirsync,uid=1023,gid=1023,fmask=0007,dmask=0007,allow_utime=0020,codepage=cp437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro
29 18 179:8 /.android_secure /mnt/secure/asec rw,nosuid,nodev,noexec,relatime - vfat /dev/block/vold/179:8 rw,dirsync,uid=1023,gid=1023,fmask=0007,dmask=0007,allow_utime=0020,codepage=cp437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro
30 1 0:19 / /storage/sdcard0 rw,nosuid,nodev,relatime - fuse /dev/fuse rw,user_id=1023,group_id=1023,default_permissions,allow_other
31 1 179:97 / /mnt/media_rw/sdcard1 rw,nosuid,nodev,noexec,relatime - vfat /dev/block/vold/179:97 rw,dirsync,uid=1023,gid=1023,fmask=0007,dmask=0007,allow_utime=0020,codepage=cp437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro
32 1 0:20 / /storage/sdcard1 rw,nosuid,nodev,relatime - fuse /dev/fuse rw,user_id=1023,group_id=1023,default_permissions,allow_other

but i have only these folders:
u0_a174@719v92_hydy_hd_oppo:/sys/devices/virtual/bdi $ ls
0:19
0:20
179:0
179:32
179:64
179:96
253:0
7:0
7:1
7:2
7:3
7:4
7:5
7:6
7:7
default
mtd-romap
mtd-rwmap
mtd-unmap

What hapens?
 

Top Liked Posts

  • There are no posts matching your filters.
  • 5
    Changing read ahead values

    Hello there,

    i was a bit shocked when i checked the diskstats from my Cm 7.2 and saw, that only about 5 - 10% of the readings from the /system /cache partition are actuallly merged.
    Now i asked myself why was that?
    Linux has a function called read ahead, which tells the system to read further then it actually needs. Not a bad thing, considering it is very likely that you will need object B, once you called object A.
    The problem with a too high value for read ahead is once you red object A, the one that you were looking for, the system is going to call for object B, C, D, E, F, G, and so on... Now you might also need object B, maybe even C, but it gets more unlikely that you will need all the following data as well...
    This information will just be flushed from the memory, hence only 5 - 10% of the readings are actually merged.

    Digging a bit deeper reveals read ahead values of 768kb for the /system and /cache partition, which seems a bit pointless to me, especially on the cache partition. (Bear in mind, linux default is 4kb)

    So i called:

    Code:
    proc/self/mountinfo

    to get a detailed info about the partitions. (Importent part in bold)
    Code:
    C:\adb>adb shell cat /proc/self/mountinfo
    1 1 0:1 / / rw,relatime - rootfs rootfs rw
    11 1 0:11 / /dev rw,relatime - tmpfs tmpfs rw,mode=755
    12 11 0:9 / /dev/pts rw,relatime - devpts devpts rw,mode=600
    13 1 0:3 / /proc rw,relatime - proc proc rw
    14 1 0:12 / /sys rw,relatime - sysfs sysfs rw
    15 1 0:13 / /acct rw,relatime - cgroup none rw,cpuacct
    16 1 0:14 / /mnt/asec rw,relatime - tmpfs tmpfs rw,mode=755,gid=1000
    17 1 0:15 / /mnt/obb rw,relatime - tmpfs tmpfs rw,mode=755,gid=1000
    18 11 0:16 / /dev/cpuctl rw,relatime - cgroup none rw,cpu
    [SIZE="4"][B]19 1 138:12 / /system rw,relatime - ext4 /dev/block/stl12 rw,barrier=1,data=ordered
    20 1 138:13 / /data rw,nosuid,nodev,relatime - ext4 /dev/block/stl13 rw,barrier=1,data=ordered
    21 1 138:14 / /cache rw,nosuid,nodev,relatime - ext4 /dev/block/stl14 rw,barrier=1,data=ordered
    22 21 138:13 /local/download /cache/download rw,nosuid,nodev,relatime - ext4 /dev/block/stl13 rw,barrier=1,data=ordered
    23 20 179:2 / /data/sdext2 rw,relatime - ext4 /dev/block/mmcblk0p2 rw,barrier=1,data=ordered
    24 1 179:1 / /mnt/sdcard rw,nosuid,nodev,noexec,relatime - vfat /dev/block/vold/179:1 rw,dirsync,uid=1000,gid=1015,fmask=0602,dmask=0602,allow_utime=0020,codepage=cp437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro[/B][/SIZE]
    25 1 179:1 /.android_secure /mnt/secure/asec rw,nosuid,nodev,noexec,relatime - vfat /dev/block/vold/179:1rw,dirsync,uid=1000,gid=1015,fmask=0602,dmask=0602,allow_utime=0020,codepage=cp437,iocharset=iso88591,shortname=mixed,utf8,errors=remount-ro
    26 24 0:17 / /mnt/sdcard/.android_secure ro,relatime - tmpfs tmpfs ro,size=0k,mode=000

    Adding the following lines to init.gt-s5570.rc in the kernel ramdisk, changes the default read ahead value (768 :eek:) to smaller ones.

    Code:
    # Read Ahead
            write /sys/block/mmcblk0/bdi/read_ahead_kb 512
            write /sys/block/mmcblk0p2/bdi/read_ahead_kb 512
        	write /sys/block/stl12/queue/read_ahead_kb 4
    	write /sys/block/stl13/queue/read_ahead_kb 4
    	write /sys/block/stl14/queue/read_ahead_kb 4
    	write /sys/devices/virtual/block/stl12/queue/read_ahead_kb 4
    	write /sys/devices/virtual/block/stl13/queue/read_ahead_kb 4
    	write /sys/devices/virtual/block/stl14/queue/read_ahead_kb 4

    /sdcard (including sdext) 512kb (Maybe not optimal if you use a swap file)
    /system 4kb
    /cache 4kb
    /data 4kb

    I now have about 30% of my readings actually merged and i guess that is way better.

    If you want to confirm, that you have done everything right, browse to:
    sys/devices/virtual/bdi/x:x

    where x:x should be replaced by:
    Code:
    [I]179:1 / 179:2 / 179:0 for the [B]sdcard[/B]
    138:12 for the [B]/system[/B] partition
    138:13 for the [B]/data[/B] partition
    138:14 for the [B]/cache[/B] partition[/I]

    Now look for the read_ahead_kb file, open it and confirm the value.


    I do have the feeling, that my phone is a lot snappier then before... Also my battery seems to last longer... All this might of course be a placebo, also it does make sense (Less readings should result in less battery consumption and of course free up some ressources).

    If someone knows a bit more on that topic (And why the values were 768kb in the first place anyway...) i would be happy to learn more about it.

    Take care

    Wooaarr

    Edit: I included this in the Badass Kernel for Gingerbread from alin.p (Just the Kernel, not the keylayout!)

    This is not my work, but alin.p's!
    1
    If i use sd with sd-ext and swap, which readahead value would u set?

    I have to be honest with you, that is a bit tricky.
    For the sd-ext i would set it to 512kb.

    Do have a a swap file, or do you use a swap partition? If you use a swap partition you should be able to give it a seperate read_ahead value.

    Anyway i wouldn't know which value would be good, as swap is kind of a Ram exchange, so i don't know what data lies in there (Probably similiar to /data?). From my guts i would say 512, but just experiment a little bit=)

    Maybe someone else could help out.
    1
    Just to make it a bit easier I made a script that sets

    /cache to 4 kb
    /system to 4 kb
    /data to 512 kb
    /sdcard to 512 kb
    /sdcard android.secure to 512 kb
    /sd ext to 512 kb


    Just download the script:

    1. Rename it from 99readahead.txt to 99readahead
    2. Push 99readahead to /system/etc/init.d
    3. Set the permissions to -rwxr-x----

    Take care