Is it possible to switch kernel scheduler?

Asked by Uqbar

Is there a way to play with different kernel schedulers (as seen in other distros) in Ubuntu?
I'm running 2.6.35-24-generic under Maverick.

Question information

Language:
Persian Edit question
Status:
Solved
For:
Ubuntu linux Edit question
Assignee:
No assignee Edit question
Solved by:
Eliah Kagan
Solved:
Last query:
Last reply:
Revision history for this message
Eliah Kagan (degeneracypressure) said :
#1

To try out different schedulers at runtime, without having to reboot to apply the change, follow these instructions (which work on any Linux-based system, so long as the kernel version is at least 2.6.10):

http://www.mjmwired.net/kernel/Documentation/block/switching-sched.txt

Revision history for this message
Uqbar (uqbar) said :
#2

Nice! But thos are for the I/O.
Any hint for the process schedulers?

Revision history for this message
Eliah Kagan (degeneracypressure) said :
#3

Other distros let you change the process scheduling algorithm, while maintaining the same kernel version?

My understanding is that the linux kernel doesn't have pluggable process schedulers (see http://kerneltrap.org/node/11737).

Or do you just want to change the scheduling priority of a running process?

Revision history for this message
Uqbar (uqbar) said :
#4

That is what I remeber from past (circa 2005), something like writing in /proc or /sys.
If this is not (any more) an option, then I wan definitely to recompile the kernel, which seems not to be a trivial task.
Any hint in here?

I do know how to re-nice and re-ionice a process, but doing it by hand is a cumbersome and error prone task.

Revision history for this message
Eliah Kagan (degeneracypressure) said :
#5

Recompiling the kernel in Ubuntu is not particularly difficult, but I am not sure that would help you. I don't think current Linux kernels support multiple options for the process scheduling algorithm. I could be mistaken.

What process scheduling algorithm do you want to use?

If you have programs that you often run with a specific priority (or io priority), then you could make launchers for them (or scripts to launch them, or shell aliases for them) that run them with the nice (or ionice) command. This doesn't really have anything to do with what scheduling algorithm is used to actually implement the priorities you set, though.

Revision history for this message
Uqbar (uqbar) said :
#6

I've go my ideas clearer (I think) by browsing the /boot/config-2.6.35-24-generic file and searching a lot more.

These are my plans, as long as I've correctly understood the meaning (of life, universe and everything):

1. enable the "Pre-emptible kernel" preemtion model. This seems to be a compilation time decision that forks a server kernel from a responsive desktop.

2. define the default I/O scheduler as "deadline" (vs "CFQ").

My point here: what to do after "make"?

Revision history for this message
Best Eliah Kagan (degeneracypressure) said :
#7

Kernel preemption is entirely separate from process scheduling. The process scheduling algorithm is the algorithm used to control how CPU timeslices are doled out to different competing threads. Kernel preemption, if enabled, means that a thread running kernel code can be preempted (before it's done running kernel code). Threads executing instructions in "user mode" (which is most of the work the computer performs) are always subject to preemption, no matter how you configure your kernel.

Please note that whether or not you enable kernel preemption is not the only, or even the primary distinction between a server-optimized and desktop-optimized kernel. The time quantum (or "timer interrupt rate") is also extremely important in this regard.

(See http://www.serverwatch.com/tutorials/article.php/3715071/Ubuntu-Server--Kernel-Configuration-Considerations.htm for a good summary of these issues, and others.)

Since Ubuntu's generic (desktop) kernel enables preemption and sets the default I/O scheduler to CFQ, and Ubuntu's server kernel disables preemption and sets the default I/O scheduler to Deadline, you are correct that, to have a preemptible kernel with the default I/O scheduler as Deadline, you'll have to compile your own kernel.

But do you really need the default I/O scheduler (as compiled into the kernel) to be Deadline? If you want to always use the Deadline scheduler, you can still have CFQ set as the default in the kernel, but configure your system to automatically use the Deadline scheduler. You can make this happen as the system boots up via upstart by editing init scripts; I believe that you can also pass it as an argument to the kernel (in the grub2 configuration).

If you do decide to build a custom kernel on an Ubuntu system, you can do so by following the official instructions here:
https://help.ubuntu.com/community/Kernel/Compile

One of the (multiple) reasons you might *not* want to build your own kernel is that, every time the kernel receives an update, you'll have to rebuild your kernel to apply it, or at least rebuild the affected part and reinstall your custom kernel.

Revision history for this message
Uqbar (uqbar) said :
#8

Thanks Eliah Kagan, that solved my question.