简体   繁体   中英

Shared memory marked as virtual memory?

I run a program which allocates 64MB as shared memory for IPC communication. pmap shows that chunk of 64MB is allocated. However, "top" shows the RES memory of the proc is just about 40MB! I conclude the shared memory is marked as VIRT. But why? There Linux still has more than 1GB RAM available.

Have you actually used any of that 64MB yet? Linux defers allocation.

cf. Does malloc lazily create the backing pages for an allocation on Linux (and other platforms)?

Linux doesn't load all memory the process "obtain" to RAM , it load memory form virtual place to RAM just when you program refer that block of memory. Here "memory" means private mem & shared mem both. I haven't done any experiments to verify the above opinion, but I have seen this in many places like SO, and I do believe it . Just FYI.

Shared memory is, just like most if not all of the memory userland programs deal with, virtual. Only active pages need to be mapped to physical (ie resident memory). Doing differently would be a waste of resources.

The only exception is when the process specifically locks the pages in RAM with mlock .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM