This is an old revision of the document!
Memory Limits
Jails can now have the amount of memory available to their processes' resident sets (RSS) with arguments to the jail command (and shortly, the jtune command once a jail is running). A kernel thread for each jail, jpager_td, periodically traverses the processes in the jail and sums the amount of memory being consumed by the jail; if that exceeds the pre-set limit, jpager_td asks the virtual memory system to reclaim some of the memory being used by the jail's processes.
Currently, memory reclamation is based on a fraction of the process's RSS and is applied to all of the processes in the jail (e.g. both a 30MB Apache process and a 300KB shell might be asked to return 5% of their RSS). This allows for short-term overcommits which return to the established limit over time; a sysctl will allow tuning of how quickly that return happens.
Things to think about: progressive taxation of processes (e.g. charging the 30MB Apache process a higher rate).
CPU Limits
CPU limiting is implemented by giving each jail a (user-changeable) number of CPU shares and tracking the estimated CPU usage of the tasks that run in that jail. If the ratio of the jail's estimated CPU usage to total CPU usage exceeds the ratio of the jail's CPU shares to total CPU shares outstanding, the jailed processes have their priorities decreased until the ratio of actual usage (estimated CPU) drops below permitted usage (shares). Unjailed processes are not subject to this regime.
This system does not prevent a jailed process from monopolizing the CPU when there are no other runnable processes; rather, it only prevents a jail from using more CPU time than its share if there are other jailed processes (in which case they will tend to share CPU time in proportion to their respective CPU share allocations).
Future work could look at implementing a full-blown fair-share scheduler (see Kay & Lauder or Waldspurger).
To-do List
- Implement memory limits in kern_jail.c [done, except memory limiter doesn't stop trying to page a jail's processes out when it drops below the threshold]
- Implement CPU share limiting in sched_hier.c [done, except debug info needs removing]
- jtune program to modify CPU and memory limits on running jails [done]
- Release patches for testing [expected Sat. 19 August]
- Change '-j' flag to jail to '-c' to reflect new terminology [done]
- Write / update man pages for jtune, jail [done]
- Make memory limiter stop paging when jail is under limit
- Port from RELENG_6 to -CURRENT [post-SoC?]