On Fri, Feb 21, 2020 at 1:36 AM Michal Hocko <mhocko@xxxxxxxxxx> wrote: > > On Fri 21-02-20 10:04:18, Rafael J. Wysocki wrote: > > On Fri, Feb 21, 2020 at 9:49 AM Michal Hocko <mhocko@xxxxxxxxxx> wrote: > > > > > > On Thu 20-02-20 09:38:06, Luigi Semenzato wrote: > > > > I was forgetting: forcing swap by eating up memory is dangerous > > > > because it can lead to unexpected OOM kills > > > > > > Could you be more specific what you have in mind? swapoff causing the > > > OOM killer? No, not swapoff, just fast allocation. Also, in some earlier experiments I tried gradually increasing min_free_kbytes (precisely as suggested) and this would randomly trigger OOM kills when swap space was still available. > > > > , but you can mitigate that > > > > by giving the memory-eaters a higher OOM kill score. Still, some way > > > > of calling try_to_free_pages() directly from user-level would be > > > > preferable. I wonder if such API has been discussed. > > > > > > No, there is no API to trigger the global memory reclaim. You could > > > start the reclaim by increasing min_free_kbytes but I wouldn't really > > > recommend that unless you know exactly what you are doing and also I > > > fail to see the point. If s2disk fails due to insufficient swap space > > > then how can a pro-active reclaim help in the first place? > > > > My understanding of the problem is that the size of swap is > > (theoretically) sufficient, but it is not used as expected during the > > preallocation of image memory. > > > > It was stated in one of the previous messages (not in this thread, > > cannot find it now) that swap (of the same size as RAM) was activated > > (swapon) right before hibernation, so theoretically that should be > > sufficient AFAICS. Correct, those were my experiments. Search the archives for "semenzato", there are a couple of threads on the topic. But really, why not have a user-level interface for reclaim? I find it very difficult to understand the behavior of the reclaim code, and any attempt to reclaim from user level (memory-eating processes, raising min_free_kbytes) can end in the OOM-kill path. Using cgroups' memory.limit_in_bytes doesn't have this problem, precisely because it only calls try_to_free_pages(), which doesn't trigger OOM killing. If I could make that call from user level (without cgroups) it would greatly simplify my current workaround, and would be useful in other situations as well. Something like echo $page_count > /proc/sys/vm/try_to_free_pages cat /proc/sys/vm/pages_freed # the number of pages freed at the latest request > Hmm, this is interesting. Let me have a closer look... > > pm_restrict_gfp_mask which would completely rule out any IO > happens after hibernate_preallocate_memory is done and my limited > understanding tells me that this is where all the reclaim happens > (via shrink_all_memory). It is quite possible that the MM decides to > not swap in that path - depending on the memory usage - and miss it's > target. More details would be needed. E.g. vmscan tracepoints could tell > us more. > > -- > Michal Hocko > SUSE Labs