On Tue 18-01-22 23:31:07, Yu Zhao wrote: > On Thu, Jan 13, 2022 at 01:02:26PM +0100, Michal Hocko wrote: > > On Thu 13-01-22 02:43:38, Yu Zhao wrote: > > [...] > > > > > The bottom line is I can try various optimizations, e.g., preallocate > > > > > a few buffers for a limited number of page walkers and if this number > > > > > has been reached, fallback to the rmap-based function. But I have yet > > > > > to see evidence that calls for additional complexity. > > > > > > > > I would disagree here. This is not an optimization. You should be > > > > avoiding allocations from the memory reclaim because any allocation just > > > > add a runtime behavior complexity and potential corner cases. > > > > > > Would __GFP_NOMEMALLOC address your concern? It prevents allocations > > > from accessing the reserves even under PF_MEMALLOC. > > > > __GFP_NOMEMALLOC would deal with the complete memory depletion concern > > for sure but I am not sure how any of these allocations would succeed > > when called from the direct reclaim. Some access to memory reserves is > > necessary if you insist on allocating from the reclaim process. > > > > You can have a look at the limited memory reserves access by oom victims > > for an example of how this can be done. > > Thanks. I'll change GFP_KERNEL to __GFP_HIGH | __GFP_NOMEMALLOC. > __GFP_HIGH allows some access to memory reserves and __GFP_NOMEMALLOC > prevents the complete depletion. Basically the combination lower the > min watermark by 1/2, and we have been using them for > add_to_swap_cache(). Yes this will prevent the complete memory depletion. There are other users of this portion of memory reserves so the reclaim might be out of luck. How this turns out in practice remains to be seen though but it certainly is an opportunity for corner cases and hard to test behavior. -- Michal Hocko SUSE Labs