Interview kitsBlog

Your dream job? Lets Git IT.
Interactive technical interview preparation platform designed for modern developers.

XGitHub

Platform

  • Categories

Resources

  • Blog
  • About the app
  • FAQ
  • Feedback

Legal

  • Privacy Policy
  • Terms of Service

© 2026 LetsGit.IT. All rights reserved.

LetsGit.IT/Categories/Operating Systems
Operating Systemshard

What is memory-mapped I/O (mmap) and when would you use it?

Tags
#mmap#memory#io
Back to categoryPractice quiz

Answer

mmap maps a file or device into a process’s address space so it can be accessed like memory. It’s useful for large files, random access, and zero-copy sharing.

Advanced answer

Deep dive

mmap trades explicit I/O for VM mechanisms:

  • The OS loads pages on-demand via page faults.
  • Can reduce syscalls and copy overhead.
  • Useful for shared memory between processes.
  • Requires careful handling of page faults and alignment.

Examples

Random access to a large file:

mmap file -> pointer arithmetic -> OS pages in data as needed

Common pitfalls

  • Assuming mmap is always faster than read/write.
  • Not handling SIGBUS on truncated files.
  • Poor access patterns causing thrashing.

Interview follow-ups

  • When would you prefer read/write over mmap?
  • How does mmap interact with page cache?
  • What are the risks for concurrent writers?

Related questions

Operating Systems
What are file descriptors and how does I/O buffering work?
#file-descriptors#io#buffering
Java
Generational garbage collection: why does the JVM split memory into young/old?
#java#gc#jvm
Data Structures
Sparse matrix representation: when would you use CSR/COO instead of a dense array?
#sparse-matrix
#csr
#coo
Data Structures
What is a Bloom filter and what trade-off does it make?
#bloom-filter#probabilistic#hashing
Data Structures
Bitset/bitmap: what is it and when is it a good choice?
#bitset#bitmap#memory