Skip to content

Commit 16ad3be

Browse files
fdmananakdave
authored andcommitted
Btrfs: remove unnecessary delalloc mutex for inodes
The inode delalloc mutex was added a long time ago by commit f248679 ("Btrfs: add a delalloc mutex to inodes for delalloc reservations"), and the reason for its introduction is not very clear from the change log. It claims it solves bogus warnings from lockdep, however it lacks an example report/warning from lockdep, or any explanation. Since we have enough concurrentcy protection from the locks of the space info and block reserve objects, and such lockdep warnings don't seem to exist anymore (at least on a 5.3 kernel I couldn't get them with fstests, ltp, fs_mark, etc), remove it, simplifying things a bit and decreasing the size of the btrfs_inode structure. With some quick fio tests doing direct IO and mmap writes I couldn't observe any significant performance increase either (direct IO writes that don't increase the file's size don't hold the inode's lock for their entire duration and mmap writes don't hold the inode's lock at all), which are the only type of writes that could see any performance gain due to less serialization. Review feedback from Josef: The problem was taking the i_mutex in mmap, which is how I was protecting delalloc reservations originally. The delalloc mutex didn't come with all of the other dependencies. That's what the lockdep messages were about, removing the lock isn't going to make them appear again. We _had_ to lock around this because we used to do tricks to keep from over-reserving, and if we didn't serialize delalloc reservations we'd end up with ugly accounting problems when we tried to clean things up. However with my recentish changes this isn't the case anymore. Every operation is responsible for reserving its space, and then adding it to the inode. Then cleaning up is straightforward and can't be mucked up by other users. So we no longer need the delalloc mutex to safe us from ourselves. Reviewed-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Filipe Manana <fdmanana@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent bf2df5a commit 16ad3be

3 files changed

Lines changed: 5 additions & 20 deletions

File tree

‎fs/btrfs/btrfs_inode.h‎

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

66-
/* held while doing delalloc reservations */
67-
struct mutex delalloc_mutex;
68-
6966
/* used to order data wrt metadata */
7067
struct btrfs_ordered_inode_tree ordered_tree;
7168

‎fs/btrfs/delalloc-space.c‎

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,6 @@ int btrfs_delalloc_reserve_metadata(struct btrfs_inode *inode, u64 num_bytes)
307307
unsigned nr_extents;
308308
enum btrfs_reserve_flush_enum flush = BTRFS_RESERVE_FLUSH_ALL;
309309
int ret = 0;
310-
bool delalloc_lock = true;
311310

312311
/*
313312
* If we are a free space inode we need to not flush since we will be in
@@ -320,7 +319,6 @@ int btrfs_delalloc_reserve_metadata(struct btrfs_inode *inode, u64 num_bytes)
320319
*/
321320
if (btrfs_is_free_space_inode(inode)) {
322321
flush = BTRFS_RESERVE_NO_FLUSH;
323-
delalloc_lock = false;
324322
} else {
325323
if (current->journal_info)
326324
flush = BTRFS_RESERVE_FLUSH_LIMIT;
@@ -329,9 +327,6 @@ int btrfs_delalloc_reserve_metadata(struct btrfs_inode *inode, u64 num_bytes)
329327
schedule_timeout(1);
330328
}
331329

332-
if (delalloc_lock)
333-
mutex_lock(&inode->delalloc_mutex);
334-
335330
num_bytes = ALIGN(num_bytes, fs_info->sectorsize);
336331

337332
/*
@@ -348,10 +343,12 @@ int btrfs_delalloc_reserve_metadata(struct btrfs_inode *inode, u64 num_bytes)
348343
&qgroup_reserve);
349344
ret = btrfs_qgroup_reserve_meta_prealloc(root, qgroup_reserve, true);
350345
if (ret)
351-
goto out_fail;
346+
return ret;
352347
ret = btrfs_reserve_metadata_bytes(root, block_rsv, meta_reserve, flush);
353-
if (ret)
354-
goto out_qgroup;
348+
if (ret) {
349+
btrfs_qgroup_free_meta_prealloc(root, qgroup_reserve);
350+
return ret;
351+
}
355352

356353
/*
357354
* Now we need to update our outstanding extents and csum bytes _first_
@@ -375,15 +372,7 @@ int btrfs_delalloc_reserve_metadata(struct btrfs_inode *inode, u64 num_bytes)
375372
block_rsv->qgroup_rsv_reserved += qgroup_reserve;
376373
spin_unlock(&block_rsv->lock);
377374

378-
if (delalloc_lock)
379-
mutex_unlock(&inode->delalloc_mutex);
380375
return 0;
381-
out_qgroup:
382-
btrfs_qgroup_free_meta_prealloc(root, qgroup_reserve);
383-
out_fail:
384-
if (delalloc_lock)
385-
mutex_unlock(&inode->delalloc_mutex);
386-
return ret;
387376
}
388377

389378
/**

‎fs/btrfs/inode.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9356,7 +9356,6 @@ struct inode *btrfs_alloc_inode(struct super_block *sb)
93569356
ei->io_failure_tree.track_uptodate = true;
93579357
atomic_set(&ei->sync_writers, 0);
93589358
mutex_init(&ei->log_mutex);
9359-
mutex_init(&ei->delalloc_mutex);
93609359
btrfs_ordered_inode_tree_init(&ei->ordered_tree);
93619360
INIT_LIST_HEAD(&ei->delalloc_inodes);
93629361
INIT_LIST_HEAD(&ei->delayed_iput);

0 commit comments

Comments
 (0)