Resources for working with persistent memory (PMem) on CloudLab hosts and the Hustle server.
This section describes how to provision a host with PMem. If you are simply emulating PMem in DRAM, you can skip to the next section.
-
If the device is already provisioned in a different mode, clear existing namespaces and goals.
ndctl destroy-namespace -f all ipmctl delete -goal systemctl reboot
-
Create a new memory allocation goal. To configure all the PMem capacity in Memory Mode, run the following command.
sudo ipmctl create -goal MemoryMode=100
To configure all the PMem capacity as App Direct, run the following command.
sudo ipmctl create -goal PersistentMemoryType=AppDirect
-
Reboot the host.
sudo reboot
-
Verify that the provisioning was successful.
sudo ipmctl show -memoryresources
-
Create new namespaces if necessary.
First list existing namespaces and regions.
sudo ndctl list -Ni sudo ndctl list --regions
To create a namespace on region1, run the following command.
sudo ndctl create-namespace -r region1 --mode fsdax -M dev
The above command creates a namespace in region1 in the fsdax mode, with page metadata stored on the device.
For more information, refer to IPMCTL User Guide and the NDCTL User Guide.
This section describes how to emulate PMem on a CloudLab hosts (or similar Linux environment). If you have a host that has been provisioned with real PMem, you can skip to the next section.
-
Determine the usable memory space by querying the e820 table.
dmesg | grep BIOS-e820The output of this command will be similar to the following.
[ 0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009d7ff] usable [ 0.000000] BIOS-e820: [mem 0x000000000009d800-0x000000000009ffff] reserved [ 0.000000] BIOS-e820: [mem 0x00000000000e0000-0x00000000000fffff] reserved [ 0.000000] BIOS-e820: [mem 0x0000000000100000-0x000000006a01afff] usable [ 0.000000] BIOS-e820: [mem 0x000000006a01b000-0x000000006c90dfff] reserved [ 0.000000] BIOS-e820: [mem 0x000000006c90e000-0x000000006ca7bfff] usable [ 0.000000] BIOS-e820: [mem 0x000000006ca7c000-0x000000006d4cafff] ACPI NVS [ 0.000000] BIOS-e820: [mem 0x000000006d4cb000-0x000000006f30bfff] reserved [ 0.000000] BIOS-e820: [mem 0x000000006f30c000-0x000000006f7fffff] usable [ 0.000000] BIOS-e820: [mem 0x000000006f800000-0x000000008fffffff] reserved [ 0.000000] BIOS-e820: [mem 0x00000000fd000000-0x00000000fe7fffff] reserved [ 0.000000] BIOS-e820: [mem 0x00000000fed20000-0x00000000fed44fff] reserved [ 0.000000] BIOS-e820: [mem 0x00000000ff000000-0x00000000ffffffff] reserved [ 0.000000] BIOS-e820: [mem 0x0000000100000000-0x000000303fffffff] usableIn this example, there is usable memory between 4 GiB (0x100000000) and ~193 GiB (0x303fffffff).
-
Create a new memory mapping by modifying the GRUB entry. Ensure that the new mapping is in the usable space. The following example adds a new mapping of 16 GiB starting at 4 GiB.
sudo vim /etc/default/grub
Add or edit the
GRUB_CMDLINE_LINUXto include the mapping.GRUB_CMDLINE_LINUX="memmap=16G!4G"There may be multiple redefinitions of
GRUB_CMDLINE_LINUXin the file. You must edit the last one in order for the changes to take effect. To edit an existingGRUB_CMDLINE_LINUXentry, add the new option with a space separator. For example, the updated entry may look like the following.GRUB_CMDLINE_LINUX="console=ttyS0,115200 memmap=16G!4G" -
Update GRUB and reboot the machine.
sudo update-grub2 sudo reboot
-
After rebooting, a new
/dev/pmem{N}device should exist, one for each memmap region specified in the GRUB config. These can be shown usingls /dev/pmem*. You can also verify that a new user-defined e820 table entry shows that the range is now persistent.dmesg | grep user:The output of this command will be similar to the following.
[ 0.000000] user: [mem 0x0000000000000000-0x000000000009d7ff] usable [ 0.000000] user: [mem 0x000000000009d800-0x000000000009ffff] reserved [ 0.000000] user: [mem 0x00000000000e0000-0x00000000000fffff] reserved [ 0.000000] user: [mem 0x0000000000100000-0x000000006a01afff] usable [ 0.000000] user: [mem 0x000000006a01b000-0x000000006c90dfff] reserved [ 0.000000] user: [mem 0x000000006c90e000-0x000000006ca7bfff] usable [ 0.000000] user: [mem 0x000000006ca7c000-0x000000006d4cafff] ACPI NVS [ 0.000000] user: [mem 0x000000006d4cb000-0x000000006f30bfff] reserved [ 0.000000] user: [mem 0x000000006f30c000-0x000000006f7fffff] usable [ 0.000000] user: [mem 0x000000006f800000-0x000000008fffffff] reserved [ 0.000000] user: [mem 0x00000000fd000000-0x00000000fe7fffff] reserved [ 0.000000] user: [mem 0x00000000fed20000-0x00000000fed44fff] reserved [ 0.000000] user: [mem 0x00000000ff000000-0x00000000ffffffff] reserved [ 0.000000] user: [mem 0x0000000100000000-0x00000004ffffffff] persistent (type 12) [ 0.000000] user: [mem 0x0000000500000000-0x000000303fffffff] usable
For more information, refer to Linux Environments - Persistent Memory Documentation.
This section describes how to create and mount a new filesystem on a /dev/pmem{N} device.
-
Create and mount a new filesystem. The following shows how to create and mount an EXT4 filesystem for the
/dev/pmem0device.sudo mkfs.ext4 /dev/pmem0 sudo mkdir /mnt/pmem0 sudo mount -o dax /dev/pmem0 /mnt/pmem0
-
Verify that the new filesystem has been mounted and the
daxflag has been set.sudo mount -v | grep /mnt/pmem0This output of this command will be similar to the following.
/dev/pmem0 on /mnt/pmem0 type ext4 (rw,relatime,dax)
You can now write code that uses the /mnt/pmem{0} filesystem as a PMem store. The Persistent Memory Development Kit (PMDK) provides a collection of libraries to program PMem in DAX mode and also has coding examples to help get started.