前言

这是操作系统课的一次作业,探究虚拟机的特性与运行效果。

什么是虚拟机?

虚拟机技术是一种在隔离环境中运行操作系统的技术,虚拟机便是通过软件模拟的具有完整硬件系统功能的、运行在一个完全隔离环境中的完整计算机系统。

中国IBM解释为:

虚拟机是物理计算机的虚拟表示形式或仿真环境。 虚拟机通常被称为访客机,而它们运行所在的物理计算机被称为主机。

虚拟化使人能够在一台物理计算机上创建多个虚拟机,每个虚拟机具有各自的操作系统 (OS) 和应用。虚拟机无法与物理计算机直接交互。 而是需要借助一个叫做虚拟机管理器的轻量级软件层,在它与底层物理硬件之间进行协调。虚拟机管理器将物理计算资源(例如处理器、内存和存储)分配给每个虚拟机。 它使虚拟机之间相互分离,从而互不干扰。

虚拟机有哪些?

目前的虚拟机主要分为两大类:Type1和Type2.

Type1虚拟机管理器直接在主机的物理硬件上运行,它被称为裸机虚拟机管理程序,它不必预先加载底层操作系统。通过直接访问底层硬件而无需其他软件(例如操作系统和设备驱动程序)。

Type2虚拟机管理器通常安装在现有操作系统之上,它称为托管虚拟机管理程序,因为它依赖于主机预先安装的操作系统来管理对CPU、内存、存储和网络资源的调用。

由此可见,Type1虚拟机与主操作系统,包括其他Type1虚拟机之间的关系更像是并行的,他们都直接建立在物理硬件上,调用物理资源的地位是平等的。而Type2虚拟机与主操作系统的关系则是派生的,堆叠的。Type2虚拟机实际上就是一个运行着操作系统的应用程序,他的资源要由主操作系统来分配、调度。

虚拟机的性能测试

如同上文所说,不论是Type1还是Type2,虚拟机系统的运行往往伴随着主操作系统。这意味着一套硬件要运行多个系统,每个系统的性能必然比运行单个系统的情况缩水很多。

下面我们对Type1虚拟机的性能进行一个简单的测试。测试方案如下:

  • Type1虚拟机管理器:WSL2(适用于Windows的Linux子系统,是基于Hyper-V实现的)
  • 虚拟机操作系统:Ubuntu20.04
  • Benchmark:HPL
  • Baseline:运行在真机上的Ubuntu20.04
  • 概述:分别对运行在WSL2上的Ubuntu和运行在真机上的Ubuntu进行HPL测试,通过比较两者的Gflop/s(每秒浮点运算次数),从而得出虚拟机系统与真机系统的性能差距。

HPL是在双精度下使用分布式内存计算机求解稠密线性系统的软件包。他可以看作是高性能计算基准测试的一个方便的实现。

相关配置如下:

Item Description Version
CPU Intel® Core™ i5-9300H CPU @ 2.40GHz 2.40 GHz -
Memory 海力士DDR4 16GB -
OS Ubuntu 20.04
Linpack HPL 2.3
Math Libary Intel® oneAPI Math Kernel Library 2022.0.1
C/C++ Compiler Intel® oneAPI DPC++/C++ Compiler 2022.0.1
Fortran Compiler Intel Fortran Compiler Classic 2022.0.2
MPI Intel® MPI Library 2021.5.0

具体的环境搭建这里不再阐述,我们直接进入测试环节。

HPL配置文件

HPL测试参数由HPL.dat控制。基于控制变量的原则,我们在两个系统上的测试均采用同样的配置。配置文件如下。

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
28
29
30
31
HPLinpack benchmark input file
Innovative Computing Laboratory, University of Tennessee
HPL.out output file name (if any)
6 device out (6=stdout,7=stderr,file)
1 # of problems sizes (N)
20000 Ns
1 # of NBs
64 NBs
0 PMAP process mapping (0=Row-,1=Column-major)
1 # of process grids (P x Q)
2 Ps
4 Qs
16.0 threshold
1 # of panel fact
0 1 2 PFACTs (0=left, 1=Crout, 2=Right)
1 # of recursive stopping criterium
4 2 8 NBMINs (>= 1)
1 # of panels in recursion
2 NDIVs
1 # of recursive panel fact.
0 1 RFACTs (0=left, 1=Crout, 2=Right)
1 # of broadcast
0 BCASTs (0=1rg,1=1rM,2=2rg,3=2rM,4=Lng,5=LnM)
1 # of lookahead depth
0 DEPTHs (>=0)
2 SWAP (0=bin-exch,1=long,2=mix)
64 swapping threshold
0 L1 in (0=transposed,1=no-transposed) form
0 U in (0=transposed,1=no-transposed) form
1 Equilibration (0=no,1=yes)
8 memory alignment in double (> 0)

运行终端展示

WSL2显示效果如图:
wsl2

真机显示效果如图:
real

WSL2测试

运行命令:mpirun -np 8 ./xhpl >info_wsl2.txt测试结果在info_wsl2.txt中。结果如下。

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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
================================================================================
HPLinpack 2.3 -- High-Performance Linpack benchmark -- December 2, 2018
Written by A. Petitet and R. Clint Whaley, Innovative Computing Laboratory, UTK
Modified by Piotr Luszczek, Innovative Computing Laboratory, UTK
Modified by Julien Langou, University of Colorado Denver
================================================================================

An explanation of the input/output parameters follows:
T/V : Wall time / encoded variant.
N : The order of the coefficient matrix A.
NB : The partitioning blocking factor.
P : The number of process rows.
Q : The number of process columns.
Time : Time in seconds to solve the linear system.
Gflops : Rate of execution for solving the linear system.

The following parameter values will be used:

N : 20000
NB : 64
PMAP : Row-major process mapping
P : 2
Q : 4
PFACT : Left
NBMIN : 4
NDIV : 2
RFACT : Left
BCAST : 1ring
DEPTH : 0
SWAP : Mix (threshold = 64)
L1 : transposed form
U : transposed form
EQUIL : yes
ALIGN : 8 double precision words

--------------------------------------------------------------------------------

- The matrix A is randomly generated for each test.
- The following scaled residual check will be computed:
||Ax-b||_oo / ( eps * ( || x ||_oo * || A ||_oo + || b ||_oo ) * N )
- The relative machine precision (eps) is taken to be 1.110223e-16
- Computational tests pass if scaled residuals are less than 16.0

================================================================================
T/V N NB P Q Time Gflops
--------------------------------------------------------------------------------
WR00L2L4 20000 64 2 4 54.26 9.8304e+01
HPL_pdgesv() start time Thu Mar 24 21:05:27 2022

HPL_pdgesv() end time Thu Mar 24 21:06:21 2022

--------------------------------------------------------------------------------
||Ax-b||_oo/(eps*(||A||_oo*||x||_oo+||b||_oo)*N)= 3.56304264e-03 ...... PASSED
================================================================================

Finished 1 tests with the following results:
1 tests completed and passed residual checks,
0 tests completed and failed residual checks,
0 tests skipped because of illegal input values.
--------------------------------------------------------------------------------

End of Tests.
================================================================================

结果表明,WSL2的成绩是98.304 Gflop/s。

真机测试

笔者电脑装的是win+ubuntu双系统。现在切换到Ubuntu系统进行测试。
运行命令

1
mpirun -np 8 ./xhpl >info_real.txt

测试结果如下。

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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
================================================================================
HPLinpack 2.3 -- High-Performance Linpack benchmark -- December 2, 2018
Written by A. Petitet and R. Clint Whaley, Innovative Computing Laboratory, UTK
Modified by Piotr Luszczek, Innovative Computing Laboratory, UTK
Modified by Julien Langou, University of Colorado Denver
================================================================================

An explanation of the input/output parameters follows:
T/V : Wall time / encoded variant.
N : The order of the coefficient matrix A.
NB : The partitioning blocking factor.
P : The number of process rows.
Q : The number of process columns.
Time : Time in seconds to solve the linear system.
Gflops : Rate of execution for solving the linear system.

The following parameter values will be used:

N : 20000
NB : 64
PMAP : Row-major process mapping
P : 2
Q : 4
PFACT : Left
NBMIN : 4
NDIV : 2
RFACT : Left
BCAST : 1ring
DEPTH : 0
SWAP : Mix (threshold = 64)
L1 : transposed form
U : transposed form
EQUIL : yes
ALIGN : 8 double precision words

--------------------------------------------------------------------------------

- The matrix A is randomly generated for each test.
- The following scaled residual check will be computed:
||Ax-b||_oo / ( eps * ( || x ||_oo * || A ||_oo + || b ||_oo ) * N )
- The relative machine precision (eps) is taken to be 1.110223e-16
- Computational tests pass if scaled residuals are less than 16.0

================================================================================
T/V N NB P Q Time Gflops
--------------------------------------------------------------------------------
WR00L2L4 20000 64 2 4 38.91 1.3710e+02
HPL_pdgesv() start time Thu Mar 24 21:10:25 2022

HPL_pdgesv() end time Thu Mar 24 21:11:04 2022

--------------------------------------------------------------------------------
||Ax-b||_oo/(eps*(||A||_oo*||x||_oo+||b||_oo)*N)= 3.56304264e-03 ...... PASSED
================================================================================

Finished 1 tests with the following results:
1 tests completed and passed residual checks,
0 tests completed and failed residual checks,
0 tests skipped because of illegal input values.
--------------------------------------------------------------------------------

End of Tests.
================================================================================

结果表明,真机的成绩是137.10 Gflop/s

总结

实验表明,在以上HPL.dat的配置下,WSL2的成绩为98.304 Gflop/s,真机的成绩为137.10 Gflop/s。这证明虚拟机系统性能比真机系统缩水了28.3%。

补充说明

注意,该实验非常粗糙简单,数据仅供参考。下面列举了几个实验忽略的因素。

  • WSL2测试伴随着windows10系统的运行,真机测试伴随着ubuntu桌面环境的运行。因此两个实验中HPL分配到的计算资源并不相同。
  • 为了便于比对,两个测试使用了相同的HPL配置。然而对于两个系统来说,这都不是最佳配置,不能反映系统的最佳性能。
  • 在两个系统上分别只进行了一次测试,实验不具有普遍性。

另外,本实验只测试了Type1虚拟机的性能。因为Type2虚拟机往往不能调用计算机所有可用资源(在安装时会让用户手动分配资源),所以不太好找baseline,没法与真机对比。而Type1跑HPL时是可以把CPU拉满的。不过可想而知,只能使用有限资源的Type2虚拟机,其性能必然比Type1更逊一筹。