Re: Hard disk read-ahead & hdparm

2007-09-08 Thread Thomas Petazzoni
Hi,

Le Sat, 8 Sep 2007 18:51:44 +0100,
"Ioannis Koltsidas" <[EMAIL PROTECTED]> a écrit :

> a) Does the value of /sys/block/sda/queue/read_ahead_kb (typically
> 128k) decide the amount of data that every read() fetches from the
> disk ?

Not for every read() : for uncached read()s only. E.g, if you read() 4
Kb from a disk, through the cache, it will in fact read 128 kb from the
disk to the cache, and then return the 4 kb to your application. When
you'll request the next 4 kb, they'll already be in cache.

The read-ahead functionality improves performances for sequential
read() operations. For random reads, read-ahead has no effect, or can
even degrade performances.

> b) hdparm specifies that parameter -m specifies the sector count for
> the Multiple Sector mode (aka IDE Block mode), which "permits the
> transfer of multiple sectors per I/O interrupt, rather than the usual
> one sector per interrupt". Are these multiple sectors consecutive
> (physically) or not? Because I can't see any benefit if they are not
> consecutive. And if they are indeed consecutive, isn't it the same
> thing with read_ahead_kb ?

No. The multiple sector mode allows the disk driver to request for more
than one sector at once. For example, to read 4 kb, without multiple
sector mode, the disk driver would have to send 8 requests to the disk
controller. Using multiple sector mode, it can simply ask for 8 sectors
at once (4 kb).

I would say that on current disks, multiple sector mode is always
available.

> I disabled the read_ahead feature (hdparm -A0 /dev/sda). Then I
> repeated the above and got:

You are making a confusion between software read-ahead and hardware
look-ahead. Software read-ahead is done by the linux kernel, and can be
configured using /sys/block/sda/queue/read_ahead_kb. Hardware
look-ahead is configured using hdparm's -A option.

For more information about hardware look-ahead, here is an excerpt from
[1] :

«
Read Look Ahead Feature
---
The Read Look Ahead feature improves performance by reading sectors
into a buffer before the sectors are actually requested by the host.
Assuming the disc is formatted for a 1:1 interleave, a series of
sequential reads of small blocks of data, rather than a single large
block, can cause a performance loss of up to one revolution per
command. The performance loss occurs when the controller is busy
sending the next Read command to the drive. During this interval, the
next sectors to be read can spin past the head. If this occurs,
reading the logical sector after the previously read sector requires
an extra revolution of the disc.
The Read Look Ahead feature improves performance by reading the
logical sector after the previously read sector into a buffer for
possible later use.
»

Sincerly,

Thomas

[1]
http://stason.org/TULARC/pc/hard-drives-hdd/seagate/ST1201A-SWIFT-178MB-3-5-HH-IDE-AT.html
-- 
PETAZZONI Thomas - [EMAIL PROTECTED] 
http://{thomas,sos,kos}.enix.org - Jabber: [EMAIL PROTECTED]
http://{agenda,livret}dulibre.org - http://www.toulibre.org
Fingerprint : 0BE1 4CF3 CEA4 AC9D CC6E  1624 F653 CB30 98D3 F7A7


signature.asc
Description: PGP signature


Hard disk read-ahead & hdparm

2007-09-08 Thread Ioannis Koltsidas
Developing a buffer manager for a database system, I want to find out
how many pages the operating system fetches from the disk on every
read operation (so that, on every read() I read into the bufferpool as
many pages as possible). My questions are the following:

a) Does the value of /sys/block/sda/queue/read_ahead_kb (typically
128k) decide the amount of data that every read() fetches from the
disk ? (this value can also be decided by hdparm -a /dev/sda, but is
measured in sectors). If this is true, then I guess that each time I
do a read() operation for 128 consecutive kbytes, I can be sure that
at most one IO request will reach the disk.

b) hdparm specifies that parameter -m specifies the sector count for
the Multiple Sector mode (aka IDE Block mode), which "permits the
transfer of multiple sectors per I/O interrupt, rather than the usual
one sector per interrupt". Are these multiple sectors consecutive
(physically) or not? Because I can't see any benefit if they are not
consecutive. And if they are indeed consecutive, isn't it the same
thing with read_ahead_kb ?

c) Playing around a little with hdparm, I benchmarked my disk (Seagate
ST340014A) using the --direct mode (which performs operations with
O_DIRECT). Using read_ahead_kb = 128 i got the following (each
measurement was repeated 3 times):

$ sudo hdparm -t /dev/sda
/dev/sda:
Timing buffered disk reads: 160 MB in 3.03 seconds = 52.76 MB/sec

Then i used --direct and got:
$ sudo hdparm -t --direct /dev/sda
/dev/sda:
Timing O_DIRECT disk reads: 168 MB in 3.02 seconds = 55.69 MB/sec

I disabled the read_ahead feature (hdparm -A0 /dev/sda). Then I
repeated the above and got:
$ sudo hdparm -t /dev/sda
/dev/sda:
Timing buffered disk reads: 30 MB in 3.03 seconds = 9.91 MB/sec

and:
$ sudo hdparm -t --direct /dev/sda
/dev/sda:
Timing O_DIRECT disk reads: 88 MB in 3.04 seconds = 28.98 MB/sec

How do you explain this difference?

Any help would be greatly appreciated...

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to [EMAIL PROTECTED]
Please read the FAQ at http://kernelnewbies.org/FAQ