mm,page_owner: don't remove GFP flags in add_stack_record_to_list
Subsystems (2)
PATCH 1/1 mm,page_owner: don't remove GFP flags in add_stack_record_to_list
This loses flags like GFP_NOFS and GFP_NOIO that are important to avoid deadlocks as well as GFP_NOLOCKDEP that otherwise generates lockdep false positives.
--- mm/page_owner.c | 2 -- 1 file changed, 2 deletions(-)
mm/page_owner.c +0 -2
@@ -168,9 +168,7 @@ static void add_stack_record_to_list(struct stack_record *stack_record,unsigned long flags;struct stack *stack; -/* Filter gfp_mask the same way stackdepot does, for consistency */ gfp_mask &= ~GFP_ZONEMASK ; - gfp_mask &= (GFP_ATOMIC |GFP_KERNEL ); gfp_mask |= __GFP_NOWARN;set_current_in_page_owner ();
Signature · 1 line
2.39.2
Quoted 3 lines · Christoph Hellwig
This loses flags like
GFP_NOFSandGFP_NOIOthat are important to avoid deadlocks as well asGFP_NOLOCKDEPthat otherwise generates lockdep false positives.
GFP_NOFS and GFP_NOIO translate to GFP_KERNEL without __GFP_FS/__GFP_IO so I don't see how this patch would have helped with those. __GFP_NOLOCKDEP is likely the actual issue and stackdepot solved it like this:
https://lore.kernel.org/linux-xfs/[email protected]/
So we could just do the same here.
Quoted 21 lines
Fixes 217b2119b9e2 ("mm,page_owner: implement the tracking of the stacks count")Reported-by Reported-by: [email protected]Signed-off-by Christoph Hellwig <[email protected]>--- mm/page_owner.c | 2 -- 1 file changed, 2 deletions(-)mm/page_owner.c +0
-2@@ -168,9 +168,7 @@ static void add_stack_record_to_list(struct stack_record *stack_record,unsigned long flags;struct stack *stack; -/* Filter gfp_mask the same way stackdepot does, for consistency */ gfp_mask &= ~GFP_ZONEMASK ; - gfp_mask &= (GFP_ATOMIC |GFP_KERNEL ); gfp_mask |= __GFP_NOWARN;set_current_in_page_owner ();
Quoted 5 lines · Vlastimil Babka
Quoted 3 lines · Christoph Hellwig
This loses flags like
GFP_NOFSandGFP_NOIOthat are important to avoid deadlocks as well asGFP_NOLOCKDEPthat otherwise generates lockdep false positives.
Quoted 7 lines
GFP_NOFSandGFP_NOIOtranslate toGFP_KERNELwithout __GFP_FS/__GFP_IO so I don't see how this patch would have helped with those.__GFP_NOLOCKDEPis likely the actual issue and stackdepot solved it like this:https://lore.kernel.org/linux-xfs/[email protected]/
So we could just do the same here.
Yes, it is __GFP_NOLOCKDEP that is the issue here, but cargo-cult-copying of that stackdepot fix is just whack-a-mole bug fixing without addressing the technical debt that got us here in the first place. Has anyone else bothered to look to see if kmemleak has the same problem?
If anyone bothered to do an audit, they would see that gfp_kmemleak_mask() handles the reclaim context masks correctly. Further, it adds NOWARN, NOMEMALLOC and
NORETRY, which means the debug code is silent when it fails, it doesn't deplete emergency reserves and doesn't bog down retrying forever when there are sustained low memory situations.
This also points out that the page-owner/stackdepot code that strips GFP_ZONEMASK is completely redundant. Doing:
gfp_flags &= GFP_KERNEL|GFP_ATOMIC|__GFP_NOLOCKDEP;
strips everything but __GFP_RECLAIM, __GFP_FS, __GFP_IO, __GFP_HIGH and __GFP_NOLOCKDEP. This already strips the zonemask info, so there's no need to do it explicitly.
IOWs, the right way to fix this set of problems is to lift gfp_kmemleak_mask() to include/linux/gfp.h and then use it across all these nested allocations that occur behind the public memory allocation API.
I've got a patchset under test at the moment that does this....
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
Quoted 12 lines · Dave Chinner
Quoted 11 lines · Vlastimil Babka
Quoted 3 lines · Christoph Hellwig
This loses flags like
GFP_NOFSandGFP_NOIOthat are important to avoid deadlocks as well asGFP_NOLOCKDEPthat otherwise generates lockdep false positives.
GFP_NOFSandGFP_NOIOtranslate toGFP_KERNELwithout __GFP_FS/__GFP_IO so I don't see how this patch would have helped with those.__GFP_NOLOCKDEPis likely the actual issue and stackdepot solved it like this:
Quoted 7 lines
Quoted 1 line
So we could just do the same here.
Yes, it is
__GFP_NOLOCKDEPthat is the issue here, but cargo-cult-copying of that stackdepot fix is just whack-a-mole bug fixing without addressing the technical debt that got us here in the first place. Has anyone else bothered to look to see if kmemleak has the same problem?
Looks like you did :)
Quoted 6 lines
If anyone bothered to do an audit, they would see that
gfp_kmemleak_mask()handles the reclaim context masks correctly. Further, it adds NOWARN, NOMEMALLOC and
NORETRY, which means the debug code is silent when it fails, it doesn't deplete emergency reserves and doesn't bog down retrying forever when there are sustained low memory situations.
So we do have NOWARN here. __GFP_RETRY_MAYFAIL might have been slightly better than __GFP_NOWARN wrt "not retrying forever" but also not giving up too soon. If we want to be really careful about reserves, it's a question whether to keep the | GFP_ATOMIC which translates to leaving __GFP_HIGH. OTOH if we don't keep it, these allocations might fail too easily from an atomic context and we could miss the debugging data.
Quoted 8 lines
This also points out that the page-owner/stackdepot code that strips
GFP_ZONEMASKis completely redundant. Doing:gfp_flags &= GFP_KERNEL|GFP_ATOMIC|__GFP_NOLOCKDEP;strips everything but
__GFP_RECLAIM,__GFP_FS,__GFP_IO,__GFP_HIGHand__GFP_NOLOCKDEP. This already strips the zonemask info, so there's no need to do it explicitly.
True.
Quoted 4 lines
IOWs, the right way to fix this set of problems is to lift
gfp_kmemleak_mask()toinclude/linux/gfp.hand then use it across all these nested allocations that occur behind the public memory allocation API.
Agree. But arguably these quick fixes adding __GFP_NOLOCKDEP were appropriate for the late rc phase we're in.
Quoted 1 line
I've got a patchset under test at the moment that does this....
Great! Thanks.
Quoted 1 line
-Dave.