DevPrep

All topics › Memory management

How do file-backed pages differ from anonymous?

Senior PRO

Two kinds of pages

File-backed — the page is mapped from a file on disk: code (__TEXT), constants, the dyld shared cache, mmap'd resources and databases. The system always has an "original", so under memory pressure such a page can simply be evicted (if clean) and re-read from disk on the next access. The cost is a page fault and a flash read, not data loss.

Anonymous — nothing backs the page: the heap (malloc), stacks, image buffers, vm_allocate. The only copy of the data is in RAM. It cannot be evicted; the system's options are to keep it, compress it (memory compressor), or kill the process.

The rest of this answer, with code and interview follow-ups, is in the DevPrep app.

Read the full answer in DevPrep

Practice this before your interview

DevPrep turns these answers into one-minute challenges: what does this code print, find the bug, mock interviews. One challenge a day.

Get DevPrep on the App Store