Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,733,782 Members 45,907 Now Online
XDA Developers Android and Mobile Development Forum

Increasing readahead in a not completely retarded manner

Tip us?
 
glitterballs
Old
(Last edited by glitterballs; 12th April 2011 at 03:48 PM.)
#1  
Retired Recognized Developer - OP
Thanks Meter 187
Posts: 422
Join Date: Sep 2010
Location: Bed-Stuy
Default Increasing readahead in a not completely retarded manner

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.
Powered by thanks and beer.

ROM - Eclair Stock JF6.
Kernel - Stock JF6, not even rooted.
The Following 28 Users Say Thank You to glitterballs For This Useful Post: [ Click to Expand ]
 
phlunkie
Old
#2  
phlunkie's Avatar
Senior Member
Thanks Meter 107
Posts: 408
Join Date: Apr 2007
Location: Orlando
good read and explanation. thanks
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Galaxy Note 3 N900T on att
Amazon Fire TV
AT&T Galaxy Note i717
Asus Transformer
AT&T Samsung Galaxy S Captivate-demoted to media device around the house.
Logitech Revue
sony nsz gs7
 
Dani897
Old
#3  
Senior Member
Thanks Meter 683
Posts: 3,539
Join Date: Aug 2010
im guessing the new kernel will have the above mentioned readahead mods? cant wait!
 
iRAY
Old
#4  
Member
Thanks Meter 12
Posts: 32
Join Date: 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.
 
npt1988
Old
#5  
Member
Thanks Meter 2
Posts: 35
Join Date: Jan 2011
so, is it a good idea to increase readahead if the only files on the sd card are mp3's, jpeg's and documents?
 
themichael
Old
#6  
themichael's Avatar
Senior Member
Thanks Meter 132
Posts: 491
Join Date: Jul 2011
Location: New York

 
DONATE TO ME
Quote:
Originally Posted by npt1988 View Post
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.
- theMichael
Thread Tools
Display Modes


XDA PORTAL POSTS

Slate Calendar Helps You Organize Your Life

Without calendars in some form or another, most of our lives would be utter chaos. Unless you are … more

Shane Francis to Talk Android, Robotics, and Vision at XDA:DevCon 2014

Our international xda:devcon 14in Manchester, UK on the weekend of … more

LG G Watch Tool is a Toolkit all Owners Need

The LG G Watch is one of the first two devices hitting the market rocking the highly anticipated … more

Benchmark Your CPU Performance with Mini CPU Integer Script

When it comes to device testing, there are two types of people on XDA. The first … more