Documentation/driver-api/cxl/allocation/dax.rst GitHub 원문 ↗

Linux 6.18.37 · Driver API / CXL / Allocation

DAX Devices

CXL DAX 용량의 직접 mmap, flush와 alignment 요구 사항을 설명합니다.

Source pathDocumentation/driver-api/cxl/allocation/dax.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

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

1. 요약·해설

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

요약과 해설

dax.rst:1-60

CXL DAX 용량의 직접 mmap, flush와 alignment 요구 사항을 설명합니다. 영어 원문 전체와 한국어 전문 번역을 함께 제공하며 directive, 코드, symbol, source path와 원문 줄 좌표를 보존합니다.

2. 영어 원문 전체

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

원문 전체 펼치기
1 .. SPDX-License-Identifier: GPL-2.0
2
3 ===========
4 DAX Devices
5 ===========
6 CXL capacity exposed as a DAX device can be accessed directly via mmap.
7 Users may wish to use this interface mechanism to write their own userland
8 CXL allocator, or to managed shared or persistent memory regions across multiple
9 hosts.
10
11 If the capacity is shared across hosts or persistent, appropriate flushing
12 mechanisms must be employed unless the region supports Snoop Back-Invalidate.
13
14 Note that mappings must be aligned (size and base) to the dax device's base
15 alignment, which is typically 2MB - but maybe be configured larger.
16
17 ::
18
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <stdint.h>
22 #include <sys/mman.h>
23 #include <fcntl.h>
24 #include <unistd.h>
25
26 #define DEVICE_PATH "/dev/dax0.0" // Replace DAX device path
27 #define DEVICE_SIZE (4ULL * 1024 * 1024 * 1024) // 4GB
28
29 int main() {
30 int fd;
31 void* mapped_addr;
32
33 /* Open the DAX device */
34 fd = open(DEVICE_PATH, O_RDWR);
35 if (fd < 0) {
36 perror("open");
37 return -1;
38 }
39
40 /* Map the device into memory */
41 mapped_addr = mmap(NULL, DEVICE_SIZE, PROT_READ | PROT_WRITE,
42 MAP_SHARED, fd, 0);
43 if (mapped_addr == MAP_FAILED) {
44 perror("mmap");
45 close(fd);
46 return -1;
47 }
48
49 printf("Mapped address: %p\n", mapped_addr);
50
51 /* You can now access the device through the mapped address */
52 uint64_t* ptr = (uint64_t*)mapped_addr;
53 *ptr = 0x1234567890abcdef; // Write a value to the device
54 printf("Value at address %p: 0x%016llx\n", ptr, *ptr);
55
56 /* Clean up */
57 munmap(mapped_addr, DEVICE_SIZE);
58 close(fd);
59 return 0;
60 }
61

3. 한국어 전문 번역

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

CXL DAX 장치

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

DAX 장치로 노출된 CXL 용량은 `mmap()`을 통해 직접 접근할 수 있습니다. 사용자는 이 인터페이스로 자체 사용자 공간 CXL allocator를 작성하거나 여러 호스트에 걸친 공유 또는 영속 메모리 영역을 관리할 수 있습니다.

용량이 호스트 사이에서 공유되거나 영속성을 가진다면 해당 영역이 Snoop Back-Invalidate를 지원하지 않는 한 적절한 flush 메커니즘을 사용해야 합니다.

mapping의 크기와 base 주소는 DAX 장치의 기본 alignment에 맞춰야 합니다. 일반적으로 2 MiB이지만 더 큰 값으로 구성할 수도 있습니다.

DAX mmap 예제

17-60

다음 C 프로그램은 `/dev/dax0.0` 장치를 읽기·쓰기 모드로 열고 4 GiB를 공유 mapping으로 연결합니다. mapping된 주소의 첫 64비트 위치에 값을 쓴 뒤 값을 확인하고, `munmap()`과 `close()`로 정리합니다. 실제 환경에서는 `DEVICE_PATH`와 `DEVICE_SIZE`를 대상 DAX 장치에 맞춰야 합니다.

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>

#define DEVICE_PATH "/dev/dax0.0" // Replace DAX device path
#define DEVICE_SIZE (4ULL * 1024 * 1024 * 1024) // 4GB

int main() {
    int fd;
    void* mapped_addr;

    /* Open the DAX device */
    fd = open(DEVICE_PATH, O_RDWR);
    if (fd < 0) {
        perror("open");
        return -1;
    }

    /* Map the device into memory */
    mapped_addr = mmap(NULL, DEVICE_SIZE, PROT_READ | PROT_WRITE,
                       MAP_SHARED, fd, 0);
    if (mapped_addr == MAP_FAILED) {
        perror("mmap");
        close(fd);
        return -1;
    }

    printf("Mapped address: %p\n", mapped_addr);

    /* You can now access the device through the mapped address */
    uint64_t* ptr = (uint64_t*)mapped_addr;
    *ptr = 0x1234567890abcdef; // Write a value to the device
    printf("Value at address %p: 0x%016llx\n", ptr, *ptr);

    /* Clean up */
    munmap(mapped_addr, DEVICE_SIZE);
    close(fd);
    return 0;
}