Deep understanding of swapper processes in perf reports

1. Preface

1. When perf monitors the system calls of the process, a large number of swapper processes will appear
2. The official description of the process is that swapper is executed when no other tasks are running on the CPU.In other words, swapper means that the CPU did nothing and ran to rest
3. This article will observe the performance of swapper on cpu


2. Environmental Preparation

assembly Edition
OS Ubuntu 16.04.4 LTS
systemtap version 4.2/0.165, commit release-4.1-41-g9cde541d4464


3. Preparing scripts

In honor of our powerful tool, systemtap, it is important to note that there are some differences between versions of systemtap. My version is downloaded here: https://sourceware.org/systemtap/getinvolved.html

root@wilson-ubuntu:/opt/stap# stap -V
Systemtap translator/driver (version 4.2/0.165, commit release-4.1-41-g9cde541d4464)
Copyright (C) 2005-2019 Red Hat, Inc. and others
This is free software; see the source for copying conditions.
tested kernel versions: 2.6.18 ... 5.1-rc2
enabled features: PYTHON3 NLS

Once you've determined the version, write a script that will primarily use probe::scheduler.cpu_off, https://sourceware.org/systemtap/tapsets/API-scheduler-cpu-off.html

The script is as follows:

probe scheduler.cpu_off
{
        printf("%20s (%5d) %5s %20s (%5d)  , is idle:%d \n ", task_execname(task_prev),task_pid(task_prev),"==>",task_execname(task_next),task_pid(task_next),idle)
}

The script is very simple, and scheduler.cpu_off mainly describes the state of a process leaving the CPU:
task_prev: Process leaving CPU
task_next: Process about to enter CPU
Idle: Whether or not the CPU is idle is the focus of our attention. If idle is 1, then the CPU is not running tasks.

4. Running scripts

Due to the large amount of data, we screened a portion:

root@wilson-ubuntu:/opt/stap# stap switch.stp
...
            swapper/0 (    0)   ==>               stapio (29159)  , is idle:1
               stapio (29159)   ==>            swapper/0 (    0)  , is idle:0
            swapper/0 (    0)   ==>            rcu_sched (    7)  , is idle:1
            rcu_sched (    7)   ==>            swapper/0 (    0)  , is idle:0
            swapper/2 (    0)   ==>       irq/31-iwlwifi (  542)  , is idle:1
       irq/31-iwlwifi (  542)   ==>            swapper/2 (    0)  , is idle:0
            swapper/2 (    0)   ==>       irq/31-iwlwifi (  542)  , is idle:1
       irq/31-iwlwifi (  542)   ==>            swapper/2 (    0)  , is idle:0
            swapper/2 (    0)   ==>       irq/31-iwlwifi (  542)  , is idle:1
       irq/31-iwlwifi (  542)   ==>            swapper/2 (    0)  , is idle:0
            swapper/2 (    0)   ==>       irq/31-iwlwifi (  542)  , is idle:1
       irq/31-iwlwifi (  542)   ==>            swapper/2 (    0)  , is idle:0
            swapper/0 (    0)   ==>            rcu_sched (    7)  , is idle:1
            rcu_sched (    7)   ==>            swapper/0 (    0)  , is idle:0
            swapper/2 (    0)   ==>       irq/31-iwlwifi (  542)  , is idle:1
       irq/31-iwlwifi (  542)   ==>            swapper/2 (    0)  , is idle:0
            swapper/2 (    0)   ==>       irq/31-iwlwifi (  542)  , is idle:1
       irq/31-iwlwifi (  542)   ==>            swapper/2 (    0)  , is idle:0
            swapper/0 (    0)   ==>            rcu_sched (    7)  , is idle:1
            swapper/1 (    0)   ==>               stapio (29159)  , is idle:1
...

1. Because it is a 4-core cpu, there are 4 swappers, swapper/n
2. swapper's process number is 0, the init process is created at system initialization, and then it becomes a minimum priority idle task
3. When swapper appears on the left (the process leaving the cpu), corresponding to the last field idle is 1, which proves the swapper process running on the CPU (the CPU is idle)
4. This verifies that when the cpu runs the swapper process, the cpu is actually idle, and there are no real tasks running on it, and it is idle


This concludes the article
In the next few days, there are leaks of soup, you are not stingy to give advice...

Keywords: Linux Ubuntu REST Red Hat

Added by Kold on Sun, 29 Sep 2019 05:41:43 +0300