SlideShare a Scribd company logo
1 of 11
Download to read offline
How to analysis the performance issue in linux kernel? 
Xu Jiang (xjiang@ebay) 
2013-3-12 
Purpose 
We use a case study to demonstrate how different profiling tools and kernel code analysis the root cause of linux kernel level performance issue. 
1. Standardize the profiling process of kernel issue 
2. Demonstrate the usage of profiling tool 
3. Explore the runtime behavior of kernel code 
Study Case 
The “perf bench” command is general framework for benchmark suites. We find that “sched pipe” benchmark suite run much faster on kvm vm than on kvm host. It’s wired that vm is faster than bare metal. 
1. VM 
2. HOST 
Profiling & Analysis 
There are some principles to simplify the profiling & analysis: 
1. Compare the difference of profiling results between esx vm, kvm vm and bare metal host. 
2. Use perf as the main profiling tools to narrow down analysis process. The key point is to
find the good perf event. 
3. Use micro benchmark tools to narrow down the issue and make it easily reproducible. 
System Level Profiling & Analysis 
Target: what kernel activity cause host os much slow? 
1. Check “dmesg” to make sure that OS is in normal mode. 
2. Use “vmstat” to check the overall OS status. We find that there is much more interrupts on host than on vm. 
a) VM 
b) HOST 
3. Since the vm has only 8 vcpu and host 24 cpu, use “top -H” or “mpstat –P ALL” to verify how many thread & cpu is used on vm and host. “perf bench sched pipe” use 2 processes to send/receive on one pipe. 
a) HOST
b) VM 
4. Since host has much more interrupts, we use “itop” to analysis the interrupts in /proc/interrupts. We find lots of IPI rescheduling interrupts. 
a) HOST
b) VM 
5. Use “perf record -e cycles:pp -g perf bench sched pipe” to profiling the benchmark. And use “perf report -n” to analysis the results. We find many schedule related functions at the top of host profiling. 
a) HOST (NOTE: “-e cycles:pp” can enable intel PEBS that provide precise instruction address.)
b) VM (NOTE: kvm don’t support PEBS. And it’s better to disable NMI watchdog on a host. http://www.linux-kvm.org/wiki/index.php?title=Guest_PMU&printable=yes ) 
6. Since the rescheduling interrupt will trigger cpu migration, we use “perf record -e migrations -g perf bench sched pipe” to profile the migration events. We find that most migrations is triggered by try_to_wake_up() kernel fucntion. 
a) HOST
b) VM 
7. We use “perf stat -e 'kvm:*' -a sleep 10s” on host to profiling the kvm events. We find that the number of “kvm:kvm_apic_ipi” is low
Code Level Profiling & Analysis 
Target: why the host os has much more cpu migration? 
1. Search http://lkml.org/ for more information 
a) Click any message in home page. 
b) You can find a “google search” box at the head of page. 
2. Install debug symbol package of kernel (NOTE: set http_proxy & apt.conf proxy if necessary) 
a) Add ddeb source 
b) Add ddeb key 
c) Install dbgsym 
echo "deb http://ddebs.ubuntu.com $(lsb_release -cs) main restricted universe multiverse 
deb http://ddebs.ubuntu.com $(lsb_release -cs)-updates main restricted universe multiverse 
deb http://ddebs.ubuntu.com $(lsb_release -cs)-security main restricted universe multiverse 
deb http://ddebs.ubuntu.com $(lsb_release -cs)-proposed main restricted universe multiverse" | 
sudo tee -a /etc/apt/sources.list.d/ddebs.list 
sudo gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys ECDCAD72428D7C01
d) Verify buildid of image & debug symbol package 
3. Study kernel code in lxr: http://lxr.free-electrons.com/ 
a) Choose same kernel version as the test host 
b) Use “Identifier search” to find the source code. For example: http://lxr.free-electrons.com/ident?v=3.2&i=select_task_rq & http://lxr.free-electrons.com/source/kernel/sched_fair.c?v=3.2#L2401 
c) CPU migration code path: try_to_wake_up --> select_task_rq --> select_task_rq_fair --> select_idle_sibling & find_idlest_cpu 
4. Add dynamic probe for kernel function 
a) We add dynamic probe to understand the code path of cpu migration 
sudo apt-get install linux-image-$(uname -r)-dbgsym 
eu-readelf -n /boot/vmlinuz-3.2.0-24-generic | grep Build 
eu-readelf -n /usr/lib/debug/boot/vmlinux-3.2.0-24-generic | grep Build
5. Profile these dynamic probes 
a) To get accurate code execute path, we use “-c 1” to set the event sample period as 1. We can find that select_idle_sibling decide the new cpu. 
6. Use systemtap to analysis the kernel function internal 
a) As perf can only give the statistics data, we use systemtap to internal info of kernel function. 
b) Use “stap -L” to get the arguments of select_idle_sibling(). 
c) Write a systemtap script for profiling select_idle_sibling(). 
d) Run systemtap script: stap ./schedule.stp -c 'perf bench sched pipe -l 100'. We can find 
perf probe -k /usr/lib/debug/boot/vmlinux-3.2.0-24-generic -a select_task_rq_fair 
perf probe -k /usr/lib/debug/boot/vmlinux-3.2.0-24-generic -a select_idle_sibling 
perf probe -k /usr/lib/debug/boot/vmlinux-3.2.0-24-generic -a find_idlest_cpu 
perf record -e probe:select_task_rq_fair -e probe:select_idle_sibling -e probe:find_idlest_cpu -c 1 perf bench sched pipe -l 1000 
global diff_count 
probe kernel.function("select_idle_sibling").return 
{ 
if ($target != $return) 
{ 
#printf("from=%d, to=%dn", $target, $return); 
diff_count++; 
} 
} 
probe end 
{ 
printf("nn+++different cpu: %d+++n", diff_count); 
}
vm always using the same cpu for new task and host may use different task. 
i. HOST 
ii. VM 
7. The cpu migration is decided by schedule domain. It organizes the cpus on a multi-processor system into a hierarchy and balancing the load across CPUs. As host has 12 siblings and vm has no sibling, will always return the same cpu and host may return different cpu. So, vm won’t have cpu migration for this case. 
a) /proc/cpuinfo 
i. HOST 
ii. VM
b) /sys/devices/system/cpu/cpuX/topology 
i. HOST 
ii. VM

More Related Content

Viewers also liked

Boost UDP Transaction Performance
Boost UDP Transaction PerformanceBoost UDP Transaction Performance
Boost UDP Transaction PerformanceLF Events
 
Improving Hadoop Performance via Linux
Improving Hadoop Performance via LinuxImproving Hadoop Performance via Linux
Improving Hadoop Performance via LinuxAlex Moundalexis
 
2 Linux Container and Docker
2 Linux Container and Docker2 Linux Container and Docker
2 Linux Container and DockerFabio Fumarola
 
Improving Hadoop Cluster Performance via Linux Configuration
Improving Hadoop Cluster Performance via Linux ConfigurationImproving Hadoop Cluster Performance via Linux Configuration
Improving Hadoop Cluster Performance via Linux ConfigurationAlex Moundalexis
 
Docker in the Oracle Universe / WebLogic 12c / OFM 12c
Docker in the Oracle Universe / WebLogic 12c / OFM 12cDocker in the Oracle Universe / WebLogic 12c / OFM 12c
Docker in the Oracle Universe / WebLogic 12c / OFM 12cFrank Munz
 
NVMe Over Fabrics Support in Linux
NVMe Over Fabrics Support in LinuxNVMe Over Fabrics Support in Linux
NVMe Over Fabrics Support in LinuxLF Events
 
SR-IOV ixgbe Driver Limitations and Improvement
SR-IOV ixgbe Driver Limitations and ImprovementSR-IOV ixgbe Driver Limitations and Improvement
SR-IOV ixgbe Driver Limitations and ImprovementLF Events
 
WebLogic im Docker Container
WebLogic im Docker ContainerWebLogic im Docker Container
WebLogic im Docker ContainerAndreas Koop
 
Container Landscape in 2017
Container Landscape in 2017Container Landscape in 2017
Container Landscape in 2017Arun Gupta
 
Advanced troubleshooting linux performance
Advanced troubleshooting linux performanceAdvanced troubleshooting linux performance
Advanced troubleshooting linux performanceForthscale
 
Feature rich BTRFS is Getting Richer with Encryption
Feature rich BTRFS is Getting Richer with EncryptionFeature rich BTRFS is Getting Richer with Encryption
Feature rich BTRFS is Getting Richer with EncryptionLF Events
 
Container Storage Best Practices in 2017
Container Storage Best Practices in 2017Container Storage Best Practices in 2017
Container Storage Best Practices in 2017Keith Resar
 
Linux Containers From Scratch
Linux Containers From ScratchLinux Containers From Scratch
Linux Containers From Scratchjoshuasoundcloud
 
Container World 2017!
Container World 2017!Container World 2017!
Container World 2017!kgraham32
 
Oracle: Building Cloud Native Applications
Oracle: Building Cloud Native ApplicationsOracle: Building Cloud Native Applications
Oracle: Building Cloud Native ApplicationsKelly Goetsch
 
Linux: the first second
Linux: the first secondLinux: the first second
Linux: the first secondAlison Chaiken
 
Docker: the road ahead
Docker: the road aheadDocker: the road ahead
Docker: the road aheadshykes
 
More tips and tricks for running containers like a pro - Rancher Online MEetu...
More tips and tricks for running containers like a pro - Rancher Online MEetu...More tips and tricks for running containers like a pro - Rancher Online MEetu...
More tips and tricks for running containers like a pro - Rancher Online MEetu...Shannon Williams
 
Mastering DevOps With Oracle
Mastering DevOps With OracleMastering DevOps With Oracle
Mastering DevOps With OracleKelly Goetsch
 

Viewers also liked (20)

Boost UDP Transaction Performance
Boost UDP Transaction PerformanceBoost UDP Transaction Performance
Boost UDP Transaction Performance
 
Improving Hadoop Performance via Linux
Improving Hadoop Performance via LinuxImproving Hadoop Performance via Linux
Improving Hadoop Performance via Linux
 
2 Linux Container and Docker
2 Linux Container and Docker2 Linux Container and Docker
2 Linux Container and Docker
 
Improving Hadoop Cluster Performance via Linux Configuration
Improving Hadoop Cluster Performance via Linux ConfigurationImproving Hadoop Cluster Performance via Linux Configuration
Improving Hadoop Cluster Performance via Linux Configuration
 
Docker in the Oracle Universe / WebLogic 12c / OFM 12c
Docker in the Oracle Universe / WebLogic 12c / OFM 12cDocker in the Oracle Universe / WebLogic 12c / OFM 12c
Docker in the Oracle Universe / WebLogic 12c / OFM 12c
 
NVMe Over Fabrics Support in Linux
NVMe Over Fabrics Support in LinuxNVMe Over Fabrics Support in Linux
NVMe Over Fabrics Support in Linux
 
SR-IOV ixgbe Driver Limitations and Improvement
SR-IOV ixgbe Driver Limitations and ImprovementSR-IOV ixgbe Driver Limitations and Improvement
SR-IOV ixgbe Driver Limitations and Improvement
 
WebLogic im Docker Container
WebLogic im Docker ContainerWebLogic im Docker Container
WebLogic im Docker Container
 
Container Landscape in 2017
Container Landscape in 2017Container Landscape in 2017
Container Landscape in 2017
 
Advanced troubleshooting linux performance
Advanced troubleshooting linux performanceAdvanced troubleshooting linux performance
Advanced troubleshooting linux performance
 
Feature rich BTRFS is Getting Richer with Encryption
Feature rich BTRFS is Getting Richer with EncryptionFeature rich BTRFS is Getting Richer with Encryption
Feature rich BTRFS is Getting Richer with Encryption
 
Container Storage Best Practices in 2017
Container Storage Best Practices in 2017Container Storage Best Practices in 2017
Container Storage Best Practices in 2017
 
Linux Containers From Scratch
Linux Containers From ScratchLinux Containers From Scratch
Linux Containers From Scratch
 
Container World 2017!
Container World 2017!Container World 2017!
Container World 2017!
 
Function Point Analysis
Function Point AnalysisFunction Point Analysis
Function Point Analysis
 
Oracle: Building Cloud Native Applications
Oracle: Building Cloud Native ApplicationsOracle: Building Cloud Native Applications
Oracle: Building Cloud Native Applications
 
Linux: the first second
Linux: the first secondLinux: the first second
Linux: the first second
 
Docker: the road ahead
Docker: the road aheadDocker: the road ahead
Docker: the road ahead
 
More tips and tricks for running containers like a pro - Rancher Online MEetu...
More tips and tricks for running containers like a pro - Rancher Online MEetu...More tips and tricks for running containers like a pro - Rancher Online MEetu...
More tips and tricks for running containers like a pro - Rancher Online MEetu...
 
Mastering DevOps With Oracle
Mastering DevOps With OracleMastering DevOps With Oracle
Mastering DevOps With Oracle
 

More from Xu Jiang

Sybase BAM Overview
Sybase BAM OverviewSybase BAM Overview
Sybase BAM OverviewXu Jiang
 
Kylin Engineering Principles
Kylin Engineering PrinciplesKylin Engineering Principles
Kylin Engineering PrinciplesXu Jiang
 
KVM Tuning @ eBay
KVM Tuning @ eBayKVM Tuning @ eBay
KVM Tuning @ eBayXu Jiang
 
Apache Kylin: OLAP Engine on Hadoop - Tech Deep Dive
Apache Kylin: OLAP Engine on Hadoop - Tech Deep DiveApache Kylin: OLAP Engine on Hadoop - Tech Deep Dive
Apache Kylin: OLAP Engine on Hadoop - Tech Deep DiveXu Jiang
 
eBay Cloud CMS - QCon 2012 - http://yidb.org/
eBay Cloud CMS - QCon 2012 - http://yidb.org/eBay Cloud CMS - QCon 2012 - http://yidb.org/
eBay Cloud CMS - QCon 2012 - http://yidb.org/Xu Jiang
 
eBay Cloud CMS based on NOSQL
eBay Cloud CMS based on NOSQLeBay Cloud CMS based on NOSQL
eBay Cloud CMS based on NOSQLXu Jiang
 

More from Xu Jiang (6)

Sybase BAM Overview
Sybase BAM OverviewSybase BAM Overview
Sybase BAM Overview
 
Kylin Engineering Principles
Kylin Engineering PrinciplesKylin Engineering Principles
Kylin Engineering Principles
 
KVM Tuning @ eBay
KVM Tuning @ eBayKVM Tuning @ eBay
KVM Tuning @ eBay
 
Apache Kylin: OLAP Engine on Hadoop - Tech Deep Dive
Apache Kylin: OLAP Engine on Hadoop - Tech Deep DiveApache Kylin: OLAP Engine on Hadoop - Tech Deep Dive
Apache Kylin: OLAP Engine on Hadoop - Tech Deep Dive
 
eBay Cloud CMS - QCon 2012 - http://yidb.org/
eBay Cloud CMS - QCon 2012 - http://yidb.org/eBay Cloud CMS - QCon 2012 - http://yidb.org/
eBay Cloud CMS - QCon 2012 - http://yidb.org/
 
eBay Cloud CMS based on NOSQL
eBay Cloud CMS based on NOSQLeBay Cloud CMS based on NOSQL
eBay Cloud CMS based on NOSQL
 

Recently uploaded

How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfSrushith Repakula
 
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfThe Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfFIDO Alliance
 
AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101vincent683379
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyJohn Staveley
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераMark Opanasiuk
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfFIDO Alliance
 
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfFIDO Alliance
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessUXDXConf
 
PLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. StartupsPLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. StartupsStefano
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutesconfluent
 
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfHow Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfFIDO Alliance
 
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomSalesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomCzechDreamin
 
A Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System StrategyA Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System StrategyUXDXConf
 
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...marcuskenyatta275
 
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...FIDO Alliance
 
Top 10 Symfony Development Companies 2024
Top 10 Symfony Development Companies 2024Top 10 Symfony Development Companies 2024
Top 10 Symfony Development Companies 2024TopCSSGallery
 
What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024Stephanie Beckett
 
THE BEST IPTV in GERMANY for 2024: IPTVreel
THE BEST IPTV in  GERMANY for 2024: IPTVreelTHE BEST IPTV in  GERMANY for 2024: IPTVreel
THE BEST IPTV in GERMANY for 2024: IPTVreelreely ones
 
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka DoktorováCzechDreamin
 
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxWSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxJennifer Lim
 

Recently uploaded (20)

How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdf
 
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfThe Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
 
AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджера
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
 
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
 
PLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. StartupsPLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. Startups
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfHow Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
 
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomSalesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
 
A Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System StrategyA Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System Strategy
 
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
 
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
 
Top 10 Symfony Development Companies 2024
Top 10 Symfony Development Companies 2024Top 10 Symfony Development Companies 2024
Top 10 Symfony Development Companies 2024
 
What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024
 
THE BEST IPTV in GERMANY for 2024: IPTVreel
THE BEST IPTV in  GERMANY for 2024: IPTVreelTHE BEST IPTV in  GERMANY for 2024: IPTVreel
THE BEST IPTV in GERMANY for 2024: IPTVreel
 
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
 
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxWSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
 

How To Analysis The Performance Issue Of Linux Kernel

  • 1. How to analysis the performance issue in linux kernel? Xu Jiang (xjiang@ebay) 2013-3-12 Purpose We use a case study to demonstrate how different profiling tools and kernel code analysis the root cause of linux kernel level performance issue. 1. Standardize the profiling process of kernel issue 2. Demonstrate the usage of profiling tool 3. Explore the runtime behavior of kernel code Study Case The “perf bench” command is general framework for benchmark suites. We find that “sched pipe” benchmark suite run much faster on kvm vm than on kvm host. It’s wired that vm is faster than bare metal. 1. VM 2. HOST Profiling & Analysis There are some principles to simplify the profiling & analysis: 1. Compare the difference of profiling results between esx vm, kvm vm and bare metal host. 2. Use perf as the main profiling tools to narrow down analysis process. The key point is to
  • 2. find the good perf event. 3. Use micro benchmark tools to narrow down the issue and make it easily reproducible. System Level Profiling & Analysis Target: what kernel activity cause host os much slow? 1. Check “dmesg” to make sure that OS is in normal mode. 2. Use “vmstat” to check the overall OS status. We find that there is much more interrupts on host than on vm. a) VM b) HOST 3. Since the vm has only 8 vcpu and host 24 cpu, use “top -H” or “mpstat –P ALL” to verify how many thread & cpu is used on vm and host. “perf bench sched pipe” use 2 processes to send/receive on one pipe. a) HOST
  • 3. b) VM 4. Since host has much more interrupts, we use “itop” to analysis the interrupts in /proc/interrupts. We find lots of IPI rescheduling interrupts. a) HOST
  • 4. b) VM 5. Use “perf record -e cycles:pp -g perf bench sched pipe” to profiling the benchmark. And use “perf report -n” to analysis the results. We find many schedule related functions at the top of host profiling. a) HOST (NOTE: “-e cycles:pp” can enable intel PEBS that provide precise instruction address.)
  • 5. b) VM (NOTE: kvm don’t support PEBS. And it’s better to disable NMI watchdog on a host. http://www.linux-kvm.org/wiki/index.php?title=Guest_PMU&printable=yes ) 6. Since the rescheduling interrupt will trigger cpu migration, we use “perf record -e migrations -g perf bench sched pipe” to profile the migration events. We find that most migrations is triggered by try_to_wake_up() kernel fucntion. a) HOST
  • 6. b) VM 7. We use “perf stat -e 'kvm:*' -a sleep 10s” on host to profiling the kvm events. We find that the number of “kvm:kvm_apic_ipi” is low
  • 7. Code Level Profiling & Analysis Target: why the host os has much more cpu migration? 1. Search http://lkml.org/ for more information a) Click any message in home page. b) You can find a “google search” box at the head of page. 2. Install debug symbol package of kernel (NOTE: set http_proxy & apt.conf proxy if necessary) a) Add ddeb source b) Add ddeb key c) Install dbgsym echo "deb http://ddebs.ubuntu.com $(lsb_release -cs) main restricted universe multiverse deb http://ddebs.ubuntu.com $(lsb_release -cs)-updates main restricted universe multiverse deb http://ddebs.ubuntu.com $(lsb_release -cs)-security main restricted universe multiverse deb http://ddebs.ubuntu.com $(lsb_release -cs)-proposed main restricted universe multiverse" | sudo tee -a /etc/apt/sources.list.d/ddebs.list sudo gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys ECDCAD72428D7C01
  • 8. d) Verify buildid of image & debug symbol package 3. Study kernel code in lxr: http://lxr.free-electrons.com/ a) Choose same kernel version as the test host b) Use “Identifier search” to find the source code. For example: http://lxr.free-electrons.com/ident?v=3.2&i=select_task_rq & http://lxr.free-electrons.com/source/kernel/sched_fair.c?v=3.2#L2401 c) CPU migration code path: try_to_wake_up --> select_task_rq --> select_task_rq_fair --> select_idle_sibling & find_idlest_cpu 4. Add dynamic probe for kernel function a) We add dynamic probe to understand the code path of cpu migration sudo apt-get install linux-image-$(uname -r)-dbgsym eu-readelf -n /boot/vmlinuz-3.2.0-24-generic | grep Build eu-readelf -n /usr/lib/debug/boot/vmlinux-3.2.0-24-generic | grep Build
  • 9. 5. Profile these dynamic probes a) To get accurate code execute path, we use “-c 1” to set the event sample period as 1. We can find that select_idle_sibling decide the new cpu. 6. Use systemtap to analysis the kernel function internal a) As perf can only give the statistics data, we use systemtap to internal info of kernel function. b) Use “stap -L” to get the arguments of select_idle_sibling(). c) Write a systemtap script for profiling select_idle_sibling(). d) Run systemtap script: stap ./schedule.stp -c 'perf bench sched pipe -l 100'. We can find perf probe -k /usr/lib/debug/boot/vmlinux-3.2.0-24-generic -a select_task_rq_fair perf probe -k /usr/lib/debug/boot/vmlinux-3.2.0-24-generic -a select_idle_sibling perf probe -k /usr/lib/debug/boot/vmlinux-3.2.0-24-generic -a find_idlest_cpu perf record -e probe:select_task_rq_fair -e probe:select_idle_sibling -e probe:find_idlest_cpu -c 1 perf bench sched pipe -l 1000 global diff_count probe kernel.function("select_idle_sibling").return { if ($target != $return) { #printf("from=%d, to=%dn", $target, $return); diff_count++; } } probe end { printf("nn+++different cpu: %d+++n", diff_count); }
  • 10. vm always using the same cpu for new task and host may use different task. i. HOST ii. VM 7. The cpu migration is decided by schedule domain. It organizes the cpus on a multi-processor system into a hierarchy and balancing the load across CPUs. As host has 12 siblings and vm has no sibling, will always return the same cpu and host may return different cpu. So, vm won’t have cpu migration for this case. a) /proc/cpuinfo i. HOST ii. VM