]> www.infradead.org Git - users/dwmw2/linux.git/commit
btrfs: preallocate inodes xarray entry to avoid transaction abort
authorFilipe Manana <fdmanana@suse.com>
Mon, 29 Apr 2024 12:08:12 +0000 (13:08 +0100)
committerDavid Sterba <dsterba@suse.com>
Thu, 11 Jul 2024 13:33:17 +0000 (15:33 +0200)
commit061ea8581b2e0ade913c8f5cd845e801976a577b
tree247ad71b877a75816791cc02cb1be61cf23a974b
parent310b2f5d5a9451b708ab1d3385c3b0998084904c
btrfs: preallocate inodes xarray entry to avoid transaction abort

When creating a new inode, at btrfs_create_new_inode(), one of the very
last steps is to add the inode to the root's inodes xarray. This often
requires allocating memory which may fail (even though xarrays have a
dedicated kmem_cache which make it less likely to fail), and at that point
we are forced to abort the current transaction (as some, but not all, of
the inode metadata was added to its subvolume btree).

To avoid a transaction abort, preallocate memory for the xarray early at
btrfs_create_new_inode(), so that if we fail we don't need to abort the
transaction and the insertion into the xarray is guaranteed to succeed.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/inode.c