How to ensure I am programming on persistent memory

127 views Asked by At

I am working on a final project for school that involves making a program that reads and writes to files on persistent memory. I don't have access to an actual persistent memory device so I followed the tutorial at the following link to emulate it: https://kb.pmem.io/howto/100000012-How-To-Emulate-Persistent-Memory-using-the-Linux-memmapKernel-Option/

user@node:~/test2$ sudo fdisk -l /dev/pmem0
Disk /dev/pmem0: 8 GiB, 8589934592 bytes, 16777216 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes

According to the above output, I have an emulated persistent memory partition on my dram hard drive named pmem0. I used the tutorial at the following link to get some sample code on how to read and write from files on persistent memory: https://www.intel.com/content/www/us/en/developer/articles/code-sample/create-a-persistent-memory-hello-world-program-using-libpmemobj-with-c.html

I compile and run the code and the output of the program says it is writing a file to persistent memory. I wanted to check if the file is being written to the correct partition so I used the command: df -P fileName | tail -1 | cut -d' ' -f 1 (which I got from another stackoverflow post) and the output is /dev/sda1 when I believe it should be /dev/pmem0 if it is actually using the persistent memory partition.

I'm looking for tips on how to ensure I am actually mapping my code to the persistent memory partition I created.

The code from the second link needs to have the pmdk library setup to run properly and I needed to modify my linux kernel boot parameters to setup the partition so I'm not sure if I can supply a much better minimal example.

Edit: I believe the exact lines of code I need to modify would be one of:

    pop = pmemobj_create(path, LAYOUT, PMEMOBJ_MIN_POOL, 0666);
    PMEMoid root = pmemobj_root(pop, sizeof (struct my_root));
    pmemobj_persist(pop, &rootp->len, sizeof (rootp->len));`

This creates the persistent memory pool but the tutorial doesn't seem to mention how to actually map to a persistent memory device.

1

There are 1 answers

2
Armali On

why does the string get written to the hard drive in sda1, which I believe is regular memory?

The referred C program calls pmemobj_create() with the path you specify as the second program argument, in your case fileName. If the current working directory is on the hard drive, the created memory pool file fileName is of course also residing on the hard drive. If you want a file to be created on your /dev/pmem0 disk, you have to mount that file system and use a path to a file thereon.