Skip to content

Commit f4a9c16

Browse files
committed
Merge branch 'for-linus-4.8' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs
Pull btrfs fixes from Chris Mason: "I'm not proud of how long it took me to track down that one liner in btrfs_sync_log(), but the good news is the patches I was trying to blame for these problems were actually fine (sorry Filipe)" * 'for-linus-4.8' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs: btrfs: introduce tickets_id to determine whether asynchronous metadata reclaim work makes progress btrfs: remove root_log_ctx from ctx list before btrfs_sync_log returns btrfs: do not decrease bytes_may_use when replaying extents
2 parents 067c2f4 + b7f3c7d commit f4a9c16

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

fs/btrfs/ctree.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,7 @@ struct btrfs_space_info {
427427
struct list_head ro_bgs;
428428
struct list_head priority_tickets;
429429
struct list_head tickets;
430+
u64 tickets_id;
430431

431432
struct rw_semaphore groups_sem;
432433
/* for block groups in our same type */

fs/btrfs/extent-tree.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4966,12 +4966,12 @@ static void wake_all_tickets(struct list_head *head)
49664966
*/
49674967
static void btrfs_async_reclaim_metadata_space(struct work_struct *work)
49684968
{
4969-
struct reserve_ticket *last_ticket = NULL;
49704969
struct btrfs_fs_info *fs_info;
49714970
struct btrfs_space_info *space_info;
49724971
u64 to_reclaim;
49734972
int flush_state;
49744973
int commit_cycles = 0;
4974+
u64 last_tickets_id;
49754975

49764976
fs_info = container_of(work, struct btrfs_fs_info, async_reclaim_work);
49774977
space_info = __find_space_info(fs_info, BTRFS_BLOCK_GROUP_METADATA);
@@ -4984,8 +4984,7 @@ static void btrfs_async_reclaim_metadata_space(struct work_struct *work)
49844984
spin_unlock(&space_info->lock);
49854985
return;
49864986
}
4987-
last_ticket = list_first_entry(&space_info->tickets,
4988-
struct reserve_ticket, list);
4987+
last_tickets_id = space_info->tickets_id;
49894988
spin_unlock(&space_info->lock);
49904989

49914990
flush_state = FLUSH_DELAYED_ITEMS_NR;
@@ -5005,10 +5004,10 @@ static void btrfs_async_reclaim_metadata_space(struct work_struct *work)
50055004
space_info);
50065005
ticket = list_first_entry(&space_info->tickets,
50075006
struct reserve_ticket, list);
5008-
if (last_ticket == ticket) {
5007+
if (last_tickets_id == space_info->tickets_id) {
50095008
flush_state++;
50105009
} else {
5011-
last_ticket = ticket;
5010+
last_tickets_id = space_info->tickets_id;
50125011
flush_state = FLUSH_DELAYED_ITEMS_NR;
50135012
if (commit_cycles)
50145013
commit_cycles--;
@@ -5384,6 +5383,7 @@ static void space_info_add_old_bytes(struct btrfs_fs_info *fs_info,
53845383
list_del_init(&ticket->list);
53855384
num_bytes -= ticket->bytes;
53865385
ticket->bytes = 0;
5386+
space_info->tickets_id++;
53875387
wake_up(&ticket->wait);
53885388
} else {
53895389
ticket->bytes -= num_bytes;
@@ -5426,6 +5426,7 @@ static void space_info_add_new_bytes(struct btrfs_fs_info *fs_info,
54265426
num_bytes -= ticket->bytes;
54275427
space_info->bytes_may_use += ticket->bytes;
54285428
ticket->bytes = 0;
5429+
space_info->tickets_id++;
54295430
wake_up(&ticket->wait);
54305431
} else {
54315432
trace_btrfs_space_reservation(fs_info, "space_info",
@@ -8216,6 +8217,7 @@ int btrfs_alloc_logged_file_extent(struct btrfs_trans_handle *trans,
82168217
{
82178218
int ret;
82188219
struct btrfs_block_group_cache *block_group;
8220+
struct btrfs_space_info *space_info;
82198221

82208222
/*
82218223
* Mixed block groups will exclude before processing the log so we only
@@ -8231,9 +8233,14 @@ int btrfs_alloc_logged_file_extent(struct btrfs_trans_handle *trans,
82318233
if (!block_group)
82328234
return -EINVAL;
82338235

8234-
ret = btrfs_add_reserved_bytes(block_group, ins->offset,
8235-
ins->offset, 0);
8236-
BUG_ON(ret); /* logic error */
8236+
space_info = block_group->space_info;
8237+
spin_lock(&space_info->lock);
8238+
spin_lock(&block_group->lock);
8239+
space_info->bytes_reserved += ins->offset;
8240+
block_group->reserved += ins->offset;
8241+
spin_unlock(&block_group->lock);
8242+
spin_unlock(&space_info->lock);
8243+
82378244
ret = alloc_reserved_file_extent(trans, root, 0, root_objectid,
82388245
0, owner, offset, ins, 1);
82398246
btrfs_put_block_group(block_group);

fs/btrfs/tree-log.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2867,6 +2867,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
28672867

28682868
if (log_root_tree->log_transid_committed >= root_log_ctx.log_transid) {
28692869
blk_finish_plug(&plug);
2870+
list_del_init(&root_log_ctx.list);
28702871
mutex_unlock(&log_root_tree->log_mutex);
28712872
ret = root_log_ctx.log_ret;
28722873
goto out;

0 commit comments

Comments
 (0)