What Is It?
The Cap Processor Usage patch (or CPU patch for short) is
a modification to the Linux kernel that allows you to limit
the amount of CPU power any given task can get.
Unlike the
ulimit
command it does not limit total time a task can run - instead
it limits how much percentage of the CPU the task can get.
It also differs from
nice command as it does not change priority
of the task.
Where It Works?
The CPU patch works with Linux kernels from 2.4.x series.
All vanilla kernels available at the moment (up to 2.4.18)
are supported. Additionally RedHat 7.2 default kernel (2.4.7-10)
is supported.
NEW Ingo Molnar's O(1) scheduler (as of kernel 2.4.19-pre10-ac2)
is supported.
Please note that RedHat 7.3 default kernel (2.4.18-3)
is still
not supported, even if the O(1) scheduler is.
You may however expect a patch in few days time.
All the supported kernels were tested for proper compilation.
Kernels 2.4.0, 2.4.7-10, 2.4.18 and 2.4.19-pre10-ac2 were also tested for
proper functioning. Your mileage may vary, of course.
As of now the patch works only for i386 architecture.
To use the capabilities provided by the CPU patch you have to run
the
cap command.
How To Make It Work?
Please visit the
instructions page.
And remember to read the
README file.
Why?
The Cap Processor Usage patch (or CPU patch for short) appeared
because I grew tired of my web browser hogging all the CPU for
itself and eating through my laptop's batteries every time
I needed each and every last Watt of power.
I also use to run CPU-hungry computing tasks once in a while and
I personally don't like aforementioned laptop to heat itself
to the point of melting.
As
nice doesn't solve either problem I came up with an idea
of freeing processor by force. After recalling seeing people
asking on news for a way to limit the CPU usage to given percentage,
I decided it's high time someone do it.
Why This Way?
After looking at the scheduler code
it seemed that there are two ways of doing this:
either by adding new
rlimit or by implementing the desired
behaviour by hand.
I tried both solutions, but the code with extra
rlimit
seemed ugly. And I would have had to enhance
ulimit command
or add a specialized version of it.
I decided on a simpler and cleaner solution - adding three extra
variables to the
task_struct plus slightly tweaking scheduler
made it.
The Future
The nearest future for the CAP patch
should be people trying it up,
commenting and giving new ideas. What the future
will be -
we shall see.
Things that may be done if I have spare time or enough encouragement:
Patch for limiting CPU usage for a given process group.
Patch for limiting CPU usage for a given user.