0001 .. SPDX-License-Identifier: GPL-2.0
0002 .. include:: ../../../disclaimer-zh_CN.rst
0003
0004 :Original: Documentation/admin-guide/mm/damon/start.rst
0005
0006 :翻译:
0007
0008 司延腾 Yanteng Si <siyanteng@loongson.cn>
0009
0010 :校译:
0011
0012 ========
0013 入门指南
0014 ========
0015
0016 本文通过演示DAMON的默认用户空间工具,简要地介绍了如何使用DAMON。请注意,为了简洁
0017 起见,本文档只描述了它的部分功能。更多细节请参考该工具的使用文档。
0018 `doc <https://github.com/awslabs/damo/blob/next/USAGE.md>`_ .
0019
0020
0021 前提条件
0022 ========
0023
0024 内核
0025 ----
0026
0027 首先,你要确保你当前系统中跑的内核构建时选定了这个功能选项 ``CONFIG_DAMON_*=y``.
0028
0029
0030 用户空间工具
0031 ------------
0032
0033 在演示中,我们将使用DAMON的默认用户空间工具,称为DAMON Operator(DAMO)。它可以在
0034 https://github.com/awslabs/damo找到。下面的例子假设DAMO在你的$PATH上。当然,但
0035 这并不是强制性的。
0036
0037 因为DAMO使用的是DAMON的debugfs接口(详情请参考 :doc:`usage` 中的使用方法) 你应该
0038 确保debugfs被挂载。手动挂载它,如下所示::
0039
0040 # mount -t debugfs none /sys/kernel/debug/
0041
0042 或者在你的 ``/etc/fstab`` 文件中添加以下一行,这样你的系统就可以在启动时自动挂载
0043 debugfs了::
0044
0045 debugfs /sys/kernel/debug debugfs defaults 0 0
0046
0047
0048 记录数据访问模式
0049 ================
0050
0051 下面的命令记录了一个程序的内存访问模式,并将监测结果保存到文件中。 ::
0052
0053 $ git clone https://github.com/sjp38/masim
0054 $ cd masim; make; ./masim ./configs/zigzag.cfg &
0055 $ sudo damo record -o damon.data $(pidof masim)
0056
0057 命令的前两行下载了一个人工内存访问生成器程序并在后台运行。生成器将重复地逐一访问两个
0058 100 MiB大小的内存区域。你可以用你的真实工作负载来代替它。最后一行要求 ``damo`` 将
0059 访问模式记录在 ``damon.data`` 文件中。
0060
0061
0062 将记录的模式可视化
0063 ==================
0064
0065 你可以在heatmap中直观地看到这种模式,显示哪个内存区域(X轴)何时被访问(Y轴)以及访
0066 问的频率(数字)。::
0067
0068 $ sudo damo report heats --heatmap stdout
0069 22222222222222222222222222222222222222211111111111111111111111111111111111111100
0070 44444444444444444444444444444444444444434444444444444444444444444444444444443200
0071 44444444444444444444444444444444444444433444444444444444444444444444444444444200
0072 33333333333333333333333333333333333333344555555555555555555555555555555555555200
0073 33333333333333333333333333333333333344444444444444444444444444444444444444444200
0074 22222222222222222222222222222222222223355555555555555555555555555555555555555200
0075 00000000000000000000000000000000000000288888888888888888888888888888888888888400
0076 00000000000000000000000000000000000000288888888888888888888888888888888888888400
0077 33333333333333333333333333333333333333355555555555555555555555555555555555555200
0078 88888888888888888888888888888888888888600000000000000000000000000000000000000000
0079 88888888888888888888888888888888888888600000000000000000000000000000000000000000
0080 33333333333333333333333333333333333333444444444444444444444444444444444444443200
0081 00000000000000000000000000000000000000288888888888888888888888888888888888888400
0082 [...]
0083 # access_frequency: 0 1 2 3 4 5 6 7 8 9
0084 # x-axis: space (139728247021568-139728453431248: 196.848 MiB)
0085 # y-axis: time (15256597248362-15326899978162: 1 m 10.303 s)
0086 # resolution: 80x40 (2.461 MiB and 1.758 s for each character)
0087
0088 你也可以直观地看到工作集的大小分布,按大小排序。::
0089
0090 $ sudo damo report wss --range 0 101 10
0091 # <percentile> <wss>
0092 # target_id 18446632103789443072
0093 # avr: 107.708 MiB
0094 0 0 B | |
0095 10 95.328 MiB |**************************** |
0096 20 95.332 MiB |**************************** |
0097 30 95.340 MiB |**************************** |
0098 40 95.387 MiB |**************************** |
0099 50 95.387 MiB |**************************** |
0100 60 95.398 MiB |**************************** |
0101 70 95.398 MiB |**************************** |
0102 80 95.504 MiB |**************************** |
0103 90 190.703 MiB |********************************************************* |
0104 100 196.875 MiB |***********************************************************|
0105
0106 在上述命令中使用 ``--sortby`` 选项,可以显示工作集的大小是如何按时间顺序变化的。::
0107
0108 $ sudo damo report wss --range 0 101 10 --sortby time
0109 # <percentile> <wss>
0110 # target_id 18446632103789443072
0111 # avr: 107.708 MiB
0112 0 3.051 MiB | |
0113 10 190.703 MiB |***********************************************************|
0114 20 95.336 MiB |***************************** |
0115 30 95.328 MiB |***************************** |
0116 40 95.387 MiB |***************************** |
0117 50 95.332 MiB |***************************** |
0118 60 95.320 MiB |***************************** |
0119 70 95.398 MiB |***************************** |
0120 80 95.398 MiB |***************************** |
0121 90 95.340 MiB |***************************** |
0122 100 95.398 MiB |***************************** |
0123
0124
0125 数据访问模式感知的内存管理
0126 ==========================
0127
0128 以下三个命令使每一个大小>=4K的内存区域在你的工作负载中没有被访问>=60秒,就会被换掉。 ::
0129
0130 $ echo "#min-size max-size min-acc max-acc min-age max-age action" > test_scheme
0131 $ echo "4K max 0 0 60s max pageout" >> test_scheme
0132 $ damo schemes -c test_scheme <pid of your workload>