[Script][CWM] Increase Read Cache for better SD Card access

Search This thread

brainmaster

Inactive Recognized Developer
Dec 10, 2006
4,064
4,507
Huawei Watch
OnePlus 7T Pro
Many of us are disappointed about the reading speed of the SD Cards on our Android Phones. It doesn't matter if you have fast 10 Class SD Card, it performs very poorly on the Phone comparing how it performs on the PC.

The clue is the Cache size for reading from SD Card. It's set to 128 KB, on some ROM's even to 4 KB!


You can check for yourself your Cache size by looking into this file:

/sys/devices/virtual/bdi/179:0/read_ahead_kb


You can change it manually but it will be reverted to default on the reboot. The changes need to be done permanently by loading the script on the startup through the init.d.


Or you can flash the CWM zip files that I made for you.

For RA 1.7 Recovery zip look into this post. Many thanx to user laie1472 for making them.

You must find which Cache size fits best for your SD Card. In my case its the 3072 KB Cache size.At best, use the Root Explorer to change the value, then run SD Tools Benchmark - finally flash the CWM zip file that fits your SD Card.

Here are two screenshots - the first one shows the reading speeds with the default Cache 128 KB and the second one is with the 3072 KB Cache with my Class 4 SD Card on CM7 RC2 by Charnsingh.


The Benchmark is made with the SD Tools program. Caution: The SD Tools developer states that his benchmark sometimes gives inaccurate readings.

If you want to convince yourself of the speed improvement after applying the fix, just open your Gallery and see how fast it loads the photos!

Suggestion: 2048 KB Cache size performs at best for most of the SD Cards!


If you don't have CWM then you can do following:

Make a file with this content:

Version 1:
#!/system/bin/sh
if [ -e /sys/devices/virtual/bdi/179:0/read_ahead_kb ]
then
/system/xbin/echo "128" > /sys/devices/virtual/bdi/179:0/read_ahead_kb;
fi;
Version 2 (If the Version 1 is not working for your ROM - credit goes to rafpigna):
# Tweak mmc read-ahead - rafpigna -
mmcfolder="/sys/devices/platform/msm_sdcc.2/mmc_host/mmc1"
cd $mmcfolder
folderlist=`ls -1`
mmcresult=`echo $folderlist | grep -o '\bmmc1:\w*' | sed 's/mmc1://'`
echo 128 > /sys/devices/platform/msm_sdcc.2/mmc_host/mmc1/mmc1:$mmcresult/block/mmcblk0/queue/read_ahead_kb
cd /
Change the red marked number from 128 to what you need (example 2048) and save it as "99sdcardreadfix", copy it with the Root explorer or push it with ADB into /system/etc/init.d and set permissions to 777. Reboot.




Some of the ROM chiefs have hardcoded this values in the init, that can't be changed - only by the chief himself.

Some of the ROM's already contain this tweak in another script that is saved in the init.d folder. Probably it's tagged with the number 99 in the filename to be sure that it's executed at last. You have to change it there.

Rafpigna - the HD2 Android chief - pointed that out over here.





For ROM Cookers - add this line into init.rc file:

# sd card read speed fix
write /sys/block/mmcblk0/bdi/read_ahead_kb 2048
UPDATE: There is now free app on the market that do this for you.


htc%20htc%20hd2%202011-04-07%2002-39-44.png
htc%20htc%20hd2%202011-04-07%2002-42-06.png
 

Attachments

  • SDCardSpeedFixDefault128KB.zip
    155.7 KB · Views: 11,856
  • SDCardSpeedFix1024KB.zip
    155.7 KB · Views: 12,782
  • SDCardSpeedFix2048KB.zip
    155.7 KB · Views: 40,687
  • SDCardSpeedFix3072KB.zip
    155.7 KB · Views: 16,839
  • SDCardSpeedFix4096KB.zip
    155.7 KB · Views: 24,722
Last edited:

opher50

Senior Member
Nov 28, 2010
656
101
Sounds great! I will wait for some more people to give they're thoughts about it ... does it matter which phone you use? or only the SD card class?
 
  • Like
Reactions: Divr and CitizenLee

Cuspide

Senior Member
Jul 5, 2007
130
10
You can flash with xrecovery?
1024 seems fine with my 32go sd card

Sent from my X10i using XDA App
 

Cuspide

Senior Member
Jul 5, 2007
130
10
Not working with xrecovery, still 128 after reboot .. ;-)

Sent from my X10i using XDA App
 
Last edited:

brainmaster

Inactive Recognized Developer
Dec 10, 2006
4,064
4,507
Huawei Watch
OnePlus 7T Pro
Not working with xrecovery, still 128 after reboot .. ;-)

Sent from my X10i using XDA App

If you don't have CWM then you can do following:

Make a file with this content:

#!/system/bin/sh
if [ -e /sys/devices/virtual/bdi/179:0/read_ahead_kb ]
then
/system/xbin/echo "128" > /sys/devices/virtual/bdi/179:0/read_ahead_kb;
fi;
Change the red marked number from 128 to what you need (example 2048) and save it as "77sdcardreadfix", copy it with the Root explorer or push it with ADB into /system/etc/init.d and set permissions to 777. Reboot.
 
  • Like
Reactions: waqasr

skymera

Senior Member
Mar 28, 2010
833
214
Not sure if this an error but the format it needed to be in ADB was

echo "2048" > /sys/devices/virtual/bdi/179\:0/read_ahead_kb
 

opher50

Senior Member
Nov 28, 2010
656
101
Does it really work? :S

Flashing with CWM means what? I do Install From Sd card? or ?
 

usrname

Senior Member
Aug 20, 2007
248
11
wow im surprised. my cache size was at 128kb. after raising it to 2048 on my milestone (stock sd card) with cyanogen 6.2.1 my writing speed went from 2.1 mb/s up to 4.2 megs. reading from 10.1 to 22.2 megs/s. with cache size of 3072 it went up once more to 8.7 for writing and 31mb/s reading ... amazing!

but - are there any negative sideeffects somewhere in the system while using this fix? i mean, if it is just that simple to tripple write an readspeeds, why isn't this setting stock?
 
Last edited:

opher50

Senior Member
Nov 28, 2010
656
101
wow im surprised. my cache size was at 128kb. after raising it to 2048 on my milestone (stock sd card) with cyanogen 6.2.1 my writing speed went from 2.1 mb/s up to 4.2 megs. reading from 10.1 to 22.2 megs/s. with cache size of 3072 it went up once more to 8.7 for writing and 31mb/s reading ... amazing!

but - are there any negative sideeffects somewhere in the system while using this fix? i mean, if it is just that simple to tripple write an readspeeds, why isn't this setting stock?

Exactly what im afraid of!
*btw .. asking agian! flashing via CWM means to put it in SD CARD and in the CWM click "INSTALL FROM SD CARD"?
 

khaytsus

Senior Member
Apr 8, 2008
7,258
1,175
Central Kentucky
Transcend 8G Class 6, ran each of the following 7 times. Threw out the fastest and slowest time.

128k
Read Min: 2.0 Max: 4.4 Average: 3.3
Write Min: 13.2 Max: 14.8 Average: 13.9

1024k
Read Min: 3.2 Max: 4.6 Average: 5.5
Write Min: 20.7 Max: 25.4 Average: 22.9

2048k
Read Min: 3.1 Max: 4.0 Average: 3.4
Write Min: 41 Max: 82.2 Average: 66

Not sure I'm believing SD Tools, it always goes with the LAST reading, which doesn't at a glance appear to be the overall File/Time speed, just the last transfer speed measured. It could be continuously averaging, however.

Also another observation.. Exiting the program and re-entering it gives you better speeds than running it repeatedly without exiting.

And probably should exit as many apps as possible, I didn't do this... You'll probably get wildly varying results otherwise ;) I got 17m/sec reading one test and 88m/sec the next test. Again, I threw out top/bottom reads to minimize that a bit, but..

I think I'll leave it at 2k, don't want to find out the max really... Just in case that's bad for things.
 

gandalf_sw

Member
May 21, 2010
6
1
Pre Patch:

Read: 7,7 MB
Write: 3,4 MB

Read: 70,1 MB
Write 3,5 MB

Using 2046 setting. And only one run of the benchmark. Will do some more tests later on. Just wanted to test it quickly.
 

brainmaster

Inactive Recognized Developer
Dec 10, 2006
4,064
4,507
Huawei Watch
OnePlus 7T Pro
wow im surprised. my cache size was at 128kb. after raising it to 2048 on my milestone (stock sd card) with cyanogen 6.2.1 my writing speed went from 2.1 mb/s up to 4.2 megs. reading from 10.1 to 22.2 megs/s. with cache size of 3072 it went up once more to 8.7 for writing and 31mb/s reading ... amazing!

but - are there any negative sideeffects somewhere in the system while using this fix? i mean, if it is just that simple to tripple write an readspeeds, why isn't this setting stock?

As I already wrote in the HD2 section, the Cache size itself is the bottleneck between the fast SD Card and the Android interface. They are no known negative side effects with this hack. If you see one, please post it. It is always easy to revert back to the default settings.

Alone the faster gallery loading photos are worth of doing the hack.

Exactly what im afraid of!
*btw .. asking agian! flashing via CWM means to put it in SD CARD and in the CWM click "INSTALL FROM SD CARD"?

Correct, start the Clockwork Recovery and choose the zip file - flash it.

Transcend 8G Class 6, ran each of the following 7 times. Threw out the fastest and slowest time.

128k
Read Min: 2.0 Max: 4.4 Average: 3.3
Write Min: 13.2 Max: 14.8 Average: 13.9

1024k
Read Min: 3.2 Max: 4.6 Average: 5.5
Write Min: 20.7 Max: 25.4 Average: 22.9

2048k
Read Min: 3.1 Max: 4.0 Average: 3.4
Write Min: 41 Max: 82.2 Average: 66

Not sure I'm believing SD Tools, it always goes with the LAST reading, which doesn't at a glance appear to be the overall File/Time speed, just the last transfer speed measured. It could be continuously averaging, however.

Also another observation.. Exiting the program and re-entering it gives you better speeds than running it repeatedly without exiting.

And probably should exit as many apps as possible, I didn't do this... You'll probably get wildly varying results otherwise ;) I got 17m/sec reading one test and 88m/sec the next test. Again, I threw out top/bottom reads to minimize that a bit, but..

I think I'll leave it at 2k, don't want to find out the max really... Just in case that's bad for things.

There should be no problems with the 2048 KB setting.
 

opher50

Senior Member
Nov 28, 2010
656
101
As I already wrote in the HD2 section, the Cache size itself is the bottleneck between the fast SD Card and the Android interface. They are no known negative side effects with this hack. If you see one, please post it. It is always easy to revert back to the default settings.

Alone the faster gallery loading photos are worth of doing the hack.



Correct, start the Clockwork Recovery and choose the zip file - flash it.



There should be no problems with the 2048 KB setting.


Sounds cool :p I'll try the 2048KB on my galaxy S :D

Edit: flashed via CWM .. saw no change at all :S Il check the benchmark .. maybe it didnt change it ..

Writing speed : 2.7 MB/s
Read Speed : 11.8 MB/s
- definetly not the correct 1. . il try the 3000kb!
 
Last edited:

melvinchng

Senior Member
Oct 17, 2010
4,205
1,748
Penang
Sounds cool :p I'll try the 2048KB on my galaxy S :D

Edit: flashed via CWM .. saw no change at all :S Il check the benchmark .. maybe it didnt change it ..

Writing speed : 2.7 MB/s
Read Speed : 11.8 MB/s
- definetly not the correct 1. . il try the 3000kb!

I have 8.1 writing, 27 reading in my class 4 16gb sd card with 4mb.(with Cache and data on ext partition)

Sent from my HTC Wildfire using XDA Premium App
 

opher50

Senior Member
Nov 28, 2010
656
101
Guys the 77Fix files I create here ... what is the file type? it is TXT and i think its not the correct 1?
 

xheavymetaldadx

Senior Member
Oct 20, 2010
311
77
Humble
Thank you I've been looking for this usually my gallery will fc before it can load everything especially after a reboot, this more than fixed the prob. When I get on my laptop I'll hit up the thanks button for sure lmao

Sent from my ADR6300 using XDA Premium App
 

Top Liked Posts

  • There are no posts matching your filters.
  • 293
    Many of us are disappointed about the reading speed of the SD Cards on our Android Phones. It doesn't matter if you have fast 10 Class SD Card, it performs very poorly on the Phone comparing how it performs on the PC.

    The clue is the Cache size for reading from SD Card. It's set to 128 KB, on some ROM's even to 4 KB!


    You can check for yourself your Cache size by looking into this file:

    /sys/devices/virtual/bdi/179:0/read_ahead_kb


    You can change it manually but it will be reverted to default on the reboot. The changes need to be done permanently by loading the script on the startup through the init.d.


    Or you can flash the CWM zip files that I made for you.

    For RA 1.7 Recovery zip look into this post. Many thanx to user laie1472 for making them.

    You must find which Cache size fits best for your SD Card. In my case its the 3072 KB Cache size.At best, use the Root Explorer to change the value, then run SD Tools Benchmark - finally flash the CWM zip file that fits your SD Card.

    Here are two screenshots - the first one shows the reading speeds with the default Cache 128 KB and the second one is with the 3072 KB Cache with my Class 4 SD Card on CM7 RC2 by Charnsingh.


    The Benchmark is made with the SD Tools program. Caution: The SD Tools developer states that his benchmark sometimes gives inaccurate readings.

    If you want to convince yourself of the speed improvement after applying the fix, just open your Gallery and see how fast it loads the photos!

    Suggestion: 2048 KB Cache size performs at best for most of the SD Cards!


    If you don't have CWM then you can do following:

    Make a file with this content:

    Version 1:
    #!/system/bin/sh
    if [ -e /sys/devices/virtual/bdi/179:0/read_ahead_kb ]
    then
    /system/xbin/echo "128" > /sys/devices/virtual/bdi/179:0/read_ahead_kb;
    fi;
    Version 2 (If the Version 1 is not working for your ROM - credit goes to rafpigna):
    # Tweak mmc read-ahead - rafpigna -
    mmcfolder="/sys/devices/platform/msm_sdcc.2/mmc_host/mmc1"
    cd $mmcfolder
    folderlist=`ls -1`
    mmcresult=`echo $folderlist | grep -o '\bmmc1:\w*' | sed 's/mmc1://'`
    echo 128 > /sys/devices/platform/msm_sdcc.2/mmc_host/mmc1/mmc1:$mmcresult/block/mmcblk0/queue/read_ahead_kb
    cd /
    Change the red marked number from 128 to what you need (example 2048) and save it as "99sdcardreadfix", copy it with the Root explorer or push it with ADB into /system/etc/init.d and set permissions to 777. Reboot.




    Some of the ROM chiefs have hardcoded this values in the init, that can't be changed - only by the chief himself.

    Some of the ROM's already contain this tweak in another script that is saved in the init.d folder. Probably it's tagged with the number 99 in the filename to be sure that it's executed at last. You have to change it there.

    Rafpigna - the HD2 Android chief - pointed that out over here.





    For ROM Cookers - add this line into init.rc file:

    # sd card read speed fix
    write /sys/block/mmcblk0/bdi/read_ahead_kb 2048
    UPDATE: There is now free app on the market that do this for you.


    htc%20htc%20hd2%202011-04-07%2002-39-44.png
    htc%20htc%20hd2%202011-04-07%2002-42-06.png
    20
    Great Mod All Results are from the sd/tools app posted in the op
    I took the zips from the op and made them flashable for those who want them and for those who are using RA1.7,1.6 etc also for those using CWM 2.5



    4069= w/s 5.6 r/s 13.7

    Download zip here For Ra.1.7
    http://db.tt/3Lvbazr


    2048= w/s 7.9 r/s 21.7

    Download Zip here For RA1.7
    http://db.tt/V3mAVyV


    3072= w/s 6.6 r/s 20.1

    Download Zip here For RA.1.7
    http://db.tt/WJDdgxB


    1024= w/s 7.1 r/s 17.5

    Download Zip For RA1.7 here
    http://db.tt/Oss3SKD


    Also if you try this mod and want to revert just flash the stock zip here

    http://db.tt/nW8SVWA



    The results posted from each zip are mine with with the setup posted below. Diffrent sd/cards will produce different results.

    Running this on a
    Class4 sd/card 16gb 1024ext2 partition


    @Brainmaster Great MOD BIG THANKS
    7
    Tasker - Apply Settings on Device Boot

    For those of you that use Tasker, I've knocked up a profile that will set your chosen value when the device boots and confirm it has successfully done so.

    You'll need the locale execute plugin.

    Edit action number #2 with your chosen cache size and a different file path if necessary.

    Job done...

    Edit: When testing for the best settings, 'apply' out of Tasker and go back into the application between each change - You may also have to give permission via the SuperUser application before the settings will stick. You can also variable clear %SDCACHE at the end of the task if you don't wish to use it anywhere else. Tidy files, tidy mind.
    5
    The Downside to Higher Reach Ahead Cache Sizes

    Many people are wondering why higher read ahead cache sizes aren't used in stock ROMs since they show significantly higher read speeds in benchmarks. Well the reason is because a benchmark is just a benchmark. The benchmarks applied to test the SD card speeds tend to test SD cards under maximum pressure. However this is not usually the case. This means that in normal use, where the device is accessing a few small files, as opposed to one large file during a transfer or download, a smaller read ahead is better to reduce lag. A large read ahead means that even when accessing extremely small files, the read ahead size must be met, which creates wastefulness and reduces performance. This is the reason why just placing the read ahead size at maximum is not the best and shows slower speeds sometimes.
    5
    Hello !

    I wrote a little App to do this at once!

    SD-Booster comes with a easy to understand UI and sets all stuff automaticly during the Android boot process. It's free. Just search on the market for "SD-Booster" by Akusari.

    Have fun!