Emulated a PMEM but need to know how allocate in the PMEM region

51 views
Skip to first unread message

Tonmoy Dey

unread,
May 30, 2019, 4:26:55 PM5/30/19
to pmem
I have emulated a 2G PMEM region following the tutorial provided in  https://pmem.io/2016/02/22/pm-emulation.html
As per dmesg the persistent memory region is 
user: [mem 0x0000000180000000-0x00000001ffffffff] persistent (type 12).

When I call pmem_map_file(const char *path, size_t len, int flags,  mode_t mode, size_t *mapped_lenp, int *is_pmemp) it returns an address but that does not belong to the persistent memory region and pmem_is_pmem() returns false.
Do I invoke mmap() with MAP_FIXED and specify the address to allocate in the pmem region?
Kindly let me know if there are other ways of allocating in the pmem region.

Thanks,
Tonmoy Dey

Andy Rudoff

unread,
May 30, 2019, 5:10:05 PM5/30/19
to pmem
Hi,

Can you confirm that you created a file system, either ext4 or XFS, on the pmem device (/dev/pmem0 for example) and then mounted that file system with "-o dax" like the blog says?  If you could post the output of "ndctl list" and "mount | grep pmem" and also show us the arguments you passed to pmem_map_file(), hopefully we can help debug the issue better.

-andy

Tonmoy Dey

unread,
May 30, 2019, 5:19:41 PM5/30/19
to pmem
Hi Andy,

Yes, I have created a ext4 file system on /dev/pmem0 as mentioned in the blog.

The output of "mount | grep pmem" is:
/dev/pmem0 on /mnt/mem type ext4 (rw,relatime,dax,data=ordered)

The ndctl is not found in the system.

The pmem_map_file utilization is as follows:

#define PMEM_LEN 4096

#define PATH "/home/tonmoy/Documents/Tonmoy/pmem-fs/myfile"

int 
main(int argc, char *argv[])
{
char *pmemaddr;
size_t mapped_len;
int is_pmem;

/* create a pmem file and memory map it */
if ((pmemaddr = pmem_map_file(PATH, PMEM_LEN, PMEM_FILE_CREATE, 0666, &mapped_len, &is_pmem)) == NULL)

    .
    .
    .
}

Please let me know if you need more information.

Thanks,
Tonmoy

Ramin Izadpanah

unread,
May 30, 2019, 5:37:36 PM5/30/19
to Tonmoy Dey, pmem
Hi Tonmoy,

I believe your path should be a subdirectory of " /mnt/mem". e.g., "/mnt/mem/myfile".


Best,
Ramin

--
You received this message because you are subscribed to the Google Groups "pmem" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pmem+uns...@googlegroups.com.
To post to this group, send email to pm...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pmem/f17b49f5-6d49-4248-9ae7-b5309010d538%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Steve Scargall

unread,
May 30, 2019, 5:40:32 PM5/30/19
to pmem
Hi Tomnoy,

You mounted the emulated pmem on /mnt/mem but you're trying to memory map a file from your home directory (which isn't pmem).

Try:

#define PATH "/mnt/mem/myfile"

Or mount /dev/pmem to /home/tonmoy/Documents/Tonmoy/pmem-fs/

/Steve

Tonmoy Dey

unread,
May 30, 2019, 6:02:43 PM5/30/19
to pmem
Hi,

Even with changing the #define PATH  to "/mnt/mem/myfile", I am still getting the virtual address which does not fall in the range of the persistent memory [0x0000000180000000-0x00000001ffffffff].
Also verifying with pmem_is_pmem() functionI am still getting that it is "NOT" in pmem.

Regards,
Tonmoy

On Thu, May 30, 2019 at 5:19 PM Tonmoy Dey <deyton...@gmail.com> wrote:
--

Andy Rudoff

unread,
May 30, 2019, 6:10:24 PM5/30/19
to pmem
The virtual address is what the system allocated for you in your local process address space.  It won't have anything to do with those physical addresses printed by the kernel that you see in dmesg.

Not sure why is_pmem is false.  Can you confirm the 4k file was created in /mnt/mem with "ls -l /mnt/mem"?  Also, did mapped_len come back as 4k?

The next step is probably to use the debug version of libpmem and turn on logging to see what it thinks is going on.  See the PMEM_LOG_LEVEL variable in the man page at http://pmem.io/pmdk/manpages/linux/master/libpmem/libpmem.7.html

-andy
To unsubscribe from this group and stop receiving emails from it, send an email to pmem+unsubscribe@googlegroups.com.

Tonmoy Dey

unread,
May 30, 2019, 6:17:44 PM5/30/19
to Andy Rudoff, pmem
Hi Andy,

The output to ls -l /mnt/mem is :
drwxrwxrwx 2 root   root   16384 May 30 13:20 lost+found
-rwxrwxrwx 1 tonmoy tonmoy  4096 May 30 18:13 myfile
The file is getting created.

The size of mapped_len being returned after pmem_map_file is 4096.

I have the logging turned ON already. Please let me know if I can verify something from the log. I have attached the same for your reference.

Thanks,
Tonmoy

To unsubscribe from this group and stop receiving emails from it, send an email to pmem+uns...@googlegroups.com.

To post to this group, send email to pm...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pmem/f17b49f5-6d49-4248-9ae7-b5309010d538%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "pmem" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pmem+uns...@googlegroups.com.

To post to this group, send email to pm...@googlegroups.com.
log_info_pmem

Marcin Ślusarz

unread,
May 30, 2019, 7:18:21 PM5/30/19
to Tonmoy Dey, Andy Rudoff, pmem

Hi Tonmoy,

Your log says: "mmap with MAP_SYNC not supported".
You need kernel with MAP_SYNC support for is_pmem to be true. Linux supports this flag starting from 4.15.

Marcin

Tonmoy Dey

unread,
Jun 7, 2019, 5:21:52 PM6/7/19
to pmem
Thanks for your explanation.  
Could someone please tell me what is simplest way(API) to allocate memory in the pmem(memory mapped file)? I am looking for something similar to malloc/free in the libpmemobj. Non-transactional interface would be preferred.
Also is it possible for me to change the page size from 4Kb to something larger in pmem?

Thank you for your time.
To unsubscribe from this group and stop receiving emails from it, send an email to pm...@googlegroups.com.

To post to this group, send email to pm...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pmem/f17b49f5-6d49-4248-9ae7-b5309010d538%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "pmem" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pm...@googlegroups.com.

To post to this group, send email to pm...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pmem/b4107425-de63-4520-885c-aa3cb4f73be4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "pmem" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pm...@googlegroups.com.

Andy Rudoff

unread,
Jun 7, 2019, 5:40:25 PM6/7/19
to pmem
Hi Tonmoy,

When you say "non-transactional" you mean you don't care if the pmem file is consistent after a crash?  If that's the case, you can just use a volatile memory allocator which will use the pmem for capacity at run time, but then discard all the allocation information when the program exits or machine crashes.  See the "pmem" type of memory for libmemkind -- we have lots of applications using pmem with libmemkind where they just ignore the fact that it is persistent.

If you do care about persistence, then you need a strategy for using your allocation state after a crash, and that's what libpmemobj is all about.  Note that you don't have to use the full-featured transactions in pmemobj, you can just use the allocator and it will make sure the allocation information is consistent, but then of course you are responsible for the consistency of the data structures you build with the allocated pmem.

Depending on your use case, maybe you just want to grow the file to allocate, and truncate the file to shrink.  It is really up to your use case.

On Linux, mmap() will use large pages when mapping pmem whenever possible.

-andy
Reply all
Reply to author
Forward
0 new messages