Skip to content

Commit 1be969f

Browse files
committed
Merge tag 'for-5.0-rc2-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux
Pull btrfs fixes from David Sterba: "A handful of fixes (some of them in testing for a long time): - fix some test failures regarding cleanup after transaction abort - revert of a patch that could cause a deadlock - delayed iput fixes, that can help in ENOSPC situation when there's low space and a lot data to write" * tag 'for-5.0-rc2-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux: btrfs: wakeup cleaner thread when adding delayed iput btrfs: run delayed iputs before committing btrfs: wait on ordered extents on abort cleanup btrfs: handle delayed ref head accounting cleanup in abort Revert "btrfs: balance dirty metadata pages in btrfs_finish_ordered_io"
2 parents 315a6d8 + fd340d0 commit 1be969f

File tree

4 files changed

+35
-10
lines changed

4 files changed

+35
-10
lines changed

fs/btrfs/ctree.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
struct btrfs_trans_handle;
3636
struct btrfs_transaction;
3737
struct btrfs_pending_snapshot;
38+
struct btrfs_delayed_ref_root;
3839
extern struct kmem_cache *btrfs_trans_handle_cachep;
3940
extern struct kmem_cache *btrfs_bit_radix_cachep;
4041
extern struct kmem_cache *btrfs_path_cachep;
@@ -786,6 +787,9 @@ enum {
786787
* main phase. The fs_info::balance_ctl is initialized.
787788
*/
788789
BTRFS_FS_BALANCE_RUNNING,
790+
791+
/* Indicate that the cleaner thread is awake and doing something. */
792+
BTRFS_FS_CLEANER_RUNNING,
789793
};
790794

791795
struct btrfs_fs_info {
@@ -2661,6 +2665,9 @@ int btrfs_run_delayed_refs(struct btrfs_trans_handle *trans,
26612665
unsigned long count);
26622666
int btrfs_async_run_delayed_refs(struct btrfs_fs_info *fs_info,
26632667
unsigned long count, u64 transid, int wait);
2668+
void btrfs_cleanup_ref_head_accounting(struct btrfs_fs_info *fs_info,
2669+
struct btrfs_delayed_ref_root *delayed_refs,
2670+
struct btrfs_delayed_ref_head *head);
26642671
int btrfs_lookup_data_extent(struct btrfs_fs_info *fs_info, u64 start, u64 len);
26652672
int btrfs_lookup_extent_info(struct btrfs_trans_handle *trans,
26662673
struct btrfs_fs_info *fs_info, u64 bytenr,

fs/btrfs/disk-io.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,6 +1682,8 @@ static int cleaner_kthread(void *arg)
16821682
while (1) {
16831683
again = 0;
16841684

1685+
set_bit(BTRFS_FS_CLEANER_RUNNING, &fs_info->flags);
1686+
16851687
/* Make the cleaner go to sleep early. */
16861688
if (btrfs_need_cleaner_sleep(fs_info))
16871689
goto sleep;
@@ -1728,6 +1730,7 @@ static int cleaner_kthread(void *arg)
17281730
*/
17291731
btrfs_delete_unused_bgs(fs_info);
17301732
sleep:
1733+
clear_bit(BTRFS_FS_CLEANER_RUNNING, &fs_info->flags);
17311734
if (kthread_should_park())
17321735
kthread_parkme();
17331736
if (kthread_should_stop())
@@ -4201,6 +4204,14 @@ static void btrfs_destroy_all_ordered_extents(struct btrfs_fs_info *fs_info)
42014204
spin_lock(&fs_info->ordered_root_lock);
42024205
}
42034206
spin_unlock(&fs_info->ordered_root_lock);
4207+
4208+
/*
4209+
* We need this here because if we've been flipped read-only we won't
4210+
* get sync() from the umount, so we need to make sure any ordered
4211+
* extents that haven't had their dirty pages IO start writeout yet
4212+
* actually get run and error out properly.
4213+
*/
4214+
btrfs_wait_ordered_roots(fs_info, U64_MAX, 0, (u64)-1);
42044215
}
42054216

42064217
static int btrfs_destroy_delayed_refs(struct btrfs_transaction *trans,
@@ -4265,6 +4276,7 @@ static int btrfs_destroy_delayed_refs(struct btrfs_transaction *trans,
42654276
if (pin_bytes)
42664277
btrfs_pin_extent(fs_info, head->bytenr,
42674278
head->num_bytes, 1);
4279+
btrfs_cleanup_ref_head_accounting(fs_info, delayed_refs, head);
42684280
btrfs_put_delayed_ref_head(head);
42694281
cond_resched();
42704282
spin_lock(&delayed_refs->lock);

fs/btrfs/extent-tree.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2456,12 +2456,10 @@ static int run_and_cleanup_extent_op(struct btrfs_trans_handle *trans,
24562456
return ret ? ret : 1;
24572457
}
24582458

2459-
static void cleanup_ref_head_accounting(struct btrfs_trans_handle *trans,
2460-
struct btrfs_delayed_ref_head *head)
2459+
void btrfs_cleanup_ref_head_accounting(struct btrfs_fs_info *fs_info,
2460+
struct btrfs_delayed_ref_root *delayed_refs,
2461+
struct btrfs_delayed_ref_head *head)
24612462
{
2462-
struct btrfs_fs_info *fs_info = trans->fs_info;
2463-
struct btrfs_delayed_ref_root *delayed_refs =
2464-
&trans->transaction->delayed_refs;
24652463
int nr_items = 1; /* Dropping this ref head update. */
24662464

24672465
if (head->total_ref_mod < 0) {
@@ -2544,7 +2542,7 @@ static int cleanup_ref_head(struct btrfs_trans_handle *trans,
25442542
}
25452543
}
25462544

2547-
cleanup_ref_head_accounting(trans, head);
2545+
btrfs_cleanup_ref_head_accounting(fs_info, delayed_refs, head);
25482546

25492547
trace_run_delayed_ref_head(fs_info, head, 0);
25502548
btrfs_delayed_ref_unlock(head);
@@ -4954,6 +4952,15 @@ static void flush_space(struct btrfs_fs_info *fs_info,
49544952
ret = 0;
49554953
break;
49564954
case COMMIT_TRANS:
4955+
/*
4956+
* If we have pending delayed iputs then we could free up a
4957+
* bunch of pinned space, so make sure we run the iputs before
4958+
* we do our pinned bytes check below.
4959+
*/
4960+
mutex_lock(&fs_info->cleaner_delayed_iput_mutex);
4961+
btrfs_run_delayed_iputs(fs_info);
4962+
mutex_unlock(&fs_info->cleaner_delayed_iput_mutex);
4963+
49574964
ret = may_commit_transaction(fs_info, space_info);
49584965
break;
49594966
default:
@@ -7188,7 +7195,7 @@ static noinline int check_ref_cleanup(struct btrfs_trans_handle *trans,
71887195
if (head->must_insert_reserved)
71897196
ret = 1;
71907197

7191-
cleanup_ref_head_accounting(trans, head);
7198+
btrfs_cleanup_ref_head_accounting(trans->fs_info, delayed_refs, head);
71927199
mutex_unlock(&head->mutex);
71937200
btrfs_put_delayed_ref_head(head);
71947201
return ret;

fs/btrfs/inode.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3129,9 +3129,6 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent)
31293129
/* once for the tree */
31303130
btrfs_put_ordered_extent(ordered_extent);
31313131

3132-
/* Try to release some metadata so we don't get an OOM but don't wait */
3133-
btrfs_btree_balance_dirty_nodelay(fs_info);
3134-
31353132
return ret;
31363133
}
31373134

@@ -3254,6 +3251,8 @@ void btrfs_add_delayed_iput(struct inode *inode)
32543251
ASSERT(list_empty(&binode->delayed_iput));
32553252
list_add_tail(&binode->delayed_iput, &fs_info->delayed_iputs);
32563253
spin_unlock(&fs_info->delayed_iput_lock);
3254+
if (!test_bit(BTRFS_FS_CLEANER_RUNNING, &fs_info->flags))
3255+
wake_up_process(fs_info->cleaner_kthread);
32573256
}
32583257

32593258
void btrfs_run_delayed_iputs(struct btrfs_fs_info *fs_info)

0 commit comments

Comments
 (0)