SlideShare a Scribd company logo
1 of 19
Understanding Linux system hang
Gang He <ghe@suse.com>
Aug 17th, 2017
Overview
3
Symptom I
4
Symptom II
• The system does not crash, but one or more CPUs
are locked up in kernel mode (CPU usage rate is very
high, even users can not get any response via the
keyboard).
• NMI watchdog kernel message, such as
[ 816.032003] NMI watchdog: BUG: soft lockup - CPU#0 stuck for 22s! [mdadm:2126]
• Affect other programs to get a chance to run, bring
some weird problems.
Working mechanism
6
Process scheduling
• Time sharing system, switch one process to another in
a very short time frame.
nice()/setpriority()
• Scheduling policy
sched_setscheduler()
• Process switch
schedule()
• Timer interrupt/Process preemption
(TIF_NEED_RESCHED thr flag)
7
Improper kernel programming
• Cause the kernel to loop in kernel mode for more than
20 seconds with disable process preemption, aka
softlockup.
e.g. take too long time with holding a spin_lock.
• Causes the CPU to loop in kernel mode for more than
10 seconds, without letting other interrupts have a
chance to run, aka hardlockup.
e.g. take too long time during local interrupts are
disabled.
8
Softlockup and hardlockup detector
(nmi_watchdog)
• A periodic hrtimer runs to generate interrupts and kick the
watchdog task. An NMI perf event is generated every
"watchdog_thresh"(compile-time initialized to 10 and configurable
through sysctl of the same name) seconds to check for
hardlockups. If any CPU in the system does not receive any
hrtimer interrupt during that time the 'hardlockup detector' (the
handler for the NMI perf event) will generate a kernel warning or
call panic, depending on the configuration.
• The watchdog task is a high priority kernel thread that updates a
timestamp every time it is scheduled. If that timestamp is not
updated for 2*watchdog_thresh seconds (the softlockup
threshold) the 'softlockup detector' (coded inside the hrtimer
callback function) will dump useful debug information to the
system log, after which it will call panic if it was instructed to do
so or resume execution of other kernel code.
• Code: /usr/src/linux/kernel/watchdog.c
9
Example I
10
Example II
Case study
12
Bug 1049126
• Cluster md: cluster node hangs after complain leaving
the lockspace group
• https://bugzilla.suse.com/show_bug.cgi?id=1049126
• Test script:
13
Setup System Kdump
• Edit /boot/grub2/grub.cfg
linux /boot/vmlinuz-4.4.70-2-default root=UUID=83f8e4f0-e145-4019-8834-ae5a4fe1b64e
resume=/dev/vda1 splash=silent quiet showopts crashkernel=117M,high
• Enable kdump service
# systemctl enable kdump.service
• Reboot the system to take effect
# reboot
• Test if kdump works
# echo 1 > /proc/sys/kernel/sysrq
# echo c > /proc/sysrq-trigger
14
Setup Serial Console
• Edit /boot/grub2/grub.cfg
linux /boot/vmlinuz-4.4.70-2-default root=UUID=83f8e4f0-e145-4019-8834-ae5a4fe1b64e
resume=/dev/vda1 splash=silent quiet showopts crashkernel=117M,high console=tty0
console=ttyS0,115200
• Add a Serial Device for VM
# virt-manager
• Reboot the system to take effect
# reboot
• Login the VM via serial port
# virsh console ‘VM domain’
15
Run the test script
• The system hang on one node
• See the output from serial port console
[ 784.032004] NMI watchdog: BUG: soft lockup - CPU#0 stuck for 23s! [mdadm:2126]
[ 816.032003] NMI watchdog: BUG: soft lockup - CPU#0 stuck for 22s! [mdadm:2126]
[ 844.032003] NMI watchdog: BUG: soft lockup - CPU#0 stuck for 23s! [mdadm:2126]
… …
• Reboot the system, set kernel to panic in softlockup
case
echo 1 > /proc/sys/kernel/softlockup_panic
• Run the test script to reproduce the problem
• Catch system kernel dump file
16
Kernel dump I
17
Kernel dump II
18
Questions & Open discussion
• Loop in real-time scheduling process
• Detect user-space process hang/loop
• Other watchdog mechanisms
• ...
Understanding Linux system hang

More Related Content

What's hot

Kdump-FUDcon-2015-Session
Kdump-FUDcon-2015-SessionKdump-FUDcon-2015-Session
Kdump-FUDcon-2015-Session
Buland Singh
 
HKG18-TR14 - Postmortem Debugging with Coresight
HKG18-TR14 - Postmortem Debugging with CoresightHKG18-TR14 - Postmortem Debugging with Coresight
HKG18-TR14 - Postmortem Debugging with Coresight
Linaro
 

What's hot (20)

Kdump-FUDcon-2015-Session
Kdump-FUDcon-2015-SessionKdump-FUDcon-2015-Session
Kdump-FUDcon-2015-Session
 
Kernel Recipes 2015 - Kernel dump analysis
Kernel Recipes 2015 - Kernel dump analysisKernel Recipes 2015 - Kernel dump analysis
Kernel Recipes 2015 - Kernel dump analysis
 
Systemd cheatsheet
Systemd cheatsheetSystemd cheatsheet
Systemd cheatsheet
 
Kernel Recipes 2015: Introduction to Kernel Power Management
Kernel Recipes 2015: Introduction to Kernel Power ManagementKernel Recipes 2015: Introduction to Kernel Power Management
Kernel Recipes 2015: Introduction to Kernel Power Management
 
Debugging linux kernel tools and techniques
Debugging linux kernel tools and  techniquesDebugging linux kernel tools and  techniques
Debugging linux kernel tools and techniques
 
CLUG 2010 09 - systemd - the new init system
CLUG 2010 09 - systemd - the new init systemCLUG 2010 09 - systemd - the new init system
CLUG 2010 09 - systemd - the new init system
 
SystemV vs systemd
SystemV vs systemdSystemV vs systemd
SystemV vs systemd
 
Embedded Recipes 2018 - Finding sources of Latency In your system - Steven Ro...
Embedded Recipes 2018 - Finding sources of Latency In your system - Steven Ro...Embedded Recipes 2018 - Finding sources of Latency In your system - Steven Ro...
Embedded Recipes 2018 - Finding sources of Latency In your system - Steven Ro...
 
1.3 runlevels, shutdown, and reboot v3
1.3 runlevels, shutdown, and reboot v31.3 runlevels, shutdown, and reboot v3
1.3 runlevels, shutdown, and reboot v3
 
101 1.3 runlevels, shutdown, and reboot v2
101 1.3 runlevels, shutdown, and reboot v2101 1.3 runlevels, shutdown, and reboot v2
101 1.3 runlevels, shutdown, and reboot v2
 
101 1.3 runlevels , shutdown, and reboot
101 1.3 runlevels , shutdown, and reboot101 1.3 runlevels , shutdown, and reboot
101 1.3 runlevels , shutdown, and reboot
 
How to assign unowned disk in the netapp cluster 8.3
How to assign unowned disk in the netapp cluster 8.3 How to assign unowned disk in the netapp cluster 8.3
How to assign unowned disk in the netapp cluster 8.3
 
Rac introduction
Rac introductionRac introduction
Rac introduction
 
BSides Denver: Stealthy, hypervisor-based malware analysis
BSides Denver: Stealthy, hypervisor-based malware analysisBSides Denver: Stealthy, hypervisor-based malware analysis
BSides Denver: Stealthy, hypervisor-based malware analysis
 
Kernel Recipes 2019 - BPF at Facebook
Kernel Recipes 2019 - BPF at FacebookKernel Recipes 2019 - BPF at Facebook
Kernel Recipes 2019 - BPF at Facebook
 
Kernel Recipes 2015: Solving the Linux storage scalability bottlenecks
Kernel Recipes 2015: Solving the Linux storage scalability bottlenecksKernel Recipes 2015: Solving the Linux storage scalability bottlenecks
Kernel Recipes 2015: Solving the Linux storage scalability bottlenecks
 
On-Demand Image Resizing
On-Demand Image ResizingOn-Demand Image Resizing
On-Demand Image Resizing
 
HKG18-TR14 - Postmortem Debugging with Coresight
HKG18-TR14 - Postmortem Debugging with CoresightHKG18-TR14 - Postmortem Debugging with Coresight
HKG18-TR14 - Postmortem Debugging with Coresight
 
Crash Dump Analysis 101
Crash Dump Analysis 101Crash Dump Analysis 101
Crash Dump Analysis 101
 
Kernel Recipes 2013 - Kernel for your device
Kernel Recipes 2013 - Kernel for your deviceKernel Recipes 2013 - Kernel for your device
Kernel Recipes 2013 - Kernel for your device
 

Similar to Understanding Linux system hang

the NML project
the NML projectthe NML project
the NML project
Lei Yang
 
SCADA Strangelove: Hacking in the Name
SCADA Strangelove: Hacking in the NameSCADA Strangelove: Hacking in the Name
SCADA Strangelove: Hacking in the Name
Positive Hack Days
 
SCADA Strangelove: взлом во имя
SCADA Strangelove: взлом во имяSCADA Strangelove: взлом во имя
SCADA Strangelove: взлом во имя
Ekaterina Melnik
 
[Wroclaw #3] Trusted Computing
[Wroclaw #3] Trusted Computing[Wroclaw #3] Trusted Computing
[Wroclaw #3] Trusted Computing
OWASP
 

Similar to Understanding Linux system hang (20)

the NML project
the NML projectthe NML project
the NML project
 
Docker Security Paradigm
Docker Security ParadigmDocker Security Paradigm
Docker Security Paradigm
 
Fast boot
Fast bootFast boot
Fast boot
 
HKG15-409: ARM Hibernation enablement on SoCs - a case study
HKG15-409: ARM Hibernation enablement on SoCs - a case studyHKG15-409: ARM Hibernation enablement on SoCs - a case study
HKG15-409: ARM Hibernation enablement on SoCs - a case study
 
systemd
systemdsystemd
systemd
 
(SAS) UNIX X Command Tips and Tricks
(SAS) UNIX X Command Tips and Tricks(SAS) UNIX X Command Tips and Tricks
(SAS) UNIX X Command Tips and Tricks
 
SCADA Strangelove: Hacking in the Name
SCADA Strangelove: Hacking in the NameSCADA Strangelove: Hacking in the Name
SCADA Strangelove: Hacking in the Name
 
SCADA Strangelove: взлом во имя
SCADA Strangelove: взлом во имяSCADA Strangelove: взлом во имя
SCADA Strangelove: взлом во имя
 
Techno-Fest-15nov16
Techno-Fest-15nov16Techno-Fest-15nov16
Techno-Fest-15nov16
 
202110 SESUG 49 UNIX X Command Tips and Tricks
202110 SESUG 49 UNIX X Command Tips and Tricks202110 SESUG 49 UNIX X Command Tips and Tricks
202110 SESUG 49 UNIX X Command Tips and Tricks
 
[Wroclaw #3] Trusted Computing
[Wroclaw #3] Trusted Computing[Wroclaw #3] Trusted Computing
[Wroclaw #3] Trusted Computing
 
Using CloudStack With Clustered LVM
Using CloudStack With Clustered LVMUsing CloudStack With Clustered LVM
Using CloudStack With Clustered LVM
 
Cs8493 unit 2
Cs8493 unit 2Cs8493 unit 2
Cs8493 unit 2
 
Windows process-scheduling
Windows process-schedulingWindows process-scheduling
Windows process-scheduling
 
202202 SUGUKI UNIX X Command Tips and Tricks
202202 SUGUKI UNIX X Command Tips and Tricks202202 SUGUKI UNIX X Command Tips and Tricks
202202 SUGUKI UNIX X Command Tips and Tricks
 
Locked down openSUSE Tumbleweed kernel
Locked down openSUSE Tumbleweed kernelLocked down openSUSE Tumbleweed kernel
Locked down openSUSE Tumbleweed kernel
 
fall2013
fall2013fall2013
fall2013
 
Process scheduling
Process schedulingProcess scheduling
Process scheduling
 
Ch04 system administration
Ch04 system administration Ch04 system administration
Ch04 system administration
 
Ch04
Ch04Ch04
Ch04
 

Recently uploaded

Introduction to Robotics in Mechanical Engineering.pptx
Introduction to Robotics in Mechanical Engineering.pptxIntroduction to Robotics in Mechanical Engineering.pptx
Introduction to Robotics in Mechanical Engineering.pptx
hublikarsn
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
jaanualu31
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
HenryBriggs2
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
Epec Engineered Technologies
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 

Recently uploaded (20)

Introduction to Geographic Information Systems
Introduction to Geographic Information SystemsIntroduction to Geographic Information Systems
Introduction to Geographic Information Systems
 
Augmented Reality (AR) with Augin Software.pptx
Augmented Reality (AR) with Augin Software.pptxAugmented Reality (AR) with Augin Software.pptx
Augmented Reality (AR) with Augin Software.pptx
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
 
Electromagnetic relays used for power system .pptx
Electromagnetic relays used for power system .pptxElectromagnetic relays used for power system .pptx
Electromagnetic relays used for power system .pptx
 
Introduction to Robotics in Mechanical Engineering.pptx
Introduction to Robotics in Mechanical Engineering.pptxIntroduction to Robotics in Mechanical Engineering.pptx
Introduction to Robotics in Mechanical Engineering.pptx
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
 
Memory Interfacing of 8086 with DMA 8257
Memory Interfacing of 8086 with DMA 8257Memory Interfacing of 8086 with DMA 8257
Memory Interfacing of 8086 with DMA 8257
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Introduction to Artificial Intelligence ( AI)
Introduction to Artificial Intelligence ( AI)Introduction to Artificial Intelligence ( AI)
Introduction to Artificial Intelligence ( AI)
 
8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...
 
Path loss model, OKUMURA Model, Hata Model
Path loss model, OKUMURA Model, Hata ModelPath loss model, OKUMURA Model, Hata Model
Path loss model, OKUMURA Model, Hata Model
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Basic Electronics for diploma students as per technical education Kerala Syll...
Basic Electronics for diploma students as per technical education Kerala Syll...Basic Electronics for diploma students as per technical education Kerala Syll...
Basic Electronics for diploma students as per technical education Kerala Syll...
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Signal Processing and Linear System Analysis
Signal Processing and Linear System AnalysisSignal Processing and Linear System Analysis
Signal Processing and Linear System Analysis
 
Ground Improvement Technique: Earth Reinforcement
Ground Improvement Technique: Earth ReinforcementGround Improvement Technique: Earth Reinforcement
Ground Improvement Technique: Earth Reinforcement
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 

Understanding Linux system hang

  • 1. Understanding Linux system hang Gang He <ghe@suse.com> Aug 17th, 2017
  • 4. 4 Symptom II • The system does not crash, but one or more CPUs are locked up in kernel mode (CPU usage rate is very high, even users can not get any response via the keyboard). • NMI watchdog kernel message, such as [ 816.032003] NMI watchdog: BUG: soft lockup - CPU#0 stuck for 22s! [mdadm:2126] • Affect other programs to get a chance to run, bring some weird problems.
  • 6. 6 Process scheduling • Time sharing system, switch one process to another in a very short time frame. nice()/setpriority() • Scheduling policy sched_setscheduler() • Process switch schedule() • Timer interrupt/Process preemption (TIF_NEED_RESCHED thr flag)
  • 7. 7 Improper kernel programming • Cause the kernel to loop in kernel mode for more than 20 seconds with disable process preemption, aka softlockup. e.g. take too long time with holding a spin_lock. • Causes the CPU to loop in kernel mode for more than 10 seconds, without letting other interrupts have a chance to run, aka hardlockup. e.g. take too long time during local interrupts are disabled.
  • 8. 8 Softlockup and hardlockup detector (nmi_watchdog) • A periodic hrtimer runs to generate interrupts and kick the watchdog task. An NMI perf event is generated every "watchdog_thresh"(compile-time initialized to 10 and configurable through sysctl of the same name) seconds to check for hardlockups. If any CPU in the system does not receive any hrtimer interrupt during that time the 'hardlockup detector' (the handler for the NMI perf event) will generate a kernel warning or call panic, depending on the configuration. • The watchdog task is a high priority kernel thread that updates a timestamp every time it is scheduled. If that timestamp is not updated for 2*watchdog_thresh seconds (the softlockup threshold) the 'softlockup detector' (coded inside the hrtimer callback function) will dump useful debug information to the system log, after which it will call panic if it was instructed to do so or resume execution of other kernel code. • Code: /usr/src/linux/kernel/watchdog.c
  • 12. 12 Bug 1049126 • Cluster md: cluster node hangs after complain leaving the lockspace group • https://bugzilla.suse.com/show_bug.cgi?id=1049126 • Test script:
  • 13. 13 Setup System Kdump • Edit /boot/grub2/grub.cfg linux /boot/vmlinuz-4.4.70-2-default root=UUID=83f8e4f0-e145-4019-8834-ae5a4fe1b64e resume=/dev/vda1 splash=silent quiet showopts crashkernel=117M,high • Enable kdump service # systemctl enable kdump.service • Reboot the system to take effect # reboot • Test if kdump works # echo 1 > /proc/sys/kernel/sysrq # echo c > /proc/sysrq-trigger
  • 14. 14 Setup Serial Console • Edit /boot/grub2/grub.cfg linux /boot/vmlinuz-4.4.70-2-default root=UUID=83f8e4f0-e145-4019-8834-ae5a4fe1b64e resume=/dev/vda1 splash=silent quiet showopts crashkernel=117M,high console=tty0 console=ttyS0,115200 • Add a Serial Device for VM # virt-manager • Reboot the system to take effect # reboot • Login the VM via serial port # virsh console ‘VM domain’
  • 15. 15 Run the test script • The system hang on one node • See the output from serial port console [ 784.032004] NMI watchdog: BUG: soft lockup - CPU#0 stuck for 23s! [mdadm:2126] [ 816.032003] NMI watchdog: BUG: soft lockup - CPU#0 stuck for 22s! [mdadm:2126] [ 844.032003] NMI watchdog: BUG: soft lockup - CPU#0 stuck for 23s! [mdadm:2126] … … • Reboot the system, set kernel to panic in softlockup case echo 1 > /proc/sys/kernel/softlockup_panic • Run the test script to reproduce the problem • Catch system kernel dump file
  • 18. 18 Questions & Open discussion • Loop in real-time scheduling process • Detect user-space process hang/loop • Other watchdog mechanisms • ...