diff options
| author | Michal Hocko <mhocko@suse.com> | 2017-05-03 17:53:12 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2017-05-03 18:52:09 -0400 |
| commit | 9070733b4efac4bf17f299a81b01c15e206f9ff5 (patch) | |
| tree | 19e7b43ddbaee5b5bc5996fc26fd549d3c1f7775 | |
| parent | 7e7844226f1053236b6f6d5d122a06509fb14fd9 (diff) | |
xfs: abstract PF_FSTRANS to PF_MEMALLOC_NOFS
xfs has defined PF_FSTRANS to declare a scope GFP_NOFS semantic quite
some time ago. We would like to make this concept more generic and use
it for other filesystems as well. Let's start by giving the flag a more
generic name PF_MEMALLOC_NOFS which is in line with an exiting
PF_MEMALLOC_NOIO already used for the same purpose for GFP_NOIO
contexts. Replace all PF_FSTRANS usage from the xfs code in the first
step before we introduce a full API for it as xfs uses the flag directly
anyway.
This patch doesn't introduce any functional change.
Link: http://lkml.kernel.org/r/20170306131408.9828-4-mhocko@kernel.org
Signed-off-by: Michal Hocko <mhocko@suse.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
Cc: Dave Chinner <david@fromorbit.com>
Cc: Theodore Ts'o <tytso@mit.edu>
Cc: Chris Mason <clm@fb.com>
Cc: David Sterba <dsterba@suse.cz>
Cc: Jan Kara <jack@suse.cz>
Cc: Nikolay Borisov <nborisov@suse.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
| -rw-r--r-- | fs/xfs/kmem.c | 4 | ||||
| -rw-r--r-- | fs/xfs/kmem.h | 2 | ||||
| -rw-r--r-- | fs/xfs/libxfs/xfs_btree.c | 2 | ||||
| -rw-r--r-- | fs/xfs/xfs_aops.c | 6 | ||||
| -rw-r--r-- | fs/xfs/xfs_trans.c | 12 | ||||
| -rw-r--r-- | include/linux/sched.h | 2 |
6 files changed, 15 insertions, 13 deletions
diff --git a/fs/xfs/kmem.c b/fs/xfs/kmem.c index 70a5b55e0870..d0ac1a065539 100644 --- a/fs/xfs/kmem.c +++ b/fs/xfs/kmem.c | |||
| @@ -63,13 +63,13 @@ kmem_zalloc_large(size_t size, xfs_km_flags_t flags) | |||
| 63 | * context via PF_MEMALLOC_NOIO to prevent memory reclaim re-entering | 63 | * context via PF_MEMALLOC_NOIO to prevent memory reclaim re-entering |
| 64 | * the filesystem here and potentially deadlocking. | 64 | * the filesystem here and potentially deadlocking. |
| 65 | */ | 65 | */ |
| 66 | if ((current->flags & PF_FSTRANS) || (flags & KM_NOFS)) | 66 | if ((current->flags & PF_MEMALLOC_NOFS) || (flags & KM_NOFS)) |
| 67 | noio_flag = memalloc_noio_save(); | 67 | noio_flag = memalloc_noio_save(); |
| 68 | 68 | ||
| 69 | lflags = kmem_flags_convert(flags); | 69 | lflags = kmem_flags_convert(flags); |
| 70 | ptr = __vmalloc(size, lflags | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL); | 70 | ptr = __vmalloc(size, lflags | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL); |
| 71 | 71 | ||
| 72 | if ((current->flags & PF_FSTRANS) || (flags & KM_NOFS)) | 72 | if ((current->flags & PF_MEMALLOC_NOFS) || (flags & KM_NOFS)) |
| 73 | memalloc_noio_restore(noio_flag); | 73 | memalloc_noio_restore(noio_flag); |
| 74 | 74 | ||
| 75 | return ptr; | 75 | return ptr; |
diff --git a/fs/xfs/kmem.h b/fs/xfs/kmem.h index f0fc84fcaac2..a6c8da40c70d 100644 --- a/fs/xfs/kmem.h +++ b/fs/xfs/kmem.h | |||
| @@ -50,7 +50,7 @@ kmem_flags_convert(xfs_km_flags_t flags) | |||
| 50 | lflags = GFP_ATOMIC | __GFP_NOWARN; | 50 | lflags = GFP_ATOMIC | __GFP_NOWARN; |
| 51 | } else { | 51 | } else { |
| 52 | lflags = GFP_KERNEL | __GFP_NOWARN; | 52 | lflags = GFP_KERNEL | __GFP_NOWARN; |
| 53 | if ((current->flags & PF_FSTRANS) || (flags & KM_NOFS)) | 53 | if ((current->flags & PF_MEMALLOC_NOFS) || (flags & KM_NOFS)) |
| 54 | lflags &= ~__GFP_FS; | 54 | lflags &= ~__GFP_FS; |
| 55 | } | 55 | } |
| 56 | 56 | ||
diff --git a/fs/xfs/libxfs/xfs_btree.c b/fs/xfs/libxfs/xfs_btree.c index c3decedc9455..3059a3ec7ecb 100644 --- a/fs/xfs/libxfs/xfs_btree.c +++ b/fs/xfs/libxfs/xfs_btree.c | |||
| @@ -2886,7 +2886,7 @@ xfs_btree_split_worker( | |||
| 2886 | struct xfs_btree_split_args *args = container_of(work, | 2886 | struct xfs_btree_split_args *args = container_of(work, |
| 2887 | struct xfs_btree_split_args, work); | 2887 | struct xfs_btree_split_args, work); |
| 2888 | unsigned long pflags; | 2888 | unsigned long pflags; |
| 2889 | unsigned long new_pflags = PF_FSTRANS; | 2889 | unsigned long new_pflags = PF_MEMALLOC_NOFS; |
| 2890 | 2890 | ||
| 2891 | /* | 2891 | /* |
| 2892 | * we are in a transaction context here, but may also be doing work | 2892 | * we are in a transaction context here, but may also be doing work |
diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c index 61494295d92f..05eca126c688 100644 --- a/fs/xfs/xfs_aops.c +++ b/fs/xfs/xfs_aops.c | |||
| @@ -189,7 +189,7 @@ xfs_setfilesize_trans_alloc( | |||
| 189 | * We hand off the transaction to the completion thread now, so | 189 | * We hand off the transaction to the completion thread now, so |
| 190 | * clear the flag here. | 190 | * clear the flag here. |
| 191 | */ | 191 | */ |
| 192 | current_restore_flags_nested(&tp->t_pflags, PF_FSTRANS); | 192 | current_restore_flags_nested(&tp->t_pflags, PF_MEMALLOC_NOFS); |
| 193 | return 0; | 193 | return 0; |
| 194 | } | 194 | } |
| 195 | 195 | ||
| @@ -252,7 +252,7 @@ xfs_setfilesize_ioend( | |||
| 252 | * thus we need to mark ourselves as being in a transaction manually. | 252 | * thus we need to mark ourselves as being in a transaction manually. |
| 253 | * Similarly for freeze protection. | 253 | * Similarly for freeze protection. |
| 254 | */ | 254 | */ |
| 255 | current_set_flags_nested(&tp->t_pflags, PF_FSTRANS); | 255 | current_set_flags_nested(&tp->t_pflags, PF_MEMALLOC_NOFS); |
| 256 | __sb_writers_acquired(VFS_I(ip)->i_sb, SB_FREEZE_FS); | 256 | __sb_writers_acquired(VFS_I(ip)->i_sb, SB_FREEZE_FS); |
| 257 | 257 | ||
| 258 | /* we abort the update if there was an IO error */ | 258 | /* we abort the update if there was an IO error */ |
| @@ -1016,7 +1016,7 @@ xfs_do_writepage( | |||
| 1016 | * Given that we do not allow direct reclaim to call us, we should | 1016 | * Given that we do not allow direct reclaim to call us, we should |
| 1017 | * never be called while in a filesystem transaction. | 1017 | * never be called while in a filesystem transaction. |
| 1018 | */ | 1018 | */ |
| 1019 | if (WARN_ON_ONCE(current->flags & PF_FSTRANS)) | 1019 | if (WARN_ON_ONCE(current->flags & PF_MEMALLOC_NOFS)) |
| 1020 | goto redirty; | 1020 | goto redirty; |
| 1021 | 1021 | ||
| 1022 | /* | 1022 | /* |
diff --git a/fs/xfs/xfs_trans.c b/fs/xfs/xfs_trans.c index 70f42ea86dfb..f5969c8274fc 100644 --- a/fs/xfs/xfs_trans.c +++ b/fs/xfs/xfs_trans.c | |||
| @@ -134,7 +134,7 @@ xfs_trans_reserve( | |||
| 134 | bool rsvd = (tp->t_flags & XFS_TRANS_RESERVE) != 0; | 134 | bool rsvd = (tp->t_flags & XFS_TRANS_RESERVE) != 0; |
| 135 | 135 | ||
| 136 | /* Mark this thread as being in a transaction */ | 136 | /* Mark this thread as being in a transaction */ |
| 137 | current_set_flags_nested(&tp->t_pflags, PF_FSTRANS); | 137 | current_set_flags_nested(&tp->t_pflags, PF_MEMALLOC_NOFS); |
| 138 | 138 | ||
| 139 | /* | 139 | /* |
| 140 | * Attempt to reserve the needed disk blocks by decrementing | 140 | * Attempt to reserve the needed disk blocks by decrementing |
| @@ -144,7 +144,7 @@ xfs_trans_reserve( | |||
| 144 | if (blocks > 0) { | 144 | if (blocks > 0) { |
| 145 | error = xfs_mod_fdblocks(tp->t_mountp, -((int64_t)blocks), rsvd); | 145 | error = xfs_mod_fdblocks(tp->t_mountp, -((int64_t)blocks), rsvd); |
| 146 | if (error != 0) { | 146 | if (error != 0) { |
| 147 | current_restore_flags_nested(&tp->t_pflags, PF_FSTRANS); | 147 | current_restore_flags_nested(&tp->t_pflags, PF_MEMALLOC_NOFS); |
| 148 | return -ENOSPC; | 148 | return -ENOSPC; |
| 149 | } | 149 | } |
| 150 | tp->t_blk_res += blocks; | 150 | tp->t_blk_res += blocks; |
| @@ -221,7 +221,7 @@ undo_blocks: | |||
| 221 | tp->t_blk_res = 0; | 221 | tp->t_blk_res = 0; |
| 222 | } | 222 | } |
| 223 | 223 | ||
| 224 | current_restore_flags_nested(&tp->t_pflags, PF_FSTRANS); | 224 | current_restore_flags_nested(&tp->t_pflags, PF_MEMALLOC_NOFS); |
| 225 | 225 | ||
| 226 | return error; | 226 | return error; |
| 227 | } | 227 | } |
| @@ -914,7 +914,7 @@ __xfs_trans_commit( | |||
| 914 | 914 | ||
| 915 | xfs_log_commit_cil(mp, tp, &commit_lsn, regrant); | 915 | xfs_log_commit_cil(mp, tp, &commit_lsn, regrant); |
| 916 | 916 | ||
| 917 | current_restore_flags_nested(&tp->t_pflags, PF_FSTRANS); | 917 | current_restore_flags_nested(&tp->t_pflags, PF_MEMALLOC_NOFS); |
| 918 | xfs_trans_free(tp); | 918 | xfs_trans_free(tp); |
| 919 | 919 | ||
| 920 | /* | 920 | /* |
| @@ -944,7 +944,7 @@ out_unreserve: | |||
| 944 | if (commit_lsn == -1 && !error) | 944 | if (commit_lsn == -1 && !error) |
| 945 | error = -EIO; | 945 | error = -EIO; |
| 946 | } | 946 | } |
| 947 | current_restore_flags_nested(&tp->t_pflags, PF_FSTRANS); | 947 | current_restore_flags_nested(&tp->t_pflags, PF_MEMALLOC_NOFS); |
| 948 | xfs_trans_free_items(tp, NULLCOMMITLSN, !!error); | 948 | xfs_trans_free_items(tp, NULLCOMMITLSN, !!error); |
| 949 | xfs_trans_free(tp); | 949 | xfs_trans_free(tp); |
| 950 | 950 | ||
| @@ -998,7 +998,7 @@ xfs_trans_cancel( | |||
| 998 | xfs_log_done(mp, tp->t_ticket, NULL, false); | 998 | xfs_log_done(mp, tp->t_ticket, NULL, false); |
| 999 | 999 | ||
| 1000 | /* mark this thread as no longer being in a transaction */ | 1000 | /* mark this thread as no longer being in a transaction */ |
| 1001 | current_restore_flags_nested(&tp->t_pflags, PF_FSTRANS); | 1001 | current_restore_flags_nested(&tp->t_pflags, PF_MEMALLOC_NOFS); |
| 1002 | 1002 | ||
| 1003 | xfs_trans_free_items(tp, NULLCOMMITLSN, dirty); | 1003 | xfs_trans_free_items(tp, NULLCOMMITLSN, dirty); |
| 1004 | xfs_trans_free(tp); | 1004 | xfs_trans_free(tp); |
diff --git a/include/linux/sched.h b/include/linux/sched.h index 3d4fa448223f..8ac11465ac5b 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h | |||
| @@ -1237,6 +1237,8 @@ extern struct pid *cad_pid; | |||
| 1237 | #define PF_FREEZER_SKIP 0x40000000 /* Freezer should not count it as freezable */ | 1237 | #define PF_FREEZER_SKIP 0x40000000 /* Freezer should not count it as freezable */ |
| 1238 | #define PF_SUSPEND_TASK 0x80000000 /* This thread called freeze_processes() and should not be frozen */ | 1238 | #define PF_SUSPEND_TASK 0x80000000 /* This thread called freeze_processes() and should not be frozen */ |
| 1239 | 1239 | ||
| 1240 | #define PF_MEMALLOC_NOFS PF_FSTRANS /* Transition to a more generic GFP_NOFS scope semantic */ | ||
| 1241 | |||
| 1240 | /* | 1242 | /* |
| 1241 | * Only the _current_ task can read/write to tsk->flags, but other | 1243 | * Only the _current_ task can read/write to tsk->flags, but other |
| 1242 | * tasks can access tsk->flags in readonly mode for example | 1244 | * tasks can access tsk->flags in readonly mode for example |
