On a modern 64-bit x86 Linux, how is the mapping between virtual and physical pages set up, kernel side? On the user side, you can mmap in pages from the page cache, and this will map 4K pages in directly into user space - but I am interesting in how the pages are mapped in the kernel side.

Does it make use of the "whole ram identity mapping" or something else? Is that whole ram identity mapping generally using 1GB pages?

  • Which cache are you talking about? – Gilles 'SO- stop being evil' Dec 31 '16 at 21:41
  • @Gilles - the page cache, i.e., the cache that holds pages read from disk (including unwritten dirty blocks). – BeeOnRope Dec 31 '16 at 21:50

On a modern 64-bit x86 Linux?

Yes. It calls kmap() or kmap_atomic(), but on x86-64 these will always use the identity mapping. x86-32 has a specific definition of it, but I think x86-64 uses a generic definition in include/linux/highmem.h.

And yes, the identity mapping uses 1GB hugepages.

LWN article which mentions kmap_atomic.

I found kmap_atomic() by looking at the PIO code.[*]

Finally, when read() / write() copy data from/to the page cache:

generic_file_buffered_read -> copy_page_to_iter -> kmap_atomic() again.

[*] I looked at PIO, because I realized that when performing DMA to/from the page cache, the kernel could avoid using any mapping. The kernel could just resolve the physical address and pass it to the hardware :-). (Subject to IOMMU). Although, the kernel will need a mapping if it wants to checksum or encrypt the data first.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.