What is jetsam? How does the system decide which app to kill?
What it is
Jetsam is the XNU kernel subsystem that forcibly terminates processes when memory runs low (the analogue of Linux's OOM killer, but with stricter policies because iOS has no swap). It fires in two cases:
- system-wide pressure: free memory is scarce even after compressing and evicting clean pages;
- per-process limit: the app's footprint exceeded its personal limit (for iOS apps on modern devices that is a few GB in the foreground, hundreds of MB for extensions and background; the exact value comes from
os_proc_available_memory()).
The rest of this answer, with code and interview follow-ups, is in the DevPrep app.
Read the full answer in DevPrep