What does the Linux /proc/meminfo "Mapped" topic mean? I have seen several one-liners that tell me it is the "Total size of memory in kilobytes that is mapped by devices or libraries with mmap." But I have now spent almost twenty hours searching the 2.6.30.5 kernel source code trying to confirm this statement, and I have been unable to do so -- indeed I see some things which seem to conflict with it.
The "Mapped" count is held in global_page_state[NR_FILE_MAPPED]
. The comment near the declaration of NR_FILE_MAPPED
says: "Pagecache pages mapped into pagetables. Only modified from process context."
Aren't all of the pages referred to by meminfo's "Cached" topic file-backed? Doesn't that mean that all these pages must be "Mapped"? I've looked at a few dozen meminfo listings, from several different architectures, and always the "Mapped" value is much smaller than the "Cached" value.
At any given time most of memory is filled with executable images and shared libraries. Looking at /proc/pid/smaps, I see that all of these are mapped into VMAs. Are all of these mapped into memory using mmap()? If so, why is "Mapped" so small? If they aren't mapped into memory using mmap(), how do they get mapped? Calls on
handle_mm_fault
, which is called byget_user_pages
and various architecture-dependent page-fault handlers, increment the "Mapped" count, and they seem to do so for any page associated with a VMA.I've looked at the mmap() functions of a bunch of drivers. Many of these call
vm_insert_page
orremap_vmalloc_range
to establish their mappings, and these functions do increment the "Mapping" count. But a good many other drivers seem to callremap_pfn_range
, which, as far as I can tell, doesn't increment the "Mapping" count.