1 - CPU命令

Linux CPU相关的命令

1.1 - lscpu命令

查询 cpu 信息

1.1.1 - lscpu命令的案例

收集一些lscpu命令的案例

Intel Core

Intel Core i7-13700K

lscpu   
Architecture:            x86_64
  CPU op-mode(s):        32-bit, 64-bit
  Address sizes:         46 bits physical, 48 bits virtual
  Byte Order:            Little Endian
CPU(s):                  24
  On-line CPU(s) list:   0-23
Vendor ID:               GenuineIntel
  Model name:            13th Gen Intel(R) Core(TM) i7-13700K
    CPU family:          6
    Model:               183
    Thread(s) per core:  2
    Core(s) per socket:  16
    Socket(s):           1
    Stepping:            1
    CPU max MHz:         5700.0000
    CPU min MHz:         800.0000
    BogoMIPS:            6835.20
    Flags:               fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fx
                         sr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts re
                         p_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor 
                         ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm sse4_1 sse4_2 x2apic movbe popcnt tsc_dead
                         line_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb ssbd ibrs ibpb s
                         tibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 s
                         mep bmi2 erms invpcid rdseed adx smap clflushopt clwb intel_pt sha_ni xsaveopt xsavec xgetbv1 x
                         saves split_lock_detect avx_vnni dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp 
                         hwp_pkg_req umip pku ospke waitpkg gfni vaes vpclmulqdq tme rdpid movdiri movdir64b fsrm md_cle
                         ar serialize pconfig arch_lbr flush_l1d arch_capabilities
Virtualization features: 
  Virtualization:        VT-x
Caches (sum of all):     
  L1d:                   640 KiB (16 instances)
  L1i:                   768 KiB (16 instances)
  L2:                    24 MiB (10 instances)
  L3:                    30 MiB (1 instance)
NUMA:                    
  NUMA node(s):          1
  NUMA node0 CPU(s):     0-23
Vulnerabilities:         
  Itlb multihit:         Not affected
  L1tf:                  Not affected
  Mds:                   Not affected
  Meltdown:              Not affected
  Mmio stale data:       Not affected
  Retbleed:              Not affected
  Spec store bypass:     Mitigation; Speculative Store Bypass disabled via prctl and seccomp
  Spectre v1:            Mitigation; usercopy/swapgs barriers and __user pointer sanitization
  Spectre v2:            Mitigation; Enhanced IBRS, IBPB conditional, RSB filling, PBRSB-eIBRS SW sequence
  Srbds:                 Not affected
  Tsx async abort:       Not affected

频率情况:

lscpu -e
CPU NODE SOCKET CORE L1d:L1i:L2:L3 ONLINE    MAXMHZ   MINMHZ      MHZ
  0    0      0    0 0:0:0:0          yes 5300.0000 800.0000 1598.945
  1    0      0    0 0:0:0:0          yes 5300.0000 800.0000 3400.000
  2    0      0    1 4:4:1:0          yes 5300.0000 800.0000 3400.000
  3    0      0    1 4:4:1:0          yes 5300.0000 800.0000 3400.000
  4    0      0    2 8:8:2:0          yes 5300.0000 800.0000 1056.193
  5    0      0    2 8:8:2:0          yes 5300.0000 800.0000 3400.000
  6    0      0    3 12:12:3:0        yes 5300.0000 800.0000 3400.000
  7    0      0    3 12:12:3:0        yes 5300.0000 800.0000 3400.000
  8    0      0    4 16:16:4:0        yes 5400.0000 800.0000 3400.000
  9    0      0    4 16:16:4:0        yes 5700.0000 800.0000 3400.000
 10    0      0    5 20:20:5:0        yes 5700.0000 800.0000 3400.000
 11    0      0    5 20:20:5:0        yes 5700.0000 800.0000 3400.000
 12    0      0    6 24:24:6:0        yes 5700.0000 800.0000 3400.000
 13    0      0    6 24:24:6:0        yes 5700.0000 800.0000 3400.000
 14    0      0    7 28:28:7:0        yes 5700.0000 800.0000 3400.000
 15    0      0    7 28:28:7:0        yes 5700.0000 800.0000 3400.000
 16    0      0    8 32:32:8:0        yes 4200.0000 800.0000 3400.000
 17    0      0    9 33:33:8:0        yes 4200.0000 800.0000 3400.000
 18    0      0   10 34:34:8:0        yes 4200.0000 800.0000 3400.000
 19    0      0   11 35:35:8:0        yes 4200.0000 800.0000 3400.000
 20    0      0   12 36:36:9:0        yes 4200.0000 800.0000 3400.000
 21    0      0   13 37:37:9:0        yes 4200.0000 800.0000 3400.000
 22    0      0   14 38:38:9:0        yes 4200.0000 800.0000 3400.000
 23    0      0   15 39:39:9:0        yes 4200.0000 800.0000 3400.000

Intel Core i5-12400

$ lscpu

Architecture:            x86_64
  CPU op-mode(s):        32-bit, 64-bit
  Address sizes:         39 bits physical, 48 bits virtual
  Byte Order:            Little Endian
CPU(s):                  12
  On-line CPU(s) list:   0-11
Vendor ID:               GenuineIntel
  BIOS Vendor ID:        Intel(R) Corporation
  Model name:            12th Gen Intel(R) Core(TM) i5-12400
    BIOS Model name:     12th Gen Intel(R) Core(TM) i5-12400 To Be Filled By O.E.M. CPU @ 2.4GHz
    BIOS CPU family:     205
    CPU family:          6
    Model:               151
    Thread(s) per core:  2
    Core(s) per socket:  6
    Socket(s):           1
    Stepping:            5
    Frequency boost:     enabled
    CPU(s) scaling MHz:  32%
    CPU max MHz:         2501.0000
    CPU min MHz:         800.0000
    BogoMIPS:            4992.00
    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 tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx 
                         est tm2 ssse3 sdbg fma cx16 xtpr pdcm sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid
                         _fault epb cat_l2 cdp_l2 ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erm
                         s invpcid rdt_a rdseed adx smap clflushopt clwb intel_pt sha_ni xsaveopt xsavec xgetbv1 xsaves split_lock_detect avx_vnni dtherm ida arat pln pts hw
                         p hwp_notify hwp_act_window hwp_epp hwp_pkg_req hfi umip pku ospke waitpkg gfni vaes vpclmulqdq rdpid movdiri movdir64b fsrm md_clear serialize arch
                         _lbr ibt flush_l1d arch_capabilities
Virtualization features: 
  Virtualization:        VT-x
Caches (sum of all):     
  L1d:                   288 KiB (6 instances)
  L1i:                   192 KiB (6 instances)
  L2:                    7.5 MiB (6 instances)
  L3:                    18 MiB (1 instance)
NUMA:                    
  NUMA node(s):          1
  NUMA node0 CPU(s):     0-11
Vulnerabilities:         
  Itlb multihit:         Not affected
  L1tf:                  Not affected
  Mds:                   Not affected
  Meltdown:              Not affected
  Mmio stale data:       Not affected
  Retbleed:              Not affected
  Spec store bypass:     Mitigation; Speculative Store Bypass disabled via prctl
  Spectre v1:            Mitigation; usercopy/swapgs barriers and __user pointer sanitization
  Spectre v2:            Mitigation; Enhanced IBRS, IBPB conditional, RSB filling, PBRSB-eIBRS SW sequence
  Srbds:                 Not affected
  Tsx async abort:       Not affected

频率情况:

lscpu -e
CPU NODE SOCKET CORE L1d:L1i:L2:L3 ONLINE    MAXMHZ   MINMHZ      MHZ
  0    0      0    0 0:0:0:0          yes 2501.0000 800.0000 800.0070
  1    0      0    0 0:0:0:0          yes 2501.0000 800.0000 800.0000
  2    0      0    1 1:1:1:0          yes 2501.0000 800.0000 800.0000
  3    0      0    1 1:1:1:0          yes 2501.0000 800.0000 800.0550
  4    0      0    2 2:2:2:0          yes 2501.0000 800.0000 800.0000
  5    0      0    2 2:2:2:0          yes 2501.0000 800.0000 800.0000
  6    0      0    3 3:3:3:0          yes 2501.0000 800.0000 800.0000
  7    0      0    3 3:3:3:0          yes 2501.0000 800.0000 800.0000
  8    0      0    4 4:4:4:0          yes 2501.0000 800.0000 800.0000
  9    0      0    4 4:4:4:0          yes 2501.0000 800.0000 800.0000
 10    0      0    5 5:5:5:0          yes 2501.0000 800.0000 800.0000
 11    0      0    5 5:5:5:0          yes 2501.0000 800.0000 800.1110

Intel Xeon

Intel Xeon E5-2630L v3

$ lscpu

Architecture:                    x86_64
CPU op-mode(s):                  32-bit, 64-bit
Byte Order:                      Little Endian
Address sizes:                   46 bits physical, 48 bits virtual
CPU(s):                          16
On-line CPU(s) list:             0-15
Thread(s) per core:              2
Core(s) per socket:              8
Socket(s):                       1
NUMA node(s):                    1
Vendor ID:                       GenuineIntel
CPU family:                      6
Model:                           63
Model name:                      Intel(R) Xeon(R) CPU E5-2630L v3 @ 1.80GHz
Stepping:                        2
CPU MHz:                         1199.975
CPU max MHz:                     2900.0000
CPU min MHz:                     1200.0000
BogoMIPS:                        3599.72
Virtualization:                  VT-x
L1d cache:                       256 KiB
L1i cache:                       256 KiB
L2 cache:                        2 MiB
L3 cache:                        20 MiB
NUMA node0 CPU(s):               0-15
Vulnerability Itlb multihit:     KVM: Mitigation: Split huge pages
Vulnerability L1tf:              Mitigation; PTE Inversion; VMX conditional cache flushes, SMT vulnerable
Vulnerability Mds:               Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Meltdown:          Mitigation; PTI
Vulnerability Mmio stale data:   Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Retbleed:          Not affected
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl and seccomp
Vulnerability Spectre v1:        Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:        Mitigation; Retpolines, IBPB conditional, IBRS_FW, STIBP conditional, RSB filling, PBRSB-eIBRS Not affected
Vulnerability Srbds:             Not affected
Vulnerability Tsx async abort:   Not affected
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 r
                                 dtscp lm constant_tsc 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 c
                                 puid_fault epb invpcid_single pti intel_ppin ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2
                                  smep bmi2 erms invpcid cqm xsaveopt cqm_llc cqm_occup_llc dtherm ida arat pln pts md_clear flush_l1d

频率情况:

 lscpu -e    
CPU NODE SOCKET CORE L1d:L1i:L2:L3 ONLINE    MAXMHZ    MINMHZ
  0    0      0    0 0:0:0:0          yes 2900.0000 1200.0000
  1    0      0    1 1:1:1:0          yes 2900.0000 1200.0000
  2    0      0    2 2:2:2:0          yes 2900.0000 1200.0000
  3    0      0    3 3:3:3:0          yes 2900.0000 1200.0000
  4    0      0    4 4:4:4:0          yes 2900.0000 1200.0000
  5    0      0    5 5:5:5:0          yes 2900.0000 1200.0000
  6    0      0    6 6:6:6:0          yes 2900.0000 1200.0000
  7    0      0    7 7:7:7:0          yes 2900.0000 1200.0000
  8    0      0    0 0:0:0:0          yes 2900.0000 1200.0000
  9    0      0    1 1:1:1:0          yes 2900.0000 1200.0000
 10    0      0    2 2:2:2:0          yes 2900.0000 1200.0000
 11    0      0    3 3:3:3:0          yes 2900.0000 1200.0000
 12    0      0    4 4:4:4:0          yes 2900.0000 1200.0000
 13    0      0    5 5:5:5:0          yes 2900.0000 1200.0000
 14    0      0    6 6:6:6:0          yes 2900.0000 1200.0000
 15    0      0    7 7:7:7:0          yes 2900.0000 1200.0000

Intel Xeon E5-2698B v3 (双路)

$ lscpu

Architecture:            x86_64
  CPU op-mode(s):        32-bit, 64-bit
  Address sizes:         46 bits physical, 48 bits virtual
  Byte Order:            Little Endian
CPU(s):                  64
  On-line CPU(s) list:   0-63
Vendor ID:               GenuineIntel
  BIOS Vendor ID:        Intel
  Model name:            Intel(R) Xeon(R) CPU E5-2698B v3 @ 2.00GHz
    BIOS Model name:     Intel(R) Xeon(R) CPU E5-2698B v3 @ 2.00GHz  CPU @ 2.0GHz
    BIOS CPU family:     179
    CPU family:          6
    Model:               63
    Thread(s) per core:  2
    Core(s) per socket:  16
    Socket(s):           2
    Stepping:            2
    Frequency boost:     enabled
    CPU(s) scaling MHz:  60%
    CPU max MHz:         2001.0000
    CPU min MHz:         1200.0000
    BogoMIPS:            3990.62
    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 arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 s
                         dbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm cpuid_fault epb invpcid_s
                         ingle pti intel_ppin ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm xsav
                         eopt cqm_llc cqm_occup_llc dtherm ida arat pln pts md_clear flush_l1d
Virtualization features: 
  Virtualization:        VT-x
Caches (sum of all):     
  L1d:                   1 MiB (32 instances)
  L1i:                   1 MiB (32 instances)
  L2:                    8 MiB (32 instances)
  L3:                    80 MiB (2 instances)
NUMA:                    
  NUMA node(s):          2
  NUMA node0 CPU(s):     0-15,32-47
  NUMA node1 CPU(s):     16-31,48-63
Vulnerabilities:         
  Itlb multihit:         KVM: Mitigation: VMX disabled
  L1tf:                  Mitigation; PTE Inversion; VMX conditional cache flushes, SMT vulnerable
  Mds:                   Mitigation; Clear CPU buffers; SMT vulnerable
  Meltdown:              Mitigation; PTI
  Mmio stale data:       Mitigation; Clear CPU buffers; SMT vulnerable
  Retbleed:              Not affected
  Spec store bypass:     Mitigation; Speculative Store Bypass disabled via prctl
  Spectre v1:            Mitigation; usercopy/swapgs barriers and __user pointer sanitization
  Spectre v2:            Mitigation; Retpolines, IBPB conditional, IBRS_FW, STIBP conditional, RSB filling, PBRSB-eIBRS Not affected
  Srbds:                 Not affected
  Tsx async abort:       Not affected

频率情况:

lscpu -e         
CPU NODE SOCKET CORE L1d:L1i:L2:L3 ONLINE    MAXMHZ    MINMHZ       MHZ
  0    0      0    0 0:0:0:0          yes 2001.0000 1200.0000 1200.0000
  1    0      0    1 1:1:1:0          yes 2001.0000 1200.0000 1197.1820
  2    0      0    2 2:2:2:0          yes 2001.0000 1200.0000 1200.0000
  3    0      0    3 3:3:3:0          yes 2001.0000 1200.0000 1200.0000
  4    0      0    4 4:4:4:0          yes 2001.0000 1200.0000 1200.0000
  5    0      0    5 5:5:5:0          yes 2001.0000 1200.0000 1197.3110
  6    0      0    6 6:6:6:0          yes 2001.0000 1200.0000 1200.0000
  7    0      0    7 7:7:7:0          yes 2001.0000 1200.0000 1200.0000
  8    0      0    8 8:8:8:0          yes 2001.0000 1200.0000 1200.0000
  9    0      0    9 9:9:9:0          yes 2001.0000 1200.0000 1200.0000
 10    0      0   10 10:10:10:0       yes 2001.0000 1200.0000 1200.0000
 11    0      0   11 11:11:11:0       yes 2001.0000 1200.0000 1200.0000
 12    0      0   12 12:12:12:0       yes 2001.0000 1200.0000 1200.0000
 13    0      0   13 13:13:13:0       yes 2001.0000 1200.0000 1200.0000
 14    0      0   14 14:14:14:0       yes 2001.0000 1200.0000 1200.0000
 15    0      0   15 15:15:15:0       yes 2001.0000 1200.0000 1200.0000
 16    1      1   16 16:16:16:1       yes 2001.0000 1200.0000 1200.0000
 17    1      1   17 17:17:17:1       yes 2001.0000 1200.0000 1200.0000
 18    1      1   18 18:18:18:1       yes 2001.0000 1200.0000 1200.0000
 19    1      1   19 19:19:19:1       yes 2001.0000 1200.0000 1200.0000
 20    1      1   20 20:20:20:1       yes 2001.0000 1200.0000 1200.0000
 21    1      1   21 21:21:21:1       yes 2001.0000 1200.0000 1200.0000
 22    1      1   22 22:22:22:1       yes 2001.0000 1200.0000 1200.0000
 23    1      1   23 23:23:23:1       yes 2001.0000 1200.0000 1200.0000
 24    1      1   24 24:24:24:1       yes 2001.0000 1200.0000 1200.0000
 25    1      1   25 25:25:25:1       yes 2001.0000 1200.0000 1200.0000
 26    1      1   26 26:26:26:1       yes 2001.0000 1200.0000 1200.0000
 27    1      1   27 27:27:27:1       yes 2001.0000 1200.0000 1200.0000
 28    1      1   28 28:28:28:1       yes 2001.0000 1200.0000 1202.1851
 29    1      1   29 29:29:29:1       yes 2001.0000 1200.0000 1197.1851
 30    1      1   30 30:30:30:1       yes 2001.0000 1200.0000 1201.3190
 31    1      1   31 31:31:31:1       yes 2001.0000 1200.0000 1195.7460
 32    0      0    0 0:0:0:0          yes 2001.0000 1200.0000 1200.0000
 33    0      0    1 1:1:1:0          yes 2001.0000 1200.0000 1200.0000
 34    0      0    2 2:2:2:0          yes 2001.0000 1200.0000 1200.0000
 35    0      0    3 3:3:3:0          yes 2001.0000 1200.0000 1200.0000
 36    0      0    4 4:4:4:0          yes 2001.0000 1200.0000 1200.0000
 37    0      0    5 5:5:5:0          yes 2001.0000 1200.0000 1200.0000
 38    0      0    6 6:6:6:0          yes 2001.0000 1200.0000 1200.0000
 39    0      0    7 7:7:7:0          yes 2001.0000 1200.0000 1200.0000
 40    0      0    8 8:8:8:0          yes 2001.0000 1200.0000 1200.0000
 41    0      0    9 9:9:9:0          yes 2001.0000 1200.0000 1200.0000
 42    0      0   10 10:10:10:0       yes 2001.0000 1200.0000 1200.0000
 43    0      0   11 11:11:11:0       yes 2001.0000 1200.0000 1200.0000
 44    0      0   12 12:12:12:0       yes 2001.0000 1200.0000 1200.0000
 45    0      0   13 13:13:13:0       yes 2001.0000 1200.0000 1200.0000
 46    0      0   14 14:14:14:0       yes 2001.0000 1200.0000 1200.0000
 47    0      0   15 15:15:15:0       yes 2001.0000 1200.0000 1200.0000
 48    1      1   16 16:16:16:1       yes 2001.0000 1200.0000 1387.6670
 49    1      1   17 17:17:17:1       yes 2001.0000 1200.0000 1200.0000
 50    1      1   18 18:18:18:1       yes 2001.0000 1200.0000 1200.0000
 51    1      1   19 19:19:19:1       yes 2001.0000 1200.0000 1200.0000
 52    1      1   20 20:20:20:1       yes 2001.0000 1200.0000 1200.0000
 53    1      1   21 21:21:21:1       yes 2001.0000 1200.0000 1200.0000
 54    1      1   22 22:22:22:1       yes 2001.0000 1200.0000 1200.0000
 55    1      1   23 23:23:23:1       yes 2001.0000 1200.0000 1200.0000
 56    1      1   24 24:24:24:1       yes 2001.0000 1200.0000 1200.0000
 57    1      1   25 25:25:25:1       yes 2001.0000 1200.0000 1200.0000
 58    1      1   26 26:26:26:1       yes 2001.0000 1200.0000 1200.0000
 59    1      1   27 27:27:27:1       yes 2001.0000 1200.0000 1200.0000
 60    1      1   28 28:28:28:1       yes 2001.0000 1200.0000 1200.0000
 61    1      1   29 29:29:29:1       yes 2001.0000 1200.0000 1200.0000
 62    1      1   30 30:30:30:1       yes 2001.0000 1200.0000 1200.0000
 63    1      1   31 31:31:31:1       yes 2001.0000 1200.0000 1200.0000

2 - 内存命令

Linux 内存相关的命令

3 - 硬盘命令

Linux 硬盘相关的命令

3.1 - fdisk命令

Linux fdisk 命令

查看分区情况

sudo fdisk -l

输出类似,这里有两块sdd硬盘:

Disk /dev/nvme1n1: 465.78 GiB, 500107862016 bytes, 976773168 sectors
Disk model: WDC WDS500G1B0C-00S6U0                  
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: AB8D3D88-0124-404E-B1BC-658E567C569D

Device             Start       End   Sectors  Size Type
/dev/nvme1n1p1      2048   1050623   1048576  512M EFI System
/dev/nvme1n1p2   1050624 839911423 838860800  400G Linux filesystem
/dev/nvme1n1p3 839911424 976771071 136859648 65.3G Linux filesystem


Disk /dev/nvme0n1: 3.74 TiB, 4096805658624 bytes, 8001573552 sectors
Disk model: YSSDHB-4TN7000                          
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

对硬盘进行分区

通过 fdisk -l 命令找到要进行分区的硬盘,比如这里是 /dev/nvme0n1

sudo fdisk /dev/nvme0n1

如果硬盘没有分区表,则会提示:

Device does not contain a recognized partition table.
The size of this disk is 3.7 TiB (4096805658624 bytes). DOS partition table format cannot be used on drives for volumes larger than 2199023255040 bytes for 512-byte sectors. Use GUID partition table format (GPT).

Created a new DOS disklabel with disk identifier 0x55c9e168.

Command (m for help):

推荐使用 GPT 分区。

之后输入 m 可以得到帮助菜单:

Command (m for help): m

Help:

  DOS (MBR)
   a   toggle a bootable flag
   b   edit nested BSD disklabel
   c   toggle the dos compatibility flag

  Generic
   d   delete a partition
   F   list free unpartitioned space
   l   list known partition types
   n   add a new partition
   p   print the partition table
   t   change a partition type
   v   verify the partition table
   i   print information about a partition

  Misc
   m   print this menu
   u   change display/entry units
   x   extra functionality (experts only)

  Script
   I   load disk layout from sfdisk script file
   O   dump disk layout to sfdisk script file

  Save & Exit
   w   write table to disk and exit
   q   quit without saving changes

  Create a new label
   g   create a new empty GPT partition table
   G   create a new empty SGI (IRIX) partition table
   o   create a new empty DOS partition table
   s   create a new empty Sun partition table

这里首先输入 g 来创建 GPT 分区表:

Command (m for help): g
Created a new GPT disklabel (GUID: DA503D82-D785-4A47-A701-504DB1ED256C).

然后输入 n 来创建新的分区,这里简单起见,将整个硬盘作为一个单个分区 3.7T:

Command (m for help): n
Partition number (1-128, default 1): 1
First sector (2048-8001573518, default 2048): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-8001573518, default 8001573518): 

Created a new partition 1 of type 'Linux filesystem' and of size 3.7 TiB.

输入 w 写入硬盘并退出:

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

分区完成之后检查硬盘:

sudo fdisk -l 

Disk /dev/nvme1n1: 465.78 GiB, 500107862016 bytes, 976773168 sectors
Disk model: WDC WDS500G1B0C-00S6U0                  
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: AB8D3D88-0124-404E-B1BC-658E567C569D

Device             Start       End   Sectors  Size Type
/dev/nvme1n1p1      2048   1050623   1048576  512M EFI System
/dev/nvme1n1p2   1050624 839911423 838860800  400G Linux filesystem
/dev/nvme1n1p3 839911424 976771071 136859648 65.3G Linux filesystem


Disk /dev/nvme0n1: 3.74 TiB, 4096805658624 bytes, 8001573552 sectors
Disk model: YSSDHB-4TN7000                          
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: DA503D82-D785-4A47-A701-504DB1ED256C

Device         Start        End    Sectors  Size Type
/dev/nvme0n1p1  2048 8001573518 8001571471  3.7T Linux filesystem

后续操作

格式化

再对分区进行格式化,这里采用 ext4 格式:

sudo mkfs.ext4 /dev/nvme0n1p1

➜  ~ sudo mkfs.ext4 /dev/nvme0n1p1
mke2fs 1.45.5 (07-Jan-2020)
Discarding device blocks: done                            
Creating filesystem with 1000196433 4k blocks and 250052608 inodes
Filesystem UUID: 0478bcae-bab0-4762-a48a-6bdab9d99d5b
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
	4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
	102400000, 214990848, 512000000, 550731776, 644972544

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information: done 

挂载

通过

lsblk --fs

命令查看分区的 UUID 备用:


NAME        FSTYPE   LABEL UUID                                 FSAVAIL FSUSE% MOUNTPOINT
nvme1n1                                                                        
|-nvme1n1p1 vfat           4FD8-D561                             504.9M     1% /boot/efi
|-nvme1n1p2 ext4           7a60bb3b-ea82-47c0-86d0-f92edba2a466  356.4G     4% /
`-nvme1n1p3 ext4           68100d98-ccea-4f5e-8663-16ff1b194ac1   52.7G    12% /timeshift
nvme0n1                                                                        
`-nvme0n1p1 ext4           0478bcae-bab0-4762-a48a-6bdab9d99d5b  

执行

sudo vi /etc/fstab

可以看到:

# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/nvme0n1p2 during curtin installation
/dev/disk/by-uuid/7a60bb3b-ea82-47c0-86d0-f92edba2a466 / ext4 defaults 0 1
# /timeshift was on /dev/nvme0n1p3 during curtin installation
/dev/disk/by-uuid/68100d98-ccea-4f5e-8663-16ff1b194ac1 /timeshift ext4 defaults 0 1
# /boot/efi was on /dev/nvme0n1p1 during curtin installation
/dev/disk/by-uuid/4FD8-D561 /boot/efi vfat defaults 0 1

类似的增加一行记录

/dev/disk/by-uuid/0478bcae-bab0-4762-a48a-6bdab9d99d5b /data ext4 defaults 0 1

注意需要提前创建挂载的目录

sudo mkdir /data

保存后,重启或者执行 sudo mount -a 生效。

3.2 - dd命令

Linux dd 命令

3.2.1 - dd命令介绍

Linux dd 命令介绍

介绍

使用

测试硬盘读取速度

dd if=/dev/zero of=/tmp/test1.img bs=1G count=1 oflag=dsync

dd if=/dev/zero of=/root/temp/test1.img bs=10G count=1 oflag=dsync

参考资料

3.2.2 - 三星pm983测试数据

三星pm983测试数据

硬盘型号 三星 pm983,容量 900G, m2 接口 nvme 协议, pcie 3.0 x4, 规格为 22110。

华硕z690

主板为华硕 z690-p d4, m2 接口 pcie 4.0 x4,受硬盘限制实际为 pcie 3.0 x4。

安装 pve 8.0 系统,6.2 内核。

基本信息

$ lspci | grep SSD 

08:00.0 Non-Volatile memory controller: Samsung Electronics Co Ltd NVMe SSD Controller SM981/PM981/PM983

磁盘数据:

$ fdisk -l

Disk /dev/nvme1n1: 838.36 GiB, 900185481216 bytes, 219771846 sectors
Disk model: MZ1LB960HBJR-000FB                      
Units: sectors of 1 * 4096 = 4096 bytes
Sector size (logical/physical): 4096 bytes / 4096 bytes
I/O size (minimum/optimal): 131072 bytes / 131072 bytes
Disklabel type: gpt
Disk identifier: 87408245-67E3-47E0-AF90-85B8DDDAD75D

Device             Start       End   Sectors   Size Type
/dev/nvme1n1p1 193462528 219771647  26309120 100.4G Linux filesystem
/dev/nvme1n1p2       256    262399    262144     1G EFI System
/dev/nvme1n1p3    262400 193462272 193199873   737G Linux LVM

分区信息:

$ hdparm /dev/nvme1n1p3

/dev/nvme1n1p3:
 readonly      =  0 (off)
 readahead     = 512 (on)
 geometry      = 754687/64/32, sectors = 1545598984, start = 2099200

速度测试

硬盘写入速度:

$ dd if=/dev/zero of=/root/temp/test1.img bs=1G count=10 oflag=dsync

10+0 records in
10+0 records out
10737418240 bytes (11 GB, 10 GiB) copied, 14.4349 s, 744 MB/s

只有 744 兆,低的有点出乎意外,应该是缓存耗尽。

硬盘读取速度:

dd if=/root/temp/test1.img of=/dev/null bs=8k

对比

hdparm -tT /dev/nvme1n1p3

/dev/nvme1n1p3:
 Timing cached reads:   32260 MB in  2.00 seconds = 16152.14 MB/sec
 Timing buffered disk reads: 5074 MB in  3.00 seconds = 1691.16 MB/sec

参考资料

3.2.3 - 爱国者p7000z测试数据

爱国者p7000z 测试数据

硬盘型号 爱国者p7000z,容量 4T , m2 接口 nvme 协议, pcie 4.0 x4, 规格为 2280。

华硕z690 + pve 8

主板为华硕 z690-p d4, m2 接口 pcie 4.0 x4。

安装 ubuntu 20.04 系统,5.4 内核, ext4 格式。

基本信息

$ lspci | grep Volatile

02:00.0 Non-Volatile memory controller: Device 1e4b:1602 (rev 01)

磁盘数据:

$ sudo fdisk -l

Disk /dev/nvme0n1: 3.74 TiB, 4096805658624 bytes, 8001573552 sectors
Disk model: aigo NVMe SSD P7000Z 4TB
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: EE02EE97-D530-4107-9D83-6A15532005BA

Device              Start        End    Sectors  Size Type
/dev/nvme0n1p1       2048    1050623    1048576  512M EFI System
/dev/nvme0n1p2    1050624 1074792447 1073741824  512G Linux filesystem
/dev/nvme0n1p3 1074792448 1179650047  104857600   50G Linux filesystem
/dev/nvme0n1p4 1179650048 8001570815 6821920768  3.2T Linux filesystem

测试分区为 nvme0n1p4,分区信息:

$ sudo hdparm /dev/nvme0n1p4

/dev/nvme0n1p4:
 HDIO_DRIVE_CMD(identify) failed: Inappropriate ioctl for device
 readonly      =  0 (off)
 readahead     = 256 (on)
 HDIO_DRIVE_CMD(identify) failed: Inappropriate ioctl for device
 geometry      = 3331016/64/32, sectors = 6821920768, start = 1179650048

速度测试

硬盘写入速度:

$ dd if=/dev/zero of=/mnt/data/share/temp/test1.img bs=1G count=10 oflag=dsync

10+0 records in
10+0 records out
10737418240 bytes (11 GB, 10 GiB) copied, 5.96539 s, 1.8 GB/s

只有 1.4 GB,有点低的,p7000z 是 pcie 4.0,按说写入速度应该是5-6GB级别。

持续写入 100G的文件,还是 1.8 GB/秒:

$ dd if=/dev/zero of=/mnt/data/share/temp/test1.img bs=1G count=100 oflag=dsync

100+0 records in
100+0 records out
107374182400 bytes (107 GB, 100 GiB) copied, 60.8423 s, 1.8 GB/s

硬盘读取速度(直接以 8M 的 block size 读取 100GB 大文件):

$ dd if=/mnt/data/share/temp/test1.img of=/dev/null bs=8M
                                             
12800+0 records in
12800+0 records out
107374182400 bytes (107 GB, 100 GiB) copied, 26.7172 s, 4.0 GB/s

4.0GB/s 的速度只能说差强人意,凑合吧。

3.2.4 - 凯侠cd6测试数据

凯侠cd6 测试数据

硬盘信息

硬盘型号 凯侠cd6,容量 3.84T , u2 接口 nvme 协议, pcie 4.0 x4。

windows 下测试的性能数据:

as-ssd-bench

CrystalDiskMark_20230810091559

华硕z690 + ubuntu 22.04

主板为华硕 z690-p d4, m2 接口 pcie 4.0 x4 转 u2。

安装 linux lint 操作系统,基于 ubuntu 22.04,5.15 内核。

基本信息

$ lspci | grep SSD 

02:00.0 Non-Volatile memory controller: KIOXIA Corporation NVMe SSD Controller Cx6 (rev 01)

磁盘数据:

sudo fdisk -l
Disk /dev/nvme0n1: 3.49 TiB, 3840755982336 bytes, 7501476528 sectors
Disk model: KCD61LUL3T84                            
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: FBEFBE02-9843-4FEC-8B2C-C50B5EAD8069

Device              Start        End    Sectors   Size Type
/dev/nvme0n1p1       2048     206847     204800   100M EFI System
/dev/nvme0n1p2     206848     239615      32768    16M Microsoft reserved
/dev/nvme0n1p3     239616 1047643943 1047404328 499.4G Microsoft basic data
/dev/nvme0n1p4 1047644160 1048813567    1169408   571M Windows recovery environment
/dev/nvme0n1p5 1048815616 2097391615 1048576000   500G Microsoft basic data
/dev/nvme0n1p6 2097391616 7340271615 5242880000   2.4T Microsoft basic data
/dev/nvme0n1p7 7340271616 7501475839  161204224  76.9G Microsoft basic data

测试两个分区,nvme0n1p5 是 ex4 格式(上面的数据有问题) ,nvme0n1p6 是 ntfs 格式,通过 ntfs-3g 读写。

分区信息:

$ sudo hdparm /dev/nvme0n1p5

/dev/nvme0n1p5:
 readonly      =  0 (off)
 readahead     = 256 (on)
 geometry      = 512000/64/32, sectors = 1048576000, start = 1048815616

$ sudo hdparm /dev/nvme0n1p6

/dev/nvme0n1p6:
 readonly      =  0 (off)
 readahead     = 256 (on)
 geometry      = 2560000/64/32, sectors = 5242880000, start = 2097391616

nvme0n1p5 速度测试

nvme0n1p5 硬盘写入速度:

$ dd if=/dev/zero of=/home/sky/temp/test1.img bs=1G count=10 oflag=dsync

10+0 records in
10+0 records out
10737418240 bytes (11 GB, 10 GiB) copied, 7.69088 s, 1.4 GB/s

只有 1.4 GB,低的有点出乎意外,cd6 是 pcie 4.0,按说写入速度应该是5-6GB级别。

持续写入 100G的性能,还是 1.4 GB/秒:

$ dd if=/dev/zero of=/home/sky/temp/test1.img bs=1G count=100 oflag=dsync

100+0 records in
100+0 records out
107374182400 bytes (107 GB, 100 GiB) copied, 77.9087 s, 1.4 GB/s

nvme0n1p5 硬盘读取速度:

$ dd if=/home/sky/temp/test1.img of=/dev/null bs=8k

1310720+0 records in
1310720+0 records out
10737418240 bytes (11 GB, 10 GiB) copied, 0.681243 s, 15.8 GB/s

15.8 GB 的速度又离谱了,应该是有缓存在。尝试读取 100G 大小:

$ dd if=/home/sky/temp/test1.img of=/dev/null bs=8k
13107200+0 records in
13107200+0 records out
107374182400 bytes (107 GB, 100 GiB) copied, 53.4742 s, 2.0 GB/s

每秒2GB的速度还是有点低,离 pcie 4.0 硬盘的标称速度 6-7 GB差距很大,尝试将 bs (block-size)加大到 8M 继续读取这个 100GB的文件:

$ dd if=/home/sky/temp/test1.img of=/dev/null bs=8M
12800+0 records in
12800+0 records out
107374182400 bytes (107 GB, 100 GiB) copied, 24.9262 s, 4.3 GB/s

4.3 GB/s 就相对比较合理了。

对比

$ sudo hdparm -tT /dev/nvme0n1p5

/dev/nvme0n1p5:
 Timing cached reads:   48164 MB in  2.00 seconds = 24121.05 MB/sec
 Timing buffered disk reads: 7166 MB in  3.00 seconds = 2388.55 MB/sec

nvme0n1p6 速度测试

nvme0n1p6 这个分区是 ntfs 格式。

nvme0n1p6 硬盘写入速度:

$ dd if=/dev/zero of=/media/d/temp/test1.img bs=1G count=10 oflag=dsync

10+0 records in
10+0 records out
10737418240 bytes (11 GB, 10 GiB) copied, 29.3955 s, 365 MB/s

只有 365 兆,低的有点出乎意外,应该是 linux 读写 ntfs 格式有速度问题。

nvme0n1p6 硬盘读取速度:

$ dd if=/media/d/temp/test1.img of=/dev/null bs=8k

1310720+0 records in
1310720+0 records out
10737418240 bytes (11 GB, 10 GiB) copied, 1.91374 s, 5.6 GB/s

5.6GB 的速度有点偏高,估计还是缓存。尝试读取 100 GB大小的文件:

$ dd if=/dev/zero of=/media/d/temp/test1.img bs=1G count=100 oflag=dsync

100+0 records in
100+0 records out
107374182400 bytes (107 GB, 100 GiB) copied, 242.065 s, 444 MB/s

444 MB/s 每秒的速度和前面 ext4 下的 4.3 GB/s 相比,nfts 格式会让磁盘性能下降到 10% ,实在恐怖。所以还是要避免在 linux 下使用 ntfs 格式。

对比

$ sudo hdparm -tT /dev/nvme0n1p6

/dev/nvme0n1p6:
 Timing cached reads:   49004 MB in  2.00 seconds = 24540.33 MB/sec
 Timing buffered disk reads: 7452 MB in  3.00 seconds = 2483.48 MB/sec

2483.48 MB/sec 这个数据完全不真实。

3.2.5 - 西数sn550测试数据

西数 sn550 测试数据

硬盘型号 西数 sn520,容量 500 GB , m2 接口 nvme 协议, pcie 3.0 x4。

技嘉 x99 + ubuntu 20.04

主板为技嘉 x99 ud4 主板, m2 接口 pcie 3.0 x4。但这个主板自带的 m2 接口速度只有 10G,不是正常满血 pcie 3.0 x4 的 32G。

安装 ubuntu 20.04 操作系统,5.4 内核。

基本信息

$ lspci | grep Non-Volatile 

06:00.0 Non-Volatile memory controller: Sandisk Corp WD Black 2018/PC SN520 NVMe SSD (rev 01)

磁盘数据:

$ sudo fdisk -l

Disk /dev/nvme1n1: 465.78 GiB, 500107862016 bytes, 976773168 sectors
Disk model: WDC WDS500G1B0C-00S6U0                  
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: AB8D3D88-0124-404E-B1BC-658E567C569D

Device             Start       End   Sectors  Size Type
/dev/nvme1n1p1      2048   1050623   1048576  512M EFI System
/dev/nvme1n1p2   1050624 839911423 838860800  400G Linux filesystem
/dev/nvme1n1p3 839911424 976771071 136859648 65.3G Linux filesystem

测试分区为 nvme1n1p2,分区信息:

$ sudo hdparm /dev/nvme1n1p2

/dev/nvme1n1p2:
 HDIO_DRIVE_CMD(identify) failed: Inappropriate ioctl for device
 readonly      =  0 (off)
 readahead     = 256 (on)
 HDIO_DRIVE_CMD(identify) failed: Inappropriate ioctl for device
 geometry      = 409600/64/32, sectors = 838860800, start = 1050624

速度测试

硬盘写入速度:

$ dd if=/dev/zero of=/home/sky/temp/test1.img bs=1G count=10 oflag=dsync

10+0 records in
10+0 records out
10737418240 bytes (11 GB, 10 GiB) copied, 23.3803 s, 459 MB/s

只有 459 MB/s,低的有点出乎意外,虽然是块笔记本用的 ssd 硬盘,但这个速度也没比机械硬盘快多少。

持续写入 100G的性能,还是 454 MB/s:

$ dd if=/dev/zero of=/home/sky/temp/test1.img bs=1G count=100 oflag=dsync

100+0 records in
100+0 records out
107374182400 bytes (107 GB, 100 GiB) copied, 236.347 s, 454 MB/s

硬盘读取速度(直接以 8M 的 block size 读取 100GB 大文件):

$ dd if=/home/sky/temp/test1.img of=/dev/null bs=8M

dd if=/home/sky/temp/test1.img of=/dev/null bs=8M
12800+0 records in
12800+0 records out
107374182400 bytes (107 GB, 100 GiB) copied, 131.35 s, 817 MB/s

817 MB/s ,看来这就是这块硬盘的最大速度了,10G 接口对它而言反而不是瓶颈。

对比

$ sudo hdparm -tT /dev/nvme1n1p2

/dev/nvme1n1p2:
 Timing cached reads:   19496 MB in  1.99 seconds = 9792.62 MB/sec
 HDIO_DRIVE_CMD(identify) failed: Inappropriate ioctl for device
 Timing buffered disk reads: 2298 MB in  3.00 seconds = 765.56 MB/sec

765.56 MB/sec 这个数据还比较符合实际测试性能。

总结

这个 sn520 硬盘的性能实在不堪,二手出掉吧。

3.2.6 - 隐速4TN7000测试数据

隐速4TN7000测试数据

硬盘型号 隐速4TN7000,容量 4T , m2 接口 nvme 协议, pcie 4.0 x4, 规格为 2280。

技嘉x99 ud4 + ubuntu server

主板为技嘉x99 ud4, 通过pcie拆分卡得到了一个 m2 接口 pcie 4.0 x4。

安装 ubuntu 20.04 系统,5.4 内核, ext4 格式。

基本信息

$ lspci | grep Volatile

03:00.0 Non-Volatile memory controller: Device 1e4b:1602 (rev 01)

磁盘数据:

$ sudo fdisk -l

Disk /dev/nvme0n1: 3.74 TiB, 4096805658624 bytes, 8001573552 sectors
Disk model: YSSDHB-4TN7000                          
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: DA503D82-D785-4A47-A701-504DB1ED256C

Device         Start        End    Sectors  Size Type
/dev/nvme0n1p1  2048 8001573518 8001571471  3.7T Linux filesystem

测试分区为 nvme0n1p1,分区信息:

$ sudo hdparm /dev/nvme0n1p1

/dev/nvme0n1p1:
 readonly      =  0 (off)
 readahead     = 256 (on)
 geometry      = 3907017/64/32, sectors = 8001571471, start = 2048

速度测试

硬盘写入速度:

$ sudo dd if=/dev/zero of=/data/temp/test1.img bs=1G count=10 oflag=dsync
10+0 records in
10+0 records out
10737418240 bytes (11 GB, 10 GiB) copied, 11.6533 s, 921 MB/s

只有 0.9 GB,低的离谱,虽然主板限制只能跑pcie 3.0 x4 32G的带宽, 但按说写入速度应该是3-4GB级别,就算打折扣也不应该这么低。参考爱国者p7000z的速度是 1.8GB/秒。

读取速度为 6.6GB/S,这个还行,应该是缓存:

$ dd if=/data/temp/test1.img of=/dev/null bs=8M
1280+0 records in
1280+0 records out
10737418240 bytes (11 GB, 10 GiB) copied, 1.62146 s, 6.6 GB/s

持续写入 100G的文件,还是 0.9 GB/秒:

$ sudo dd if=/dev/zero of=/data/temp/test1.img bs=1G count=100 oflag=dsync

100+0 records in
100+0 records out
107374182400 bytes (107 GB, 100 GiB) copied, 118.151 s, 909 MB/s

硬盘读取速度(直接以 8M 的 block size 读取 100GB 大文件):

$ dd if=/data/temp/test1.img of=/dev/null bs=8M                           
12800+0 records in
12800+0 records out
107374182400 bytes (107 GB, 100 GiB) copied, 37.7508 s, 2.8 GB/s

2.8 GB的速度有点低,对比爱国者p7000z 是 4.0GB/s 。

持续写入 1T的文件,还是 0.9 GB/秒,看来缓外速度就真的只有900M了:

$ sudo dd if=/dev/zero of=/data/temp/test-1t.img bs=1G count=1000 oflag=dsync
1000+0 records in
1000+0 records out
1073741824000 bytes (1.1 TB, 1000 GiB) copied, 1221.81 s, 879 MB/s

硬盘读取速度(以 8M 的 block size 读取 1 TB 大文件):

dd if=/data/temp/test-1t.img of=/dev/null bs=8M     
128000+0 records in
128000+0 records out
1073741824000 bytes (1.1 TB, 1000 GiB) copied, 368.641 s, 2.9 GB/s

看来 2.8/2.9G 就是 pcie3 下的无缓存极限速度了。

华硕z690 + windows10

TBD

华硕z690 + ubuntu

TBD

速度参考资料

3.2.7 - 三星980测试数据

三星 980 测试数据

硬盘信息

硬盘型号 三星980,容量 1 T, m2 接口 nvme 协议, pcie 3.0 x4。

三星官方给到980 1TB的参数为:

  • pcie3.0×4,nvme1.4,HMB无缓设计
  • 最大读:3500MB/s
  • 最大写:3000MB/s
  • 最大随读:50W IOPS
  • 最大随写:48W IOPS

相关资料参考:

技嘉 x99 + ubuntu 20.04

主板为技嘉 x99 ud4 主板, m2 接口 pcie 3.0 x4。

安装 ubuntu 20.04 操作系统,5.4 内核。

基本信息

$ lspci | grep Non-Volatile 

03:00.0 Non-Volatile memory controller: Samsung Electronics Co Ltd Device a809

磁盘数据:

$ sudo fdisk -l

Disk /dev/nvme0n1: 931.53 GiB, 1000204886016 bytes, 1953525168 sectors
Disk model: Samsung SSD 980 1TB                     
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 16384 bytes / 131072 bytes
Disklabel type: gpt
Disk identifier: DB6DCF2B-7BCD-4C10-8B72-B95EF2DD634A

Device         Start        End    Sectors   Size Type
/dev/nvme0n1p1  2048 1953525134 1953523087 931.5G Linux filesystem

测试分区为 nvme0n1p1,分区信息:

$ sudo hdparm /dev/nvme0n1p1

/dev/nvme0n1p1:
 HDIO_DRIVE_CMD(identify) failed: Inappropriate ioctl for device
 readonly      =  0 (off)
 readahead     = 256 (on)
 HDIO_DRIVE_CMD(identify) failed: Inappropriate ioctl for device
 geometry      = 953868/64/32, sectors = 1953523087, start = 2048

速度测试

硬盘写入速度:

$ dd if=/dev/zero of=/mnt/data/share/temp/test1.img bs=1G count=10 oflag=dsync

10+0 records in
10+0 records out
10737418240 bytes (11 GB, 10 GiB) copied, 11.9802 s, 896 MB/s

只有 896 MB/s,低的有点出乎意外,这个标称写入速度是3G啊。

持续写入 100G的性能,这次只有 794 MB/s:

$ dd if=/dev/zero of=/mnt/data/share/temp/test1.img bs=1G count=100 oflag=dsync

100+0 records in
100+0 records out
107374182400 bytes (107 GB, 100 GiB) copied, 135.252 s, 794 MB/s

硬盘读取速度(直接以 8M 的 block size 读取 100GB 大文件):

$ dd if=/mnt/data/share/temp/test1.img of=/dev/null bs=8M

12800+0 records in
12800+0 records out
107374182400 bytes (107 GB, 100 GiB) copied, 44.1279 s, 2.4 GB/s

2.4 GB/s ,和宣称的 3G 速度有一点出入,但好在没有离谱。

对比

$ sudo hdparm -tT /dev/nvme0n1p1

/dev/nvme0n1p1:
 Timing cached reads:   20218 MB in  1.99 seconds = 10157.69 MB/sec
 HDIO_DRIVE_CMD(identify) failed: Inappropriate ioctl for device
 Timing buffered disk reads: 5302 MB in  3.00 seconds = 1767.28 MB/sec

1767.28 MB/sec 这个数据比实际测试性能(2.4 GB/s)要小一点。

总结

这个 三星 980 硬盘按说是 pcie3.0 中高端硬盘,宣称的读写性能应该在 3 GB这个级别,接近 pcie3.0 x4 32G 的理论带宽。但实际测试下来,读 2.4 GB/s 勉强还能凑合,写 800M 就差的很远。

3.3 - hdparm命令

Linux hdparm 命令

3.3.1 - hdparm命令

hdparm 命令用于显示与设定硬盘的参数,还可以测试硬盘的读取速度

介绍

在Linux下可以使用hdparm工具查看硬盘的相关信息或对硬盘进行测速、优化、修改硬盘相关参数设定。

安装

一般 ubutu server 都自带 hdparm 命令,如果没有则通过下面的命令安装:

sudo apt install hdparm

更新,如果遇到 HDIO_DRIVE_CMD(identify) failed: Inappropriate ioctl for device 错误:

$ sudo hdparm -tT /dev/nvme0n1p1

/dev/nvme0n1p1:
 Timing cached reads:   20218 MB in  1.99 seconds = 10157.69 MB/sec
 HDIO_DRIVE_CMD(identify) failed: Inappropriate ioctl for device
 Timing buffered disk reads: 5302 MB in  3.00 seconds = 1767.28 MB/sec

则需要更新 hdparm 的版本,一般 apt 安装的版本是 v9.58:

$ hdparm -V
hdparm v9.58

最新版本下载地址: https://sourceforge.net/projects/hdparm/

目前最新的版本是 v9.65,下载完成后执行:

tar xvf hdparm-9.65.tar.gz
cd hdparm-9.65
make
sudo make install

查看新安装的版本:

$ hdparm -V
hdparm v9.65

这个时候就不会再出现 HDIO_DRIVE_CMD(identify) failed: Inappropriate ioctl for device 的报错了。

实践案例

查看硬盘的相关设置

sudo hdparm /dev/sdb1

输出为:

/dev/sdb1:
SG_IO: bad/missing sense data, sb[]:  70 00 05 00 00 00 00 0a 00 00 00 00 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 multcount     =  0 (off)
 readonly      =  0 (off)
 readahead     = 256 (on)
 geometry      = 401023/255/63, sectors = 6442448863, start = 2048

其中 geometry 的参数解释为:

geometry = 401023[柱面数]/ 255[磁头数]/ 63[扇区数], sectors = 6442448863[总扇区数], start = 2048[起始扇区数]

测试硬盘的读取速度

sudo hdparm -t /dev/sdb1

输出为:

/dev/sdb1:
SG_IO: bad/missing sense data, sb[]:  70 00 05 00 00 00 00 0a 00 00 00 00 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 Timing buffered disk reads: 9652 MB in  3.00 seconds = 3217.29 MB/sec

测试硬盘缓存的读取速度

sudo hdparm -T /dev/sdb1

输出为:

/dev/sdb1:
 Timing cached reads:   25838 MB in  1.99 seconds = 12959.95 MB/sec

检测硬盘的电源管理模式

sudo hdparm -C /dev/sdb1

输出为:

/dev/sdb1:
SG_IO: bad/missing sense data, sb[]:  70 00 05 00 00 00 00 0a 00 00 00 00 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 drive state is:  standby

参考资料

3.3.2 - sandisk sn520的测试结果

sandisk sn520的测试结果

硬盘型号 sandisk sn520,容量 512G, m2 接口 nvme 协议, pcie 3.0 x4。

技嘉x99 + 10G M2

在技嘉 x99 ud4 主板上,m2 接口为 10G 带宽。

物理机安装 ubuntu 20.04 系统, 5.4 内核。

基本信息

$ lspci | grep disk
05:00.0 Non-Volatile memory controller: Sandisk Corp WD Black 2018/PC SN520 NVMe SSD (rev 01)

磁盘数据:

Disk /dev/nvme0n1: 465.78 GiB, 500107862016 bytes, 976773168 sectors
Disk model: WDC WDS500G1B0C-00S6U0                  
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: AB8D3D88-0124-404E-B1BC-658E567C569D

Device             Start       End   Sectors  Size Type
/dev/nvme0n1p1      2048   1050623   1048576  512M EFI System
/dev/nvme0n1p2   1050624 839911423 838860800  400G Linux filesystem
/dev/nvme0n1p3 839911424 976771071 136859648 65.3G Linux filesystem

分区信息:

sudo hdparm /dev/nvme0n1p3


/dev/nvme0n1p3:
 HDIO_DRIVE_CMD(identify) failed: Inappropriate ioctl for device
 readonly      =  0 (off)
 readahead     = 256 (on)
 HDIO_DRIVE_CMD(identify) failed: Inappropriate ioctl for device
 geometry      = 66826/64/32, sectors = 136859648, start = 839911424

速度测试

读取速度测试:

sudo hdparm -t /dev/nvme0n1p3


/dev/nvme0n1p3:
 HDIO_DRIVE_CMD(identify) failed: Inappropriate ioctl for device
 Timing buffered disk reads: 2294 MB in  3.00 seconds = 764.43 MB/sec

缓存读取速度测试:

sudo hdparm -T /dev/nvme0n1p3


/dev/nvme0n1p3:
 Timing cached reads:   20412 MB in  1.99 seconds = 10261.23 MB/sec

3.4 - du命令

Linux fdisk 命令: 展示磁盘使用量的统计信息

du 命令,全称是 disk usage,用来展示磁盘使用量的统计信息。

4 - 文件命令

Linux 文件命令

4.1 - Linux find 命令

Linux find 命令

4.1.1 - Linux find 命令的 -exec 选项

Linux find 命令的 -exec 选项
find . -type f -exec grep "192.168.0.30:10808" {} \;

4.2 - mkisofs命令

mkisofs 命令用于制作 ISO 文件

制作 ISO 文件

使用某个目录的文件

使用指定文件夹中的所有文件制作 iso 文件:

mkisofs -r -o file.iso your_folder_name/

可以选择生成对应 MD5 文件,只要执行:

md5sum file.iso > file.iso.md5

参考资料

5 - 网络命令

Linux 网络命令

5.1 - netstat 命令

netstat 命令

5.2 - lsof 命令

lsof 命令

5.3 - ss 命令

ss 命令

介绍

ss 是 Socket Statistics 的缩写。

ss 命令可以用来获取 socket 统计信息,它显示的内容和 netstat 类似。但 ss 的优势在于它能够显示更多更详细的有关 TCP 和连接状态的信息,而且比 netstat 更快。当服务器的 socket 连接数量变得非常大时,无论是使用 netstat 命令还是直接 cat /proc/net/tcp,执行速度都会很慢。

ss 命令利用到了 TCP 协议栈中 tcp_diag。tcp_diag 是一个用于分析统计的模块,可以获得 Linux 内核中第一手的信息,因此 ss 命令的性能会好很多。

用法

常用选项

-h, –help 帮助

-V, –version 显示版本号

-t, –tcp 显示 TCP 协议的 sockets

-u, –udp 显示 UDP 协议的 sockets

-x, –unix 显示 unix domain sockets,与 -f 选项相同

-n, –numeric 不解析服务的名称,如 “22” 端口不会显示成 “ssh”

-l, –listening 只显示处于监听状态的端口

-p, –processes 显示监听端口的进程(Ubuntu 上需要 sudo)

-a, –all 对 TCP 协议来说,既包含监听的端口,也包含建立的连接

-r, –resolve 把 IP 解释为域名,把端口号解释为协议名称

具体可见:

s -h
Usage: ss [ OPTIONS ]
       ss [ OPTIONS ] [ FILTER ]
   -h, --help          this message
   -V, --version       output version information
   -n, --numeric       don't resolve service names
   -r, --resolve       resolve host names
   -a, --all           display all sockets
   -l, --listening     display listening sockets
   -o, --options       show timer information
   -e, --extended      show detailed socket information
   -m, --memory        show socket memory usage
   -p, --processes     show process using socket
   -i, --info          show internal TCP information
       --tipcinfo      show internal tipc socket information
   -s, --summary       show socket usage summary
       --tos           show tos and priority information
   -b, --bpf           show bpf filter socket information
   -E, --events        continually display sockets as they are destroyed
   -Z, --context       display process SELinux security contexts
   -z, --contexts      display process and socket SELinux security contexts
   -N, --net           switch to the specified network namespace name

   -4, --ipv4          display only IP version 4 sockets
   -6, --ipv6          display only IP version 6 sockets
   -0, --packet        display PACKET sockets
   -t, --tcp           display only TCP sockets
   -S, --sctp          display only SCTP sockets
   -u, --udp           display only UDP sockets
   -d, --dccp          display only DCCP sockets
   -w, --raw           display only RAW sockets
   -x, --unix          display only Unix domain sockets
       --tipc          display only TIPC sockets
       --vsock         display only vsock sockets
   -f, --family=FAMILY display sockets of type FAMILY
       FAMILY := {inet|inet6|link|unix|netlink|vsock|tipc|xdp|help}

   -K, --kill          forcibly close sockets, display what was closed
   -H, --no-header     Suppress header line
   -O, --oneline       socket's data printed on a single line

   -A, --query=QUERY, --socket=QUERY
       QUERY := {all|inet|tcp|udp|raw|unix|unix_dgram|unix_stream|unix_seqpacket|packet|netlink|vsock_stream|vsock_dgram|tipc}[,QUERY]

   -D, --diag=FILE     Dump raw information about TCP sockets to FILE
   -F, --filter=FILE   read filter information from FILE
       FILTER := [ state STATE-FILTER ] [ EXPRESSION ]
       STATE-FILTER := {all|connected|synchronized|bucket|big|TCP-STATES}
         TCP-STATES := {established|syn-sent|syn-recv|fin-wait-{1,2}|time-wait|closed|close-wait|last-ack|listening|closing}
          connected := {established|syn-sent|syn-recv|fin-wait-{1,2}|time-wait|close-wait|last-ack|closing}
       synchronized := {established|syn-recv|fin-wait-{1,2}|time-wait|close-wait|last-ack|closing}
             bucket := {syn-recv|time-wait}
                big := {established|syn-sent|fin-wait-{1,2}|closed|close-wait|last-ack|listening|closing}

5.4 - route 命令

route 命令
route -n                                                
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.100.40  0.0.0.0         UG    100    0        0 ens1
0.0.0.0         192.168.0.1     0.0.0.0         UG    101    0        0 eno1
10.0.0.0        192.168.100.40  255.0.0.0       UG    0      0        0 ens1
169.254.0.0     0.0.0.0         255.255.0.0     U     1000   0        0 ens1
172.17.0.0      0.0.0.0         255.255.0.0     U     0      0        0 docker0
192.168.0.0     0.0.0.0         255.255.255.0   U     101    0        0 eno1
192.168.100.0   0.0.0.0         255.255.255.0   U     100    0        0 ens1

5.5 - traceroute 命令

traceroute 命令用于追踪数据包在网络上的传输时的全部路径

安装

ubuntu 默认居然没有自带 traceroute 命令,apt 安装一个:

sudo apt install traceroute

参考资料

5.6 - wireshark

wireshark

5.6.1 - wireshark 介绍

Wireshark是广泛使用的网络协议分析器

Wireshark是世界上最重要和广泛使用的网络协议分析器。它可以让你在微观层面上看到网络上发生的事情,并且是许多商业和非盈利企业、政府机构和教育机构的事实(通常也是法律)标准。Wireshark的发展得益于全球网络专家的志愿贡献,是Gerald Combs在1998年开始的项目的延续。

介绍

https://www.wireshark.org/

功能介绍

Wireshark具有丰富的功能,包括以下内容:

  • 对数百种协议进行深入探查,并不断增加更多的协议
  • 实时捕获和离线分析
  • 标准的三窗体数据包浏览器
  • 多平台。可在Windows、Linux、macOS、Solaris、FreeBSD、NetBSD和其他许多平台上运行
  • 捕获的网络数据可以通过GUI或TTY模式的TShark工具进行浏览
  • 行业中最强大的显示过滤器
  • 丰富的VoIP分析
  • 读取/写入许多不同的捕获文件格式。tcpdump (libpcap), Pcap NG, Catapult DCT2000, Cisco Secure IDS iplog, Microsoft Network Monitor, Network General Sniffer® (compressed and uncompressed), Sniffer® Pro, and NetXray®, Network Instruments Observer, NetScreen snoop, Novell LANalyzer, RADCOM WAN/LAN Analyzer, Shomiti/Finisar Surveyor, Tektronix K12xx, Visual Networks Visual UpTime, WildPackets EtherPeek/TokenPeek/AiroPeek, 和许多其他产品。
  • 用gzip压缩的捕获文件可以在运行中解压缩
  • 可以从以太网、IEEE 802.11、PPP/HDLC、ATM、蓝牙、USB、令牌环、帧中继、FDDI等读取实时数据(取决于您的平台)
  • 支持许多协议的解密,包括IPsec、ISAKMP、Kerberos、SNMPv3、SSL/TLS、WEP和WPA/WPA2
  • 着色规则可应用于数据包列表,以进行快速、直观的分析
  • 输出可以导出为XML、PostScript®、CSV或纯文本

资料

官方资料

https://www.wireshark.org/#learnWS

  • 培训
  • 用户文档
  • 开发文档
  • 各种视频和演讲

5.6.2 - 安装 wireshark

在 ubuntu 上安装 wireshark

安装

安装最新稳定版本

ubuntu 下可以直接安装,但默认的版本是3.2.3,发布于2019年,而最新的版本是 3.6.3。

参考官方文档: https://launchpad.net/~wireshark-dev/+archive/ubuntu/stable

安装最新稳定版本:

sudo add-apt-repository ppa:wireshark-dev/stable
sudo apt-get update
sudo apt install wireshark

但这个方式安装下来的版本是 3.4.8-1

$ apt-cache madison wireshark
 wireshark | 3.4.8-1~ubuntu20.04.0+wiresharkdevstable1 | http://ppa.launchpad.net/wireshark-dev/stable/ubuntu focal/main amd64 Packages
 wireshark |    3.2.3-1 | http://mirrors.aliyun.com/ubuntu focal/universe amd64 Packages

安装最新开发版本

如果要安装最新的dev版本,可以考虑从源码编译,参考:

https://www.linuxfromscratch.org/blfs/view/svn/basicnet/wireshark.html

但这个实在麻烦了一点。好在ubuntu下有ppt:

sudo add-apt-repository ppa:dreibh/ppa
sudo apt update
sudo apt -y install wireshark

最新的开发版本已经是 3.7.0 了:

$ apt-cache madison wireshark
 wireshark | 3.7.0+git20220406073638~7adc301d-1ppa~focal1 | http://ppa.launchpad.net/dreibh/ppa/ubuntu focal/main amd64 Packages
 wireshark | 3.4.8-1~ubuntu20.04.0+wiresharkdevstable1 | http://ppa.launchpad.net/wireshark-dev/stable/ubuntu focal/main amd64 Packages
 wireshark |    3.2.3-1 | http://mirrors.aliyun.com/ubuntu focal/universe amd64 Packages

配置

允许非超级用户捕获数据包

启动时提示是否允许非超级用户捕获数据包:

permisions

按照提示操作:

sudo dpkg-reconfigure wireshark-common

configure

选择 yes,然后将自己加入到 wireshark group:

sudo usermod -a -G wireshark $USER

注销账号再重新登录。

参考资料

5.6.3 - filter的用法

wireshark filter 的用法

5.6.3.1 - filter 概述

wireshark filter 概述

参考资料

5.6.4 - 各种协议的抓包方式

wireshark 各种协议的抓包方式

5.6.4.1 - 抓取 http 包

在 ubuntu 上安装 wireshark 抓取 http 包

抓取本地http包

目标是抓取访问 http://localhost:1313/ 地址的HTTP包,设置中选择 “Loopback: lo”, filter 设置为 http and tcp.port=1313:

http-local

以下是抓取多次 http 交互的一个例子,这是 dapr java-sdk 中的一个bug,当时排查时发现 https://github.com/dapr/java-sdk/issues/709

http-example

5.7 - Linux ip 命令

Linux ip 命令

5.7.1 - 使用 ip 命令操作路由

使用 ip 命令操作路由

添加路由

$ route -n                                                
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.100.40  0.0.0.0         UG    100    0        0 ens1
0.0.0.0         192.168.0.1     0.0.0.0         UG    101    0        0 eno1
169.254.0.0     0.0.0.0         255.255.0.0     U     1000   0        0 ens1
172.17.0.0      0.0.0.0         255.255.0.0     U     0      0        0 docker0
192.168.0.0     0.0.0.0         255.255.255.0   U     101    0        0 eno1
192.168.100.0   0.0.0.0         255.255.255.0   U     100    0        0 ens1

为了访问 10.0.0.0/8 号段,增加一条路由规则:

sudo ip route add 10.0.0.0/8 via 192.168.100.40 dev ens1

完成后的路由情况:

route -n                                                
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.100.40  0.0.0.0         UG    100    0        0 ens1
0.0.0.0         192.168.0.1     0.0.0.0         UG    101    0        0 eno1
10.0.0.0        192.168.100.40  255.0.0.0       UG    0      0        0 ens1
169.254.0.0     0.0.0.0         255.255.0.0     U     1000   0        0 ens1
172.17.0.0      0.0.0.0         255.255.0.0     U     0      0        0 docker0
192.168.0.0     0.0.0.0         255.255.255.0   U     101    0        0 eno1
192.168.100.0   0.0.0.0         255.255.255.0   U     100    0        0 ens1

参考资料

5.8 - nfs 命令

Linux nfs 相关命令

5.8.1 - nfs命令概述

常用nfs命令

安装

nfs 服务器和客户端的安装见 安装配置nfs文件共享

使用

列出远程nfs服务器上的挂载信息,然后在本地建立目录并挂载:

# 查看远程服务器的挂载情况
$ showmount --exports 192.168.0.40 
Export list for 192.168.0.40:
/mnt/d         192.168.0.0/16
/mnt/nfs-share 192.168.0.0/16

# 挂载到本地
$ mkdir -p /mnt/d
$ sudo mount -t nfs 192.168.0.40:/mnt/d /mnt/d

# 不使用时卸载
$ sudo umount /mnt/d

资料

5.8.2 - showmount命令

showmount用来显示nfs服务器的挂载信息

使用

$ showmount --exports 192.168.0.40 
Export list for 192.168.0.40:
/mnt/d         192.168.0.0/16
/mnt/nfs-share 192.168.0.0/16

资料

5.8.4 - NFSoRDMA

准备工作

正确安装网卡的 MLNX_OFED 驱动

注意在安装时,一定要加 --add-kernel-support 参数,否则只能重新安装。我之前安装 MLNX_OFED 驱动时没有加这个参数,因此不得不重新安装:

 sudo ./mlnxofedinstall --without-fw-update --force --add-kernel-support

这个命令会删除现有已经安装的驱动,然后重新安装

安装 rdma 相关的包

参考 redhat 的文档 通过 RDMA(NFSoRDMA)启用 NFS

在 nfs 服务器端和客户端都安装 rdma-core :

sudo apt install rdma-core

并确保 /etc/rdma/modules/rdma.conf 文件中没有注释掉 xprtrdmasvcrdma 这两行:

# NFS over RDMA client support
xprtrdma

# NFS over RDMA server support
svcrdma

确保 rdma 相关的 mod 正确装载

参考 oracle 的这个文档, Using the NFS over RDMA Client

在 nfs 服务器端,检查:

sudo modprobe svcrdma

在 nfs 客户端,检查:

sudo modprobe xprtrdma

备注: svcrdma 和 xprtrdma 似乎都只是 rpcrdma mod 的别名??

sudo modprobe -r xprtrdma
modprobe: FATAL: Module rpcrdma is in use.

安装

安装 VAST-NFS Client Driver

https://vastnfs.vastdata.com/docs/4.0/Intro.html

下载最新版本:

curl -sSf https://vast-nfs.s3.amazonaws.com/download.sh | bash

Checking latest version...
Downloaded: vastnfs-4.0.18.tar.xz

解压缩:

tar xvf vastnfs-4.0.18.tar.xz
cd vastnfs-4.0.18

编译:

./build.sh bin

......
dpkg-buildpackage: info: binary-only upload (no source included)
total 912
-rw-r--r-- 1 sky sky 933788 Aug 11 02:17 vastnfs-dkms_4.0.18-vastdata-MLNX.OFED.LINUX-4.9-6.0.6.0_all.deb
------------------------------------------------------------------

Output in dist/

total 912
-rw-r--r-- 1 sky sky 933788 Aug 11 02:17 vastnfs-dkms_4.0.18-vastdata-MLNX.OFED.LINUX-4.9-6.0.6.0_all.deb

注意这里,如果编译出来的文件名是类似上面的 “vastnfs-dkms_4.0.18-vastdata-MLNX.OFED.LINUX-4.9-6.0.6.0_all.deb”,是有问题的,需要重新安装。

这是因为 MLNX_OFED 驱动在安装是没有加 --add-kernel-support 参数。如果 MLNX_OFED 驱动在安装时有正确的加 --add-kernel-support 参数,则编译出来的文件名会类似 vastnfs-modules_4.0.18-vastdata-MLNX.OFED.LINUX-4.9-6.0.6.0.kver.5.4.0-156-generic_amd64.deb 这样带有 linux 内核的版本。

安装:

cd dist
# 注意这个文件是有问题的
# sudo apt install ./vastnfs-dkms_4.0.18-vastdata-MLNX.OFED.LINUX-4.9-6.0.6.0_all.deb
# 这个文件才是对的
sudo apt install ./vastnfs-modules_4.0.18-vastdata-MLNX.OFED.LINUX-4.9-6.0.6.0.kver.5.4.0-156-generic_amd64.deb

......
compat_nfs_ssc.ko:
Running module version sanity check.
 - Original module
   - No original module exists within this kernel
 - Installation
   - Installing to /lib/modules/5.4.0-156-generic/updates/dkms/

depmod...

DKMS: install completed.

更新 initramfs:

sudo update-initramfs -u -k `uname -r`

update-initramfs: Generating /boot/initrd.img-5.4.0-156-generic

重启机器。然后检验:

$ cat /sys/module/sunrpc/srcversion
FAA3D4CDBA86B8279289A02

$ modinfo sunrpc | grep srcversion
srcversion:     FAA3D4CDBA86B8279289A02

两个 srcversion 要一致。

$ vastnfs-ctl status          

version: 4.0.18-vastdata-MLNX.OFED.LINUX-4.9-6.0.6.0
kernel modules: sunrpc rpcrdma compat_nfs_ssc lockd nfs_acl auth_rpcgss nfsd nfs nfsv3
services: rpcbind.socket rpcbind
rpc_pipefs: /run/rpc_pipefs

启动 nfs 服务器端

sudo vi /etc/exports

设置 nfs export 的内容,比如我这里要导出两个地址:

/mnt/data/share 192.168.0.0/16(fsid=0,rw,async,insecure,no_root_squash,no_subtree_check)
/mnt/data/pve-share 192.168.0.0/16(fsid=0,rw,async,insecure,no_root_squash,no_subtree_check)

重启 nfs-server :

sudo systemctl restart nfs-server

关键设置,在启动 nfs-server 之后再设置 rdma 的端口 20049:

# 还不能用 sudo,会宝座
sudo echo rdma 20049 > /proc/fs/nfsd/portlist
zsh: permission denied: /proc/fs/nfsd/portlist

# 要先 su 到 root
sudo su
# 看一眼现在的设置, rdma 20049 端口的设置在 restart nfs-server 之后就消失了
vi /proc/fs/nfsd/portlist
# 也不能通过 vi 命令来修改,会无法保存文件

# 可以这样修改
echo rdma 20049 > /proc/fs/nfsd/portlist

这个时候 /proc/fs/nfsd/portlist 文件的内容是这样的:

rdma 20049
rdma 20049
udp 2049
tcp 2049
udp 2049
tcp 2049

nfs 客户端mount

在 nfs 客户端执行命令,尝试 mount :

sudo mount -t nfs -o vers=3,proto=rdma,port=20049 192.168.99.100:/mnt/data/share /mnt/nfs-fast

如果 mount 命令一直卡住不返回,一般是 nfs 服务器端无法连接,在 ip 地址和路径没问题的情况下,最大可能性就是 20049 端口没有开启或者无法连接。

如果成功,此时就可以看到服务器端的文件被 mount 过来了。

验证

执行 dd 命令读取一个 100G 的大文件验证一下:

dd if=/mnt/nfs-fast/temp/test1.img of=/dev/null bs=8M
12800+0 records in
12800+0 records out
107374182400 bytes (107 GB, 100 GiB) copied, 72.2484 s, 1.5 GB/s

很遗憾,1.5GB/s 的速度明显不是 rdma 开启后应有的速度。

再次重复上面的测试,期间通过 top 命令查看 nfs 服务器端的 cpu 使用情况:

top - 06:56:12 up  3:15,  2 users,  load average: 0.90, 0.36, 0.14
Tasks: 259 total,   1 running, 258 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.0 us, 10.2 sy,  0.0 ni, 88.5 id,  1.0 wa,  0.0 hi,  0.3 si,  0.0 st
MiB Mem :  31841.3 total,    261.1 free,   1129.2 used,  30451.0 buff/cache
MiB Swap:   8192.0 total,   8180.2 free,     11.8 used.  30244.3 avail Mem 

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND                                
   5950 root      20   0       0      0      0 D  45.5   0.0   0:45.37 nfsd  
   5951 root      20   0       0      0      0 S  45.2   0.0   0:46.05 nfsd  
    153 root      20   0       0      0      0 S  32.2   0.0   1:10.76 kswapd0 
    744 root       0 -20       0      0      0 I   2.3   0.0   0:02.72 kworker/5:1H-ib-comp-wq 
   5949 root      20   0       0      0      0 S   1.0   0.0   0:00.91 nfsd  
     10 root      20   0       0      0      0 I   0.3   0.0   0:03.39 rcu_sched  

直接在 nfs 服务器端执行 dd 命令读取这个 100G 的大文件试试:

dd if=/mnt/data/share/temp/test1.img of=/dev/null bs=8M

12800+0 records in
12800+0 records out
107374182400 bytes (107 GB, 100 GiB) copied, 25.8021 s, 4.2 GB/s

可以看到读取的速度是 4.2 GB/s,可见ssd硬盘的读取速度(4.2 GB/s)远远大于 nfs 传输的速度(1.5 GB/s)。

推断:从传输速度上看,rdma 应该是没有开启。

期间通过 top 命令查看 nfs 服务器端的 cpu 使用情况:

top - 06:59:16 up  3:18,  2 users,  load average: 0.41, 0.40, 0.20
Tasks: 261 total,   2 running, 259 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.0 us,  9.2 sy,  0.0 ni, 89.7 id,  0.9 wa,  0.0 hi,  0.3 si,  0.0 st
MiB Mem :  31841.3 total,    238.3 free,   1131.8 used,  30471.2 buff/cache
MiB Swap:   8192.0 total,   8169.7 free,     22.2 used.  30242.1 avail Mem 

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND  
   6046 root      20   0   13724   9896   1728 R  89.0   0.0   0:17.25 dd 
    153 root      20   0       0      0      0 S  23.0   0.0   1:29.40 kswapd0 
     10 root      20   0       0      0      0 I   0.3   0.0   0:03.57 rcu_sched    
   5866 root      20   0       0      0      0 I   0.3   0.0   0:01.62 kworker/u24:2-mlx4_en  
   5955 root      20   0       0      0      0 I   0.3   0.0   0:00.04 kworker/0:2-events  

发现和走 nfs 传输相比,服务器端的 cpu 消耗基本相当: 10.2 sy, 0.0 ni, 88.5 id9.2 sy, 0.0 ni, 89.7 id

推断:从nfs服务器端 cpu 占用上看,rdma 应该是开启了。

现在就有点矛盾了!

参考资料

5.9 - nc命令

netcat命令

使用

检查端口:

# 查看单个端口
$ nc  -zv  192.168.0.40 2049
Connection to 192.168.0.40 2049 port [tcp/nfs] succeeded!

# 查看多个端口
$ nc -zv 192.168.56.10 80 22 21

# 查看指定端口范围 
$ nc -zv 192.168.56.10 20-80

-w 可用于设置超时:

nc -w 5 -zv  192.168.0.40 2049

参考资料