Efficient Memory Management on Mobile Devices
Discusses efficient Memory Management on Mobile Devices and evaluates key implications for security practitioners.
Summary
### Overview In this talk, Bartłomiej Wołnerkiewicz, a software engineer at Samsung R&D Institute Poland, discusses strategies and kernel mechanisms for managing memory efficiently on resource-constrained mobile devices. Mobile platforms face unique challenges: limited physical RAM, lack of physical swap storage, and the need for user-space-driven Out of Memory (OOM) handling. Because standard Linux kernels lack awareness of which applications are critical to user experience (e.g., active foreground apps versus background tasks), custom memory management policies must bridge kernel capabilities and user-space requirements.
### Key Topics The presentation evaluates several kernel and user-space mechanisms designed to monitor, reclaim, compress, and share memory on mobile platforms: - **Control Groups Memory Controller (memcg)**: Managing, accounting, and constraining memory consumption per group of tasks. - **Memory Pressure Notifiers and Shrinkers**: Event-driven mechanisms notifying user space of varying degrees of memory pressure. - **Reclaim Interfaces**: Per-process and per-cgroup memory reclaim capabilities. - **Transparent Memory Compression**: Using in-memory compressed swap mechanisms like zswap and zram. - **User-Space OOM Handling**: Replacing or augmenting the kernel's low memory killer with flexible user-space daemons. - **Volatile Memory Ranges and Kernel Samepage Merging (KSM)**: APIs enabling user applications to hint discardable memory or share identical memory pages.
### Technical Details - **Control Groups & memcg**: Control groups aggregate tasks hierarchically. The memory controller isolates task groups, accounting and enforcing limits for anonymous pages and file caches, with optional accounting for stack, slab, and socket/TCP buffers. It supports soft limits (triggering reclamation under pressure) and memory threshold notifiers. - **Memory Pressure Cgroup Notifier**: Introduced in Linux kernel 3.10, this feature allows applications to monitor memory pressure across three levels: *low* (light background reclaim), *medium* (swapping occurs; non-critical caches should be freed), and *oom* (severe pressure requiring aggressive freeing). A proposed shrinker interface allows apps to declare memory in application-defined chunks (e.g., 1 MB) that can be surrendered on demand. - **Targeted Reclaim**: Per-process reclaim via `/proc/<pid>/` allows reclaiming file-backed, anonymous, or specific address ranges (useful for runtimes like WebKit) without terminating the process. Per-cgroup reclaim (`memory.force_reclaim`) was proposed but rejected (NAK'd), requiring workarounds like soft limits or task migration. - **Memory Compression**: Swapping anonymous memory into RAM can use Frontswap hooks or block devices (zram). Memory allocators include `zbud` (merged in 3.11, limited to 2 compressed pages per physical page frame with a 50% max compression ratio, but low fragmentation) and `zsmalloc` (higher density, higher fragmentation). In tests on Samsung's Exynos platform using Tizen applications, compression ratios hovered near 50%, and LZ4 demonstrated a 10% speedup over LZO with negligible change in compression ratio. - **User-Space Low Memory Killer**: Demonstrates classifying processes into foreground and background. On memory pressure, background processes are terminated or compressed first, preserving foreground user experience. - **Volatile Memory Ranges (`vrange`)**: Proposed system call allowing applications to mark cache regions as volatile (`VRANGE_VOLATILE`) or non-volatile (`VRANGE_NON_VOLATILE`). If memory was purged by the kernel under pressure, the return parameter flags data loss, or accessing it raises `SIGBUS`. - **Kernel Samepage Merging (KSM)**: Scans memory to merge identical pages via `madvise` with `MADV_MERGEABLE`. Wołnerkiewicz notes caution is needed when unmerging pages (`MADV_UNMERGEABLE`), as memory demand spikes could invoke the OOM killer.
### Takeaways Effective mobile memory management relies on a combination of kernel-level reclamation hooks and user-space policy orchestration. Moving OOM handling and pressure responses to user space allows systems to prioritize user-visible applications. While features like volatile ranges, per-process reclaim, and compression algorithms like LZ4 show clear benefits, many mobile enhancements require coordinated adjustments across kernel drivers and application frameworks.
Related talks
The Linux Foundation·40 min
Koshiro Onuki
Outlines device Management and Delta Update for Embedded Devices with SWUpdate and TUF and evaluates key implications for security practitioners.
The Linux Foundation·26 min
Jeremy Bettis
Demonstrates unit Testing Memory Mapped Device Drivers and evaluates key implications for security practitioners.
The Linux Foundation·39 min
Disha Patil · NXP Semiconductors
Provides zephyr Power Management for Wearable Devices and evaluates key implications for security practitioners.


