[laptop-mode] Improving readahead behaviour

Matthijs Kooijman matthijs at stdin.nl
Tue Dec 15 13:09:11 CET 2009


--M8S6TA+gsennFbE8
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Hi Ritesh,

> For your example, I think it makes more sense to just increase the value.=
 mp3s=20
> usually would be around 3-5 mb. So if you keep a value for 5mb, you ensur=
e=20
> that one single read is good enough to store the entire file into buffer =
and not=20
> cause the disk to keep spinning.
For a while, I've reset the value back to 128K or something similarly small,
which worked perfect (but probably because the disk never got to spin down =
:-)

Anyway, I stumbled on the "readahead" tool (package readahead-fedora in
Debian), which works perfect for what I want. My music player is commandline
and uses external programs, so I already had a wrapper perl script around my
players. I now have something like:

  $_=3D$ARGV[0];

  # Prepare a "list file" containing just the file we're about to play.
  # Let tempfile clean it up when we exit.
  ($list_fh, $list_name) =3D tempfile();
  $list_fh->print($_);
  # Call readahead to force reading the file into memory (without passing
  # --maxsize, it reads files up to 10MB).
  system("/sbin/readahead \"$list_name\"");
  # Safely cleanup the file
  unlink0($list_fh, $list_name);

  exec("mpg321 \"$_\")

This simply calls the readahead tool (which is in sbin, but works for normal
users just fine) which reads the entire file (if it's smaller than 10MB) in=
to
the filesystem cache. No more hickups in my music!

Gr.

Matthijs

--M8S6TA+gsennFbE8
Content-Description: Digital signature
Content-Disposition: inline
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit

A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: Digital signature
URL: <http://mailman.samwel.tk/pipermail/laptop-mode/attachments/20091215/6743c1ce/attachment.pgp>

--M8S6TA+gsennFbE8--


More information about the laptop-mode mailing list