How to check if a kernel scheduler is configured in Linux

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, you will learn how to check the kernel scheduler configuration in Linux. The scheduler is a fundamental component that manages how processes share CPU time. Understanding its settings is crucial for performance analysis and troubleshooting.

Through hands-on steps, you will explore three methods to inspect scheduler settings: using the sysctl command to view kernel parameters, examining the /proc/sys/kernel filesystem for scheduler-related files, and inspecting kernel logs via dmesg for scheduler-specific messages. These techniques provide different perspectives on the scheduler's current state and behavior.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("Linux")) -.-> linux/BasicSystemCommandsGroup(["Basic System Commands"]) linux(("Linux")) -.-> linux/BasicFileOperationsGroup(["Basic File Operations"]) linux(("Linux")) -.-> linux/FileandDirectoryManagementGroup(["File and Directory Management"]) linux(("Linux")) -.-> linux/TextProcessingGroup(["Text Processing"]) linux(("Linux")) -.-> linux/UserandGroupManagementGroup(["User and Group Management"]) linux/BasicSystemCommandsGroup -.-> linux/help("Command Assistance") linux/BasicSystemCommandsGroup -.-> linux/man("Manual Access") linux/BasicFileOperationsGroup -.-> linux/ls("Content Listing") linux/BasicFileOperationsGroup -.-> linux/cat("File Concatenating") linux/FileandDirectoryManagementGroup -.-> linux/cd("Directory Changing") linux/TextProcessingGroup -.-> linux/grep("Pattern Searching") linux/UserandGroupManagementGroup -.-> linux/env("Environment Managing") subgraph Lab Skills linux/help -.-> lab-558724{{"How to check if a kernel scheduler is configured in Linux"}} linux/man -.-> lab-558724{{"How to check if a kernel scheduler is configured in Linux"}} linux/ls -.-> lab-558724{{"How to check if a kernel scheduler is configured in Linux"}} linux/cat -.-> lab-558724{{"How to check if a kernel scheduler is configured in Linux"}} linux/cd -.-> lab-558724{{"How to check if a kernel scheduler is configured in Linux"}} linux/grep -.-> lab-558724{{"How to check if a kernel scheduler is configured in Linux"}} linux/env -.-> lab-558724{{"How to check if a kernel scheduler is configured in Linux"}} end

Check scheduler settings with sysctl kernel.sched

In this step, we will explore how to check the kernel's scheduler settings using the sysctl command. The scheduler is a crucial part of the Linux kernel that decides which process gets to run on the CPU and for how long. Understanding its settings can be helpful for performance tuning and troubleshooting.

The sysctl command is used to modify kernel parameters at runtime. We can also use it to view the current values of these parameters. Kernel parameters are organized in a hierarchical structure, similar to a file system.

To view parameters related to the kernel scheduler, we can use sysctl with the kernel.sched prefix.

Open your terminal if it's not already open. You can find the Xfce Terminal icon on the left side of your desktop.

Now, type the following command and press Enter:

sysctl kernel.sched

You should see output similar to this, showing various scheduler-related parameters and their current values:

kernel.sched_child_runs_first = 0
kernel.sched_min_granularity_ns = 8000000
kernel.sched_wakeup_granularity_ns = 9000000
kernel.sched_latency_ns = 24000000
kernel.sched_migration_cost_ns = 50000
kernel.sched_nr_migrate = 32
kernel.sched_tunable_scaling = 1
kernel.sched_domain.cpu0.domain0 = ...
kernel.sched_domain.cpu0.domain1 = ...
...

The exact output may vary slightly depending on the specific kernel version and system configuration. This command gives you a snapshot of how the scheduler is currently configured.

Understanding each of these parameters is beyond the scope of this introductory lab, but the key takeaway is that sysctl kernel.sched is the command to use when you want to inspect these settings.

Click Continue to proceed to the next step.

Verify scheduler in /proc/sys/kernel

In the previous step, we used sysctl to view kernel parameters. Another way to access and sometimes modify these parameters is through the /proc filesystem. The /proc filesystem is a virtual filesystem that provides information about processes and other system information.

Kernel parameters accessible via sysctl are often mirrored in the /proc/sys directory. Specifically, scheduler-related parameters can be found under /proc/sys/kernel/.

Let's navigate to this directory and list its contents. We'll use the cd command to change directories and ls to list files and directories.

Type the following command to change your current directory to /proc/sys/kernel/:

cd /proc/sys/kernel/

Now, list the files in this directory:

ls

You will see a long list of files, each representing a kernel parameter. Look for files that start with sched_. These files correspond to the kernel.sched parameters we saw with sysctl.

...
sched_child_runs_first
sched_latency_ns
sched_migration_cost_ns
sched_min_granularity_ns
sched_nr_migrate
sched_rr_timeslice_ms
sched_rt_period_us
sched_rt_runtime_us
sched_shares_window_ns
sched_tunable_scaling
sched_wakeup_granularity_ns
...

You can view the content of these files using commands like cat. For example, to see the value of sched_latency_ns, type:

cat sched_latency_ns

You should see a number, which is the same value you saw for kernel.sched_latency_ns when using sysctl.

24000000

This demonstrates that the information provided by sysctl kernel.sched is sourced from files within the /proc/sys/kernel/ directory. While sysctl is often more convenient for viewing and modifying parameters, understanding the /proc filesystem gives you a deeper insight into how the kernel exposes its internal state.

Click Continue to move on.

Inspect scheduler logs in dmesg

In this final step, we will look at kernel messages related to the scheduler using the dmesg command. dmesg is a command that displays the kernel ring buffer messages. These messages are generated by the kernel during boot-up and runtime and can contain valuable information about hardware, drivers, and system events, including scheduler activities.

While sysctl and /proc/sys show the current configuration, dmesg can sometimes show messages related to scheduler initialization or significant events.

To view the kernel messages, type the following command:

dmesg

This will likely produce a very long output, as it shows all kernel messages since the system booted. To find messages specifically related to the scheduler, we can use the grep command to filter the output. We'll search for lines containing the word "sched".

Type the following command:

dmesg | grep sched

The | symbol is called a pipe. It takes the output of the command on the left (dmesg) and sends it as input to the command on the right (grep sched). grep sched then searches for lines containing "sched" in the input it receives.

You might see output similar to this, showing messages related to the scheduler during system startup:

[    0.000000] Linux version ... (gcc version ...) #... SMP ...
[    0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-... root=... ro quiet splash vt.handoff=...
[    0.000000] Kernel command line: BOOT_IMAGE=/boot/vmlinuz-... root=... ro quiet splash vt.handoff=...
[    0.000000] PID scheduler: ...
[    0.000000] Mount-cache hash table entries: ... (order: ..., 65536 bytes, linear)
[    0.000000] Mountpoint-cache hash table entries: ... (order: ..., 65536 bytes, linear)
[    0.000000] CPU: Testing write buffer coherency: ...
[    0.000000] smpboot: CPU0: ...
[    0.000000] setup_percpu: System has ... CPUs.
[    0.000000] percpu: Embedded ... pages/cpu s...
[    0.000000] pcpu: PCPU: ...
[    0.000000] Built 1-level schedule group tree
[    0.000000] rcu: Hierarchical RCU implementation.
[    0.000000] rcu: RCU calculated value of scheduler-enlistment delay is ...
[    0.000000] rcu: Adjusting scheduler-enlistment delay with ...
[    0.000000] rcu: RCU restricting CPUs from NR_CPUS=... to nr_cpu_ids=...
[    0.000000] rcu: rcu_sched detected stalls on CPUs/tasks:
...

Again, the exact output will vary. This command is useful for diagnosing issues or understanding how the scheduler was initialized by the kernel.

You have now learned three different ways to get information about the Linux kernel scheduler: using sysctl for current parameters, inspecting files in /proc/sys/kernel/, and checking kernel messages with dmesg.

Click Continue to complete this lab.

Summary

In this lab, we learned how to check the kernel scheduler configuration in Linux using two primary methods. First, we utilized the sysctl kernel.sched command to view various scheduler-related parameters and their current values, providing a snapshot of the scheduler's runtime settings.

Secondly, we explored the /proc filesystem as an alternative way to access kernel parameters, specifically focusing on the /proc/sys/kernel path, which mirrors the parameters accessible via sysctl. These steps demonstrated how to inspect the kernel scheduler's configuration through both command-line utilities and the virtual filesystem.