Skip to content

Commit 9a8da05

Browse files
Michal Hockoakpm00
authored andcommitted
Revert "mm: introduce PF_MEMALLOC_NORECLAIM, PF_MEMALLOC_NOWARN"
This reverts commit eab0af9. There is no existing user of those flags. PF_MEMALLOC_NOWARN is dangerous because a nested allocation context can use GFP_NOFAIL which could cause unexpected failure. Such a code would be hard to maintain because it could be deeper in the call chain. PF_MEMALLOC_NORECLAIM has been added even when it was pointed out [1] that such a allocation contex is inherently unsafe if the context doesn't fully control all allocations called from this context. While PF_MEMALLOC_NOWARN is not dangerous the way PF_MEMALLOC_NORECLAIM is it doesn't have any user and as Matthew has pointed out we are running out of those flags so better reclaim it without any real users. [1] https://lore.kernel.org/all/ZcM0xtlKbAOFjv5n@tiehlicka/ Link: https://lkml.kernel.org/r/20240926172940.167084-3-mhocko@kernel.org Signed-off-by: Michal Hocko <mhocko@suse.com> Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Dave Chinner <dchinner@redhat.com> Reviewed-by: Vlastimil Babka <vbabka@suse.cz> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: Christian Brauner <brauner@kernel.org> Cc: James Morris <jmorris@namei.org> Cc: Jan Kara <jack@suse.cz> Cc: Kent Overstreet <kent.overstreet@linux.dev> Cc: Paul Moore <paul@paul-moore.com> Cc: Serge E. Hallyn <serge@hallyn.com> Cc: Yafang Shao <laoar.shao@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 9897713 commit 9a8da05

2 files changed

Lines changed: 6 additions & 15 deletions

File tree

include/linux/sched.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,8 +1681,8 @@ extern struct pid *cad_pid;
16811681
* I am cleaning dirty pages from some other bdi. */
16821682
#define PF_KTHREAD 0x00200000 /* I am a kernel thread */
16831683
#define PF_RANDOMIZE 0x00400000 /* Randomize virtual address space */
1684-
#define PF_MEMALLOC_NORECLAIM 0x00800000 /* All allocation requests will clear __GFP_DIRECT_RECLAIM */
1685-
#define PF_MEMALLOC_NOWARN 0x01000000 /* All allocation requests will inherit __GFP_NOWARN */
1684+
#define PF__HOLE__00800000 0x00800000
1685+
#define PF__HOLE__01000000 0x01000000
16861686
#define PF__HOLE__02000000 0x02000000
16871687
#define PF_NO_SETAFFINITY 0x04000000 /* Userland is not allowed to meddle with cpus_mask */
16881688
#define PF_MCE_EARLY 0x08000000 /* Early kill for mce process policy */

include/linux/sched/mm.h

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -251,25 +251,16 @@ static inline gfp_t current_gfp_context(gfp_t flags)
251251
{
252252
unsigned int pflags = READ_ONCE(current->flags);
253253

254-
if (unlikely(pflags & (PF_MEMALLOC_NOIO |
255-
PF_MEMALLOC_NOFS |
256-
PF_MEMALLOC_NORECLAIM |
257-
PF_MEMALLOC_NOWARN |
258-
PF_MEMALLOC_PIN))) {
254+
if (unlikely(pflags & (PF_MEMALLOC_NOIO | PF_MEMALLOC_NOFS | PF_MEMALLOC_PIN))) {
259255
/*
260-
* Stronger flags before weaker flags:
261-
* NORECLAIM implies NOIO, which in turn implies NOFS
256+
* NOIO implies both NOIO and NOFS and it is a weaker context
257+
* so always make sure it makes precedence
262258
*/
263-
if (pflags & PF_MEMALLOC_NORECLAIM)
264-
flags &= ~__GFP_DIRECT_RECLAIM;
265-
else if (pflags & PF_MEMALLOC_NOIO)
259+
if (pflags & PF_MEMALLOC_NOIO)
266260
flags &= ~(__GFP_IO | __GFP_FS);
267261
else if (pflags & PF_MEMALLOC_NOFS)
268262
flags &= ~__GFP_FS;
269263

270-
if (pflags & PF_MEMALLOC_NOWARN)
271-
flags |= __GFP_NOWARN;
272-
273264
if (pflags & PF_MEMALLOC_PIN)
274265
flags &= ~__GFP_MOVABLE;
275266
}

0 commit comments

Comments
 (0)