Wiedi in Wonderland

More than nice: changing CPU scheduling priority inside SmartOS LX-Zones

Sat 09 November 2019

The illumos kernel supports different process scheduling classes. The most interesting ones are:

  • RT: Real-time
  • FX: Fixed
  • FSS: Fair Share

The default class is FSS, which will dynamically adjust the process priority based on things like the nice level and also how much CPU time was used recently. FX can be used to assign a fixed priority. With RT a process can be assigned a defined time quantum. Since RT processes have higher priority than system processes special care must be taken.

You can learn more about those in priocntl(2) and the old but still correct OpenSolaris System Administration Guide.

In most cases the default FSS (Fair Share) scheduling class will work very well and be fair, so the need to make changes here are very rare. However sometimes you might want to run applications that are very timing critical alongside CPU intensive, but otherwise uncritical, processes (e.g. cron jobs).

In native SmartOS/illumos zones the scheduling parameters are changed with priocntl(1). For LX-Zones we need to hack a few things into place first.

First of all we need to grant that zone the proc_priocntl privilege, because tuning the CPU scheduling parameters is not something every user should be allowed to do:

vmadm update 874520a9-708e-41d8-86a8-f46c7a8cdf27 limit_priv=default,proc_priocntl

Inside the zone two symlinks are required to place the native tools into the Linux environment:

ln -s /native/usr/bin/priocntl /usr/bin/
ln -s /native/usr/lib/class /usr/lib/class

After that setting the priority works just like:

priocntl -s -c FX -p 60 -m 60 -i pid 30586

This changes the priority for pid 30586 to 60.