Skip to content

Commit f248679

Browse files
Josef Bacikchrismason-xx
authored andcommitted
Btrfs: add a delalloc mutex to inodes for delalloc reservations
I was using i_mutex for this, but we're getting bogus lockdep warnings by doing that and theres no real way to get rid of those, so just stop using i_mutex to protect delalloc metadata reservations and use a delalloc mutex instead. This shouldn't be contended often at all, only if you are writing and mmap writing to the file at the same time. Thanks, Signed-off-by: Josef Bacik <josef@redhat.com>
1 parent 8c2a3ca commit f248679

5 files changed

Lines changed: 7 additions & 16 deletions

File tree

‎fs/btrfs/btrfs_inode.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ struct btrfs_inode {
5151
/* held while logging the inode in tree-log.c */
5252
struct mutex log_mutex;
5353

54+
/* held while doing delalloc reservations */
55+
struct mutex delalloc_mutex;
56+
5457
/* used to order data wrt metadata */
5558
struct btrfs_ordered_inode_tree ordered_tree;
5659

‎fs/btrfs/extent-tree.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4345,12 +4345,11 @@ int btrfs_delalloc_reserve_metadata(struct inode *inode, u64 num_bytes)
43454345
/* Need to be holding the i_mutex here if we aren't free space cache */
43464346
if (btrfs_is_free_space_inode(root, inode))
43474347
flush = 0;
4348-
else
4349-
WARN_ON(!mutex_is_locked(&inode->i_mutex));
43504348

43514349
if (flush && btrfs_transaction_in_commit(root->fs_info))
43524350
schedule_timeout(1);
43534351

4352+
mutex_lock(&BTRFS_I(inode)->delalloc_mutex);
43544353
num_bytes = ALIGN(num_bytes, root->sectorsize);
43554354

43564355
spin_lock(&BTRFS_I(inode)->lock);
@@ -4405,6 +4404,7 @@ int btrfs_delalloc_reserve_metadata(struct inode *inode, u64 num_bytes)
44054404
btrfs_ino(inode),
44064405
to_free, 0);
44074406
}
4407+
mutex_unlock(&BTRFS_I(inode)->delalloc_mutex);
44084408
return ret;
44094409
}
44104410

@@ -4415,6 +4415,7 @@ int btrfs_delalloc_reserve_metadata(struct inode *inode, u64 num_bytes)
44154415
}
44164416
BTRFS_I(inode)->reserved_extents += nr_extents;
44174417
spin_unlock(&BTRFS_I(inode)->lock);
4418+
mutex_unlock(&BTRFS_I(inode)->delalloc_mutex);
44184419

44194420
if (to_reserve)
44204421
trace_btrfs_space_reservation(root->fs_info,"delalloc",

‎fs/btrfs/inode.c‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2239,14 +2239,7 @@ int btrfs_orphan_cleanup(struct btrfs_root *root)
22392239
continue;
22402240
}
22412241
nr_truncate++;
2242-
/*
2243-
* Need to hold the imutex for reservation purposes, not
2244-
* a huge deal here but I have a WARN_ON in
2245-
* btrfs_delalloc_reserve_space to catch offenders.
2246-
*/
2247-
mutex_lock(&inode->i_mutex);
22482242
ret = btrfs_truncate(inode);
2249-
mutex_unlock(&inode->i_mutex);
22502243
} else {
22512244
nr_unlink++;
22522245
}
@@ -6411,10 +6404,7 @@ int btrfs_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
64116404
u64 page_start;
64126405
u64 page_end;
64136406

6414-
/* Need this to keep space reservations serialized */
6415-
mutex_lock(&inode->i_mutex);
64166407
ret = btrfs_delalloc_reserve_space(inode, PAGE_CACHE_SIZE);
6417-
mutex_unlock(&inode->i_mutex);
64186408
if (!ret)
64196409
ret = btrfs_update_time(vma->vm_file);
64206410
if (ret) {
@@ -6758,6 +6748,7 @@ struct inode *btrfs_alloc_inode(struct super_block *sb)
67586748
extent_io_tree_init(&ei->io_tree, &inode->i_data);
67596749
extent_io_tree_init(&ei->io_failure_tree, &inode->i_data);
67606750
mutex_init(&ei->log_mutex);
6751+
mutex_init(&ei->delalloc_mutex);
67616752
btrfs_ordered_inode_tree_init(&ei->ordered_tree);
67626753
INIT_LIST_HEAD(&ei->i_orphan);
67636754
INIT_LIST_HEAD(&ei->delalloc_inodes);

‎fs/btrfs/ioctl.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -868,10 +868,8 @@ static int cluster_pages_for_defrag(struct inode *inode,
868868
return 0;
869869
file_end = (isize - 1) >> PAGE_CACHE_SHIFT;
870870

871-
mutex_lock(&inode->i_mutex);
872871
ret = btrfs_delalloc_reserve_space(inode,
873872
num_pages << PAGE_CACHE_SHIFT);
874-
mutex_unlock(&inode->i_mutex);
875873
if (ret)
876874
return ret;
877875
again:

‎fs/btrfs/relocation.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2949,9 +2949,7 @@ static int relocate_file_extent_cluster(struct inode *inode,
29492949
index = (cluster->start - offset) >> PAGE_CACHE_SHIFT;
29502950
last_index = (cluster->end - offset) >> PAGE_CACHE_SHIFT;
29512951
while (index <= last_index) {
2952-
mutex_lock(&inode->i_mutex);
29532952
ret = btrfs_delalloc_reserve_metadata(inode, PAGE_CACHE_SIZE);
2954-
mutex_unlock(&inode->i_mutex);
29552953
if (ret)
29562954
goto out;
29572955

0 commit comments

Comments
 (0)