cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JM_Park
Participant
Participant
928 Views
Registered: ‎05-17-2020

How to Change Memory Page Size in mmap() function?

Jump to solution

Hello.

I wanna change memory page size or use huge page in mmap function.

I'm using default page size (4K), so when I want to access memory over 4K size, I have to execute new mmap function.

I know that there's the two ways, one of them is changing page size returned by sysconf(_SC_PAGESIZE) function, the another one is using huge page.

How can I change the accessible size of mmap() function??

 

0 Kudos
1 Solution

Accepted Solutions
sabankocal
Voyager
Voyager
904 Views
Registered: ‎08-02-2019

Hi @JM_Park ,

I think, there is a misunderstanding.

If you want to map bigger address space, instead of changing PAGE_SIZE parameter, you need to set 2.parameter of mmap, that is named "Length". If you look manpage of mmap. This parameter described as "The length argument specifies the length of the mapping (which must be greater than 0)."  

I'm using mmap in my project to map 256kB OCM memory like that:

 

 

	char *uiod = "/dev/uio0";

	*fd = open(uiod, O_RDWR);
	if (*fd < 1) {
		printf("Invalid UIO device file:%s.\n", uiod);
		return MAP_FAILED;
	}

	// mmap the OCM memory into user space
	int pagesize= getpagesize();
	ocm_ptr = mmap(NULL, OCM_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, *fd, pagesize);
	if (ocm_ptr == MAP_FAILED) {
		printf("Mmap OCM failure.\n");
		return MAP_FAILED;
	}

 

 

Saban

 

 

<--- If reply is helpful, please feel free to give Kudos, and close if it answers your question --->

View solution in original post

3 Replies
sabankocal
Voyager
Voyager
905 Views
Registered: ‎08-02-2019

Hi @JM_Park ,

I think, there is a misunderstanding.

If you want to map bigger address space, instead of changing PAGE_SIZE parameter, you need to set 2.parameter of mmap, that is named "Length". If you look manpage of mmap. This parameter described as "The length argument specifies the length of the mapping (which must be greater than 0)."  

I'm using mmap in my project to map 256kB OCM memory like that:

 

 

	char *uiod = "/dev/uio0";

	*fd = open(uiod, O_RDWR);
	if (*fd < 1) {
		printf("Invalid UIO device file:%s.\n", uiod);
		return MAP_FAILED;
	}

	// mmap the OCM memory into user space
	int pagesize= getpagesize();
	ocm_ptr = mmap(NULL, OCM_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, *fd, pagesize);
	if (ocm_ptr == MAP_FAILED) {
		printf("Mmap OCM failure.\n");
		return MAP_FAILED;
	}

 

 

Saban

 

 

<--- If reply is helpful, please feel free to give Kudos, and close if it answers your question --->

View solution in original post

849 Views
Registered: ‎04-20-2017

Exactly... You can map many pages at once... Just the biginning of the map needs to be aligned to a page (adress%4096==0)otherwise you get MAP_FAILED as return value of mmap

0 Kudos
JM_Park
Participant
Participant
841 Views
Registered: ‎05-17-2020

Thank you very much!!

0 Kudos