# Setting "read_ahead_kb"

## snake111

Hi all, I'd like to have a custom value for "read_ahead_kb" in order to improve read performance on my SSD.

I wrote this script and put it in /etc/local.d/

```

#!/bin/sh

echo 2048 > /sys/block/sda/queue/read_ahead_kb

```

The new value is set correctly when I log in via shell, but as soon as I start X + gnome something reset it to 128!

Is there any other way to set this value permanently, or to re-set while gnome is up?

Thanks!

----------

## snake111

That's weird... created a script:

```

#!/bin/sh

/bin/echo 2048 > /sys/block/sda/queue/read_ahead_kb

touch ~/aaa

```

saved as /usr/local/bin/read_ahead.sh

added the command to sudoers, so if I do:

```

$ sudo /usr/local/bin/read_ahead.sh

```

the value in /sys/block/sda/queue/read_ahead_kb  is correctly updated to 2048, and in /root a file called 'aaa' appears. So far so good.

In gnome I created an entry for sudo /usr/local/bin/read_ahead.sh in System -> Preferences -> Startup Applications, at next reboot I will correctly find a newly created file /root/aaa but read_ahead_kb is still at 128!!

I just can't understand why is not working, maybe there's something that change it again after my script runs? Any idea?

thanks

----------

## ryszardzonk

try placing that script into /etc/local.d directory

ps do You have any benchmark showing that setting helps performance?

----------

## snake111

 *ryszardzonk wrote:*   

> try placing that script into /etc/local.d directory
> 
> ps do You have any benchmark showing that setting helps performance?

 

Thanks for reply. Placing a script in /etc/local.d was my first try, but works fine only if you don't start X + gnone, which reset back the value to 128.

That's my local.d:

```

# cat /etc/local.d/10-read_ahead.start

#!/bin/sh

echo 2048 > /sys/block/sda/queue/read_ahead_kb

```

FYI that's the benchmark I run to choose the value:

```

# for V in 128 256 512 1024 2048 4096 8192 16384; do echo $V; echo $V > /sys/block/sda/queue/read_ahead_kb && hdparm -t /dev/sda | grep "Timing"; done

128

 Timing buffered disk reads: 1022 MB in  3.00 seconds = 340.13 MB/sec

256

 Timing buffered disk reads: 1226 MB in  3.00 seconds = 408.58 MB/sec

512

 Timing buffered disk reads: 1484 MB in  3.00 seconds = 494.38 MB/sec

1024

 Timing buffered disk reads: 1536 MB in  3.00 seconds = 511.64 MB/sec

2048

 Timing buffered disk reads: 1564 MB in  3.00 seconds = 520.76 MB/sec

4096

 Timing buffered disk reads: 1578 MB in  3.00 seconds = 525.63 MB/sec

8192

 Timing buffered disk reads: 1584 MB in  3.00 seconds = 527.57 MB/sec

16384

 Timing buffered disk reads: 1586 MB in  3.00 seconds = 528.02 MB/sec

```

----------

## ryszardzonk

Results look promissing therefore I have made following script to get that running after X, but it turns out that it does not help either as when I login into Gnome Session it brings value back to 128...

/etc/init.d/ssd_drive-readahead

```
#!/sbin/runscript

description="Increase readahead on SSD drive"

depend()

{

        need localmount

        after xdm

}

start()

{

        ebegin "Increasing readahead on SSD drive"

        echo 512 > /sys/block/sda/queue/read_ahead_kb

        eend $? "Failed to increase readahead on SSD drives"

}

stop()

{

        ebegin "Decreasing readahead on SSD drive"

        echo 128 > /sys/block/sda/queue/read_ahead_kb

        eend $? "Failed to decrease readahead on SSD drive"

}
```

----------

## snake111

Thanks for the support, nice done, a lot better then mine   :Wink: 

I was tying to understand who/what is overwriting the file using sys-process/audit-2.0.5 but seems broken on my kernel (3.0.3).

Do you have any suggestion on how to log who's writing?

----------

## jmartos

If you have pm-utils running then that could be what is changing your settings. Try changing the entry

```
DRIVE_READAHEAD_AC=${DRIVE_READAHEAD_AC:-1024}
```

in /usr/lib64/pm-utils/power.d/readahead to what value you need. Mine is set to 1024.

----------

## snake111

Thanks, seen this only now. Don't seems to be related to pm-utils, I don't think it's running and in conf file the stardard value is 256.

So I think if pm-utils would change the value, should be set to 256 and not 128.

----------

## kernelOfTruth

http://wiki.osnexus.com/index.php?title=IO_Performance_Tuning#Storage_Pool_IO_Tuning_Overview

 *Quote:*   

> With SSD, there are no mechanical rotational latency issues so the SSD profile uses a small 4k read-ahead.

 

makes sense

----------

## Zucca

I wonder if this would affect the speed of hibernate image loading...

I have rather complex setup where I have put my hibernation swap on raid5 array (because Linux cannot read hibernate image from multiple swap partitions).

Of course I'd need to set the read_ahead in initramfs before loading the hibernation image...

I'm already getting bit over 400MB/s, so I wonder if it's worth it.

----------

## kernelOfTruth

That sounds like a rather "exotic" setup, especially with hibernation + raid5,

but why not give it a try ?

It sounds like it could benefit, especially since (assuming it's linear reading) it's an continuous image 

Better have a recent backup of your data though  :Smile: 

----------

## Zucca

 *kernelOfTruth wrote:*   

> Better have a recent backup of your data though 

 Only swap is on raid5. Rest are on btrfs "raid1" except /boot on (md)raid1. And on top of that backups are on my server.

----------

