cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Visitor
Visitor
270 Views
Registered: ‎12-19-2019

mmap to reserved memory using huge page

Jump to solution

Dear gurus,

 

I have an application where I need to access a large memory block (a few MiBs) reserved during boot up through "reserved-memory" in device tree. Unfortunately DMA is not viable as I have to update the area in a scattered manner.

I understand that  I can access the area using mmap with default page size of 4K however to make it efficient, I hope to mmap into the reserved memory using huge page to get the base pointer which is the start of the memory block. Otherwise I'll have to make mulitple mmap for each page which is tedious and time consuming.

I've search through the internet but so far I can only find information about huge pages preallocated during boot up. There is no info whatsoever regarding using huge pages for reserved memory. So my questions are:

1. First of all, is the idea/plan feasible? Or there is too much to do for this to happen?

2. If practical, can you please guide me on how to get it done?

 

Thanks,

Lichang

0 Kudos
1 Solution

Accepted Solutions
Highlighted
Scholar
Scholar
217 Views
Registered: ‎05-28-2013

Re: mmap to reserved memory using huge page

Jump to solution

I'm a little unclear on what you are trying to achive. Does the memory need to be continuous? Do you want to use it for DMA?

The standard answer here is "Linux Contiguous Memory Allocator", see https://elinux.org/images/2/23/LinuxCMA-cewg43.pdf, https://lwn.net/Articles/486301/, and https://github.com/torvalds/linux/blob/master/Documentation/devicetree/bindings/reserved-memory/reserved-memory.txt for more info. It seems you are already using this via "reserved-memory" in device tree.

The memory can be mmap'ed from userspace using uio_pmem_genirq (static allocation) or uio_dmem_genirq (dynamic allocation) drivers. This will give a single linear mapping for the entire reserved memory block, in the virtual address space of the user process. In other words it will be a single base address, eg. a pointer to a large array.

The page size (default 4k, versus huge pages) should not be of concern, unless I am mis-understanding what you are trying to do. Huge pages is really meant more for systems with massive amounts of memory, where the overhead of tracking memory at 4k granularity is significant.

View solution in original post

3 Replies
Visitor
Visitor
269 Views
Registered: ‎12-19-2019

Re: mmap to reserved memory using huge page

Jump to solution

BTW, I'm using Petalinux 2019.2 on a Trenz board which use Zynq MPSoC chip.

0 Kudos
Highlighted
Scholar
Scholar
218 Views
Registered: ‎05-28-2013

Re: mmap to reserved memory using huge page

Jump to solution

I'm a little unclear on what you are trying to achive. Does the memory need to be continuous? Do you want to use it for DMA?

The standard answer here is "Linux Contiguous Memory Allocator", see https://elinux.org/images/2/23/LinuxCMA-cewg43.pdf, https://lwn.net/Articles/486301/, and https://github.com/torvalds/linux/blob/master/Documentation/devicetree/bindings/reserved-memory/reserved-memory.txt for more info. It seems you are already using this via "reserved-memory" in device tree.

The memory can be mmap'ed from userspace using uio_pmem_genirq (static allocation) or uio_dmem_genirq (dynamic allocation) drivers. This will give a single linear mapping for the entire reserved memory block, in the virtual address space of the user process. In other words it will be a single base address, eg. a pointer to a large array.

The page size (default 4k, versus huge pages) should not be of concern, unless I am mis-understanding what you are trying to do. Huge pages is really meant more for systems with massive amounts of memory, where the overhead of tracking memory at 4k granularity is significant.

View solution in original post

Highlighted
Visitor
Visitor
172 Views
Registered: ‎12-19-2019

Re: mmap to reserved memory using huge page

Jump to solution

Thanks @rfs613 for your insightful comments.

Yes I realised that I could use uio for this purpose and I resoved that with mmap.

Thanks again.

 

0 Kudos