系统性能调优学习笔记02

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了系统性能调优学习笔记02相关的知识,希望对你有一定的参考价值。

1、硬件资源描述

1.1 CPU

中央处理单元(CPU)处理软件提供的机器指令。核心被集成到单个集成电路芯片中,称为芯片多处理器,或单个芯片封装中的多个芯片。每个服务器系统都有一个或多个cpu,每个cpu位于主板插座上。

尽管拥有更多的cpu可以提供更强的处理能力,但软件的编写必须也是支持多线程的,这样软件能同时使用多个cpu,从而有效地利用这种额外的处理能力。

1.2 内存

内存RAM(易失性存储器)再使用时临时存储程序或数据,拥有更多的内存可以降低系统从存储设备读取数据的频率,因为无力内存可以在未使用内存可用时用作存储设备缓存,再内存压力下,内核必须在减少缓存或移动对象来交换区域之间作出选择。虚拟内存(物理内存+交换设备上可用空间),交换设备通常是磁盘设备。

1.3 存储

存储(非易失性存储器)将程序和数据保存在物理记录介质上。机械硬盘(HDD)使用旋转磁碟和多个读写磁头,将数据移动到旋转磁碟上。固态硬盘(SSD)将数据保存在集成电路组件上,类似于内存,但可以持久保存。SSD的性能属性通常与架构相匹配,架构描述了每个单元存储的比特数。

  • 单级单元(SKC)1位,最可靠最快最昂贵
  • 多电平(MLC)2位,可靠性低于SKC,成本降低
  • 三电平(TLC)3位,可靠性低于MLC,成本降低
  • 四电平(QLC)4位,普遍用于消费市场,但是依然比HDD稳定可靠很多

1.4 网络

计算机系统通过电缆介质的连接共享资源,以太网和接口卡通常使用网络交换机连接,常见的连接容量是1Gbps和10Gbps,通常40Gbps及以上的连接容量应用于数据中心或企业。

InfiniBand是另一种常用的高吞吐量和低延迟连接技术,用于高性能计算的互联,单个InfiniBand链路可以提供高达250Gbps的每个方向的并发,InfiniBand可以聚合到当前发布的最大16条,总吞吐量为4Tbps

1.5 连接线

外部组件通过本地计算机总线连接到系统。有许多不同的总线类型可用,具有诸如功能使用优化和带宽需求等特点。外设组件互连快速(PCle)总线是最常用的用于计算机内部连接设备的标准接口。

系统性能调优学习笔记02_系统硬件资源

2、 查看内核(kernel)消息

最简单和最直接的硬件信息来源是运行中的Linux内核,它作为所有硬件访问的中介。内核通过/proc文件系统、/sys文件系统以及内核消息和事件公开信息结构。

内核消息被写入称为dmesg的预先分配的环形缓冲区,环形缓冲区是一种循环缓冲区,其中数据溢出只是在缓冲区的顶部再次开始。

随着时间的推移,更多的最新消息将填满缓冲区并覆盖原始消息,但缓冲区的大小永远不会增长。

检查dmesg缓冲区有三个常见的动机:

  1. 检查在引导时检测到什么硬件
  2. 当硬件附加或检测到时,观察驱动程序打印的消息
  3. 观察发生的警告或错误消息条件

查看内核消息命令

说明

dmesg

RHEL8开始不再自动创建

Journalctl -k

日志文件持久化存储

2.1 dmesg使用

dmesg命令的前2行显示内核版本和引导加载程序传递给内核的命令行启动选项。在需要诊断系统 行为时,了解系统初始化期间使用了哪些命令行选项是很有用的。

# 使用dmesg命令
[root@test01 ~]# dmesg | head -n10
[ 0.000000] Linux version 4.18.0-269.el8.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 8.4.1 20200928 (Red Hat 8.4.1-1) (GCC)) #1 SMP Tue Jan 12 17:55:05 UTC 2021
[ 0.000000] Command line: BOOT_IMAGE=(hd0,msdos1)/vmlinuz-4.18.0-269.el8.x86_64 root=/dev/mapper/cs-root ro crashkernel=auto resume=/dev/mapper/cs-swap rd.lvm.lv=cs/root rd.lvm.lv=cs/swap rhgb net.ifnames=0 biosdevname=0
[ 0.000000] x86/fpu: Supporting XSAVE feature 0x001: x87 floating point registers
[ 0.000000] x86/fpu: Supporting XSAVE feature 0x002: SSE registers
[ 0.000000] x86/fpu: Supporting XSAVE feature 0x004: AVX registers
[ 0.000000] x86/fpu: xstate_offset[2]: 576, xstate_sizes[2]: 256
[ 0.000000] x86/fpu: Enabled xstate features 0x7, context size is 832 bytes, using compacted format.
[ 0.000000] BIOS-provided physical RAM map:
[ 0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009fbff] usable
[ 0.000000] BIOS-e820: [mem 0x000000000009fc00-0x000000000009ffff] reserved

# 使用-k选项的journalctl命令可以显示环形缓冲区消息,日志服务可以配置为持久存储,比dmesg命令更受欢迎
[root@test01 ~]# journalctl -k | head -n 10
-- Logs begin at Tue 2023-02-14 10:59:19 CST, end at Tue 2023-02-14 16:40:01 CST. --
Feb 14 10:59:19 localhost.localdomain kernel: Linux version 4.18.0-269.el8.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 8.4.1 20200928 (Red Hat 8.4.1-1) (GCC)) #1 SMP Tue Jan 12 17:55:05 UTC 2021
Feb 14 10:59:19 localhost.localdomain kernel: Command line: BOOT_IMAGE=(hd0,msdos1)/vmlinuz-4.18.0-269.el8.x86_64 root=/dev/mapper/cs-root ro crashkernel=auto resume=/dev/mapper/cs-swap rd.lvm.lv=cs/root rd.lvm.lv=cs/swap rhgb net.ifnames=0 biosdevname=0
Feb 14 10:59:19 localhost.localdomain kernel: x86/fpu: Supporting XSAVE feature 0x001: x87 floating point registers
Feb 14 10:59:19 localhost.localdomain kernel: x86/fpu: Supporting XSAVE feature 0x002: SSE registers
Feb 14 10:59:19 localhost.localdomain kernel: x86/fpu: Supporting XSAVE feature 0x004: AVX registers
Feb 14 10:59:19 localhost.localdomain kernel: x86/fpu: xstate_offset[2]: 576, xstate_sizes[2]: 256
Feb 14 10:59:19 localhost.localdomain kernel: x86/fpu: Enabled xstate features 0x7, context size is 832 bytes, using compacted format.
Feb 14 10:59:19 localhost.localdomain kernel: BIOS-provided physical RAM map:
Feb 14 10:59:19 localhost.localdomain kernel: BIOS-e820: [mem 0x0000000000000000-0x000000000009fbff] usable

2.2 查看内存

系统内存被组织成直接内存访问(DMA)内存区域进行分配,多内核子系统和旧设备使用来自特定区域的内存,使用dmesg命令查看DMA内存区域和总可用内存。

# 查看DMA内存
[root@test01 ~]# dmesg | grep -i dma
[ 0.000000] DMA [mem 0x0000000000001000-0x0000000000ffffff]
[ 0.000000] DMA32 [mem 0x0000000001000000-0x00000000ffffffff]
[ 0.000000] DMA zone: 64 pages used for memmap
[ 0.000000] DMA zone: 158 pages reserved
[ 0.000000] DMA zone: 3998 pages, LIFO batch:0
[ 0.000000] DMA32 zone: 12224 pages used for memmap
[ 0.000000] DMA32 zone: 782303 pages, LIFO batch:63
[ 0.196499] pnp 00:03: [dma 2]
[ 0.218521] pci 0000:00:01.0: Activating ISA DMA hang workarounds
[ 0.907041] PCI-DMA: Using software bounce buffering for IO (SWIOTLB)
[ 3.590964] ata1: PATA max MWDMA2 cmd 0x1f0 ctl 0x3f6 bmdma 0xc0e0 irq 14
[ 3.590965] ata2: PATA max MWDMA2 cmd 0x170 ctl 0x376 bmdma 0xc0e8 irq 15
[ 3.654043] [TTM] Initializing DMA pool allocator
[ 3.752021] ata2.00: ATAPI: QEMU DVD-ROM, 2.4.0, max UDMA/100

查看总内存

# 查看总内存
[root@test01 ~]# dmesg | grep Memory
[ 0.000000] Memory: 2934724K/4193780K available (12293K kernel code, 2200K rwdata, 4028K rodata, 2464K init, 14608K bss, 408816K reserved, 0K cma-reserved)
[ 0.038389] x86/mm: Memory block size: 128MB

2.3 查看CPU

[root@test01 ~]# dmesg | grep CPU
[ 0.000000] smpboot: Allowing 4 CPUs, 0 hotplug CPUs
[ 0.000000] setup_percpu: NR_CPUS:8192 nr_cpumask_bits:4 nr_cpu_ids:4 nr_node_ids:1
[ 0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=4, Nodes=1
[ 0.001000] rcu: RCU restricting CPUs from NR_CPUS=8192 to nr_cpu_ids=4.
[ 0.001000] random: crng done (trusting CPUs manufacturer)
[ 0.013890] smpboot: CPU0: AMD Ryzen 9 3900X 12-Core Processor (family: 0x17, model: 0x71, stepping: 0x0)
[ 0.015874] smp: Bringing up secondary CPUs ...
[ 0.016516] .... node #0, CPUs: #1
[ 0.001000] smpboot: CPU 1 Converting physical 0 to logical die 1
[ 0.001000] smpboot: CPU 2 Converting physical 0 to logical die 2
[ 0.001000] smpboot: CPU 3 Converting physical 0 to logical die 3
[ 0.027011] smp: Brought up 1 node, 4 CPUs

2.4 查看Huge memory

初始化分配大内存页的机制

[root@test01 ~]# dmesg | grep Huge
[ 0.046077] HugeTLB registered 1.00 GiB page size, pre-allocated 0 pages
[ 0.046465] HugeTLB registered 2.00 MiB page size, pre-allocated 0 pages

2.5 查看I/O

同时也会列出设备信息

[root@test01 ~]# dmesg | grep io scheduler
[ 1.021273] io scheduler mq-deadline registered
[ 1.021614] io scheduler kyber registered
[ 1.021961] io scheduler bfq registered

2.6 错误输出

当发生错误时,会列出堆栈信息,这个时候,就需要技术支持了

系统性能调优学习笔记02_系统硬件资源_02

2.7 修改内核输出消息

使用-T参数,将时间戳设置为人类易读格式

[root@test01 ~]# dmesg -T | head -n2
[Tue Feb 14 10:59:17 2023] Linux version 4.18.0-269.el8.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 8.4.1 20200928 (Red Hat 8.4.1-1) (GCC)) #1 SMP Tue Jan 12 17:55:05 UTC 2021
[Tue Feb 14 10:59:17 2023] Command line: BOOT_IMAGE=(hd0,msdos1)/vmlinuz-4.18.0-269.el8.x86_64 root=/dev/mapper/cs-root ro crashkernel=auto resume=/dev/mapper/cs-swap rd.lvm.lv=cs/root rd.lvm.lv=cs/swap rhgb net.ifnames=0 biosdevname=0

3、检索CPU信息

现代系统通常有多个cpu,每个cpu每个插槽有多个内核,每个内核可能有多个超线程,具有不同级别的本地和共享缓存。

3.1 lscpu命令

使用此命令可以快速查看CPU基本信息,包括核心、架构、厂商等

[root@test01 ~]# lscpu 
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 4
On-line CPU(s) list: 0-3
Thread(s) per core: 1
Core(s) per socket: 1
Socket(s): 4
NUMA node(s): 1
Vendor ID: AuthenticAMD
BIOS Vendor ID: QEMU
CPU family: 23
Model: 113
Model name: AMD Ryzen 9 3900X 12-Core Processor
BIOS Model name: pc-i440fx-2.4
Stepping: 0
CPU MHz: 3799.996
BogoMIPS: 7599.99
Virtualization: AMD-V
Hypervisor vendor: KVM
Virtualization type: full
NUMA node0 CPU(s): 0-3
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm rep_good nopl cpuid extd_apicid tsc_known_freq pni pclmulqdq ssse3 fma cx16 sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm cmp_legacy svm cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw topoext ssbd vmmcall fsgsbase tsc_adjust bmi1 avx2 smep bmi2 rdseed adx smap xsaveopt xsavec xgetbv1 xsaves arat npt nrip_save vmcb_clean

虽然lscpu列出了各种CPU缓存的大小,但它没有回答哪些缓存由哪些逻辑CPU共享的问题。但是,当作为lscpu -p调用时,可解析输出可用于提取此信息。

[root@test01 ~]# lscpu -p
# The following is the parsable format, which can be fed to other
# programs. Each different item in every column has an unique ID
# starting from zero.
# CPU,Core,Socket,Node
0,0,0,0
1,1,1,0
2,2,2,0
3,3,3,0

3.2 getconf命令

POSIX标准定义了getconf库调用,用于以编程方式确定与软件优化相关的本地硬件方面,这些参数可以通过getconf命令获取,虽然大多数getconf信息与各种软件子系统的标准一致性有关,但也包含了一些重要的硬件信息。

# 使用getconf列出硬件的各种信息(此处列出1~4级缓存)
[root@test01 ~]# getconf -a | grep -i level
LEVEL1_ICACHE_SIZE 32768
LEVEL1_ICACHE_ASSOC 8
LEVEL1_ICACHE_LINESIZE 64
LEVEL1_DCACHE_SIZE 32768
LEVEL1_DCACHE_ASSOC 8
LEVEL1_DCACHE_LINESIZE 64
LEVEL2_CACHE_SIZE 524288
LEVEL2_CACHE_ASSOC 8
LEVEL2_CACHE_LINESIZE 64
LEVEL3_CACHE_SIZE 67108864
LEVEL3_CACHE_ASSOC 0
LEVEL3_CACHE_LINESIZE 64
LEVEL4_CACHE_SIZE 0
LEVEL4_CACHE_ASSOC 0
LEVEL4_CACHE_LINESIZE 0

4、 检索smbios/dmi信息

dmidecode实用程序探测本地系统管理BIOS (SMBIOS)和桌面管理接口(DMI)数据结构,并显示重要的本地硬件信息

Dmicode type键

说明

0

bios

BIOS信息

1

system

系统信息

3

Chassis

架构信息

4

Processor

CPU信息

7

cache

缓存

16

Physical Memory Array

物理存储器阵列

17

Memory Device

内存设备

19

Memory Array Mapped Address

内存阵列映射地址

27

Cooling Device

物理信息

4.1 查看内核信息

由于type 4 为processor,查看CPU信息使用 --type 4

[root@test01 ~]# dmidecode -t 4
# dmidecode 3.2
Getting SMBIOS data from sysfs.
SMBIOS 2.8 present.

Handle 0x0400, DMI type 4, 42 bytes
Processor Information
Socket Designation: CPU 0
Type: Central Processor
Family: Other
Manufacturer: QEMU
ID: 10 0F 87 00 FF FB 8B 07
Version: pc-i440fx-2.4
Voltage: Unknown
External Clock: Unknown
Max Speed: 2000 MHz
Current Speed: 2000 MHz
Status: Populated, Enabled
Upgrade: Other
L1 Cache Handle: Not Provided
L2 Cache Handle: Not Provided
L3 Cache Handle: Not Provided
Serial Number: Not Specified
Asset Tag: Not Specified
Part Number: Not Specified
Core Count: 1
Core Enabled: 1
Thread Count: 1
Characteristics: None

``` 4个CPU,下面分配了3个类似的信息,忽略

4.2 显示目标主机内存

可以使用dmidecode -t memory查看内存相关信息

[root@test01 ~]# dmidecode -t memory
# dmidecode 3.2
Getting SMBIOS data from sysfs.
SMBIOS 2.8 present.

Handle 0x1000, DMI type 16, 23 bytes
Physical Memory Array
Location: Other
Use: System Memory
Error Correction Type: Multi-bit ECC
Maximum Capacity: 4 GB
Error Information Handle: Not Provided
Number Of Devices: 1

Handle 0x1100, DMI type 17, 40 bytes
Memory Device
Array Handle: 0x1000
Error Information Handle: Not Provided
Total Width: Unknown
Data Width: Unknown
Size: 4 GB
Form Factor: DIMM
Set: None
Locator: DIMM 0
Bank Locator: Not Specified
Type: RAM
Type Detail: Other
Speed: Unknown
Manufacturer: QEMU
Serial Number: Not Specified
Asset Tag: Not Specified
Part Number: Not Specified
Rank: Unknown
Configured Memory Speed: Unknown
Minimum Voltage: Unknown
Maximum Voltage: Unknown
Configured Voltage: Unknown

4.3 显示架构信息

[root@test01 ~]# dmidecode -t 3
# dmidecode 3.2
Getting SMBIOS data from sysfs.
SMBIOS 2.8 present.

Handle 0x0300, DMI type 3, 21 bytes
Chassis Information
Manufacturer: QEMU
Type: Other
Lock: Not Present
Version: pc-i440fx-2.4
Serial Number: Not Specified
Asset Tag: Not Specified
Boot-up State: Safe
Power Supply State: Safe
Thermal State: Safe
Security Status: Unknown
OEM Information: 0x00000000
Height: Unspecified
Number Of Power Cords: Unspecified
Contained Elements: 0

4.4 显示物理设备信息

[root@test01 ~]# dmidecode -t 1,27
# dmidecode 3.2
Getting SMBIOS data from sysfs.
SMBIOS 2.8 present.

Handle 0x0100, DMI type 1, 27 bytes
System Information
Manufacturer: QEMU
Product Name: Standard PC (i440FX + PIIX, 1996)
Version: pc-i440fx-2.4
Serial Number: Not Specified
UUID: bd9096af-16d4-4caf-8e30-437479a1e149
Wake-up Type: Power Switch
SKU Number: Not Specified
Family: Not Specified

4.5 查看RAM信息

提供了支持和安装的RAM的完整分项

[root@test01 ~]# dmidecode -t 16,6,17
# dmidecode 3.2
Getting SMBIOS data from sysfs.
SMBIOS 2.8 present.

Handle 0x1000, DMI type 16, 23 bytes
Physical Memory Array
Location: Other
Use: System Memory
Error Correction Type: Multi-bit ECC
Maximum Capacity: 4 GB
Error Information Handle: Not Provided
Number Of Devices: 1

Handle 0x1100, DMI type 17, 40 bytes
Memory Device
Array Handle: 0x1000
Error Information Handle: Not Provided
Total Width: Unknown
Data Width: Unknown
Size: 4 GB
Form Factor: DIMM
Set: None
Locator: DIMM 0
Bank Locator: Not Specified
Type: RAM
Type Detail: Other
Speed: Unknown
Manufacturer: QEMU
Serial Number: Not Specified
Asset Tag: Not Specified
Part Number: Not Specified
Rank: Unknown
Configured Memory Speed: Unknown
Minimum Voltage: Unknown
Maximum Voltage: Unknown
Configured Voltage: Unknown

4.6 内核信息目录

dmidecode数据通过sysfs文件系统获取,管理员可以在“/sys/class/dmi/id”目录下查询到相同的内核提供的信息,访问存储在组件文件中用于脚本和报告的数据非常简单。

[root@test01 ~]# cd /sys/class/dmi/id/
[root@test01 /sys/class/dmi/id]# ls
bios_date bios_version chassis_serial chassis_vendor modalias product_family product_serial product_uuid subsystem uevent
bios_vendor chassis_asset_tag chassis_type chassis_version power product_name product_sku product_version sys_vendor
# 查看架构信息
[root@test01 /sys/class/dmi/id]# cat bios_date
04/01/2014
[root@test01 /sys/class/dmi/id]# cat chassis_*
1
QEMU
pc-i440fx-2.4
# 查看内核信息
[root@test01 /sys/class/dmi/id]# cat product_*
Standard PC (i440FX + PIIX, 1996)
bd9096af-16d4-4caf-8e30-437479a1e149
pc-i440fx-2.4

5、检索外部设备信息

pci、usb设备同样可以通过像lspci、lsusb方式进行检索

5.1 lspci命令

[root@test01 ~]# lspci 
00:00.0 Host bridge: Intel Corporation 440FX - 82441FX PMC [Natoma] (rev 02)
00:01.0 ISA bridge: Intel Corporation 82371SB PIIX3 ISA [Natoma/Triton II]
00:01.1 IDE interface: Intel Corporation 82371SB PIIX3 IDE [Natoma/Triton II]
00:01.2 USB controller: Intel Corporation 82371SB PIIX3 USB [Natoma/Triton II] (rev 01)
00:01.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 03)
00:02.0 VGA compatible controller: Device 1234:1111 (rev 02)
00:03.0 Ethernet controller: Red Hat, Inc. Virtio network device
00:04.0 Ethernet controller: Red Hat, Inc. Virtio network device
00:05.0 Ethernet controller: Red Hat, Inc. Virtio network device
00:06.0 Ethernet controller: Red Hat, Inc. Virtio network device
00:07.0 SCSI storage controller: Red Hat, Inc. Virtio block device

使用 -vv可以列举出设备的详细信息

[root@test01 ~]# lspci -vv
00:00.0 Host bridge: Intel Corporation 440FX - 82441FX PMC [Natoma] (rev 02)
Subsystem: Red Hat, Inc. Qemu virtual machine
Control: I/O+ Mem+ BusMaster- SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR+ FastB2B- DisINTx-
Status: Cap- 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-

00:01.0 ISA bridge: Intel Corporation 82371SB PIIX3 ISA [Natoma/Triton II]
Subsystem: Red Hat, Inc. Qemu virtual machine
Control: I/O+ Mem+ BusMaster- SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR+ FastB2B- DisINTx-
Status: Cap- 66MHz- UDF- FastB2B- ParErr- DEVSEL=medium >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-

5.2 lsusb命令

[root@test01 ~]# lsusb
Bus 001 Device 002: ID 0627:0001 Adomax Technology Co., Ltd
Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

使用 -vv列举详细信息

[root@test01 ~]# lsusb -vv

Bus 001 Device 002: ID 0627:0001 Adomax Technology Co., Ltd
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 0
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 8
idVendor 0x0627 Adomax Technology Co., Ltd
idProduct 0x0001
bcdDevice 0.00
iManufacturer 1 QEMU
iProduct 3 QEMU USB Tablet
iSerial 5 42
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 0x0022
bNumInterfaces 1
bConfigurationValue 1
iConfiguration 7 HID Tablet
bmAttributes 0xa0
(Bus Powered)
Remote Wakeup
MaxPower 100mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 1
bInterfaceClass 3 Human Interface Device
bInterfaceSubClass 0
bInterfaceProtocol 2 Mouse
iInterface 0
HID Device Descriptor:
bLength 9
bDescriptorType 33
bcdHID 0.01
bCountryCode 0 Not supported
bNumDescriptors 1
bDescriptorType 34 Report
wDescriptorLength 74
Report Descriptors:
** UNAVAILABLE **
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0008 1x 8 bytes
bInterval 10
Device Qualifier (for other device speed):
bLength 10
bDescriptorType 6
bcdUSB 2.00
bDeviceClass 0
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 64
bNumConfigurations 1
cant get debug descriptor: Resource temporarily unavailable
Device Status: 0x0000
(Bus Powered)
...

6、收集系统组件信息

使用lstopo可以查看系统组成拓扑结构

6.1 lstopo命令

[root@test01 ~]# lstopo

系统性能调优学习笔记02_系统调优学习笔记_03

6.2 非图形化方式查看

# 没有图形化的时候可以使用lstopo-no-graphics查看系统架构
[root@test01 ~]# lstopo-no-graphics
Machine (3736MB total)
NUMANode L#0 (P#0 3736MB)
Package L#0 + Core L#0 + PU L#0 (P#0)
Package L#1 + Core L#1 + PU L#1 (P#1)
Package L#2 + Core L#2 + PU L#2 (P#2)
Package L#3 + Core L#3 + PU L#3 (P#3)
HostBridge
PCI 00:01.1 (IDE)
Block "sr0"
PCI 00:02.0 (VGA)
PCI 00:03.0 (Ethernet)
Net "eth0"
PCI 00:04.0 (Ethernet)
Net "eth1"
PCI 00:05.0 (Ethernet)
Net "eth2"
PCI 00:06.0 (Ethernet)
Net "eth3"
PCI 00:07.0 (SCSI)
Block "vda"
Misc(MemoryModule)

7、查看硬件配置

7.1 lshw命令

lshw命令列出有关计算机硬件配置的详细信息,lshw命令列出确切的内存配置。例如固件版本、主板配置、CPU版本和速度、缓存配置和总线速度,lshw命令将硬件组件分成类,如系统、内存、网络等。

使用Ishw -short命令列出硬件信息的压缩版本,包括系统上可用的硬件类。

[root@test01 ~]# lshw -short 
H/W path Device Class Description
========================================================
system Standard PC (i440FX + PIIX, 1996)
/0 bus Motherboard
/0/0 memory 96KiB BIOS
/0/400 processor AMD Ryzen 9 3900X 12-Core Processor
/0/401 processor AMD Ryzen 9 3900X 12-Core Processor
/0/402 processor AMD Ryzen 9 3900X 12-Core Processor
/0/403 processor AMD Ryzen 9 3900X 12-Core Processor
/0/1000 memory 4GiB System Memory
/0/1000/0 memory 4GiB DIMM RAM
/0/100 bridge 440FX - 82441FX PMC [Natoma]
/0/100/1 bridge 82371SB PIIX3 ISA [Natoma/Triton II]
/0/100/1/0 system PnP device PNP0b00
/0/100/1/1 input PnP device PNP0303
/0/100/1/2 input PnP device PNP0f13
/0/100/1/3 storage PnP device PNP0700
/0/100/1/4 printer PnP device PNP0400
/0/100/1/5 communication PnP device PNP0501
/0/100/1.1 scsi1 storage 82371SB PIIX3 IDE [Natoma/Triton II]
/0/100/1.1/0.0.0 /dev/cdrom disk QEMU DVD-ROM
/0/100/1.2 bus 82371SB PIIX3 USB [Natoma/Triton II]
/0/100/1.2/1 usb1 bus UHCI Host Controller
/0/100/1.2/1/1 input5 input QEMU QEMU USB Tablet
/0/100/1.3 bridge 82371AB/EB/MB PIIX4 ACPI
/0/100/2 /dev/fb0 display bochs-drmdrmfb
/0/100/3 network Virtio network device
/0/100/3/0 eth0 network Ethernet interface
/0/100/4 network Virtio network device
/0/100/4/0 eth1 network Ethernet interface
/0/100/5 network Virtio network device
/0/100/5/0 eth2 network Ethernet interface
/0/100/6 network Virtio network device
/0/100/6/0 eth3 network Ethernet interface
/0/100/7 storage Virtio block device
/0/100/7/0 /dev/vda disk 536GB Virtual I/O device
/0/100/7/0/1 /dev/vda1 volume 1GiB Linux filesystem partition
/0/100/7/0/2 /dev/vda2 volume 498GiB Linux LVM Physical Volume partition
/1 input0 input Power Button
/2 input1 input AT Translated Set 2 keyboard
/3 input3 input VirtualPS/2 VMware VMMouse
/4 input4 input VirtualPS/2 VMware VMMouse
/5 input6 input PC Speaker

7.2 查看具体条目配置

使用lshw -C 参数 ,可以查看具体硬件配置

Class

说明

system

系统

processor

CPU

memory

内存

storage

存储

network

网络

volume

disk

磁盘

# 查看系统信息
[root@test01 ~]# lshw -C system
test01
description: Computer
product: Standard PC (i440FX + PIIX, 1996)
vendor: QEMU
version: pc-i440fx-2.4
width: 64 bits
capabilities: smbios-2.8 dmi-2.8 smp vsyscall32
configuration: boot=normal uuid=bd9096af-16d4-4caf-8e30-437479a1e149
*-pnp00:00
product: PnP device PNP0b00
physical id: 0
capabilities: pnp
configuration: driver=rtc_cmos

# 查看内存信息
[root@test01 ~]# lshw -C memory
*-firmware
description: BIOS
vendor: SeaBIOS
physical id: 0
version: rel-1.8.2-0-g33fbe13 by qemu-project.org
date: 04/01/2014
size: 96KiB
*-memory
description: System Memory
physical id: 1000
size: 4GiB
capabilities: ecc
configuration: errordetectinotallow=multi-bit-ecc
*-bank
description: DIMM RAM
vendor: QEMU
physical id: 0
slot: DIMM 0
size: 4GiB

# 查看网络信息
[root@test01 ~]# lshw -C network
*-network:0
description: Ethernet controller
product: Virtio network device
vendor: Red Hat, Inc.
physical id: 3
bus info: pci@0000:00:03.0
version: 00
width: 32 bits
clock: 33MHz
capabilities: msix bus_master cap_list rom
configuration: driver=virtio-pci latency=0
resources: irq:10 ioport:c060(size=32) memory:febd1000-febd1fff memory:feac0000-feafffff
*-virtio0
description: Ethernet interface
physical id: 0
bus info: virtio@0
logical name: eth0
serial: 50:00:00:01:00:00
capabilities: ethernet physical
configuration: autnotallow=off broadcast=yes driver=virtio_net driverversinotallow=1.0.0 ip=192.168.0.100 link=yes multicast=yes
...

8、硬件错误报告

用户空间守护进程rasdaemon捕获并处理内核跟踪机制生成的所有可靠性、可用性和可服务性(RAS)错误事件。

这些跟踪事件被记录在/sys/kernel/debug/tracing目录下,并通过syslog/journal上报。使用rasdaemon需要先安装rasdaemon包,然后启动并启用rasdaemon服务。

# 安装rasdaemon软件包
[root@test01 ~]# yum -y install rasdaemon

# 开机启动
[root@test01 ~]# systemctl enable --now rasdaemon.service
Created symlink /etc/systemd/system/multi-user.target.wants/rasdaemon.service → /usr/lib/systemd/system/rasdaemon.service.
[root@test01 ~]# systemctl status rasdaemon.service
● rasdaemon.service - RAS daemon to log the RAS events
Loaded: loaded (/usr/lib/systemd/system/rasdaemon.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2023-02-14 21:11:32 CST; 9s ago
Process: 15652 ExecStartPost=/usr/sbin/rasdaemon --enable (code=exited, status=0/SUCCESS)
Main PID: 15651 (rasdaemon)
Tasks: 1 (limit: 23656)
Memory: 12.6M
CGroup: /system.slice/rasdaemon.service
└─15651 /usr/sbin/rasdaemon -f -r

Feb 14 21:11:32 test01 rasdaemon[15651]: Enabled event mce:mce_record
Feb 14 21:11:32 test01 rasdaemon[15651]: ras:extlog_mem_event event enabled
Feb 14 21:11:32 test01 rasdaemon[15651]: Enabled event ras:extlog_mem_event
Feb 14 21:11:32 test01 rasdaemon[15651]: ras:memory_failure_event event enabled
Feb 14 21:11:32 test01 rasdaemon[15651]: Enabled event ras:memory_failure_event
Feb 14 21:11:32 test01 rasdaemon[15651]: rasdaemon: Recording mc_event events
Feb 14 21:11:32 test01 rasdaemon[15651]: rasdaemon: Recording aer_event events
Feb 14 21:11:32 test01 rasdaemon[15651]: rasdaemon: Recording extlog_event events
Feb 14 21:11:32 test01 rasdaemon[15651]: rasdaemon: Recording mce_record events
Feb 14 21:11:32 test01 rasdaemon[15651]: rasdaemon: Recording memory_failure_event events

# 列出所有可查询的错误报告
[root@test01 ~]# ras-mc-ctl --help
Usage: ras-mc-ctl [OPTIONS...]
--quiet Quiet operation.
--mainboard Print mainboard vendor and model for this hardware.
--status Print status of EDAC drivers.
--print-labels Print Motherboard DIMM labels to stdout.
--guess-labels Print DMI labels, when bank locator is available.
--register-labels Load Motherboard DIMM labels into EDAC driver.
--delay=N Delay N seconds before writing DIMM labels.
--labeldb=DB Load label database from file DB.
--layout Display the memory layout.
--summary Presents a summary of the logged errors.
--errors Shows the errors stored at the error database.
--error-count Shows the corrected and uncorrected error counts using sysfs.
--help This help message.

# 列出所有错误报告
[root@test01 ~]# ras-mc-ctl --summary
No Memory errors.

No PCIe AER errors.

No Extlog errors.

No Memory failure errors.

No MCE errors.

9、在虚拟机和云上显示实例

9.1 KVM介绍

KVM基于内核的虚拟机(KVM)是一个可加载的内核模块,通过使用Intel VT或AMD-V硬件扩展提供完全虚拟化,KVM本身运行在内核空间中,来宾程序作为用户空间中的单个快速模拟器(QEMU)进程在主机上运行,KVM允许主机将其物理硬件提供给虚拟机。

libvart工具包便于管理虚拟机和相关的虚拟设备。virsh命令使用libvart库和API访问虚拟机。

9.2 QEMU介绍

QEMU是一个多平台模拟器,提供完整的系统仿真,包括一个或多个处理器和外设。通过与KVM和带有虚拟化扩展的处理器结合使用,QEMU提供了完整的硬件辅助虚拟化。QEMU将虚拟设备呈现给客户虚拟机的操作系统进行枚举,包括:

  • 网络PCI控制器
  • SCSI控制器
  • 存储PCl块控制器
  • 内存PCI控制器
  • 随机数发生器PCI设备
  • USB
  • 网络设备驱动程序
  • 视频设备

Q35是最新的QEMU仿真,基于ICH9芯片组,这是KVM来宾的推荐机器类型,从旧的i44Ofx设计迁移到ICH9架构增加了重大改进,包括集成AHCI控制器、USB控制器、网络适配器、音频适配器、PCI- e和PCI总线,以及用于SuperlO设备的LPC总线。重要的是Q35现在支持PCl-E设备,不再支持ISA总线。

使用virsh dumpxml命令确定客户机是否配置为使用QEMU Q35机器类型

[root@foundation0 ~]# virsh dumpxml workstation | grep q35
<type arch=x86_64 machine=pc-q35-rhel7.6.0>hvm</type>

9.3 直通主机设备

一些硬件平台支持PCI直通,KVM客户可以直接访问特定的主机硬件设备,透传显示为客户机操作系统设备分配,就好像该设备直接连接到客户机的虚拟机,PCl直通允许来宾独占访问分配的PCI设备。

CPU直通与PCl直通不同,KVM客户设置(主机直通)使用与其所在主机相同的CPU模型特性。客户设置,主机模型,使用相同的模型系列,但没有强制所有CPU功能。

CPU都没有直接分配给客户机,而只是共享CPU特性配置

[root@foundation0 ~]# virsh dumpxml workstation | grep cpu mode
<cpu mode=XXX>

9.4 内存膨胀

virtio-balloon驱动程序控制客户机拥有的内存数量,balloon设备指定了虚拟机(VM)中未使用的RAM,并使其可供host或其他虚拟机使用。当虚拟机需要更多内存时,virtio-balloon会将内存重新分配给虚拟机,直到虚拟机的配置大小。内存膨胀可以有效地管理未使用的guest内存,同时仍然为客户提供完整定义的大小。

对于分配大量内存并将物理内存隔离设置为与定义内存相同的值的应用程序来说,内存膨胀非常理想。内存膨胀对于消耗内存缓慢、偶尔释放内存或长时间处于空闲状态的应用程序(如虚拟桌面)也很有用。

一个虚拟内存ballon设备会自动添加到所有KVM guest虚拟机中,并由libvirt管理。在XML配置文件中,内存膨胀由元素表示。没有必要显式地将此元素添加到guest虚拟机的XML中,除非您要分配一个特定的PCl插槽。如果设备必须显式禁用,则在XML文件中设置model= none 参数。

使用Ispci查看是否支持内存膨胀

[student@workstation ~]$ lspci | grep balloon
05:00.0 Unclassified device [00ff]: Red Hat, Inc. Virtio memory balloon (rev 01)

9.5 调整虚拟机实例大小

调整虚拟机实例大小的过程是规划、安装和配置适当数量的资源,以控制成本并确保最佳性能和可伸缩性。合适大小的VM实例应该安装最少数量的包,并且只运行所需工作负载所需的服务。作为云计算设计,实例的大小是适当的,并针对特定的大小进行调整,然后水平扩展到几乎任何容量。

在虚拟和云环境中监视主机和查找相关问题是优化性能的最有效方法,持续调整大小是保持一致性、控制最佳性能和操作成本的方法。观察客户机和主机的行为(例如空闲实例或繁重的工作负载)是一项持续的工作。

9.6 观察宿主机和虚拟机

使用kvm_stat从主机角度观察虚拟机行为,可以确定需要适当调整的繁重工作负载。perf kvm命令记录来宾系统和主机系统的性能计数器,为分析性能问题提供必要的信息。

[root@foundation0 ~]# kvm_stat 
kvm statistics - summary

Event Total %Total CurAvg/s
kvm_entry 164 17.8 602
kvm_exit 164 17.8 602
kvm_msr 117 12.7 433
kvm_hv_timer_state 117 12.7 433
kvm_apic 72 7.8 269
kvm_apic_accept_irq 36 3.9 129
kvm_inj_virq 35 3.8 129
kvm_eoi 35 3.8 129
kvm_pv_eoi 35 3.8 129
kvm_vcpu_wakeup 33 3.6 124
kvm_fpu 26 2.8 80
kvm_halt_poll_ns 12 1.3 45
kvm_page_fault 13 1.4 40
kvm_emulate_insn 13 1.4 40
vcpu_match_mmio 13 1.4 40
kvm_userspace_exit 13 1.4 40
kvm_mmio 13 1.4 40
kvm_msi_set_irq 12 1.3 40
Total 923 3342

# 按g查看运行虚拟机
Show statistics for specific guest or pid.
This might limit the shown data to the trace statistics.

Guest or pid [ENTER exits]:serverb



Pid Guest Name (fuzzy list, might be inaccurate!)
2902 classroom
31133 bastion
31213 workstation
31298 servera
31377 serverb

# 输入serverb,查看虚拟机资源利用率
kvm statistics - pid 31377 (serverb)

Event Total %Total CurAvg/s
kvm_entry 839 19.2 125
kvm_exit 839 19.2 125
kvm_msr 601 13.7 91
kvm_hv_timer_state 592 13.5 90
kvm_inj_virq 180 4.1 25
kvm_eoi 180 4.1 25
kvm_pv_eoi 180 4.1 25
kvm_apic_accept_irq 177 4.0 25
kvm_vcpu_wakeup 167 3.8 24
kvm_fpu 120 2.7 19
kvm_halt_poll_ns 112 2.6 18
kvm_page_fault 60 1.4 9
kvm_emulate_insn 60 1.4 9
vcpu_match_mmio 60 1.4 9
kvm_userspace_exit 60 1.4 9
kvm_msi_set_irq 60 1.4 9
kvm_mmio 60 1.4 9
kvm_apic 18 0.4 2
kvm_apic_ipi 9 0.2 1
Total 4374 651
# 输入q退出

9.7 分析虚拟机性能指标

使用性能度量来查看在代码中产生大量开销的函数,确定多余开销发生在哪里是优化性能的起点。要分析客户虚拟机的性能指标,请将两个客户设备文件的内容复制到主机。

直接处理设备文件将导致零长度文件,不提供任何信息。因此,要复制这些文件的内容,请将输出重定向到临时文件,然后再将这些文件传输到主机进行分析。

[student@workstation ~]$ cat /proc/modules > /tmp/modules
[student@workstation ~]$ cat /proc/kallsyms > /tmp/kallsyms
[root@foundation0 ~]# scp root@workstation:/tmp/modules guest-modules
[root@foundation0 ~]# scp root@workstation:/tmp/kallsyms guest-kallsyms
[root@foundation0 ~]# ls | grep gu
guest-kallsyms
guest-modules

使用perf kvm record命令记录两个文件中的事件

[root@foundation0 ~]# yum -y install perf
[root@foundation0 ~]# perf kvm --guest --guestmodules=guest-modules \\
> --guestkallsyms=guest-kallsyms record -a

将记录事件输出到文件中

tomcat学习笔记Tomcat性能优化

tomcat学习笔记Tomcat性能优化

JVM性能调优与底层原理分析(学习笔记)

《Java性能调优》学习笔记

关于Linux性能调优中系统CPU监测信息统计的一些笔记

关于Linux性能调优中系统CPU监测信息统计的一些笔记