如何用 ndctl/ipmctl 管理工具 配置不同访问模式的pmem设备
文章目錄
- 1 PMEM 底層架構
- 2 PMEM 邏輯架構
- 3 ipmctl 創建 不同模式的 region
- 3.1 安裝
- 3.2 創建AppDirect mode的region
- 3.3 創建 Memory Mode模式
- 3.4 創建 混合模式
- 3.5 查看創建的結果
- 4 ndctl 創建不同類型的 namespaces
- 4.1 安裝
- 4.2 創建/刪除 一個任意類型的namespace
- 4.3 指定類型 創建 namespaces
- 4.4 變更已有namespace 類型
- 5 namespace 的應用
- 6 fio測試 fsdax 和 devdax
- 7 參考
之前總結過一篇文章來總體介紹optane 持久內存 的架構以及其 編程模式 Intel Optane 持久內存概覽,這里主要是記錄一下針對Optane 持久內存 管理工具的使用方式,通過這一些工具的使用能夠更為清晰得了解NVM(pmem) 的底層架構。
下文中提到的創建命令都是在 centos上進行的,不過ipmctl/ndctl/fio 這種基礎命令使用方式都是一樣的,可能就是安裝這一些工具的命令和其他的系統有一些差異。
1 PMEM 底層架構
PMEM 的存儲介質是 3D Xpoint ,其底層存儲單元是PCM(phase change memory 即相變內存),這也是pmem 物理存儲和傳統的 NAND SSD最大的差異。但其和Optane NVMe SSD 最大的差異則是物理接口的不同,一個是PCIe接口(nvme ssd),一個是DIMM 接口(pmem)。 關于 NAND和3D XPoint 的物理差異可以通過從NMOS 和 PCM 底層存儲單元 來看NAND和3D XPoint的本質區別 來了解一下。
那我們先看看 PMEM 的底層物理形態,這是我們的NUMA 下的cpu和內存插槽的分布。
其中藍色區域是DRAM 插槽,黑色插槽可以插PMEM 存儲介質。
需要注意的是:
- 對于每一個CPU而言,PMEM 介質應該插在每組(一藍一黑兩個算一組)靠近CPU的那一個槽中,即黑色的插槽;另一個槽插入DRAM。
- 使用App Direct Mode 的時候每組槽中的PMEM 可以不搭配DRAM;使用Memory Mode 的時候,每組槽中的PMEM必須搭配DRAM,否則無法配置成MemoryMode 模式使用。
- 必須要確保每個CPU兩邊的 pmem 介質個數相等;而不同組 CPU 各自的PMEM數量可以不同,造成的結果就是兩個region 顯示的容量不同。
查看當前系統DRAM 和 pmem 的拓撲結構
# 需要root 用戶執行
$ ipmctl show -topologyDimmID | MemoryType | Capacity | PhysicalID| DeviceLocator
================================================================================0x0001 | Logical Non-Volatile Device | 126.375 GiB | 0x0021 | DIMM 60x0011 | Logical Non-Volatile Device | 126.375 GiB | 0x0023 | DIMM 40x0101 | Logical Non-Volatile Device | 126.375 GiB | 0x0027 | DIMM 70x0111 | Logical Non-Volatile Device | 126.375 GiB | 0x0029 | DIMM 90x1001 | Logical Non-Volatile Device | 126.375 GiB | 0x002d | DIMM 180x1011 | Logical Non-Volatile Device | 126.375 GiB | 0x002f | DIMM 160x1101 | Logical Non-Volatile Device | 126.375 GiB | 0x0033 | DIMM 190x1111 | Logical Non-Volatile Device | 126.375 GiB | 0x0035 | DIMM 21N/A | DDR4 | 32.000 GiB | 0x0020 | DIMM 5N/A | DDR4 | 32.000 GiB | 0x0022 | DIMM 3N/A | DDR4 | 32.000 GiB | 0x0024 | DIMM 1N/A | DDR4 | 32.000 GiB | 0x0026 | DIMM 8N/A | DDR4 | 32.000 GiB | 0x0028 | DIMM 10N/A | DDR4 | 32.000 GiB | 0x002a | DIMM 12N/A | DDR4 | 32.000 GiB | 0x002c | DIMM 17N/A | DDR4 | 32.000 GiB | 0x002e | DIMM 15N/A | DDR4 | 32.000 GiB | 0x0030 | DIMM 13N/A | DDR4 | 32.000 GiB | 0x0032 | DIMM 20N/A | DDR4 | 32.000 GiB | 0x0034 | DIMM 22N/A | DDR4 | 32.000 GiB | 0x0036 | DIMM 24
2 PMEM 邏輯架構
這里介紹兩種 用于組織插在DIMM 插槽之上的邏輯分離存儲形態 region 和 namespace。
- region : 用來組織pmem module的邏輯概念。一個region 中可以有一個或者多個pmem module(插在DIMM 上的pmem 存儲介質)。當前支持的region 模式有兩種: interleave 和 non-interleave 的;其中interleave 模式是一個region 可以跨當前CPU的多個 DIMM,non-interleave 模式則是一個region 只能在一個DIMM 上。
- namespace: 是一段 on pmem 的 可連續尋址的地址范圍,類似于硬盤分區 或者 SCSI的邏輯單元(LUN) 或者 NVMe 的namespace。只有在 創建的region 模式是 AppDirect 模式時才能在region 上創建namespace。
除了以上兩個主要的 對pmem 操作的邏輯分區之外,還有幾個概念需要了解:
- Label : 每一個pmem module(pmem 存儲介質) 都包涵一個 Label Storage Area(LBA) 區域,用來存儲namespace 的元數據配置。這樣,就可以在region 上創建不同類型的namespace 來支持針對pmem 的不同訪問模式。
- DAX:Direct Access。pmem 在AppDirect 模式下 通過namespace 創建的 不同類型的設備可以為用戶提供 device access 以及 fs access的訪問模式。在fs access 下 通過支持DAX 模式的文件系統(xfs, ext4, on windows ntfs)來 最大程度得縮短訪問pmem的路徑,訪問的過程都是通過mmap 來進行的,能夠by-pass page-cache, i/o subsystem 以及 中斷和上下文切換。
下面是 non-interleaved regions 和 interleaved region 以及 on interleave region下的namespaces。
關于pmem 編程架構形態如下:
其中namespace 支持的四種模式 可以匹配到上面針對 NVM-DIMMS 的訪問形態中了:
raw: 就是一個內存盤的形態來直接訪問,不支持DAX 模式的訪問。sector: 可以作為一個傳統的塊設備 以及 on 塊設備的文件系統,且這個文件系統不限制類型(任意文件系,不需要dax支持)。可以允許按字節訪問,但是不能保證訪問的原子性。fsdax: 需要 pmem-aware filter system支持,即支持dax 掛載的文件系統,這樣該namespace 可以通過標準文件接口讀寫 ,同時也支持 通過pmdk 來訪問。這個namespace 類型 是大多數的appdirect 模式下的持久內存使用方式。devdax: 允許通過 mmap 直接將指定容量的 pmem 介質映射到內存進行訪問,這個devdax 模式的namespace 被創建出來之后不能像其他的塊設備一樣創建dax文件系統,它被映射出來之后是一個字符設備形態(/dev/dax3.0 這種)。這種模式一般用作虛擬機,RDMA 以及 大頁映射。
到此,我們大體就清楚了PMEM 的邏輯架構 ,如何通過 邏輯 region 組織物理上的 DIMMS,以及如何在邏輯region之上構建數據分離存儲的namespaces。
接下來我們看看如果通過 pmem的 management tools 來組合這一些邏輯架構,構建豐富的pmem 使用形態。
3 ipmctl 創建 不同模式的 region
如果你的環境中已經有了pmem設備(直接可用的文件系統形態的pmem),可以直接跳過這一個工具的介紹,看下一個 ndctl工具。
3.1 安裝
這個工具是構建pmem region的底層工具,建議安裝的時候讓其版本在2.x 及以上。
直接源碼編譯安裝即可:
git clone https://github.com/pmem/ndctl.git
cd ndctl
./autogen.sh
./configure CFLAGS='-g -O2' --prefix=/usr --sysconfdir=/etc --libdir=/usr/lib64
make
make check
sudo make install
安裝完成之后記得更新一下PATH,否則命令行會找不到這個工具export PATH=$PATH:/usr/local/bin。
需要注意一個問題,就是如果你的ipmctl 最開始的版本比較低,可能會導致最后創建的interleaved 模式的 region 無法創建混合模式的namespaces,這個issue 解決可以參考 https://github.com/pmem/ndctl/issues/181。
關于ipmctl 工具的使用都需要在root 模式下執行
3.2 創建AppDirect mode的region
-
查看當前已有mode
# ipmctl show -memoryresourcesMemoryType | DDR | PMemModule | Total ========================================================== Volatile | 384.000 GiB | 0.000 GiB | 384.000 GiB AppDirect | - | 1008.000 GiB | 1008.000 GiB Cache | 0.000 GiB | - | 0.000 GiB Inaccessible | 0.000 GiB | 3.377 GiB | 3.377 GiB Physical | 384.000 GiB | 1011.377 GiB | 1395.377 GiB上面這個是AppDirectmode
-
創建AppDirect mode,這個命令會將當前的所有容量默認創建出interleaved mode的 region
# ipmctl create -goal PersistentMemoryType=AppDirect The following configuration will be applied:SocketID | DimmID | MemorySize | AppDirect1Size | AppDirect2Size ==================================================================0x0000 | 0x0001 | 0.000 GiB | 126.000 GiB | 0.000 GiB0x0000 | 0x0011 | 0.000 GiB | 126.000 GiB | 0.000 GiB0x0000 | 0x0101 | 0.000 GiB | 126.000 GiB | 0.000 GiB0x0000 | 0x0111 | 0.000 GiB | 126.000 GiB | 0.000 GiB0x0001 | 0x1001 | 0.000 GiB | 126.000 GiB | 0.000 GiB0x0001 | 0x1011 | 0.000 GiB | 126.000 GiB | 0.000 GiB0x0001 | 0x1101 | 0.000 GiB | 126.000 GiB | 0.000 GiB0x0001 | 0x1111 | 0.000 GiB | 126.000 GiB | 0.000 GiB Do you want to continue? [y/n] y Created following region configuration goalSocketID | DimmID | MemorySize | AppDirect1Size | AppDirect2Size ==================================================================0x0000 | 0x0001 | 0.000 GiB | 126.000 GiB | 0.000 GiB0x0000 | 0x0011 | 0.000 GiB | 126.000 GiB | 0.000 GiB0x0000 | 0x0101 | 0.000 GiB | 126.000 GiB | 0.000 GiB0x0000 | 0x0111 | 0.000 GiB | 126.000 GiB | 0.000 GiB0x0001 | 0x1001 | 0.000 GiB | 126.000 GiB | 0.000 GiB0x0001 | 0x1011 | 0.000 GiB | 126.000 GiB | 0.000 GiB0x0001 | 0x1101 | 0.000 GiB | 126.000 GiB | 0.000 GiB0x0001 | 0x1111 | 0.000 GiB | 126.000 GiB | 0.000 GiB A reboot is required to process new memory allocation goals. # reboot -n如果 想創建
non-interleaved模式的region,則可以執行命令:
ipmctl create -goal PersistentMemoryType=AppDirectNotInterleaved
3.3 創建 Memory Mode模式
其中 MemoryMode 是一個百分比,如果是100的話則表示當前所有的pmem module 容量都會作為memory mode。
# ipmctl create -goal MemoryMode=100
# reboot
重啟之后,查看free -h 時能夠看到內存的容量已經加上了所有的 pmem module 的容量了
3.4 創建 混合模式
創建內存模式的時候 有一個參數 MemoryMode 用來指定百分比,顯而易見 我們可以在一個機器上讓一部分的容量作為AppDirect 模式。
比如配置 50% 的容量為 memory mode 即可
# ipmctl create -goal MemoryMode=50
以上過程中如果想要清理所有的 config,可以通過 ipmctl delete –goal 。
3.5 查看創建的結果
- 查看 goal
ipmctl show -goal - 查看regions
ipmctl show -region - 查看內存資源情況
ipmctl show -memoryresources - 查看 dimms 分布
ipmctl show -dimms
4 ndctl 創建不同類型的 namespaces
ndctl 的創建/刪除/更新 namespace 需要root權限,查看namepace 信息則不需要root
4.1 安裝
ndctl 的安裝則不是很方便,如果系統庫不全的話可能遇到的問題會比較多,我將我的安裝完整過程貼下來:
- 前置庫安裝
sudo yum install autoconf pkg-config libndctl-devel libdaxctl-devel pandoc -y - 安裝過程
git clone https://github.com/pmem/ndctl.git cd ndctl git checkout v71 # 當前的最新版本./autogen.shActivated pre-commit hook.GIT_VERSION = 71sh: aclocal: command not foundautoreconf: aclocal failed with exit status: 127 # 執行失敗 ----------------------------------------------------# 解決 sudo yum install automake libtool -y autoreconf -ivf# 執行成功 $ ./autogen.sh ---------------------------------------------------------------- Initialized build system. For a common configuration please run: ---------------------------------------------------------------- ./configure CFLAGS='-g -O2' --prefix=/usr --sysconfdir=/etc --libdir=/usr/lib64# 執行./configure ./configure CFLAGS='-g -O2' --prefix=/usr --sysconfdir=/etc --libdir=/usr/lib64 ... checking for a sed that does not truncate output... (cached) /usr/bin/sed checking for asciidoctor... missing configure: error: asciidoctor needed to build documentation # 執行失敗 ----------------------------------------------------# 解決 sudo yum install asciidoctor -y# 重新執行 ./configure ./configure CFLAGS='-g -O2' --prefix=/usr --sysconfdir=/etc --libdir=/usr/lib64 ... checking for KMOD... no configure: error: Package requirements (libkmod) were not met:No package 'libkmod' foundConsider adjusting the PKG_CONFIG_PATH environment variable if you installed software in a non-standard prefix # 執行失敗 ----------------------------------------------------#解決 sudo yum install kmod kmod-devel -y# 再次重新執行 ./configure ./configure CFLAGS='-g -O2' --prefix=/usr --sysconfdir=/etc --libdir=/usr/lib64 ... configure: error: Package requirements (uuid) were not met:No package 'uuid' found #執行失敗 ----------------------------------------------------#解決 sudo yum install libuuid-devel json-c-devel -y# 執行./configure 成功,生成 Makefile ./configure CFLAGS='-g -O2' --prefix=/usr --sysconfdir=/etc --libdir=/usr/lib64 # 安裝ndctl make && sudo make install
4.2 創建/刪除 一個任意類型的namespace
- 查看已有的namespaces
ndctl list --namespaces --regions
能夠展示所有創建好的可用的 namespace 以及其所屬的 region信息完整打印出來。 - 創建一個namespace,如果不指定namespace 類型的話默認創建的是raw 類型
ndctl create-namespace --force - 刪除一個namespace 的話 可以通過
ndctl destroy-namespace namespace1.0 --force或者 不指定具體的某一個namespace,直接--all即可刪除所有的namespaces,需要注意的是刪除namespace 會清理掉當前namespace的所有數據。
4.3 指定類型 創建 namespaces
-
創建一個
fsdax類型的namespacendctl create-namespace --mode=fsdax --size=100G --region=region0 --force指定在region0 上創建一個100G容量的 fsdax 模式namespace,創建成功則可以在
lsblk命令下看到這個塊設備/dev/pmem0。
除了以上參數,還可以指定一個比較重要的配置--map=dev或者--map=mem,保存當前namespace 的元數據信息,大概是每4k 需要64B的存儲。dev和mem分別制定的是將這部分元數據存放在pmem設備上 或者 內存中。 -
上一條命令的基礎上 在
region0創建一個devdax模式的namespacendctl create-namespace --mode=devdax --size=100G --region=region0 --force創建好之后能
ls -l /dev/dax1.0看到這個設備,它是一個字符設備。如果這一步失敗,可以根據這個 issue 嘗試解決:https://github.com/pmem/ndctl/issues/181
這樣創建出來的namespace 對應的 region 以及 dimm 關系圖如下:
4.4 變更已有namespace 類型
變更namespace1.0 的配置,從fsdax 模式變更為 devdax模式
ndctl create-namespace --mode=devdax --size=100G --reconfig=namespace1.0。
注意:
reconfig 的流程會
- 先從已有的namespace中讀取 元數據信息
- 然后刪除已有的namespace,這一步會清理所有的數據
- 根據reconfig 的配置重新創建namespace
更多的創建信息,可以參考https://pmem.io/ndctl/ndctl-create-namespace.html
5 namespace 的應用
這里就很簡單了,主要是針對fsdax 設備的使用
通過fsdax 模式創建出來的 一個塊設備可以直接格式化成dax 支持的文件系統 并掛載:
sudo mkfs.xfs -f /dev/pmem0
sudo mount -o dax /dev/pmem0 /mnt/pmem0
此時即可使用文件接口進行讀寫。
6 fio測試 fsdax 和 devdax
建議測試的fio 版本直接使用最新的3.17,這樣能夠使用比較新的ioengine (libpmem/dev-dax)
-
測試fsdax
以下綁定的numa 不一定準確,可以通過
lscpu查看numa的cpu,隨便綁定一個,哪個性能好 則當前namespace 的region 就在哪個 numa上。[global] ioengine=libpmem #pmem引擎 direct=1 norandommap=1 randrepeat=0 runtime=60 time_based size=1G directory=./fio group_reporting [read256B-rand] bs=256B rw=randread numjobs=32 iodepth=4 cpus_allowed=0-15,16-31 #綁定numa當然,也有更準確的方法來找到當前pmem屬于哪個numa.
ndctl list --regions --namespaces查看當前的/dev/pmem0屬于哪一個regionipmctl show -region查看當前的region 屬于哪一個socket,0 則是numa node0, 1 則是numa node1等
-
測試devdax,不支持
direct開啟,直接訪問的字符設備[global] ioengine=dev-dax direct=0 norandommap=1 randrepeat=0 runtime=60 time_based size=1G filename=/dev/dax1.0 #直接指定filename 為devdax模式的字符設備即可 group_reporting [read256B-rand] bs=256B rw=randread numjobs=32 iodepth=4 cpus_allowed=0-15,16-31 #綁定numa
到此已經完整得告訴了各位如何 從0到1 在一臺服務器上創建一個混合模式的pmem 并做相關的應用 和測試,踩過的坑 希望能幫助各位節省一些時間,當然,更重要的是能夠從宏觀的角度中更進一步得了解pmem 設備 及其周邊生態,畢竟是未來的高性能存儲趨勢。
7 參考
- Introduction to Persistent Memory Configuration and Analysis Tools
- Persistent Memory Provisioning Introduction
- support virtual persistent memory
- https://pmem.io/ndctl/
- https://nvdimm.wiki.kernel.org/
- NDCTL Introduction
- PMEM 主機安裝環境詳解
總結
以上是生活随笔為你收集整理的如何用 ndctl/ipmctl 管理工具 配置不同访问模式的pmem设备的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 临字开头成语有哪些啊?
- 下一篇: 新巧格高配和低配有什么区别?