Skip to content

Commit 9ba1fb2

Browse files
Michal Hockotorvalds
authored andcommitted
xfs: use memalloc_nofs_{save,restore} instead of memalloc_noio*
kmem_zalloc_large and _xfs_buf_map_pages use memalloc_noio_{save,restore} API to prevent from reclaim recursion into the fs because vmalloc can invoke unconditional GFP_KERNEL allocations and these functions might be called from the NOFS contexts. The memalloc_noio_save will enforce GFP_NOIO context which is even weaker than GFP_NOFS and that seems to be unnecessary. Let's use memalloc_nofs_{save,restore} instead as it should provide exactly what we need here - implicit GFP_NOFS context. Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Michal Hocko <[email protected]> Reviewed-by: Brian Foster <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Acked-by: Vlastimil Babka <[email protected]> Cc: Dave Chinner <[email protected]> Cc: Theodore Ts'o <[email protected]> Cc: Chris Mason <[email protected]> Cc: David Sterba <[email protected]> Cc: Jan Kara <[email protected]> Cc: Nikolay Borisov <[email protected]> Cc: Peter Zijlstra <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 7dea19f commit 9ba1fb2

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

fs/xfs/kmem.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ kmem_alloc(size_t size, xfs_km_flags_t flags)
4848
void *
4949
kmem_zalloc_large(size_t size, xfs_km_flags_t flags)
5050
{
51-
unsigned noio_flag = 0;
51+
unsigned nofs_flag = 0;
5252
void *ptr;
5353
gfp_t lflags;
5454

@@ -60,17 +60,17 @@ kmem_zalloc_large(size_t size, xfs_km_flags_t flags)
6060
* __vmalloc() will allocate data pages and auxillary structures (e.g.
6161
* pagetables) with GFP_KERNEL, yet we may be under GFP_NOFS context
6262
* here. Hence we need to tell memory reclaim that we are in such a
63-
* context via PF_MEMALLOC_NOIO to prevent memory reclaim re-entering
63+
* context via PF_MEMALLOC_NOFS to prevent memory reclaim re-entering
6464
* the filesystem here and potentially deadlocking.
6565
*/
66-
if ((current->flags & PF_MEMALLOC_NOFS) || (flags & KM_NOFS))
67-
noio_flag = memalloc_noio_save();
66+
if (flags & KM_NOFS)
67+
nofs_flag = memalloc_nofs_save();
6868

6969
lflags = kmem_flags_convert(flags);
7070
ptr = __vmalloc(size, lflags | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL);
7171

72-
if ((current->flags & PF_MEMALLOC_NOFS) || (flags & KM_NOFS))
73-
memalloc_noio_restore(noio_flag);
72+
if (flags & KM_NOFS)
73+
memalloc_nofs_restore(nofs_flag);
7474

7575
return ptr;
7676
}

fs/xfs/xfs_buf.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -443,25 +443,25 @@ _xfs_buf_map_pages(
443443
bp->b_addr = NULL;
444444
} else {
445445
int retried = 0;
446-
unsigned noio_flag;
446+
unsigned nofs_flag;
447447

448448
/*
449449
* vm_map_ram() will allocate auxillary structures (e.g.
450450
* pagetables) with GFP_KERNEL, yet we are likely to be under
451451
* GFP_NOFS context here. Hence we need to tell memory reclaim
452-
* that we are in such a context via PF_MEMALLOC_NOIO to prevent
452+
* that we are in such a context via PF_MEMALLOC_NOFS to prevent
453453
* memory reclaim re-entering the filesystem here and
454454
* potentially deadlocking.
455455
*/
456-
noio_flag = memalloc_noio_save();
456+
nofs_flag = memalloc_nofs_save();
457457
do {
458458
bp->b_addr = vm_map_ram(bp->b_pages, bp->b_page_count,
459459
-1, PAGE_KERNEL);
460460
if (bp->b_addr)
461461
break;
462462
vm_unmap_aliases();
463463
} while (retried++ <= 1);
464-
memalloc_noio_restore(noio_flag);
464+
memalloc_nofs_restore(nofs_flag);
465465

466466
if (!bp->b_addr)
467467
return -ENOMEM;

0 commit comments

Comments
 (0)