On Fri, Mar 31, 2023 at 11:49 AM Tyler Rider <tylerjrider@xxxxxxxxx> wrote: > > Hi all, > > I've been trying to search for some mechanism(s) to reclaim resident > memory of some frozen applications on a small embedded device. The > typical use case is to bring up an app and once backgrounded/dismissed > the idea is to freeze/thaw for faster resume/restart times. > > The issue is that after starting/pausing several of these applications > (and subsequently freezing) memory begins dropping, and memory > thrashing begins. (I can stop the apps of course, but then that leads > to longer load times). > > I've already got memory constraint issues, which led to adding a swap > partition. I've tried bumping the memory.swapiness to 100 within a > memory cgroup, and waiting a few seconds for kswapd to kick in before > freezing but since the app is running it only puts a handful of pages > into swap. > > Some projects exist (crypopid(2) / CRIU) for dumping the process state > in userspace, but unless I'm missing something, I'd imagine there must > be some existing kernel mechanism (seems like a useful feature for > small memory constrained devices) within the freezer/memory cgroups > that can force all pages of the frozen process to a swap partition, > and restore on thaw. > > Does this sort of cgroup-level S4 (hibernate-to-disk) exist or even > just a mechanism to force a frozen process's pages to swap? In memory cgroups there is a memory.reclaim interface, where you can request the kernel to reclaim X amount of memory from the cgroup. A few things to keep in mind: * This is per-cgroup, not per-process. * This is irrelevant to freezing. * This will try to reclaim all types of memory, not just swapbacked (anon & tmpfs memory). So it may writeback file pages charged to the cgroup, or shrink slabs. * I am not aware of a mechanism to fault back in all the memory mapped by processes in a cgroup to restore the pages. Perhaps you can use MADV to do this per-process, or just let processes fault their memory back in on-demand. > > Thanks, > Tyler