0%

Linux查看物理CPU个数、核数、逻辑CPU个数

查看Linux的CPU信息

可以通过命令lscpu来查看

lscpu用于显示CPU的相关信息,该命令主要从sysfs和/proc/cpuinfo收集CPU体系结构信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
$ lscpu
Architecture: x86_64 # 架构
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 16 # 逻辑CPU颗数
On-line CPU(s) list: 0-15
Thread(s) per core: 2 # 每个核的线程
Core(s) per socket: 4 # 每个CPU插槽的核数
Socket(s): 2 # CPU的插槽数
NUMA node(s): 2
Vendor ID: GenuineIntel # CPU厂商ID
CPU family: 6 # CPU系列
Model: 85 # 型号
Model name: Intel(R) Xeon(R) Gold 5222 CPU @ 3.80GHz
Stepping: 7 # 步进
CPU MHz: 3538.279 # CPU主频
CPU max MHz: 3900.0000
CPU min MHz: 1200.0000
BogoMIPS: 7600.00
Virtualization: VT-x # CPU支持的虚拟化技术
L1d cache: 32K # 一级缓存
L1i cache: 32K # 一级缓存
L2 cache: 1024K # 二级缓存
L3 cache: 16896K # 三级缓存
NUMA node0 CPU(s): 0,2,4,6,8,10,12,14 # Nom-Uniform Memeory Access(NUMA)
NUMA node1 CPU(s): 1,3,5,7,9,11,13,15
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 cdp_l3 invpcid_single intel_ppin ssbd mba ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm mpx rdt_a avx512f avx512dq rdseed adx smap clflushopt clwb intel_pt avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts pku ospke avx512_vnni md_clear flush_l1d arch_capabilities

可以加上参数-p来获取比较容易解析的输出

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
$ 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,,L1d,L1i,L2,L3
0,0,0,0,,0,0,0,0
1,1,1,1,,1,1,1,1
2,2,0,0,,2,2,2,0
3,3,1,1,,3,3,3,1
4,4,0,0,,4,4,4,0
5,5,1,1,,5,5,5,1
6,6,0,0,,6,6,6,0
7,7,1,1,,7,7,7,1
8,0,0,0,,0,0,0,0
9,1,1,1,,1,1,1,1
10,2,0,0,,2,2,2,0
11,3,1,1,,3,3,3,1
12,4,0,0,,4,4,4,0
13,5,1,1,,5,5,5,1
14,6,0,0,,6,6,6,0
15,7,1,1,,7,7,7,1

或者直接读取/proc/cpuinfo文件

1
2
3
4
5
6
7
8
9
10
11
# 总核数 = 物理CPU个数 X 每颗物理CPU的核数
# 总逻辑CPU数 = 物理CPU个数 X 每颗物理CPU的核数 X 超线程数

# 查看物理CPU个数
cat /proc/cpuinfo| grep "physical id"| sort| uniq| wc -l

# 查看每个物理CPU中core的个数(即核数)
cat /proc/cpuinfo| grep "cpu cores"| uniq

# 查看逻辑CPU的个数
cat /proc/cpuinfo| grep "processor"| wc -l

kswapd often uses 100% CPU when swap is in use

如果此时的Mem并没有用很多的话,可能需要执行下面的命令来强制关闭:

1
2
$ killall -9 kswapd
$ echo 1 > /proc/sys/vm/drop_caches
处无为之事,行不言之教;作而弗始,生而弗有,为而弗恃,功成不居!

欢迎关注我的其它发布渠道