I use an anonymous mmap to allocate a giant chunk of memory. There are several contiguous pages in this that I'd like to turn into a ring buffer, using virtual memory mirroring.
This example on Wikipedia shows what I'm meaning by virtual memory mirroring.
Say the first 14 blocks below are the pages in my giant chunk. I'd like to virtually map pages 6 and 7 to another two consecutive locations.
[0][1][2][3][4][5][6][7][8][9][10][11][12][13].......[6][7][6][7]
Mike Ash gives a rundown of what I want to do, but using mach specific APIs.
How can this be done on Linux?
mmap
twice, it doesn't care where it came from. The idea being that you want the complete buffer to be mirrored (which is obviously what most people want). If you only want to mirror a part of the memory block, simply use something other than zero foroffset
. The only other possible way of mirroring pages is usingremap_file_pages
, and this, too, requires a memory mapping (so you gain nothing, really). You lose something though... portability. – Pragmatistremap_file_pages
is what I was looking for – Ruppremap_file_pages
is marked deprecated in recent Linux versions. Probably better to usemmap
. – Radmilla