Sunday, January 13, 2008

Linux: per-task I/O throttling

I've posted a patch on the LKML that allows to limit the I/O bandwidth per-task via /proc filesystem. Writing a value > 0 in /proc/PID/io_throttle allows to set the upper bound limit of the I/O bandwidth (in 512-bytes sector per second) usable by the process PID.

The patch itself it's not really useful, the same result can be obtained by ionice and a good I/O scheduler (like CFQ), but my patch it's a very simple proof-of-concept that it's possible to implement a kind of UID/GID (or even process-container) based policy of I/O bandwidth shaping (like network bandwidth shaping).

Anyway, just right now I'm running my new 2.6.24-rc7-io-throttle kernel and using the following script to throttle the I/O consumption of the backup, that now can run in backgrund with a very small impact in my other applications. ;-)

WARNING: obviously this script requires my kernel patch to work...

$ cat ~/bin/iothrottle

[ $# -lt 2 ] && echo "usage: $0 RATE CMD" && exit 1

$* &
trap "kill -9 $!" SIGINT SIGTERM
[ -e /proc/$!/io_throttle ] && echo $rate >/proc/$!/io_throttle
wait %1

No comments: