zRAM和zswap

写在前面:

ZRAM和zswap之间的区别

zram就像一个划分在RAM中的压缩交换空间

zswap是同时使用存储和RAM的。

ZRAM
实现:压缩块设备,内存在存储数据时动态分配
用途:将 ZRAM块设备配置为swap设备,从而消除对物理swap设备或swap文件的需要

优点:无需物理swap设备,ZRAM块设备可用于swap以外的其他应用程序,任何你可能使用块设备的应用程序。
缺点:一旦页面存储在ZRAM中,它就会一直保留在那里,直到页面被调入或失效。而且ZRAM是无法将页面移出到物理磁盘的。

zswap
实施:用于swap页面的压缩内核缓存。内核缓存被压缩,压缩算法可使用 CryptoAPI 插入,页面存储是动态分配的。较旧的页面可以被移出到磁盘,从而使其成为一种后写缓存
用途:用于常规swap设备(或swap文件)的缓存swap页面

优点:与swap代码的集成(使用 Frontswap API)允许 zswap 选择仅存储压缩良好的页面并处理内存分配失败的页面,在这些情况下,页面会被发送到备份swap设备,缓存中最旧的页面会被推送到备份swap设备,这样以便为新页面腾出空间
缺点:需要一个物理swap设备(或swap文件)。

源码位置:

zram:drivers/block/zram/zram_drv.c

zswap:mm/zswap.c

性能对比:

使能zram和zswap后,可以通过fio、sysbench等性能测试工具进行对比,以下是fio的使用方法

1、代码下载:

git clone https://github.com/axboe/fio.git

2、编译方法

安装交叉编译工具链
sudo apt install gcc-aarch64-linux-gnu
配置
./configure --cc=aarch64-linux-gnu-gcc --build-static --disable-shm
编译
make

3、测试命令

 fio --name=readtest --ioengine=libaio --rw=read --bs=4k --size=1G --numjobs=4 --runtime=60 --time_based

4、命令解释

--name=readtest:

定义测试的名称。在结果中,您将看到此名称与测试结果相关联。
--ioengine=libaio:

指定 I/O 引擎,这里使用的是 libaio,它是 Linux 的异步 I/O 实现。它允许多个 I/O 操作同时进行,从而提高性能。
--rw=read:

设置读写模式。read 表示只进行读取操作。fio 支持多种读写模式,例如 write(写入)、randwrite(随机写入)、randread(随机读取)等。
--bs=4k:

设置块大小,这里为 4KB。块大小会影响 I/O 性能,较小的块大小可以更好地模拟随机 I/O,而较大的块大小则适合顺序 I/O。
--size=1G:

指定测试文件的大小,这里设置为 1GB。fio 将使用此大小进行读写测试。
--numjobs=4:

设置并发作业的数量,这里为 4。它表示将同时运行 4 个 I/O 作业,以模拟更高的负载。
--runtime=60:

指定测试运行的时间,这里设置为 60 秒。测试将在此时间段内持续运行。
--time_based:

指定测试是基于时间的,而不是基于文件大小的。这意味着 fio 将在指定的运行时间内尽可能多地执行 I/O 操作,而不是在达到指定的文件大小后停止。

5、测试结果

swaptest: (groupid=0, jobs=1): err= 0: pid=21683: Fri Aug 23 07:54:33 2024
  write: IOPS=185k, BW=724MiB/s (759MB/s)(42.4GiB/60003msec); 0 zone resets
    clat (nsec): min=1937, max=276214, avg=2983.16, stdev=1788.69
     lat (usec): min=2, max=276, avg= 3.16, stdev= 1.84
    clat percentiles (nsec):
     |  1.00th=[ 2160],  5.00th=[ 2256], 10.00th=[ 2320], 20.00th=[ 2480],
     | 30.00th=[ 2640], 40.00th=[ 2736], 50.00th=[ 2832], 60.00th=[ 2928],
     | 70.00th=[ 3088], 80.00th=[ 3408], 90.00th=[ 3824], 95.00th=[ 4048],
     | 99.00th=[ 4512], 99.50th=[ 4640], 99.90th=[12864], 99.95th=[17024],
     | 99.99th=[28288]
   bw (  KiB/s): min=664264, max=774192, per=100.00%, avg=741538.41, stdev=19822.70, samples=119
   iops        : min=166066, max=193548, avg=185384.47, stdev=4955.68, samples=119
  lat (usec)   : 2=0.01%, 4=93.39%, 10=6.46%, 20=0.11%, 50=0.02%
  lat (usec)   : 100=0.01%, 250=0.01%, 500=0.01%
  cpu          : usr=27.17%, sys=71.71%, ctx=4864, majf=0, minf=0
  IO depths    : 1=100.0%, 2=0.0%, 4=0.0%, 8=0.0%, 16=0.0%, 32=0.0%, >=64=0.0%
     submit    : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     complete  : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     issued rwts: total=0,11115521,0,0 short=0,0,0,0 dropped=0,0,0,0
     latency   : target=0, window=0, percentile=100.00%, depth=1
swaptest: (groupid=0, jobs=1): err=28 (file:io_u.c:1973, func=io_u error, error=No space left on device): pid=21684: Fri Aug 23 07:54:33 2024
  cpu          : usr=0.00%, sys=0.00%, ctx=0, majf=0, minf=0
  IO depths    : 1=100.0%, 2=0.0%, 4=0.0%, 8=0.0%, 16=0.0%, 32=0.0%, >=64=0.0%
     submit    : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     complete  : 0=50.0%, 4=50.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     issued rwts: total=0,1,0,0 short=0,0,0,0 dropped=0,0,0,0
     latency   : target=0, window=0, percentile=100.00%, depth=1
swaptest: (groupid=0, jobs=1): err=28 (file:io_u.c:1973, func=io_u error, error=No space left on device): pid=21685: Fri Aug 23 07:54:33 2024
  cpu          : usr=0.00%, sys=0.00%, ctx=1, majf=0, minf=0
  IO depths    : 1=100.0%, 2=0.0%, 4=0.0%, 8=0.0%, 16=0.0%, 32=0.0%, >=64=0.0%
     submit    : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     complete  : 0=50.0%, 4=50.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     issued rwts: total=0,1,0,0 short=0,0,0,0 dropped=0,0,0,0
     latency   : target=0, window=0, percentile=100.00%, depth=1
swaptest: (groupid=0, jobs=1): err=28 (file:io_u.c:1973, func=io_u error, error=No space left on device): pid=21686: Fri Aug 23 07:54:33 2024
  cpu          : usr=0.00%, sys=0.00%, ctx=1, majf=0, minf=0
  IO depths    : 1=100.0%, 2=0.0%, 4=0.0%, 8=0.0%, 16=0.0%, 32=0.0%, >=64=0.0%
     submit    : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     complete  : 0=50.0%, 4=50.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     issued rwts: total=0,1,0,0 short=0,0,0,0 dropped=0,0,0,0
     latency   : target=0, window=0, percentile=100.00%, depth=1

Run status group 0 (all jobs):
  WRITE: bw=724MiB/s (759MB/s), 724MiB/s-724MiB/s (759MB/s-759MB/s), io=42.4GiB (45.5GB), run=60003-60003msec

Disk stats (read/write):
  sda: ios=0/48269, sectors=0/49173672, merge=0/270, ticks=0/835637, in_queue=835957, util=98.93%

6、结果解释

- 带宽 (BW): 724 MiB/s (759 MB/s)
- IOPS (每秒输入输出操作): 185k
- 测试持续时间: 60 秒
- 写入总量: 42.4 GiB (45.5 GB)
- 磁盘利用率: 98.93%

延迟 (Latency)

- 最小延迟 (min): 1937 纳秒 (ns)
- 最大延迟 (max): 276214 纳秒 (ns)
- 平均延迟 (avg): 2983.16 纳秒 (ns)
- 标准差 (stdev): 1788.69 纳秒 (ns)

延迟百分位数 (Latency Percentiles)

- 1.00th 百分位: 2160 ns
- 5.00th 百分位: 2256 ns
- 10.00th 百分位: 2320 ns
- 20.00th 百分位: 2480 ns
- 30.00th 百分位: 2640 ns
- 40.00th 百分位: 2736 ns
- 50.00th 百分位 (中位数): 2832 ns
- 60.00th 百分位: 2928 ns
- 70.00th 百分位: 3088 ns
- 80.00th 百分位: 3408 ns
- 90.00th 百分位: 3824 ns
- 95.00th 百分位: 4048 ns
- 99.00th 百分位: 4512 ns
- 99.50th 百分位: 4640 ns
- 99.90th 百分位: 12864 ns
- 99.95th 百分位: 17024 ns
- 99.99th 百分位: 28288 ns

IO 深度 (IO Depths)

- 深度 1: 100%
- 深度 2 及以上: 0%

这表示所有的 I/O 请求都在深度 1 处提交,没有使用更高的 I/O 深度。这可能表明测试配置中只使用了一个 I/O 请求队列深度。

CPU 使用情况

- 用户 CPU 使用率: 27.17%
- 系统 CPU 使用率: 71.71%

总结

1. 性能指标:
   - 带宽: 测试的带宽为 724 MiB/s (759 MB/s),说明磁盘在读写操作上具有较高的吞吐能力。
   - IOPS: 每秒操作数为 185k,表明磁盘的 I/O 操作处理能力很强。

2. 延迟:
   - 延迟分布显示,大多数操作的延迟非常低,只有少数操作的延迟较高。中位数延迟为 2832 ns,99.99 百分位的延迟为 28288 ns。

3. CPU 使用情况:
   - 系统 CPU 使用率 很高 (71.71%),表明磁盘 I/O 操作对 CPU 的负担较大。

  • 15
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值