相关资料
VMware安装(multipass/VirtualBox)
安装Ubuntu 20.04.3 LTS (Focal Fossa)
Ubuntu 20.04.3 LTS (Focal Fossa)
在VMware Fusion Pro上安装,网络连接方式选择桥接模式。
选择此版本是因为内核版本最后需要4.2以上
遇到问题
无法复制黏贴拖拽文件。暂无解决方案,目前开启ssh,使用mac终端连上去 ssh root@127.0.0.1
重装vm-tool
www.jianshu.com/p/b9585e0f4… blog.csdn.net/Victor2code…
验证是否支持PMEM
egrep '(DAX|PMEM)' /boot/config-`uname -r`
正确返回
CONFIG_X86_PMEM_LEGACY_DEVICE=y
CONFIG_X86_PMEM_LEGACY=y
CONFIG_BLK_DEV_RAM_DAX=y
CONFIG_BLK_DEV_PMEM=m
CONFIG_FS_DAX=y
CONFIG_FS_DAX_PMD=y
CONFIG_ARCH_HAS_PMEM_API=y
假如不支持还需要编译高版本内核
GRUB 配置
确认可用的物理空间
how_to_choose_the_correct_memmap_kernel_parameter_for_pmem_on_your_system
设置grub配置
# vi /etc/default/grub
GRUB_CMDLINE_LINUX="memmap=nn[KMG]!ss[KMG]"
Build the configuration on a BIOS machine:
# grub2-mkconfig -o /boot/grub2/grub.cfg
Build the configuration on an EFI machine:
Copy Code
# grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg
实际命令
grub-mkconfig -o /boot/grub/grub.cfg
预期结果
重启机器后验证
dmesg | grep user
确认到存在persistent
构建支持 DAX 的文件系统
### lsblk查看pmem内存块
mkdir /mnt/pmemdir
mkfs.ext4 /dev/pmem0
mount -o dax /dev/pmem0 /mnt/pmemdir
安装PMDK
安装依赖
执行以下命令安装必要依赖:
sudo apt-get install make build-essential libdaxctl-dev libndctl-dev pandoc m4 libfabric-dev pkg-config
过程中需要输入几次Y
安装PMDK
git clone https://github.com/pmem/pmdk.git
cd pmdk
使用最新稳定版分支
git checkout tags/1.11.0
sudo make
sudo make install
追加/usr/local/lib路径到/etc/ld.so.conf文件中(很重要)
sudo vim /etc/ld.so.conf
追加/usr/local/lib
保存退出编辑
sudo /sbin/ldconfig
安装 jDK MAVEN
sudo apt install openjdk-8-jdk-headless maven
切换jdk版本、假如不是jdk8
update-alternatives --config java
修改Maven镜像源地址到阿里云(加速用)
sudo vim /usr/share/maven/conf/settings.xml
搜索/<mirrors>
在其下方追加如下信息
<mirror>
<id>aliyunmaven</id>
<mirrorOf>*</mirrorOf>
<name>阿里云公共仓库</name>
<url>https://maven.aliyun.com/repository/public</url>
</mirror>
测试PMEM
测试代码
package io.openmessaging;
import com.intel.pmem.llpl.Heap;
import com.intel.pmem.llpl.MemoryBlock;
import org.junit.Assert;
import org.junit.Test;
public class LlplTest {
/**************************** * This function writes the "Hello..." string to persistent-memory. *****************************/
public void write_hello_string(byte[] input, Heap h, int size) {
// block allocation (transactional allocation)
MemoryBlock newBlock = h.allocateMemoryBlock(size, true);
//Attached the newBllock to the root address
h.setRoot(newBlock.handle());
// Write byte array (input) to newBlock @ offset 0 (on both) for 26 bytes
newBlock.copyFromArray(input, 0, 0, size);
//Ensure that the array (input) is in persistent memory
newBlock.flush();
//Convert byte array (input) to String format and write to console
System.out.printf("\nWrite the (%s) string to persistent-memory.\n", new String(input));
return;
}
/**************************** * This function reads the "Hello..." string from persistent-memory. *****************************/
public String read_hello_string(Heap h, int size) {
// Allocate buffer for string
// To retrieve byte array from persistent heap
byte[] output = new byte[size];
//Get the root block address
long rootAddr = h.getRoot();
if (rootAddr == 0) {
System.out.println("Root Block NOT found!");
System.exit(0);
}
// Map the newBlock to the root of Flushable class
MemoryBlock newBlock = h.memoryBlockFromHandle(rootAddr);
// Read 26 bytes @ offset 0 from newBlock to byte array (output)
newBlock.copyToArray(0L, output, 0, size);
//Convert byte array (output) to String format and write to console
String msg = new String(output);
System.out.printf("\nRead the (%s) string from persistent-memory.\n", msg);
return msg;
}
@Test
public void main0() {
String option = "0";
byte[] input;
int size; // String length
// Define Heap
String path = "./persistent_heap";
boolean initialized = Heap.exists(path);
Heap h = initialized ? Heap.openHeap(path) : Heap.createHeap(path, 1024 * 1024 * 16L);
//Initialize the msg string
String msg = "Hello Persistent Memory!!!";
// Convert String to byte array format
// To store in persistent heap
input = msg.getBytes();
// Get the array size
size = input.length;
write_hello_string(input, h, size);
String msgRead = read_hello_string(h, size);
Assert.assertEquals(msgRead, msg);
} // End of main function
}
共享对应代码文件夹
共享目录 /mnt/hgfs
执行 mvn test
待续
- 看下后续打个docker使用,更方便,docker PMDK环境