On 8/27/25 10:00, Vlastimil Babka wrote:
On 8/27/25 07:17, Harry Yoo wrote:
On Mon, Aug 25, 2025 at 05:42:52PM +0200, Vlastimil Babka wrote:
On 8/25/25 14:40, Matthew Wilcox wrote:
On Mon, Aug 25, 2025 at 08:17:37PM +0800, yangshiguang1011@163.com wrote:
Avoid deadlock caused by implicitly waking up kswapd by passing in allocation flags.
[...]
- /* Preemption is disabled in ___slab_alloc() */
- gfp_flags &= ~(__GFP_DIRECT_RECLAIM);
If you don't mean __GFP_KSWAPD_RECLAIM here, the explanation needs to be better.
It was suggested by Harry here: https://lore.kernel.org/all/aKKhUoUkRNDkFYYb@harry
I think the comment is enough? Disabling preemption means we can't direct reclaim, but we can wake up kswapd. If the slab caller context is such that we can't, __GFP_KSWAPD_RECLAIM already won't be in the gfp_flags.
To make it a little bit more verbose, this ^^ explanation can be added to the changelog?
But I think we should mask our also __GFP_NOFAIL and add __GFP_NOWARN?
That sounds good.
(we should get some common helpers for these kinds of gfp flag manipulations already)
Any ideas for its name?
gfp_dont_try_too_hard(), gfp_adjust_lightweight(), gfp_adjust_mayfail(), ...
I'm not good at naming :/
Looks like there's already gfp_nested_mask() for these purposes. I'm not sure if it should be allowing GFP_ATOMIC (thus __GFP_HIGH) as it does though. Seems to contradict the comment about not exhausing reserves. Wonder if that was raised during review...
Looks like I mentioned it but inconclusively.
https://lore.kernel.org/linux-xfs/1fb5b8f3-d8c7-4350-888a-ad8f4d54bc66@suse....
Anyway that's orthogonal to using the helper here right now.
The masking out of __GFP_DIRECT_RECLAIM is specific to the slab case so we don't need a helper for that (unless we find other users). It could be then e.g. gfp_nested_mask_noblock() ?