Re: make_persistent used to allocate objects.

37 views
Skip to first unread message

Muktikanta Sa

unread,
Sep 23, 2021, 1:09:58 PM9/23/21
to pmem
Hello All,
Can anyone help me to fix this?

I have created /pmem0/ through the emulator mentioned in the https://pmem.io/2016/02/22/pm-emulation.html.  

I have created /pmem0/ of 4GB out of 16GB RAM.

While creating half million of nodes
--> in PM through make_persistent, it takes around 1600 Seconds. 
--> in tmpfs through make_persistent, it takes around 0.675528 Seconds. 
--> In DRAM using new,  it takes around 0.113644 Seconds. 

Why so much difference? It should be near to tmpfs time.

Here is the sample code for it:

// node for non-volatile memory
struct PNode{
int key;
PNode(){}
PNode(int k):key(k){}
};

// node for volatile memory, each volatile node is connected to a non-volatile node having same key value.
struct Node{
int key;
pobj::persistent_ptr<PNode> pnext; // reference to PNode
atomic<Node*> next; // reference to next Node
Node(){}
Node(int k, pobj::persistent_ptr<PNode> n):key(k),pnext(n),next(nullptr){}
};

void PList :: initList(int seed){  // seed value is 1M
auto pool = pobj::pool_by_vptr(this);
pobj::transaction::run(pool, [this, &seed] {
Node * pred, *curr; // volatile reference
curr = Head; // Head is volatile sentinel node, it is connected with Tail sentinel node using next
pobj::persistent_ptr<PNode> newPNode; // reference for non-volatile node
for(int i=1; i<=seed; i=i+2){
auto newn = pobj::make_persistent<PNode>(i); //allocate new non-volatile node
newPNode = newn; 
Node *newv = new Node(i, newPNode); // allocate new volatile node
newv->next = Tail; // insert at the Tail position
               curr->next = newv;
               curr = newv;
}
});
}


/* handle file creation/open */
std::string path{argv[1]}; // path = "/pmem0/fp"
pmem::obj::pool<root> pop;
if (file_exists(path)) {
pop = pmem::obj::pool<root>::open(path, LAYOUT);
} else {
pop = pmem::obj::pool<root>::create(path, LAYOUT, PMEMOBJ_MIN_POOL * 450, CREATE_MODE_RW); //it creates 3.8GB memory in /pmem0/fp

/* allocate the persistent plist only when the pool is new */
pmem::obj::make_persistent_atomic<PList>(pop, pop.root()->plist);
pop.root()->plist->initList(seed); // initList method is invoked here
}


-Thanks
Mukti

Igor

unread,
Sep 24, 2021, 9:54:58 AM9/24/21
to Muktikanta Sa, pmem
Hi,

It seems that you are trying to use the pmem0 device directly. It won't work. Pmemobj only works with /dev/dax or files which reside on filesystem mounted with dax.
You should follow the instructions for installing DAX filesystem from the end of the blog post:
# sudo mkdir /mnt/mem
# sudo mkfs.ext4 /dev/pmem0    OR    #sudo mkfs.xfs -m reflink=0 /dev/pmem0
# sudo mount -o dax /dev/pmem0 /mnt/mem

Once you have '/mnt/mem' mounted with dax you can pass something like '/mn/pmem/fp' to pmem::obj::pool<>::create. 

I'm not sure what exactly happens in your code but /pmem0/fp is probably just a file on a regular (non-dax) filesystem within a /pmem0 directory (the pmem0 **device** is created in /dev subdirectory). Since the file is on non-dax fs pmemobj will use msync instead of CPU flush instructions and that's why it's so slow.

Best regards,
Igor

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/pmem/ea5bc85b-8a69-48ab-a59e-81bf5268f04fn%40googlegroups.com.

Muktikanta Sa

unread,
Sep 24, 2021, 2:27:05 PM9/24/21
to Igor, pmem
Hi Igor,
Thanks a lot for your kind information.

The name of /dev/pmem0 is /pmem0 instead of /dev/pmem0
Just I have mounted again. It looks, it is working.
Now it is taking around 0.6 seconds to initialize 1/2 million nodes.

Thanks
Mukti


Reply all
Reply to author
Forward
0 new messages