Can frequent access of a large (1~2 GB) file-mapped memory cause performance drop? (in a tight loop, say, a game's update loop)
As far as I can google, memory mapped files are cached by OS (using page fault), and that make it seems it's safe to access frequently since it's loaded on memory.
However, I also figured that since it's cached, not loaded, it might induce performance drop.
Please help me get the right answer, and a kind describtion would be appreciated. And I would like to know answers for both Linux and Windows if possible, but I doubt they would behave that different.
Note: When I said 'access' I ment both read and write.
You ask about accessing repeatedly a 1-2 GB range of a memory-mapped file. The short answer is that yes, it will have a performance downside, especially if your pages are small.
The first problem is that repeatedly accessing 1 GB of any memory will (by default) tend to evict whatever other data you have, and CPU data cache hit rates will suffer. Consider that a typical CPU data cache size is just a few megabytes.
The second problem is the Translation Lookaside Buffer. If you're using the default page size of 4 KB, then 1 GB is 250k pages. On Linux you should enable "huge pages" to reduce the TLB load imposed by accessing such a large region of memory.
The third problem is that it seems you haven't tested it. Testing is very important for this sort of thing. Without it, you'll never know if you have a real problem or only a hypothetical one.