Browse Your Files with Ease using MK Explorer

Google has made quite an effort in perfecting the powerful and multi-faceted OS that we know as … more

How to Fix the Nexus Available Storage Bug – XDA TV

Is your Nexus device only showing half of the available storage as it should? Many … more

Don’t Forget About Birthdays with Birthday Reminder

A person’s birthday is, without a doubt,one of the most important days in his … more

Don’t Fear Flashing with I Don’t Want You!

The XDA message boards are full of various modifications, with many of these helping … more

Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

Increasing readahead in a not completely retarded manner

OP glitterballs

12th April 2011, 04:40 PM   |  #1  
OP Retired Recognized Developer
Bed-Stuy
Thanks Meter: 188
 
422 posts
Join Date:Joined: Sep 2010
More
So...there have been some reports going around on reddit and, here I guess, that increasing readahead will make your sd card faster, and maybe some of you noticed that on my build from early March that I had changed the default readahead values as well. And, the truth is, that it generally does, but 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, and the way some kernel "developers" have implemented it, it is an almost unbelievably stupid way to do it.

So, to give a little background about why the way some people implemented it is a really bad idea...readahead works like this - when you need a section of data from the disk, the kernel will grab that data, and anticipating you'll also use the next X number of kb, it will also grab that data as well and put it into memory. So, when you're doing something like listening to music, or copying data from an sd card (ie long sequential file reads), having a larger readahead is a good thing, and will speed up the process and make things more efficient. But when you aren't doing long sequential reads, you end up thrashing your data. In other words, if you set the readahead value to, let's say 1024kb on /system, every time you access a file you're reading ahead the data that you need, plus and additional 1024kb, or to the end of the file (wouldn't make much sense to read ahead past the end of a file). If you don't end up using that 1024kb it gets flushed from memory, and you read ahead on some other file by 1024kb. You don't end up using that section of data from readahead, it gets flushed, etc, etc. It's a tremendously stupid waste of resources to read ahead that much when you aren't using it. I mean, there's a reason why some of these things are tunable in the kernel and not set to higher values.

And if you want some serious proof check diskstats. With readahead set to 128kb on /system, I still have less than 10% of reads merged. If you only have 10% of reads merged with a 128kb readahead, why on earth (unless you don't know what you're doing) would you want to increase readahead to 1024kb?! To take this one step farther, with readahead set to 4kb, I still only have about 1/3 of the reads merged.

Isn't there a better way to increase readahead?
Yes. The better way is to use Wu Fengguang's series of patches found here http://lwn.net/Articles/372281/. The end result of these patches is that /system, /cache and /dbdata have readahead values of 4kb, /data and your internal and external sd cards have readahead set to 512kb. If you want to take it a step farther and increase it to 1024kb (or whatever value you happen to like - note that you get to a point where you don't get any more throughput, I wouldn't go beyond 1024kb personally), you can do it manually at
Code:
echo XXXX > /sys/devices/platform/s3c-sdhci.0/mmc_host/mmc0/mmc0:0001/block/mmcblk0/queue/read_ahead_kb
(internal) and
Code:
echo XXXX > /sys/devices/platform/s3c-sdhci.2/mmc_host/mmc2/mmc2:bf2e/block/mmcblk1/queue/read_ahead_kb
(external).

What I do is have scripts set up in Gscript lite to increase and decrease readahead, but I don't even use these all the time. Also, if you don't want to flash kernels just to do this, you can set the readahead value for any drive manually, just like for the sd cards,

Code:
echo XX > /sys/devices/virtual/block/stl9/queue/read_ahead_kb
(/system)
Code:
echo XX > /sys/devices/virtual/block/stl10/queue/read_ahead_kb
(/dbdata)
(no point in increasing readahead on /cache, and really, really, really no point in doing it on bml or the other block devices...lol).

In other news...I promise I'll be back soon. I bought a house partially on a whim, partially to spite my girlfriend, and I've been rather busy tweaking the place I live in instead of my phone. But, I just started sorting through the patches I made to my personal sources and I will hopefully have it done tonight...(I know, I've said that many times before, but this time I'm serious...I think)


edit - as an aside, if you've ever wanted to have your display be at the lowered light setting that it switches to just before the screen automagically shuts off, you can control that as well at
Code:
echo 1 > /sys/devices/platform/s3cfb/spi_gpio.3/spi3.0/backlight/s5p_bl/brightness
it doesn't have to be 1, any value from 1-20 seems to have the same brightness, to my eyes at least. Again, I have this set up as a script in Gscript and if I want to dim the display a bit more I run this script...you have to use it every time you unlock the display or if you get close to the screen timeout limit and then touch the screen again.
Last edited by glitterballs; 12th April 2011 at 04:48 PM.
The Following 29 Users Say Thank You to glitterballs For This Useful Post: [ View ]
12th April 2011, 05:45 PM   |  #2  
phlunkie's Avatar
Senior Member
Flag Orlando
Thanks Meter: 111
 
410 posts
Join Date:Joined: Apr 2007
More
good read and explanation. thanks
12th April 2011, 07:24 PM   |  #3  
Senior Member
Thanks Meter: 685
 
3,539 posts
Join Date:Joined: Aug 2010
More
im guessing the new kernel will have the above mentioned readahead mods? cant wait!
23rd February 2013, 04:58 PM   |  #4  
Member
Thanks Meter: 12
 
32 posts
Join Date:Joined: Dec 2007
Thank you man. This is the only useful description about readahead I've ever read and confirms that kernel default value is not so stupid as it looks.
24th February 2013, 04:00 PM   |  #5  
Member
Flag Bangalore
Thanks Meter: 2
 
44 posts
Join Date:Joined: Jan 2011
More
so, is it a good idea to increase readahead if the only files on the sd card are mp3's, jpeg's and documents?
28th February 2014, 05:49 PM   |  #6  
themichael's Avatar
Senior Member
Flag New York
Thanks Meter: 151
 
522 posts
Join Date:Joined: Jul 2011
Donate to Me
More
Quote:
Originally Posted by npt1988

so, is it a good idea to increase readahead if the only files on the sd card are mp3's, jpeg's and documents?

Yeh, bigger files that are streamed like movies or music will benefit from a higher read ahead. Smaller files like word docs might not.
Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes