Conversation

Yeah, that's what zram does. It's in-memory compression with support for writeback. The writeback is generally very conservative. This is the setup used for Pixels: [ro.zram.first_wb_delay_mins]: [1440] [ro.zram.mark_idle_delay_mins]: [60] [ro.zram.periodic_wb_delay_hours]: [24]
2
1
The logic for the writeback is in android.googlesource.com/platform/frame. The configuration above means it marks the pages in zram as idle 60 minutes after boot. 24h after boot, it flushes out any remaining pages it marked as idle to storage. Then, it marks zram pages idle and waits 24h again.
The pages have to be unused for a whole day to actually get written out to storage. Having the storage writeback is actually relatively recent. There was traditionally never any storage-based swap on Android. Separately from this, there's also very aggressive idle app compaction.