Documentation/driver-api/crypto/iaa/iaa-crypto.rst GitHub 원문 ↗

Linux 6.18.37 · Driver API / Crypto / IAA

IAA Compression Accelerator Crypto Driver

Intel IAA의 DEFLATE 가속, IOMMU 모드, workqueue 구성, 드라이버 속성, 통계와 zswap 시험 절차를 설명합니다.

Source pathDocumentation/driver-api/crypto/iaa/iaa-crypto.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약과 해설

iaa-crypto.rst:1-849

이 문서는 Intel IAA 압축 가속기를 Linux crypto API와 zswap에서 운용하는 전체 절차를 다룹니다. 기본 구성부터 `accel-config`, sysfs, 동기·비동기 모드, 통계, 재구성 스크립트와 시험 프로그램까지 이어지는 운영 지침입니다. 영어 원문 전체와 한국어 전문 번역을 함께 제공하며 명령, 경로, symbol, 설정값, 로그와 원문 줄 좌표를 보존합니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

원문 전체 펼치기
1 .. SPDX-License-Identifier: GPL-2.0
2
3 =========================================
4 IAA Compression Accelerator Crypto Driver
5 =========================================
6
7 Tom Zanussi <tom.zanussi@linux.intel.com>
8
9 The IAA crypto driver supports compression/decompression compatible
10 with the DEFLATE compression standard described in RFC 1951, which is
11 the compression/decompression algorithm exported by this module.
12
13 The IAA hardware spec can be found here:
14
15 https://cdrdv2.intel.com/v1/dl/getContent/721858
16
17 The iaa_crypto driver is designed to work as a layer underneath
18 higher-level compression devices such as zswap.
19
20 Users can select IAA compress/decompress acceleration by specifying
21 one of the supported IAA compression algorithms in whatever facility
22 allows compression algorithms to be selected.
23
24 For example, a zswap device can select the IAA 'fixed' mode
25 represented by selecting the 'deflate-iaa' crypto compression
26 algorithm::
27
28 # echo deflate-iaa > /sys/module/zswap/parameters/compressor
29
30 This will tell zswap to use the IAA 'fixed' compression mode for all
31 compresses and decompresses.
32
33 Currently, there is only one compression modes available, 'fixed'
34 mode.
35
36 The 'fixed' compression mode implements the compression scheme
37 specified by RFC 1951 and is given the crypto algorithm name
38 'deflate-iaa'. (Because the IAA hardware has a 4k history-window
39 limitation, only buffers <= 4k, or that have been compressed using a
40 <= 4k history window, are technically compliant with the deflate spec,
41 which allows for a window of up to 32k. Because of this limitation,
42 the IAA fixed mode deflate algorithm is given its own algorithm name
43 rather than simply 'deflate').
44
45
46 Config options and other setup
47 ==============================
48
49 The IAA crypto driver is available via menuconfig using the following
50 path::
51
52 Cryptographic API -> Hardware crypto devices -> Support for Intel(R) IAA Compression Accelerator
53
54 In the configuration file the option called CONFIG_CRYPTO_DEV_IAA_CRYPTO.
55
56 The IAA crypto driver also supports statistics, which are available
57 via menuconfig using the following path::
58
59 Cryptographic API -> Hardware crypto devices -> Support for Intel(R) IAA Compression -> Enable Intel(R) IAA Compression Accelerator Statistics
60
61 In the configuration file the option called CONFIG_CRYPTO_DEV_IAA_CRYPTO_STATS.
62
63 The following config options should also be enabled::
64
65 CONFIG_IRQ_REMAP=y
66 CONFIG_INTEL_IOMMU=y
67 CONFIG_INTEL_IOMMU_SVM=y
68 CONFIG_PCI_ATS=y
69 CONFIG_PCI_PRI=y
70 CONFIG_PCI_PASID=y
71 CONFIG_INTEL_IDXD=m
72 CONFIG_INTEL_IDXD_SVM=y
73
74 IAA is one of the first Intel accelerator IPs that can work in
75 conjunction with the Intel IOMMU. There are multiple modes that exist
76 for testing. Based on IOMMU configuration, there are 3 modes::
77
78 - Scalable
79 - Legacy
80 - No IOMMU
81
82
83 Scalable mode
84 -------------
85
86 Scalable mode supports Shared Virtual Memory (SVM or SVA). It is
87 entered when using the kernel boot commandline::
88
89 intel_iommu=on,sm_on
90
91 with VT-d turned on in BIOS.
92
93 With scalable mode, both shared and dedicated workqueues are available
94 for use.
95
96 For scalable mode, the following BIOS settings should be enabled::
97
98 Socket Configuration > IIO Configuration > Intel VT for Directed I/O (VT-d) > Intel VT for Directed I/O
99
100 Socket Configuration > IIO Configuration > PCIe ENQCMD > ENQCMDS
101
102
103 Legacy mode
104 -----------
105
106 Legacy mode is entered when using the kernel boot commandline::
107
108 intel_iommu=off
109
110 or VT-d is not turned on in BIOS.
111
112 If you have booted into Linux and not sure if VT-d is on, do a "dmesg
113 | grep -i dmar". If you don't see a number of DMAR devices enumerated,
114 most likely VT-d is not on.
115
116 With legacy mode, only dedicated workqueues are available for use.
117
118
119 No IOMMU mode
120 -------------
121
122 No IOMMU mode is entered when using the kernel boot commandline::
123
124 iommu=off.
125
126 With no IOMMU mode, only dedicated workqueues are available for use.
127
128
129 Usage
130 =====
131
132 accel-config
133 ------------
134
135 When loaded, the iaa_crypto driver automatically creates a default
136 configuration and enables it, and assigns default driver attributes.
137 If a different configuration or set of driver attributes is required,
138 the user must first disable the IAA devices and workqueues, reset the
139 configuration, and then re-register the deflate-iaa algorithm with the
140 crypto subsystem by removing and reinserting the iaa_crypto module.
141
142 The :ref:`iaa_disable_script` in the 'Use Cases'
143 section below can be used to disable the default configuration.
144
145 See :ref:`iaa_default_config` below for details of the default
146 configuration.
147
148 More likely than not, however, and because of the complexity and
149 configurability of the accelerator devices, the user will want to
150 configure the device and manually enable the desired devices and
151 workqueues.
152
153 The userspace tool to help doing that is called accel-config. Using
154 accel-config to configure device or loading a previously saved config
155 is highly recommended. The device can be controlled via sysfs
156 directly but comes with the warning that you should do this ONLY if
157 you know exactly what you are doing. The following sections will not
158 cover the sysfs interface but assumes you will be using accel-config.
159
160 The :ref:`iaa_sysfs_config` section in the appendix below can be
161 consulted for the sysfs interface details if interested.
162
163 The accel-config tool along with instructions for building it can be
164 found here:
165
166 https://github.com/intel/idxd-config/#readme
167
168 Typical usage
169 -------------
170
171 In order for the iaa_crypto module to actually do any
172 compression/decompression work on behalf of a facility, one or more
173 IAA workqueues need to be bound to the iaa_crypto driver.
174
175 For instance, here's an example of configuring an IAA workqueue and
176 binding it to the iaa_crypto driver (note that device names are
177 specified as 'iax' rather than 'iaa' - this is because upstream still
178 has the old 'iax' device naming in place) ::
179
180 # configure wq1.0
181
182 accel-config config-wq --group-id=0 --mode=dedicated --type=kernel --priority=10 --name="iaa_crypto" --driver-name="crypto" iax1/wq1.0
183
184 accel-config config-engine iax1/engine1.0 --group-id=0
185
186 # enable IAA device iax1
187
188 accel-config enable-device iax1
189
190 # enable wq1.0 on IAX device iax1
191
192 accel-config enable-wq iax1/wq1.0
193
194 Whenever a new workqueue is bound to or unbound from the iaa_crypto
195 driver, the available workqueues are 'rebalanced' such that work
196 submitted from a particular CPU is given to the most appropriate
197 workqueue available. Current best practice is to configure and bind
198 at least one workqueue for each IAA device, but as long as there is at
199 least one workqueue configured and bound to any IAA device in the
200 system, the iaa_crypto driver will work, albeit most likely not as
201 efficiently.
202
203 The IAA crypto algorigthms is operational and compression and
204 decompression operations are fully enabled following the successful
205 binding of the first IAA workqueue to the iaa_crypto driver.
206
207 Similarly, the IAA crypto algorithm is not operational and compression
208 and decompression operations are disabled following the unbinding of
209 the last IAA worqueue to the iaa_crypto driver.
210
211 As a result, the IAA crypto algorithms and thus the IAA hardware are
212 only available when one or more workques are bound to the iaa_crypto
213 driver.
214
215 When there are no IAA workqueues bound to the driver, the IAA crypto
216 algorithms can be unregistered by removing the module.
217
218
219 Driver attributes
220 -----------------
221
222 There are a couple user-configurable driver attributes that can be
223 used to configure various modes of operation. They're listed below,
224 along with their default values. To set any of these attributes, echo
225 the appropriate values to the attribute file located under
226 /sys/bus/dsa/drivers/crypto/
227
228 The attribute settings at the time the IAA algorithms are registered
229 are captured in each algorithm's crypto_ctx and used for all compresses
230 and decompresses when using that algorithm.
231
232 The available attributes are:
233
234 - verify_compress
235
236 Toggle compression verification. If set, each compress will be
237 internally decompressed and the contents verified, returning error
238 codes if unsuccessful. This can be toggled with 0/1::
239
240 echo 0 > /sys/bus/dsa/drivers/crypto/verify_compress
241
242 The default setting is '1' - verify all compresses.
243
244 - sync_mode
245
246 Select mode to be used to wait for completion of each compresses
247 and decompress operation.
248
249 The crypto async interface support implemented by iaa_crypto
250 provides an implementation that satisfies the interface but does
251 so in a synchronous manner - it fills and submits the IDXD
252 descriptor and then loops around waiting for it to complete before
253 returning. This isn't a problem at the moment, since all existing
254 callers (e.g. zswap) wrap any asynchronous callees in a
255 synchronous wrapper anyway.
256
257 The iaa_crypto driver does however provide true asynchronous
258 support for callers that can make use of it. In this mode, it
259 fills and submits the IDXD descriptor, then returns immediately
260 with -EINPROGRESS. The caller can then either poll for completion
261 itself, which requires specific code in the caller which currently
262 nothing in the upstream kernel implements, or go to sleep and wait
263 for an interrupt signaling completion. This latter mode is
264 supported by current users in the kernel such as zswap via
265 synchronous wrappers. Although it is supported this mode is
266 significantly slower than the synchronous mode that does the
267 polling in the iaa_crypto driver previously mentioned.
268
269 This mode can be enabled by writing 'async_irq' to the sync_mode
270 iaa_crypto driver attribute::
271
272 echo async_irq > /sys/bus/dsa/drivers/crypto/sync_mode
273
274 Async mode without interrupts (caller must poll) can be enabled by
275 writing 'async' to it (please see Caveat)::
276
277 echo async > /sys/bus/dsa/drivers/crypto/sync_mode
278
279 The mode that does the polling in the iaa_crypto driver can be
280 enabled by writing 'sync' to it::
281
282 echo sync > /sys/bus/dsa/drivers/crypto/sync_mode
283
284 The default mode is 'sync'.
285
286 Caveat: since the only mechanism that iaa_crypto currently implements
287 for async polling without interrupts is via the 'sync' mode as
288 described earlier, writing 'async' to
289 '/sys/bus/dsa/drivers/crypto/sync_mode' will internally enable the
290 'sync' mode. This is to ensure correct iaa_crypto behavior until true
291 async polling without interrupts is enabled in iaa_crypto.
292
293 .. _iaa_default_config:
294
295 IAA Default Configuration
296 -------------------------
297
298 When the iaa_crypto driver is loaded, each IAA device has a single
299 work queue configured for it, with the following attributes::
300
301 mode "dedicated"
302 threshold 0
303 size Total WQ Size from WQCAP
304 priority 10
305 type IDXD_WQT_KERNEL
306 group 0
307 name "iaa_crypto"
308 driver_name "crypto"
309
310 The devices and workqueues are also enabled and therefore the driver
311 is ready to be used without any additional configuration.
312
313 The default driver attributes in effect when the driver is loaded are::
314
315 sync_mode "sync"
316 verify_compress 1
317
318 In order to change either the device/work queue or driver attributes,
319 the enabled devices and workqueues must first be disabled. In order
320 to have the new configuration applied to the deflate-iaa crypto
321 algorithm, it needs to be re-registered by removing and reinserting
322 the iaa_crypto module. The :ref:`iaa_disable_script` in the 'Use
323 Cases' section below can be used to disable the default configuration.
324
325 Statistics
326 ==========
327
328 If the optional debugfs statistics support is enabled, the IAA crypto
329 driver will generate statistics which can be accessed in debugfs at::
330
331 # ls -al /sys/kernel/debug/iaa-crypto/
332 total 0
333 drwxr-xr-x 2 root root 0 Mar 3 07:55 .
334 drwx------ 53 root root 0 Mar 3 07:55 ..
335 -rw-r--r-- 1 root root 0 Mar 3 07:55 global_stats
336 -rw-r--r-- 1 root root 0 Mar 3 07:55 stats_reset
337 -rw-r--r-- 1 root root 0 Mar 3 07:55 wq_stats
338
339 The global_stats file shows a set of global statistics collected since
340 the driver has been loaded or reset::
341
342 # cat global_stats
343 global stats:
344 total_comp_calls: 4300
345 total_decomp_calls: 4164
346 total_sw_decomp_calls: 0
347 total_comp_bytes_out: 5993989
348 total_decomp_bytes_in: 5993989
349 total_completion_einval_errors: 0
350 total_completion_timeout_errors: 0
351 total_completion_comp_buf_overflow_errors: 136
352
353 The wq_stats file shows per-wq stats, a set for each iaa device and wq
354 in addition to some global stats::
355
356 # cat wq_stats
357 iaa device:
358 id: 1
359 n_wqs: 1
360 comp_calls: 0
361 comp_bytes: 0
362 decomp_calls: 0
363 decomp_bytes: 0
364 wqs:
365 name: iaa_crypto
366 comp_calls: 0
367 comp_bytes: 0
368 decomp_calls: 0
369 decomp_bytes: 0
370
371 iaa device:
372 id: 3
373 n_wqs: 1
374 comp_calls: 0
375 comp_bytes: 0
376 decomp_calls: 0
377 decomp_bytes: 0
378 wqs:
379 name: iaa_crypto
380 comp_calls: 0
381 comp_bytes: 0
382 decomp_calls: 0
383 decomp_bytes: 0
384
385 iaa device:
386 id: 5
387 n_wqs: 1
388 comp_calls: 1360
389 comp_bytes: 1999776
390 decomp_calls: 0
391 decomp_bytes: 0
392 wqs:
393 name: iaa_crypto
394 comp_calls: 1360
395 comp_bytes: 1999776
396 decomp_calls: 0
397 decomp_bytes: 0
398
399 iaa device:
400 id: 7
401 n_wqs: 1
402 comp_calls: 2940
403 comp_bytes: 3994213
404 decomp_calls: 4164
405 decomp_bytes: 5993989
406 wqs:
407 name: iaa_crypto
408 comp_calls: 2940
409 comp_bytes: 3994213
410 decomp_calls: 4164
411 decomp_bytes: 5993989
412 ...
413
414 Writing to 'stats_reset' resets all the stats, including the
415 per-device and per-wq stats::
416
417 # echo 1 > stats_reset
418 # cat wq_stats
419 global stats:
420 total_comp_calls: 0
421 total_decomp_calls: 0
422 total_comp_bytes_out: 0
423 total_decomp_bytes_in: 0
424 total_completion_einval_errors: 0
425 total_completion_timeout_errors: 0
426 total_completion_comp_buf_overflow_errors: 0
427 ...
428
429
430 Use cases
431 =========
432
433 Simple zswap test
434 -----------------
435
436 For this example, the kernel should be configured according to the
437 dedicated mode options described above, and zswap should be enabled as
438 well::
439
440 CONFIG_ZSWAP=y
441
442 This is a simple test that uses iaa_compress as the compressor for a
443 swap (zswap) device. It sets up the zswap device and then uses the
444 memory_memadvise program listed below to forcibly swap out and in a
445 specified number of pages, demonstrating both compress and decompress.
446
447 The zswap test expects the work queues for each IAA device on the
448 system to be configured properly as a kernel workqueue with a
449 workqueue driver_name of "crypto".
450
451 The first step is to make sure the iaa_crypto module is loaded::
452
453 modprobe iaa_crypto
454
455 If the IAA devices and workqueues haven't previously been disabled and
456 reconfigured, then the default configuration should be in place and no
457 further IAA configuration is necessary. See :ref:`iaa_default_config`
458 below for details of the default configuration.
459
460 If the default configuration is in place, you should see the iaa
461 devices and wq0s enabled::
462
463 # cat /sys/bus/dsa/devices/iax1/state
464 enabled
465 # cat /sys/bus/dsa/devices/iax1/wq1.0/state
466 enabled
467
468 To demonstrate that the following steps work as expected, these
469 commands can be used to enable debug output::
470
471 # echo -n 'module iaa_crypto +p' > /sys/kernel/debug/dynamic_debug/control
472 # echo -n 'module idxd +p' > /sys/kernel/debug/dynamic_debug/control
473
474 Use the following commands to enable zswap::
475
476 # echo 0 > /sys/module/zswap/parameters/enabled
477 # echo 50 > /sys/module/zswap/parameters/max_pool_percent
478 # echo deflate-iaa > /sys/module/zswap/parameters/compressor
479 # echo 1 > /sys/module/zswap/parameters/enabled
480 # echo 100 > /proc/sys/vm/swappiness
481 # echo never > /sys/kernel/mm/transparent_hugepage/enabled
482 # echo 1 > /proc/sys/vm/overcommit_memory
483
484 Now you can now run the zswap workload you want to measure. For
485 example, using the memory_memadvise code below, the following command
486 will swap in and out 100 pages::
487
488 ./memory_madvise 100
489
490 Allocating 100 pages to swap in/out
491 Swapping out 100 pages
492 Swapping in 100 pages
493 Swapped out and in 100 pages
494
495 You should see something like the following in the dmesg output::
496
497 [ 404.202972] idxd 0000:e7:02.0: iaa_comp_acompress: dma_map_sg, src_addr 223925c000, nr_sgs 1, req->src 00000000ee7cb5e6, req->slen 4096, sg_dma_len(sg) 4096
498 [ 404.202973] idxd 0000:e7:02.0: iaa_comp_acompress: dma_map_sg, dst_addr 21dadf8000, nr_sgs 1, req->dst 000000008d6acea8, req->dlen 4096, sg_dma_len(sg) 8192
499 [ 404.202975] idxd 0000:e7:02.0: iaa_compress: desc->src1_addr 223925c000, desc->src1_size 4096, desc->dst_addr 21dadf8000, desc->max_dst_size 4096, desc->src2_addr 2203543000, desc->src2_size 1568
500 [ 404.202981] idxd 0000:e7:02.0: iaa_compress_verify: (verify) desc->src1_addr 21dadf8000, desc->src1_size 228, desc->dst_addr 223925c000, desc->max_dst_size 4096, desc->src2_addr 0, desc->src2_size 0
501 ...
502
503 Now that basic functionality has been demonstrated, the defaults can
504 be erased and replaced with a different configuration. To do that,
505 first disable zswap::
506
507 # echo lzo > /sys/module/zswap/parameters/compressor
508 # swapoff -a
509 # echo 0 > /sys/module/zswap/parameters/accept_threshold_percent
510 # echo 0 > /sys/module/zswap/parameters/max_pool_percent
511 # echo 0 > /sys/module/zswap/parameters/enabled
512 # echo 0 > /sys/module/zswap/parameters/enabled
513
514 Then run the :ref:`iaa_disable_script` in the 'Use Cases' section
515 below to disable the default configuration.
516
517 Finally turn swap back on::
518
519 # swapon -a
520
521 Following all that the IAA device(s) can now be re-configured and
522 enabled as desired for further testing. Below is one example.
523
524 The zswap test expects the work queues for each IAA device on the
525 system to be configured properly as a kernel workqueue with a
526 workqueue driver_name of "crypto".
527
528 The below script automatically does that::
529
530 #!/bin/bash
531
532 echo "IAA devices:"
533 lspci -d:0cfe
534 echo "# IAA devices:"
535 lspci -d:0cfe | wc -l
536
537 #
538 # count iaa instances
539 #
540 iaa_dev_id="0cfe"
541 num_iaa=$(lspci -d:${iaa_dev_id} | wc -l)
542 echo "Found ${num_iaa} IAA instances"
543
544 #
545 # disable iaa wqs and devices
546 #
547 echo "Disable IAA"
548
549 for ((i = 1; i < ${num_iaa} * 2; i += 2)); do
550 echo disable wq iax${i}/wq${i}.0
551 accel-config disable-wq iax${i}/wq${i}.0
552 echo disable iaa iax${i}
553 accel-config disable-device iax${i}
554 done
555
556 echo "End Disable IAA"
557
558 echo "Reload iaa_crypto module"
559
560 rmmod iaa_crypto
561 modprobe iaa_crypto
562
563 echo "End Reload iaa_crypto module"
564
565 #
566 # configure iaa wqs and devices
567 #
568 echo "Configure IAA"
569 for ((i = 1; i < ${num_iaa} * 2; i += 2)); do
570 accel-config config-wq --group-id=0 --mode=dedicated --wq-size=128 --priority=10 --type=kernel --name="iaa_crypto" --driver-name="crypto" iax${i}/wq${i}.0
571 accel-config config-engine iax${i}/engine${i}.0 --group-id=0
572 done
573
574 echo "End Configure IAA"
575
576 #
577 # enable iaa wqs and devices
578 #
579 echo "Enable IAA"
580
581 for ((i = 1; i < ${num_iaa} * 2; i += 2)); do
582 echo enable iaa iax${i}
583 accel-config enable-device iax${i}
584 echo enable wq iax${i}/wq${i}.0
585 accel-config enable-wq iax${i}/wq${i}.0
586 done
587
588 echo "End Enable IAA"
589
590 When the workqueues are bound to the iaa_crypto driver, you should
591 see something similar to the following in dmesg output if you've
592 enabled debug output (echo -n 'module iaa_crypto +p' >
593 /sys/kernel/debug/dynamic_debug/control)::
594
595 [ 60.752344] idxd 0000:f6:02.0: add_iaa_wq: added wq 000000004068d14d to iaa 00000000c9585ba2, n_wq 1
596 [ 60.752346] iaa_crypto: rebalance_wq_table: nr_nodes=2, nr_cpus 160, nr_iaa 8, cpus_per_iaa 20
597 [ 60.752347] iaa_crypto: rebalance_wq_table: iaa=0
598 [ 60.752349] idxd 0000:6a:02.0: request_iaa_wq: getting wq from iaa_device 0000000042d7bc52 (0)
599 [ 60.752350] idxd 0000:6a:02.0: request_iaa_wq: returning unused wq 00000000c8bb4452 (0) from iaa device 0000000042d7bc52 (0)
600 [ 60.752352] iaa_crypto: rebalance_wq_table: assigned wq for cpu=0, node=0 = wq 00000000c8bb4452
601 [ 60.752354] iaa_crypto: rebalance_wq_table: iaa=0
602 [ 60.752355] idxd 0000:6a:02.0: request_iaa_wq: getting wq from iaa_device 0000000042d7bc52 (0)
603 [ 60.752356] idxd 0000:6a:02.0: request_iaa_wq: returning unused wq 00000000c8bb4452 (0) from iaa device 0000000042d7bc52 (0)
604 [ 60.752358] iaa_crypto: rebalance_wq_table: assigned wq for cpu=1, node=0 = wq 00000000c8bb4452
605 [ 60.752359] iaa_crypto: rebalance_wq_table: iaa=0
606 [ 60.752360] idxd 0000:6a:02.0: request_iaa_wq: getting wq from iaa_device 0000000042d7bc52 (0)
607 [ 60.752361] idxd 0000:6a:02.0: request_iaa_wq: returning unused wq 00000000c8bb4452 (0) from iaa device 0000000042d7bc52 (0)
608 [ 60.752362] iaa_crypto: rebalance_wq_table: assigned wq for cpu=2, node=0 = wq 00000000c8bb4452
609 [ 60.752364] iaa_crypto: rebalance_wq_table: iaa=0
610 .
611 .
612 .
613
614 Once the workqueues and devices have been enabled, the IAA crypto
615 algorithms are enabled and available. When the IAA crypto algorithms
616 have been successfully enabled, you should see the following dmesg
617 output::
618
619 [ 64.893759] iaa_crypto: iaa_crypto_enable: iaa_crypto now ENABLED
620
621 Now run the following zswap-specific setup commands to have zswap use
622 the 'fixed' compression mode::
623
624 echo 0 > /sys/module/zswap/parameters/enabled
625 echo 50 > /sys/module/zswap/parameters/max_pool_percent
626 echo deflate-iaa > /sys/module/zswap/parameters/compressor
627 echo 1 > /sys/module/zswap/parameters/enabled
628
629 echo 100 > /proc/sys/vm/swappiness
630 echo never > /sys/kernel/mm/transparent_hugepage/enabled
631 echo 1 > /proc/sys/vm/overcommit_memory
632
633 Finally, you can now run the zswap workload you want to measure. For
634 example, using the code below, the following command will swap in and
635 out 100 pages::
636
637 ./memory_madvise 100
638
639 Allocating 100 pages to swap in/out
640 Swapping out 100 pages
641 Swapping in 100 pages
642 Swapped out and in 100 pages
643
644 You should see something like the following in the dmesg output if
645 you've enabled debug output (echo -n 'module iaa_crypto +p' >
646 /sys/kernel/debug/dynamic_debug/control)::
647
648 [ 404.202972] idxd 0000:e7:02.0: iaa_comp_acompress: dma_map_sg, src_addr 223925c000, nr_sgs 1, req->src 00000000ee7cb5e6, req->slen 4096, sg_dma_len(sg) 4096
649 [ 404.202973] idxd 0000:e7:02.0: iaa_comp_acompress: dma_map_sg, dst_addr 21dadf8000, nr_sgs 1, req->dst 000000008d6acea8, req->dlen 4096, sg_dma_len(sg) 8192
650 [ 404.202975] idxd 0000:e7:02.0: iaa_compress: desc->src1_addr 223925c000, desc->src1_size 4096, desc->dst_addr 21dadf8000, desc->max_dst_size 4096, desc->src2_addr 2203543000, desc->src2_size 1568
651 [ 404.202981] idxd 0000:e7:02.0: iaa_compress_verify: (verify) desc->src1_addr 21dadf8000, desc->src1_size 228, desc->dst_addr 223925c000, desc->max_dst_size 4096, desc->src2_addr 0, desc->src2_size 0
652 [ 409.203227] idxd 0000:e7:02.0: iaa_comp_adecompress: dma_map_sg, src_addr 21ddd8b100, nr_sgs 1, req->src 0000000084adab64, req->slen 228, sg_dma_len(sg) 228
653 [ 409.203235] idxd 0000:e7:02.0: iaa_comp_adecompress: dma_map_sg, dst_addr 21ee3dc000, nr_sgs 1, req->dst 000000004e2990d0, req->dlen 4096, sg_dma_len(sg) 4096
654 [ 409.203239] idxd 0000:e7:02.0: iaa_decompress: desc->src1_addr 21ddd8b100, desc->src1_size 228, desc->dst_addr 21ee3dc000, desc->max_dst_size 4096, desc->src2_addr 0, desc->src2_size 0
655 [ 409.203254] idxd 0000:e7:02.0: iaa_comp_adecompress: dma_map_sg, src_addr 21ddd8b100, nr_sgs 1, req->src 0000000084adab64, req->slen 228, sg_dma_len(sg) 228
656 [ 409.203256] idxd 0000:e7:02.0: iaa_comp_adecompress: dma_map_sg, dst_addr 21f1551000, nr_sgs 1, req->dst 000000004e2990d0, req->dlen 4096, sg_dma_len(sg) 4096
657 [ 409.203257] idxd 0000:e7:02.0: iaa_decompress: desc->src1_addr 21ddd8b100, desc->src1_size 228, desc->dst_addr 21f1551000, desc->max_dst_size 4096, desc->src2_addr 0, desc->src2_size 0
658
659 In order to unregister the IAA crypto algorithms, and register new
660 ones using different parameters, any users of the current algorithm
661 should be stopped and the IAA workqueues and devices disabled.
662
663 In the case of zswap, remove the IAA crypto algorithm as the
664 compressor and turn off swap (to remove all references to
665 iaa_crypto)::
666
667 echo lzo > /sys/module/zswap/parameters/compressor
668 swapoff -a
669
670 echo 0 > /sys/module/zswap/parameters/accept_threshold_percent
671 echo 0 > /sys/module/zswap/parameters/max_pool_percent
672 echo 0 > /sys/module/zswap/parameters/enabled
673
674 Once zswap is disabled and no longer using iaa_crypto, the IAA wqs and
675 devices can be disabled.
676
677 .. _iaa_disable_script:
678
679 IAA disable script
680 ------------------
681
682 The below script automatically does that::
683
684 #!/bin/bash
685
686 echo "IAA devices:"
687 lspci -d:0cfe
688 echo "# IAA devices:"
689 lspci -d:0cfe | wc -l
690
691 #
692 # count iaa instances
693 #
694 iaa_dev_id="0cfe"
695 num_iaa=$(lspci -d:${iaa_dev_id} | wc -l)
696 echo "Found ${num_iaa} IAA instances"
697
698 #
699 # disable iaa wqs and devices
700 #
701 echo "Disable IAA"
702
703 for ((i = 1; i < ${num_iaa} * 2; i += 2)); do
704 echo disable wq iax${i}/wq${i}.0
705 accel-config disable-wq iax${i}/wq${i}.0
706 echo disable iaa iax${i}
707 accel-config disable-device iax${i}
708 done
709
710 echo "End Disable IAA"
711
712 Finally, at this point the iaa_crypto module can be removed, which
713 will unregister the current IAA crypto algorithms::
714
715 rmmod iaa_crypto
716
717
718 memory_madvise.c (gcc -o memory_memadvise memory_madvise.c)::
719
720 #include <stdio.h>
721 #include <stdlib.h>
722 #include <string.h>
723 #include <unistd.h>
724 #include <sys/mman.h>
725 #include <linux/mman.h>
726
727 #ifndef MADV_PAGEOUT
728 #define MADV_PAGEOUT 21 /* force pages out immediately */
729 #endif
730
731 #define PG_SZ 4096
732
733 int main(int argc, char **argv)
734 {
735 int i, nr_pages = 1;
736 int64_t *dump_ptr;
737 char *addr, *a;
738 int loop = 1;
739
740 if (argc > 1)
741 nr_pages = atoi(argv[1]);
742
743 printf("Allocating %d pages to swap in/out\n", nr_pages);
744
745 /* allocate pages */
746 addr = mmap(NULL, nr_pages * PG_SZ, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
747 *addr = 1;
748
749 /* initialize data in page to all '*' chars */
750 memset(addr, '*', nr_pages * PG_SZ);
751
752 printf("Swapping out %d pages\n", nr_pages);
753
754 /* Tell kernel to swap it out */
755 madvise(addr, nr_pages * PG_SZ, MADV_PAGEOUT);
756
757 while (loop > 0) {
758 /* Wait for swap out to finish */
759 sleep(5);
760
761 a = addr;
762
763 printf("Swapping in %d pages\n", nr_pages);
764
765 /* Access the page ... this will swap it back in again */
766 for (i = 0; i < nr_pages; i++) {
767 if (a[0] != '*') {
768 printf("Bad data from decompress!!!!!\n");
769
770 dump_ptr = (int64_t *)a;
771 for (int j = 0; j < 100; j++) {
772 printf(" page %d data: %#llx\n", i, *dump_ptr);
773 dump_ptr++;
774 }
775 }
776
777 a += PG_SZ;
778 }
779
780 loop --;
781 }
782
783 printf("Swapped out and in %d pages\n", nr_pages);
784
785 Appendix
786 ========
787
788 .. _iaa_sysfs_config:
789
790 IAA sysfs config interface
791 --------------------------
792
793 Below is a description of the IAA sysfs interface, which as mentioned
794 in the main document, should only be used if you know exactly what you
795 are doing. Even then, there's no compelling reason to use it directly
796 since accel-config can do everything the sysfs interface can and in
797 fact accel-config is based on it under the covers.
798
799 The 'IAA config path' is /sys/bus/dsa/devices and contains
800 subdirectories representing each IAA device, workqueue, engine, and
801 group. Note that in the sysfs interface, the IAA devices are actually
802 named using iax e.g. iax1, iax3, etc. (Note that IAA devices are the
803 odd-numbered devices; the even-numbered devices are DSA devices and
804 can be ignored for IAA).
805
806 The 'IAA device bind path' is /sys/bus/dsa/drivers/idxd/bind and is
807 the file that is written to enable an IAA device.
808
809 The 'IAA workqueue bind path' is /sys/bus/dsa/drivers/crypto/bind and
810 is the file that is written to enable an IAA workqueue.
811
812 Similarly /sys/bus/dsa/drivers/idxd/unbind and
813 /sys/bus/dsa/drivers/crypto/unbind are used to disable IAA devices and
814 workqueues.
815
816 The basic sequence of commands needed to set up the IAA devices and
817 workqueues is:
818
819 For each device::
820 1) Disable any workqueues enabled on the device. For example to
821 disable workques 0 and 1 on IAA device 3::
822
823 # echo wq3.0 > /sys/bus/dsa/drivers/crypto/unbind
824 # echo wq3.1 > /sys/bus/dsa/drivers/crypto/unbind
825
826 2) Disable the device. For example to disable IAA device 3::
827
828 # echo iax3 > /sys/bus/dsa/drivers/idxd/unbind
829
830 3) configure the desired workqueues. For example, to configure
831 workqueue 3 on IAA device 3::
832
833 # echo dedicated > /sys/bus/dsa/devices/iax3/wq3.3/mode
834 # echo 128 > /sys/bus/dsa/devices/iax3/wq3.3/size
835 # echo 0 > /sys/bus/dsa/devices/iax3/wq3.3/group_id
836 # echo 10 > /sys/bus/dsa/devices/iax3/wq3.3/priority
837 # echo "kernel" > /sys/bus/dsa/devices/iax3/wq3.3/type
838 # echo "iaa_crypto" > /sys/bus/dsa/devices/iax3/wq3.3/name
839 # echo "crypto" > /sys/bus/dsa/devices/iax3/wq3.3/driver_name
840
841 4) Enable the device. For example to enable IAA device 3::
842
843 # echo iax3 > /sys/bus/dsa/drivers/idxd/bind
844
845 5) Enable the desired workqueues on the device. For example to
846 enable workques 0 and 1 on IAA device 3::
847
848 # echo wq3.0 > /sys/bus/dsa/drivers/crypto/bind
849 # echo wq3.1 > /sys/bus/dsa/drivers/crypto/bind
850

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

IAA 압축 가속기 Crypto 드라이버 개요

1-45
.. SPDX-License-Identifier: GPL-2.0

이 문서는 Tom Zanussi `<tom.zanussi@linux.intel.com>`가 작성했습니다. IAA crypto 드라이버는 RFC 1951에 정의된 DEFLATE 표준과 호환되는 압축 및 압축 해제를 지원하며, 이 모듈이 외부에 제공하는 알고리즘도 이 방식입니다.

IAA 하드웨어 사양은 다음 문서에서 확인할 수 있습니다.

https://cdrdv2.intel.com/v1/dl/getContent/721858

`iaa_crypto` 드라이버는 zswap 같은 상위 압축 장치 아래에서 동작하는 계층으로 설계됐습니다. 압축 알고리즘을 선택할 수 있는 기능에서 지원되는 IAA 알고리즘을 지정하면 IAA 압축 및 압축 해제 가속을 사용할 수 있습니다.

예를 들어 zswap에서 crypto 압축 알고리즘 `deflate-iaa`를 선택하면 IAA의 `fixed` 모드를 사용할 수 있습니다.

# echo deflate-iaa > /sys/module/zswap/parameters/compressor

이 설정은 zswap의 모든 압축과 압축 해제에 IAA `fixed` 모드를 사용하도록 지시합니다. 현재 제공되는 압축 모드는 `fixed` 하나뿐입니다.

`fixed` 모드는 RFC 1951의 압축 방식을 구현하고 crypto 알고리즘 이름으로 `deflate-iaa`를 사용합니다. IAA 하드웨어의 history window가 4 KiB로 제한되므로 버퍼가 4 KiB 이하이거나 4 KiB 이하의 history window로 압축된 경우에만, 최대 32 KiB window를 허용하는 deflate 사양을 기술적으로 충족합니다. 이 제약 때문에 단순히 `deflate`라고 하지 않고 IAA fixed 모드에 별도의 알고리즘 이름을 부여했습니다.

커널 설정과 IOMMU 모드

46-82

IAA crypto 드라이버는 menuconfig의 다음 경로에서 선택할 수 있습니다.

Cryptographic API -> Hardware crypto devices -> Support for Intel(R) IAA Compression Accelerator

설정 파일의 옵션 이름은 `CONFIG_CRYPTO_DEV_IAA_CRYPTO`입니다. 통계 지원은 다음 menuconfig 경로에서 별도로 활성화합니다.

Cryptographic API -> Hardware crypto devices -> Support for Intel(R) IAA Compression -> Enable Intel(R) IAA Compression Accelerator Statistics

통계 옵션 이름은 `CONFIG_CRYPTO_DEV_IAA_CRYPTO_STATS`입니다. 다음 관련 설정도 활성화해야 합니다.

CONFIG_IRQ_REMAP=y
CONFIG_INTEL_IOMMU=y
CONFIG_INTEL_IOMMU_SVM=y
CONFIG_PCI_ATS=y
CONFIG_PCI_PRI=y
CONFIG_PCI_PASID=y
CONFIG_INTEL_IDXD=m
CONFIG_INTEL_IDXD_SVM=y

IAA는 Intel IOMMU와 함께 동작할 수 있는 초기 Intel 가속기 IP 가운데 하나입니다. IOMMU 설정에 따라 시험할 수 있는 모드는 세 가지입니다.

- Scalable
- Legacy
- No IOMMU

Scalable 모드

83-102

Scalable 모드는 Shared Virtual Memory, 즉 SVM 또는 SVA를 지원합니다. BIOS에서 VT-d를 켜고 다음 커널 부팅 명령줄을 사용하면 이 모드로 들어갑니다.

intel_iommu=on,sm_on

Scalable 모드에서는 shared workqueue와 dedicated workqueue를 모두 사용할 수 있습니다. BIOS에서는 다음 항목을 활성화해야 합니다.

Socket Configuration > IIO Configuration > Intel VT for Directed I/O (VT-d) > Intel VT for Directed I/O

Socket Configuration > IIO Configuration > PCIe ENQCMD > ENQCMDS

Legacy 모드

103-118

다음 커널 부팅 명령줄을 사용하거나 BIOS에서 VT-d가 꺼져 있으면 Legacy 모드로 들어갑니다.

intel_iommu=off

Linux로 부팅한 뒤 VT-d 활성 여부가 확실하지 않다면 `dmesg | grep -i dmar`를 실행하십시오. 여러 DMAR 장치가 열거되지 않는다면 VT-d가 꺼져 있을 가능성이 큽니다. Legacy 모드에서는 dedicated workqueue만 사용할 수 있습니다.

IOMMU 비사용 모드

119-128

다음 커널 부팅 명령줄을 사용하면 IOMMU 비사용 모드로 들어갑니다.

iommu=off.

IOMMU를 사용하지 않는 모드에서도 dedicated workqueue만 사용할 수 있습니다.

accel-config를 이용한 구성

129-167

`iaa_crypto` 드라이버를 로드하면 기본 구성을 자동으로 만들고 활성화하며 기본 드라이버 속성을 지정합니다. 다른 구성이나 속성이 필요하면 먼저 IAA 장치와 workqueue를 비활성화하고 구성을 초기화한 다음, `iaa_crypto` 모듈을 제거했다가 다시 삽입해 `deflate-iaa` 알고리즘을 crypto 서브시스템에 재등록해야 합니다.

아래 사용 사례의 `iaa_disable_script`로 기본 구성을 비활성화할 수 있고, 기본 구성의 자세한 내용은 `iaa_default_config` 절에 있습니다.

가속기 장치는 복잡하고 구성 가능성이 높기 때문에 사용자가 장치를 직접 구성하고 원하는 장치와 workqueue를 수동으로 활성화하려는 경우가 많습니다. 이를 돕는 사용자 공간 도구가 `accel-config`입니다.

`accel-config`로 장치를 구성하거나 저장된 구성을 불러오는 방식을 강력히 권장합니다. sysfs로도 장치를 직접 제어할 수 있지만 무엇을 하는지 정확히 아는 경우에만 사용해야 합니다. 이어지는 본문은 sysfs 인터페이스 대신 `accel-config` 사용을 전제로 하며, sysfs 세부 사항은 부록의 `iaa_sysfs_config` 절에서 확인할 수 있습니다.

`accel-config` 도구와 빌드 방법은 다음 위치에 있습니다.

https://github.com/intel/idxd-config/#readme

일반적인 workqueue 구성

168-218

`iaa_crypto` 모듈이 상위 기능을 대신해 실제 압축 및 압축 해제를 수행하려면 하나 이상의 IAA workqueue가 `iaa_crypto` 드라이버에 바인딩돼야 합니다.

다음 예는 IAA workqueue를 구성하고 `iaa_crypto`에 바인딩합니다. 업스트림에 예전 장치 이름이 남아 있어 장치 이름은 `iaa`가 아니라 `iax`로 지정합니다.

# configure wq1.0

accel-config config-wq --group-id=0 --mode=dedicated --type=kernel --priority=10 --name="iaa_crypto" --driver-name="crypto" iax1/wq1.0

accel-config config-engine iax1/engine1.0 --group-id=0

# enable IAA device iax1

accel-config enable-device iax1

# enable wq1.0 on IAX device iax1

accel-config enable-wq iax1/wq1.0

새 workqueue가 `iaa_crypto`에 바인딩되거나 드라이버에서 분리될 때마다 사용 가능한 workqueue를 재균형화합니다. 특정 CPU가 제출한 작업은 가장 적절한 가용 workqueue로 전달됩니다.

현재 권장 방식은 각 IAA 장치마다 workqueue를 하나 이상 구성해 바인딩하는 것입니다. 시스템의 어느 IAA 장치든 최소 한 개의 workqueue가 구성되고 바인딩돼 있으면 드라이버는 동작하지만 효율이 떨어질 수 있습니다.

첫 IAA workqueue가 성공적으로 바인딩되면 IAA crypto 알고리즘이 동작 상태가 되고 압축 및 압축 해제가 완전히 활성화됩니다. 반대로 마지막 workqueue가 언바인딩되면 알고리즘은 동작하지 않으며 두 연산도 비활성화됩니다.

따라서 하나 이상의 workqueue가 `iaa_crypto`에 바인딩돼 있을 때만 IAA crypto 알고리즘과 IAA 하드웨어를 사용할 수 있습니다. 바인딩된 workqueue가 없으면 모듈을 제거해 알고리즘을 등록 해제할 수 있습니다.

드라이버 속성

219-292

동작 모드를 설정할 수 있는 사용자 구성 가능 속성이 몇 가지 있습니다. 속성 파일은 `/sys/bus/dsa/drivers/crypto/` 아래에 있으며, 원하는 값을 해당 파일에 써서 설정합니다. IAA 알고리즘을 등록할 당시의 속성값은 각 알고리즘의 `crypto_ctx`에 저장되고 그 알고리즘의 모든 압축 및 압축 해제에 사용됩니다.

`verify_compress`는 압축 검증을 켜거나 끕니다. 활성화하면 압축 결과를 내부적으로 다시 풀어 내용을 검증하고, 실패하면 오류 코드를 반환합니다. `0` 또는 `1`로 전환할 수 있습니다.

echo 0 > /sys/bus/dsa/drivers/crypto/verify_compress

기본값은 `1`, 즉 모든 압축을 검증하는 상태입니다.

`sync_mode`는 각 압축 및 압축 해제 완료를 기다리는 방식을 선택합니다. `iaa_crypto`의 crypto 비동기 인터페이스 구현은 인터페이스 요건을 충족하지만 기본적으로 동기 방식으로 동작합니다. IDXD descriptor를 채워 제출한 뒤 완료될 때까지 반복해서 확인하고 나서 반환합니다.

현재 zswap 같은 호출자는 비동기 피호출자를 어차피 동기 래퍼로 감싸므로 이 동작은 문제가 되지 않습니다. 한편 드라이버는 이를 활용할 수 있는 호출자를 위해 진정한 비동기 방식도 제공합니다. 이 모드에서는 descriptor를 제출한 직후 `-EINPROGRESS`를 반환합니다.

호출자는 직접 완료를 polling할 수 있지만 이를 위한 전용 코드가 필요하고 현재 업스트림 커널에는 구현한 사용자가 없습니다. 또는 sleep 상태로 들어가 완료 인터럽트를 기다릴 수 있습니다. 후자는 zswap 같은 현재 커널 사용자가 동기 래퍼를 통해 지원하지만, 드라이버 내부에서 polling하는 앞의 동기 모드보다 상당히 느립니다.

인터럽트를 사용하는 비동기 모드는 `sync_mode` 속성에 `async_irq`를 써서 활성화합니다.

echo async_irq > /sys/bus/dsa/drivers/crypto/sync_mode

호출자가 polling해야 하는 인터럽트 없는 비동기 모드는 `async`를 써서 선택합니다. 아래 주의 사항도 확인하십시오.

echo async > /sys/bus/dsa/drivers/crypto/sync_mode

`iaa_crypto` 드라이버 내부에서 polling하는 모드는 `sync`를 써서 선택합니다.

echo sync > /sys/bus/dsa/drivers/crypto/sync_mode

기본 모드는 `sync`입니다. 현재 `iaa_crypto`가 인터럽트 없는 비동기 polling을 위해 구현한 유일한 메커니즘은 앞에서 설명한 `sync` 모드이므로, 속성에 `async`를 쓰더라도 내부적으로는 `sync`가 활성화됩니다. 진정한 인터럽트 없는 비동기 polling이 구현되기 전까지 올바른 동작을 보장하기 위한 조치입니다.

IAA 기본 구성

293-324

`iaa_crypto` 드라이버를 로드하면 각 IAA 장치마다 다음 속성을 가진 workqueue 하나를 구성합니다.

mode              "dedicated"
threshold         0
size              Total WQ Size from WQCAP
priority          10
type              IDXD_WQT_KERNEL
group             0
name              "iaa_crypto"
driver_name       "crypto"

장치와 workqueue도 함께 활성화되므로 추가 구성 없이 바로 드라이버를 사용할 수 있습니다. 드라이버를 로드할 때 적용되는 기본 속성은 다음과 같습니다.

sync_mode         "sync"
verify_compress   1

장치, workqueue 또는 드라이버 속성을 바꾸려면 활성화된 장치와 workqueue를 먼저 비활성화해야 합니다. 새 구성을 `deflate-iaa` crypto 알고리즘에 적용하려면 `iaa_crypto` 모듈을 제거했다가 다시 삽입해 알고리즘을 재등록해야 합니다. 사용 사례의 `iaa_disable_script`로 기본 구성을 비활성화할 수 있습니다.

debugfs 통계

325-429

선택적인 debugfs 통계 지원을 활성화하면 IAA crypto 드라이버가 통계를 생성하며 `/sys/kernel/debug/iaa-crypto/`에서 접근할 수 있습니다.

# ls -al /sys/kernel/debug/iaa-crypto/
total 0
drwxr-xr-x  2 root root 0 Mar  3 07:55 .
drwx------ 53 root root 0 Mar  3 07:55 ..
-rw-r--r--  1 root root 0 Mar  3 07:55 global_stats
-rw-r--r--  1 root root 0 Mar  3 07:55 stats_reset
-rw-r--r--  1 root root 0 Mar  3 07:55 wq_stats

`global_stats`는 드라이버를 로드하거나 통계를 초기화한 뒤부터 수집한 전역 통계를 보여 줍니다.

# cat global_stats
global stats:
  total_comp_calls: 4300
  total_decomp_calls: 4164
  total_sw_decomp_calls: 0
  total_comp_bytes_out: 5993989
  total_decomp_bytes_in: 5993989
  total_completion_einval_errors: 0
  total_completion_timeout_errors: 0
  total_completion_comp_buf_overflow_errors: 136

`wq_stats`는 일부 전역 통계와 함께 각 IAA 장치 및 workqueue별 통계를 보여 줍니다.

# cat wq_stats
iaa device:
  id: 1
  n_wqs: 1
  comp_calls: 0
  comp_bytes: 0
  decomp_calls: 0
  decomp_bytes: 0
  wqs:
    name: iaa_crypto
    comp_calls: 0
    comp_bytes: 0
    decomp_calls: 0
    decomp_bytes: 0

iaa device:
  id: 3
  n_wqs: 1
  comp_calls: 0
  comp_bytes: 0
  decomp_calls: 0
  decomp_bytes: 0
  wqs:
    name: iaa_crypto
    comp_calls: 0
    comp_bytes: 0
    decomp_calls: 0
    decomp_bytes: 0

iaa device:
  id: 5
  n_wqs: 1
  comp_calls: 1360
  comp_bytes: 1999776
  decomp_calls: 0
  decomp_bytes: 0
  wqs:
    name: iaa_crypto
    comp_calls: 1360
    comp_bytes: 1999776
    decomp_calls: 0
    decomp_bytes: 0

iaa device:
  id: 7
  n_wqs: 1
  comp_calls: 2940
  comp_bytes: 3994213
  decomp_calls: 4164
  decomp_bytes: 5993989
  wqs:
    name: iaa_crypto
    comp_calls: 2940
    comp_bytes: 3994213
    decomp_calls: 4164
    decomp_bytes: 5993989
  ...

`stats_reset`에 값을 쓰면 장치별 및 workqueue별 통계를 포함한 모든 통계를 초기화합니다.

# echo 1 > stats_reset
# cat wq_stats
  global stats:
  total_comp_calls: 0
  total_decomp_calls: 0
  total_comp_bytes_out: 0
  total_decomp_bytes_in: 0
  total_completion_einval_errors: 0
  total_completion_timeout_errors: 0
  total_completion_comp_buf_overflow_errors: 0
  ...

간단한 zswap 시험 준비

430-458

이 예에서는 앞서 설명한 dedicated 모드 옵션에 맞춰 커널을 구성하고 zswap도 활성화해야 합니다.

CONFIG_ZSWAP=y

이 간단한 시험은 swap 장치인 zswap의 compressor로 `iaa_compress`를 사용합니다. zswap 장치를 설정한 다음 아래의 `memory_madvise` 프로그램으로 지정한 수의 페이지를 강제로 swap out과 swap in하여 압축과 압축 해제를 모두 보여 줍니다.

시스템의 각 IAA 장치에 있는 workqueue는 `driver_name`이 `crypto`인 kernel workqueue로 올바르게 구성돼 있어야 합니다. 먼저 `iaa_crypto` 모듈이 로드됐는지 확인합니다.

modprobe iaa_crypto

IAA 장치와 workqueue를 이전에 비활성화하거나 재구성하지 않았다면 기본 구성이 적용돼 있으므로 추가 IAA 설정은 필요하지 않습니다. 기본 구성의 세부 사항은 `iaa_default_config` 절을 참고하십시오.

기본 구성으로 zswap 시험

459-522

기본 구성이 적용돼 있으면 IAA 장치와 `wq0`가 활성화된 상태로 표시됩니다.

# cat /sys/bus/dsa/devices/iax1/state
enabled
# cat /sys/bus/dsa/devices/iax1/wq1.0/state
enabled

동작을 확인하기 위해 다음 명령으로 디버그 출력을 활성화할 수 있습니다.

# echo -n 'module iaa_crypto +p' > /sys/kernel/debug/dynamic_debug/control
# echo -n 'module idxd +p' > /sys/kernel/debug/dynamic_debug/control

다음 명령으로 zswap을 활성화합니다.

# echo 0 > /sys/module/zswap/parameters/enabled
# echo 50 > /sys/module/zswap/parameters/max_pool_percent
# echo deflate-iaa > /sys/module/zswap/parameters/compressor
# echo 1 > /sys/module/zswap/parameters/enabled
# echo 100 > /proc/sys/vm/swappiness
# echo never > /sys/kernel/mm/transparent_hugepage/enabled
# echo 1 > /proc/sys/vm/overcommit_memory

이제 측정할 zswap 작업을 실행할 수 있습니다. 아래 `memory_madvise` 예에서는 100페이지를 swap out한 뒤 다시 swap in합니다.

./memory_madvise 100

Allocating 100 pages to swap in/out
Swapping out 100 pages
Swapping in 100 pages
Swapped out and in 100 pages

`dmesg`에는 다음과 비슷한 압축 및 검증 출력이 나타나야 합니다.

[  404.202972] idxd 0000:e7:02.0: iaa_comp_acompress: dma_map_sg, src_addr 223925c000, nr_sgs 1, req->src 00000000ee7cb5e6, req->slen 4096, sg_dma_len(sg) 4096
[  404.202973] idxd 0000:e7:02.0: iaa_comp_acompress: dma_map_sg, dst_addr 21dadf8000, nr_sgs 1, req->dst 000000008d6acea8, req->dlen 4096, sg_dma_len(sg) 8192
[  404.202975] idxd 0000:e7:02.0: iaa_compress: desc->src1_addr 223925c000, desc->src1_size 4096, desc->dst_addr 21dadf8000, desc->max_dst_size 4096, desc->src2_addr 2203543000, desc->src2_size 1568
[  404.202981] idxd 0000:e7:02.0: iaa_compress_verify: (verify) desc->src1_addr 21dadf8000, desc->src1_size 228, desc->dst_addr 223925c000, desc->max_dst_size 4096, desc->src2_addr 0, desc->src2_size 0
...
IAA 압축과 검증 흐름
원본 4 KiB 페이지와 출력 버퍼 DMA mapping`iaa_compress` descriptor 제출228바이트 압축 결과`iaa_compress_verify` 재해제원본 4 KiB와 내용 검증

첫 번째 dmesg 추적이 보여 주는 source mapping, IAA 압축, 결과 재해제 검증 순서를 구조화했습니다.

기본 기능을 확인한 뒤에는 기본 구성을 지우고 다른 구성으로 교체할 수 있습니다. 먼저 다음 명령으로 zswap을 비활성화합니다.

# echo lzo > /sys/module/zswap/parameters/compressor
# swapoff -a
# echo 0 > /sys/module/zswap/parameters/accept_threshold_percent
# echo 0 > /sys/module/zswap/parameters/max_pool_percent
# echo 0 > /sys/module/zswap/parameters/enabled
# echo 0 > /sys/module/zswap/parameters/enabled

그런 다음 아래 사용 사례의 `iaa_disable_script`를 실행해 기본 구성을 비활성화하고 swap을 다시 켭니다.

# swapon -a

이 과정을 마치면 추가 시험에 맞춰 IAA 장치를 원하는 방식으로 재구성하고 활성화할 수 있습니다.

사용자 구성 스크립트와 workqueue 활성화

523-620

zswap 시험을 위해 각 IAA 장치의 workqueue는 `driver_name`이 `crypto`인 kernel workqueue로 구성돼야 합니다. 다음 스크립트는 IAA 인스턴스를 세고, 기존 workqueue와 장치를 비활성화하고, `iaa_crypto` 모듈을 다시 로드한 뒤, 각 장치의 workqueue와 engine을 구성해 다시 활성화합니다.

#!/bin/bash

echo "IAA devices:"
lspci -d:0cfe
echo "# IAA devices:"
lspci -d:0cfe | wc -l

#
# count iaa instances
#
iaa_dev_id="0cfe"
num_iaa=$(lspci -d:${iaa_dev_id} | wc -l)
echo "Found ${num_iaa} IAA instances"

#
# disable iaa wqs and devices
#
echo "Disable IAA"

for ((i = 1; i < ${num_iaa} * 2; i += 2)); do
    echo disable wq iax${i}/wq${i}.0
    accel-config disable-wq iax${i}/wq${i}.0
    echo disable iaa iax${i}
    accel-config disable-device iax${i}
done

echo "End Disable IAA"

echo "Reload iaa_crypto module"

rmmod iaa_crypto
modprobe iaa_crypto

echo "End Reload iaa_crypto module"

#
# configure iaa wqs and devices
#
echo "Configure IAA"
for ((i = 1; i < ${num_iaa} * 2; i += 2)); do
    accel-config config-wq --group-id=0 --mode=dedicated --wq-size=128 --priority=10 --type=kernel --name="iaa_crypto" --driver-name="crypto" iax${i}/wq${i}.0
    accel-config config-engine iax${i}/engine${i}.0 --group-id=0
done

echo "End Configure IAA"

#
# enable iaa wqs and devices
#
echo "Enable IAA"

for ((i = 1; i < ${num_iaa} * 2; i += 2)); do
    echo enable iaa iax${i}
    accel-config enable-device iax${i}
    echo enable wq iax${i}/wq${i}.0
    accel-config enable-wq iax${i}/wq${i}.0
done

echo "End Enable IAA"

workqueue가 `iaa_crypto` 드라이버에 바인딩되면 디버그 출력을 활성화한 경우 `dmesg`에서 workqueue 추가와 CPU·NUMA 노드별 재균형화 결과를 볼 수 있습니다.

[   60.752344] idxd 0000:f6:02.0: add_iaa_wq: added wq 000000004068d14d to iaa 00000000c9585ba2, n_wq 1
[   60.752346] iaa_crypto: rebalance_wq_table: nr_nodes=2, nr_cpus 160, nr_iaa 8, cpus_per_iaa 20
[   60.752347] iaa_crypto: rebalance_wq_table: iaa=0
[   60.752349] idxd 0000:6a:02.0: request_iaa_wq: getting wq from iaa_device 0000000042d7bc52 (0)
[   60.752350] idxd 0000:6a:02.0: request_iaa_wq: returning unused wq 00000000c8bb4452 (0) from iaa device 0000000042d7bc52 (0)
[   60.752352] iaa_crypto: rebalance_wq_table: assigned wq for cpu=0, node=0 = wq 00000000c8bb4452
[   60.752354] iaa_crypto: rebalance_wq_table: iaa=0
[   60.752355] idxd 0000:6a:02.0: request_iaa_wq: getting wq from iaa_device 0000000042d7bc52 (0)
[   60.752356] idxd 0000:6a:02.0: request_iaa_wq: returning unused wq 00000000c8bb4452 (0) from iaa device 0000000042d7bc52 (0)
[   60.752358] iaa_crypto: rebalance_wq_table: assigned wq for cpu=1, node=0 = wq 00000000c8bb4452
[   60.752359] iaa_crypto: rebalance_wq_table: iaa=0
[   60.752360] idxd 0000:6a:02.0: request_iaa_wq: getting wq from iaa_device 0000000042d7bc52 (0)
[   60.752361] idxd 0000:6a:02.0: request_iaa_wq: returning unused wq 00000000c8bb4452 (0) from iaa device 0000000042d7bc52 (0)
[   60.752362] iaa_crypto: rebalance_wq_table: assigned wq for cpu=2, node=0 = wq 00000000c8bb4452
[   60.752364] iaa_crypto: rebalance_wq_table: iaa=0
.
.
.

workqueue와 장치를 활성화하면 IAA crypto 알고리즘을 사용할 수 있습니다. 성공적으로 활성화됐을 때는 다음 메시지가 출력됩니다.

[   64.893759] iaa_crypto: iaa_crypto_enable: iaa_crypto now ENABLED

zswap 작업과 알고리즘 등록 해제

621-676

zswap이 `fixed` 압축 모드를 사용하도록 다음 전용 설정 명령을 실행합니다.

echo 0 > /sys/module/zswap/parameters/enabled
echo 50 > /sys/module/zswap/parameters/max_pool_percent
echo deflate-iaa > /sys/module/zswap/parameters/compressor
echo 1 > /sys/module/zswap/parameters/enabled

echo 100 > /proc/sys/vm/swappiness
echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo 1 > /proc/sys/vm/overcommit_memory

그런 다음 측정할 zswap 작업을 실행합니다. 아래 예는 100페이지를 swap out하고 다시 swap in합니다.

./memory_madvise 100

Allocating 100 pages to swap in/out
Swapping out 100 pages
Swapping in 100 pages
Swapped out and in 100 pages

디버그 출력을 활성화했다면 `dmesg`에서 DMA mapping, 압축 descriptor, 압축 검증과 압축 해제 descriptor가 이어지는 다음 추적을 볼 수 있습니다.

[  404.202972] idxd 0000:e7:02.0: iaa_comp_acompress: dma_map_sg, src_addr 223925c000, nr_sgs 1, req->src 00000000ee7cb5e6, req->slen 4096, sg_dma_len(sg) 4096
[  404.202973] idxd 0000:e7:02.0: iaa_comp_acompress: dma_map_sg, dst_addr 21dadf8000, nr_sgs 1, req->dst 000000008d6acea8, req->dlen 4096, sg_dma_len(sg) 8192
[  404.202975] idxd 0000:e7:02.0: iaa_compress: desc->src1_addr 223925c000, desc->src1_size 4096, desc->dst_addr 21dadf8000, desc->max_dst_size 4096, desc->src2_addr 2203543000, desc->src2_size 1568
[  404.202981] idxd 0000:e7:02.0: iaa_compress_verify: (verify) desc->src1_addr 21dadf8000, desc->src1_size 228, desc->dst_addr 223925c000, desc->max_dst_size 4096, desc->src2_addr 0, desc->src2_size 0
[  409.203227] idxd 0000:e7:02.0: iaa_comp_adecompress: dma_map_sg, src_addr 21ddd8b100, nr_sgs 1, req->src 0000000084adab64, req->slen 228, sg_dma_len(sg) 228
[  409.203235] idxd 0000:e7:02.0: iaa_comp_adecompress: dma_map_sg, dst_addr 21ee3dc000, nr_sgs 1, req->dst 000000004e2990d0, req->dlen 4096, sg_dma_len(sg) 4096
[  409.203239] idxd 0000:e7:02.0: iaa_decompress: desc->src1_addr 21ddd8b100, desc->src1_size 228, desc->dst_addr 21ee3dc000, desc->max_dst_size 4096, desc->src2_addr 0, desc->src2_size 0
[  409.203254] idxd 0000:e7:02.0: iaa_comp_adecompress: dma_map_sg, src_addr 21ddd8b100, nr_sgs 1, req->src 0000000084adab64, req->slen 228, sg_dma_len(sg) 228
[  409.203256] idxd 0000:e7:02.0: iaa_comp_adecompress: dma_map_sg, dst_addr 21f1551000, nr_sgs 1, req->dst 000000004e2990d0, req->dlen 4096, sg_dma_len(sg) 4096
[  409.203257] idxd 0000:e7:02.0: iaa_decompress: desc->src1_addr 21ddd8b100, desc->src1_size 228, desc->dst_addr 21f1551000, desc->max_dst_size 4096, desc->src2_addr 0, desc->src2_size 0
zswap의 IAA 압축 및 압축 해제 경로
swap-out 원본 페이지source/destination DMA mapping`iaa_compress`압축 데이터 저장`iaa_compress_verify`
swap-in 압축 데이터source/destination DMA mapping`iaa_decompress`4 KiB 페이지 복원

두 번째 dmesg 추적의 왕복 데이터 경로를 압축 단계와 swap-in 해제 단계로 나눠 정리했습니다.

다른 매개변수로 새 IAA crypto 알고리즘을 등록하려면 현재 알고리즘 사용자를 모두 중지하고 IAA workqueue와 장치를 비활성화해야 합니다. zswap에서는 IAA 알고리즘을 compressor에서 제거하고 swap을 꺼서 `iaa_crypto`에 대한 모든 참조를 없앱니다.

echo lzo > /sys/module/zswap/parameters/compressor
swapoff -a

echo 0 > /sys/module/zswap/parameters/accept_threshold_percent
echo 0 > /sys/module/zswap/parameters/max_pool_percent
echo 0 > /sys/module/zswap/parameters/enabled

zswap이 비활성화돼 더 이상 `iaa_crypto`를 사용하지 않으면 IAA workqueue와 장치를 비활성화할 수 있습니다.

IAA 비활성화 스크립트

677-717

다음 스크립트는 IAA 인스턴스를 세고 각 장치의 workqueue를 먼저 비활성화한 뒤 장치를 비활성화합니다.

#!/bin/bash

echo "IAA devices:"
lspci -d:0cfe
echo "# IAA devices:"
lspci -d:0cfe | wc -l

#
# count iaa instances
#
iaa_dev_id="0cfe"
num_iaa=$(lspci -d:${iaa_dev_id} | wc -l)
echo "Found ${num_iaa} IAA instances"

#
# disable iaa wqs and devices
#
echo "Disable IAA"

for ((i = 1; i < ${num_iaa} * 2; i += 2)); do
    echo disable wq iax${i}/wq${i}.0
    accel-config disable-wq iax${i}/wq${i}.0
    echo disable iaa iax${i}
    accel-config disable-device iax${i}
done

echo "End Disable IAA"

이 시점에는 `iaa_crypto` 모듈을 제거할 수 있으며, 그러면 현재 IAA crypto 알고리즘도 등록 해제됩니다.

rmmod iaa_crypto

memory_madvise 시험 프로그램

718-784

다음 `memory_madvise.c`는 `gcc -o memory_memadvise memory_madvise.c`로 빌드합니다. 인자로 받은 수만큼 4 KiB 페이지를 익명 공유 mapping으로 할당해 `*` 문자로 채우고, `MADV_PAGEOUT`으로 즉시 swap out을 요청합니다.

프로그램은 잠시 기다린 뒤 각 페이지를 다시 읽어 swap in을 유발하고 데이터가 `*`인지 확인합니다. 값이 다르면 압축 해제 오류를 알리고 페이지 앞부분의 데이터를 출력합니다.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/mman.h>
#include <linux/mman.h>

#ifndef MADV_PAGEOUT
#define MADV_PAGEOUT    21      /* force pages out immediately */
#endif

#define PG_SZ           4096

int main(int argc, char **argv)
{
      int i, nr_pages = 1;
      int64_t *dump_ptr;
      char *addr, *a;
      int loop = 1;

      if (argc > 1)
              nr_pages = atoi(argv[1]);

      printf("Allocating %d pages to swap in/out\n", nr_pages);

      /* allocate pages */
      addr = mmap(NULL, nr_pages * PG_SZ, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
      *addr = 1;

      /* initialize data in page to all '*' chars */
      memset(addr, '*', nr_pages * PG_SZ);

       printf("Swapping out %d pages\n", nr_pages);

      /* Tell kernel to swap it out */
      madvise(addr, nr_pages * PG_SZ, MADV_PAGEOUT);

      while (loop > 0) {
              /* Wait for swap out to finish */
              sleep(5);

              a = addr;

              printf("Swapping in %d pages\n", nr_pages);

              /* Access the page ... this will swap it back in again */
              for (i = 0; i < nr_pages; i++) {
                      if (a[0] != '*') {
                              printf("Bad data from decompress!!!!!\n");

                              dump_ptr = (int64_t *)a;
                               for (int j = 0; j < 100; j++) {
                                      printf("  page %d data: %#llx\n", i, *dump_ptr);
                                      dump_ptr++;
                              }
                      }

                      a += PG_SZ;
              }

              loop --;
      }

     printf("Swapped out and in %d pages\n", nr_pages);

부록: IAA sysfs 구성 인터페이스

785-849

이 부록은 IAA sysfs 인터페이스를 설명합니다. 본문에서 강조했듯 무엇을 하는지 정확히 아는 경우에만 직접 사용해야 합니다. `accel-config`가 sysfs 기능을 모두 제공하고 내부적으로도 이 인터페이스를 기반으로 하므로 직접 사용할 특별한 이유는 없습니다.

IAA 구성 경로는 `/sys/bus/dsa/devices`이며 각 IAA 장치, workqueue, engine, group을 나타내는 하위 디렉터리를 포함합니다. sysfs에서는 IAA 장치 이름으로 `iax1`, `iax3` 같은 `iax`를 사용합니다. 홀수 번호가 IAA 장치이고 짝수 번호는 DSA 장치이므로 IAA 구성에서는 무시할 수 있습니다.

IAA 장치 활성화 파일은 `/sys/bus/dsa/drivers/idxd/bind`, IAA workqueue 활성화 파일은 `/sys/bus/dsa/drivers/crypto/bind`입니다. 비활성화에는 각각 `/sys/bus/dsa/drivers/idxd/unbind`와 `/sys/bus/dsa/drivers/crypto/unbind`를 사용합니다.

기본 설정 순서는 장치별로 활성 workqueue를 모두 비활성화하고, 장치를 비활성화하고, 원하는 workqueue를 구성한 다음, 장치와 workqueue를 다시 활성화하는 것입니다. IAA 장치 3의 workqueue 0과 1을 비활성화하는 예는 다음과 같습니다.

# echo wq3.0 > /sys/bus/dsa/drivers/crypto/unbind
# echo wq3.1 > /sys/bus/dsa/drivers/crypto/unbind

IAA 장치 3 자체를 비활성화합니다.

# echo iax3 > /sys/bus/dsa/drivers/idxd/unbind

IAA 장치 3의 workqueue 3을 dedicated kernel workqueue로 구성하고 크기, group, priority, 이름과 driver 이름을 지정합니다.

# echo dedicated > /sys/bus/dsa/devices/iax3/wq3.3/mode
# echo 128 > /sys/bus/dsa/devices/iax3/wq3.3/size
# echo 0 > /sys/bus/dsa/devices/iax3/wq3.3/group_id
# echo 10 > /sys/bus/dsa/devices/iax3/wq3.3/priority
# echo "kernel" > /sys/bus/dsa/devices/iax3/wq3.3/type
# echo "iaa_crypto" > /sys/bus/dsa/devices/iax3/wq3.3/name
# echo "crypto" > /sys/bus/dsa/devices/iax3/wq3.3/driver_name

IAA 장치 3을 다시 활성화합니다.

# echo iax3 > /sys/bus/dsa/drivers/idxd/bind

마지막으로 원하는 workqueue 0과 1을 활성화합니다.

# echo wq3.0 > /sys/bus/dsa/drivers/crypto/bind
# echo wq3.1 > /sys/bus/dsa/drivers/crypto/bind