Commit 6e8e777d authored by Filipe Manana's avatar Filipe Manana Committed by David Sterba

btrfs: eliminate some false positives when checking if inode was logged

When checking if an inode was previously logged in the current transaction
through the helper inode_logged(), we can return some false positives that
can be easily eliminated. These correspond to the cases where an inode has
a ->logged_trans value that is not zero and its value is smaller then the
ID of the current transaction. This means we know exactly that the inode
was never logged before in the current transaction, so we can return false
and avoid the callers to do extra work:

1) Having btrfs_del_dir_entries_in_log() and btrfs_del_inode_ref_in_log()
   unnecessarily join a log transaction and do deletion searches in a log
   tree that will not find anything. This just adds unnecessary contention
   on extent buffer locks;

2) Having btrfs_log_new_name() unnecessarily log an inode when it is not
   needed. If the inode was not logged before, we don't need to log it in
   LOG_INODE_EXISTS mode.

So just make sure that any false positive only happens when ->logged_trans
has a value of 0.
Signed-off-by: default avatarFilipe Manana <fdmanana@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 42b5d73b
...@@ -3421,14 +3421,10 @@ int btrfs_free_log_root_tree(struct btrfs_trans_handle *trans, ...@@ -3421,14 +3421,10 @@ int btrfs_free_log_root_tree(struct btrfs_trans_handle *trans,
} }
/* /*
* Check if an inode was logged in the current transaction. We can't always rely * Check if an inode was logged in the current transaction. This may often
* on an inode's logged_trans value, because it's an in-memory only field and * return some false positives, because logged_trans is an in memory only field,
* therefore not persisted. This means that its value is lost if the inode gets * not persisted anywhere. This is meant to be used in contexts where a false
* evicted and loaded again from disk (in which case it has a value of 0, and * positive has no functional consequences.
* certainly it is smaller then any possible transaction ID), when that happens
* the full_sync flag is set in the inode's runtime flags, so on that case we
* assume eviction happened and ignore the logged_trans value, assuming the
* worst case, that the inode was logged before in the current transaction.
*/ */
static bool inode_logged(struct btrfs_trans_handle *trans, static bool inode_logged(struct btrfs_trans_handle *trans,
struct btrfs_inode *inode) struct btrfs_inode *inode)
...@@ -3436,7 +3432,18 @@ static bool inode_logged(struct btrfs_trans_handle *trans, ...@@ -3436,7 +3432,18 @@ static bool inode_logged(struct btrfs_trans_handle *trans,
if (inode->logged_trans == trans->transid) if (inode->logged_trans == trans->transid)
return true; return true;
if (inode->last_trans == trans->transid && /*
* The inode's logged_trans is always 0 when we load it (because it is
* not persisted in the inode item or elsewhere). So if it is 0, the
* inode was last modified in the current transaction and has the
* full_sync flag set, then the inode may have been logged before in
* the current transaction, then evicted and loaded again in the current
* transaction - or may have never been logged in the current transaction,
* but since we can not be sure, we have to assume it was, otherwise our
* callers can leave an inconsistent log.
*/
if (inode->logged_trans == 0 &&
inode->last_trans == trans->transid &&
test_bit(BTRFS_INODE_NEEDS_FULL_SYNC, &inode->runtime_flags) && test_bit(BTRFS_INODE_NEEDS_FULL_SYNC, &inode->runtime_flags) &&
!test_bit(BTRFS_FS_LOG_RECOVERING, &trans->fs_info->flags)) !test_bit(BTRFS_FS_LOG_RECOVERING, &trans->fs_info->flags))
return true; return true;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment