pmdk icon indicating copy to clipboard operation
pmdk copied to clipboard

libpmem-issue: unchangeability of relative address:: pmem_map_file

Open James-tech-007 opened this issue 3 years ago • 2 comments

issue 1 unchangeability of relative address

can I access data on pmem based on their offset from the start virtual address getting from pmem_map_file() when I reboot my application?

descripton

if I use libpmem library to store a very long string begining from the start virtual address I get from pmem_map_file() on pmem, like "abcd....dfdegh"(assume I get enough mapped length), can I access each char based on their offset from the start virtual address getting from pmem_map_file() when I reboot my application(assume I don't change the mapped length argument)?

i.e. every time we use pmem_map_file() to map a file on pmem(the mapped length argument is not changed), it will return a virtual address which associates with the same region on pmem so that we can use the offset from the start address we get from the return value of pmem_map_file() to locate our data stored on pmem, ==is this statement true?==

for example:

//first launch
#include <libpmem.h>
#include <cstring>
#include <iostream>
using namespace std;
#define PATH "/mnt/pmem0/pool"
#define MAPLEN 4096<<4

char c[1000000];
char *pmemaddr;

int main(){
    if ((pmemaddr = (char*)pmem_map_file(path.c_str(), MAPLEN,
		PMEM_FILE_CREATE,
		0666, &mapped_len, &is_pmem)) == NULL) {
		cerr << "err pmem_map_file\n";
		exit(1);
	}
    int i;
    for(i=0;i<2000000*3;i+=3){
        c[i] = 'a';
        c[i+1] ='b';
        c[i+2] ='c';
    }
    c[i] = '\0';
    strcpy(pmemaddr,c);
    pmem_persist(pmemaddr,strlen(c));
    pmem_unmap(pmemaddr);
}


//second lauch
int main(){
    if ((pmemaddr = (char*)pmem_map_file(path.c_str(), MAPLEN,
		PMEM_FILE_CREATE,
		0666, &mapped_len, &is_pmem)) == NULL) {
		cerr << "err pmem_map_file\n";
		exit(1);
	}
    char * pb = pmemaddr + 3*1000000 + 2;
    cout << (*pb) << endl ;//can we make sure that the output is "c"?
}

I would really appreciate if some body can help me soon.

James-tech-007 avatar May 02 '22 13:05 James-tech-007

image-20220502214506543 this picture illustrates my idea.

James-tech-007 avatar May 02 '22 14:05 James-tech-007

Yes. If you are mapping the same part of the file, you will always get the same data.

pbalcer avatar May 12 '22 09:05 pbalcer

This issue seems inactive now, if you still have some questions, please re-open it.

lukaszstolarczuk avatar Mar 13 '23 11:03 lukaszstolarczuk