Chapter 23. Setting scheduler priorities


Red Hat Enterprise Linux for Real Time kernel provides fine-grained control of scheduler priorities. It also lets application-level programs to be scheduled at a higher priority than kernel threads.

Warning

Setting scheduler priorities can carry consequences and might cause the system to become unresponsive or behave unpredictably if crucial kernel processes are prevented from running as needed. Ultimately, the correct settings are workload-dependent.

23.1. Viewing thread scheduling priorities

Thread priorities are set using a series of levels, ranging from 0 (lowest priority) to 99 (highest priority). The systemd service manager can be used to change the default priorities of threads after the kernel boots.

Procedure

  • To view scheduling priorities of running threads, use the tuna utility:

    # tuna --show_threads
                          thread       ctxt_switches
        pid SCHED_ rtpri affinity voluntary nonvoluntary             cmd
      2      OTHER     0    0xfff       451            3        kthreadd
      3       FIFO     1        0     46395            2     ksoftirqd/0
      5      OTHER     0        0        11            1    kworker/0:0H
      7       FIFO    99        0         9            1   posixcputmr/0
      ...[output truncated]...

Using systemd, you can configure real-time priority for services launched during the boot process.

Unit configuration directives are used to change the priority of a service during boot process. The boot process priority change is done by using the following directives in the service section of /etc/systemd/system/service.service.d/priority.conf:

CPUSchedulingPolicy=
Sets the CPU scheduling policy for executed processes. Takes one of the scheduling classes available on Linux: other, batch, idle, fifo, or rr.
CPUSchedulingPriority=
Sets the CPU scheduling priority for an executed processes. The available priority range depends on the selected CPU scheduling policy. For real-time scheduling policies, an integer between 1 (lowest priority) and 99 (highest priority) can be used.

Prerequisites

  • You have administrator privileges.
  • A service that runs on boot.

Procedure

  1. For an existing service, create a supplementary service configuration directory file for the service.

    # cat <<-EOF > /etc/systemd/system/mcelog.service.d/priority.conf
  2. Add the scheduling policy and priority to the file in the [Service] section.

    For example:

    [Service]
    CPUSchedulingPolicy=fifo
    CPUSchedulingPriority=20
    EOF
  3. Reload the systemd scripts configuration.

    # systemctl daemon-reload
  4. Restart the service.

    # systemctl restart mcelog

Verification

  • Display the service’s priority.

    $ tuna -t mcelog -P

    The output shows the configured priority of the service.

    For example:

                        thread       ctxt_switches
      pid SCHED_ rtpri affinity voluntary nonvoluntary             cmd
    826     FIFO    20  0,1,2,3        13            0          mcelog

23.3. Configuring the CPU usage of a service

Using systemd, you can specify the CPUs on which services can run.

Prerequisites

  • You have administrator privileges.

Procedure

  1. Create a supplementary service configuration directory file for the service.

    # mkdir -p /etc/systemd/system/service.service.d/
  2. Add the CPUs to use for the service to the file using the CPUAffinity attribute in the [Service] section.

    For example:

    [Service]
    CPUAffinity=0,1
    EOF
  3. Reload the systemd scripts configuration.

    # systemctl daemon-reload
  4. Restart the service.

    # systemctl restart service

Verification

  • Display the CPUs to which the specified service is limited.

    $ tuna -t mcelog -P

    where service is the specified service.

    The following output shows that the mcelog service is limited to CPUs 0 and 1.

                        thread       ctxt_switches
      pid SCHED_ rtpri affinity voluntary nonvoluntary             cmd
    12954   FIFO    20      0,1         2            1          mcelog

23.4. Priority map

Priorities are defined in groups, with some groups dedicated to certain kernel functions. For real-time scheduling policies, an integer between 1 (lowest priority) and 99 (highest priority) is used.

The following table describes the priority range, which can be used when setting the scheduling policy of a process.

Expand
Table 23.1. Description of the priority range
PriorityThreadsDescription

1

Low priority kernel threads

This priority is usually reserved for the tasks that need to be just prior to SCHED_OTHER.

2 - 49

Available for use

The range used for typical application priorities.

50

Default hard-IRQ value

 

51 - 98

High priority threads

Use this range for threads that run periodically and must have quick response times. Do not use this range for CPU-bound threads as you will starve interrupts.

99

Watchdogs and migration

System threads that must run at the highest priority.

Red Hat logoGithubredditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat Documentation

Legal Notice

Theme

© 2026 Red Hat
Back to top