ndctl

Concepts

NVDIMM Devices

A generic DIMM device object, named /dev/nmemX, is registered for each physical memory device indicated in the ACPI NFIT table, or other platform NVDIMM resource discovery mechanism.

1
2
$ ls /dev | grep nm
nmem0 nmem1 nmem2 ... nmem7 # 这是字符设备

( ? Why nmem as char-dev while pmem as blk-dev (under fsdax mode) )

ACPI NFIT

Advanced Configuration and Power Interface (ACPI): 高级配置和电源管理接口

提供很多表用于 OS 对硬件配置进行管理。

ACPI NVDIMM Firmware Interface Table (NFIT): NVDIMM 固件接口表

NVDIMM

NVDIMM,即非易失性双列直插式内存模块 (non-volatile DIMM),相对于传统的易失性内存,NVDIMM 在断电后其中的内容也不会消失。

Linux LIBNVDIMM Subsystem

The Linux LIBNVDIMM core provides a built-in driver for these DIMM devices. The driver is responsible for determining if the DIMM implements a namespace label area, and initializing the kernel’s in-memory copy of that label data.

PMEM and BLK Modes

The NFIT specification defined by the ACPI v6.0 standardizes not only the description of Persistent Memory (PMEM) and Block (BLK) modes.

Managing Namespaces

Listing

List all enabled and disabled namespaces.

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
$ ndctl list -Ni
[
{
"dev":"namespace1.0",
"mode":"fsdax",
"map":"dev",
"size":532708065280,
"uuid":"c2595cad-9e1e-4eb4-b1f0-32508ed14484",
"sector_size":512,
"align":2097152,
"blockdev":"pmem1"
},
{
"dev":"namespace1.1",
"mode":"raw",
"size":0,
"uuid":"00000000-0000-0000-0000-000000000000",
"sector_size":512,
"state":"disabled"
},
{
"dev":"namespace0.1",
"mode":"raw",
"size":0,
"uuid":"00000000-0000-0000-0000-000000000000",
"sector_size":512,
"state":"disabled"
},
{
"dev":"namespace0.0",
"mode":"fsdax",
"map":"dev",
"size":532708065280,
"uuid":"bc29b02c-54de-41d1-9ec2-1f7088beb4e5",
"sector_size":512,
"align":2097152,
"blockdev":"pmem0"
}
]

当前 4 个 namespace 中,两个为 fsdax (file-system DAX),即利用支持 NVDIMM 的文件系统进行 DAX,另两个为 raw,只是不支持 DAX 的 memory disk (?),其状态为 disabled.

Creating

See Reproduction/Memtis.

Character Device File

一切皆文件。字符 (char) 设备 (c) 是能够像字节流一样被访问的设备,由字符设备驱动程序来实现这种特性。字符设备驱动程序通常至少要实现 openclosereadwrite 的系统调用。字符设备可以通过文件节点来访问,如 /dev/tty1,大多数字符设备是一个只能顺序访问的数据通道。少数设备具有数据区特性,如 framebuffer,访问它们时可前后移动访问位置。

多数驱动为字符设备;loop / pmem 等为块设备 (b)

  • d: 目录

RDMA

Remote Direct Memory Access (RDMA),远端内存直接访问。

传统应用要发送数据,‍‍需要通过 OS 封装 TCP/IP,‍‍依次经过主缓存、网卡缓存,‍‍再发出去。‍‍这样会导致两个限制。

  • TCP/IP 协议栈处理会带来数 10 微秒的时延。‍‍TCP 协议栈在接收发送报文时,‍‍内核需要做多次上下文的切换,‍‍每次切换需要耗费 5-10 微秒。‍另外还需要至少三次的数据拷贝‍‍和依赖 CPU 进行协议工作。‍‍
  • TCP 协议栈处理导致服务器 CPU 负载‍‍居高不下。‍‍主机 CPU‍‍ 多次参与协议的内存拷贝,‍‍网络规模越大,‍‍网络带宽越高,‍‍CPU 在收发数据时的调度负担越大,‍‍导致 CPU 持续高负载。‍‍

RDMA 优势:

  • 内存零拷贝 (Zero Copy): RDMA 可以绕过内核网络栈直接进行数据传输,不需要再将数据从应用程序的用户态内存空间拷贝到内核网络栈内存空间。
  • 内核旁路 (Kernel bypass): RDMA 应用程序可以直接在用户态发起数据传输,不需要在内核态与用户态之间做上下文切换。
  • CPU减负 (CPU offload): RDMA 可以直接访问远程主机内存,不需要消耗远程主机中的任何 CPU,这样远端主机的 CPU 可以专注自己的业务,避免其 cache 被干扰并充满大量被访问的内存内容。

当前主流 RDMA 协议为 RoCE.

FSDAX and DEVDAX Capacity Considerations

元数据规模估计