Advertisement
Guest User

readhead

a guest
Dec 9th, 2011
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.29 KB | None | 0 0
  1. ### cat /usr/lib/pm-utils/power.d/readahead
  2. #!/bin/sh
  3.  
  4. [ -x /sbin/blockdev ] || exit $NA
  5.  
  6. # more readahead = (hopefully) less hard drive activity.
  7. # less readahead = less trashing the page cache.
  8.  
  9. DRIVE_READAHEAD_AC=${DRIVE_READAHEAD_AC:-12288}
  10. DRIVE_READAHEAD_AC=${DRIVE_READAHEAD_AC:-12288}
  11.  
  12. help() {
  13.     cat <<EOF
  14. --------
  15. $0: Control drive readahead.
  16.  
  17. This hook tries to trade off the number of times we spin up a drive
  18. to read for potentially wasted cache.
  19.  
  20. Drive readahead parameters:
  21. DRIVE_READAHEAD_AC = Number of KB to speculatively read on AC.
  22. Defaults to 256 KB.
  23.  
  24. DRIVE_READAHEAD_BAT = Number of KB to speculatively read on battery.
  25. Defaults to 3072 KB.
  26.  
  27. EOF
  28. }
  29.  
  30. readahead() {
  31.     # the intent here is to iterate through all filesystems
  32.     # mounted on a local block device. It Works For The Maintainer(tm).
  33.     # More sophistication in figuring out what exactly is a local block device
  34.     # would be welcome.
  35.     for dev in $(awk '/^\/dev\// {print $1}'</etc/mtab); do
  36.     printf "Setting readahead for %s to %d..." "$dev" "$1"
  37.     /sbin/blockdev --setfra $1 "$dev" && echo Done. || echo Failed.
  38.     done
  39. }
  40.  
  41. case $1 in
  42.     true) readahead "$DRIVE_READAHEAD_BAT" ;;
  43.     false) readahead "$DRIVE_READAHEAD_AC" ;;
  44.     help) help;;
  45.     *) exit $NA ;;
  46. esac
  47.  
  48. exit 0
  49.  
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement