iesd - Interactivity Enhancing Shell Daemon
Recently on the LKML there was a lot of excitement when a nearly 200 line patch to the kernel was posted which grouped CPU scheduling to each TTY. This alone improved interactivity hugely, enabling people to do crazy things like 'make -j64'ing kernels whilst playing movies and browsing the web all at the same time. A little later in the thread a four line shell implementation was given that improved things even further.
Both the kernel patch and shell script have their advantages and disadvantages:
- kernel
- - advantages
- fully automagical
- based on tty and not Session ID (SID)
not mainlined and you need to patch your kernel - mainline as of 2.6.39 and is SID based
- - advantages
- shell
- - advantages
- no need to patch your kernel (should work since kernel 2.6.24)
- effect is the same
- depends on bash
- does not feel 'correct' putting the logic into the users shell script
- grouped by TTY and not Session ID (SID)
- - advantages
So, to try and find a well blended solution, I opted to put together a shell daemon that groups tasks firstly by User ID (regular users on the system, ignoring system processes) and then with a second level of grouping by Session ID.
The daemon should work on kernels since 2.6.24 (tested with 2.6.32) supporting grouping CPU scheduling, and if your kernel is equal or newer than 2.6.38 it also has the ability to group task disk IO which improves things further (not done by sched_autogroup_enabled).
Save the daemon to '/usr/local/sbin' and make it executable ('chmod +x /usr/local/sbin/iesd'). Now run it by typing as root:
# iesd start
Stopping the daemon is easy:
# iesd stop
N.B. the daemon takes a while to start up and shutdown, so do not expect the effects to take place immediately
To make the daemon automatically load on boot, place the following in your '/etc/rc.local' file:
[ -f /proc/sys/kernel/sched_autogroup_enabled ] && echo 0 > /proc/sys/kernel/sched_autogroup_enabled nohup /usr/local/sbin/iesd start || true
Changelog
20110806 - GPLv3 licence added, enabled blkio and added hooks for notify_on_release
20110107 - included processes that have no parent process
20110105 - first version released
Thanks
Thanks to Steven Capper (@robotmonkeys.org.uk) for testing, giving feedback and suggestions plus providing some actual improvements; the 'brains' behind the 'quit()' subroutine.