Commit 1edf8056 authored by Darrick J. Wong's avatar Darrick J. Wong

xfs: speed up write operations by using non-overlapped lookups when possible

Reverse mapping on a reflink-capable filesystem has some pretty high
overhead when performing file operations.  This is because the rmap
records for logically and physically adjacent extents might not be
adjacent in the rmap index due to data block sharing.  As a result, we
use expensive overlapped-interval btree search, which walks every record
that overlaps with the supplied key in the hopes of finding the record.

However, profiling data shows that when the index contains a record that
is an exact match for a query key, the non-overlapped btree search
function can find the record much faster than the overlapped version.
Try the non-overlapped lookup first when we're trying to find the left
neighbor rmap record for a given file mapping, which makes unwritten
extent conversion and remap operations run faster if data block sharing
is minimal in this part of the filesystem.
Signed-off-by: default avatarDarrick J. Wong <djwong@kernel.org>
Reviewed-by: default avatarDave Chinner <dchinner@redhat.com>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
parent 75d893d1
...@@ -265,7 +265,6 @@ xfs_rmap_get_rec( ...@@ -265,7 +265,6 @@ xfs_rmap_get_rec(
struct xfs_find_left_neighbor_info { struct xfs_find_left_neighbor_info {
struct xfs_rmap_irec high; struct xfs_rmap_irec high;
struct xfs_rmap_irec *irec; struct xfs_rmap_irec *irec;
int *stat;
}; };
/* For each rmap given, figure out if it matches the key we want. */ /* For each rmap given, figure out if it matches the key we want. */
...@@ -290,7 +289,6 @@ xfs_rmap_find_left_neighbor_helper( ...@@ -290,7 +289,6 @@ xfs_rmap_find_left_neighbor_helper(
return 0; return 0;
*info->irec = *rec; *info->irec = *rec;
*info->stat = 1;
return -ECANCELED; return -ECANCELED;
} }
...@@ -299,7 +297,7 @@ xfs_rmap_find_left_neighbor_helper( ...@@ -299,7 +297,7 @@ xfs_rmap_find_left_neighbor_helper(
* return a match with the same owner and adjacent physical and logical * return a match with the same owner and adjacent physical and logical
* block ranges. * block ranges.
*/ */
int STATIC int
xfs_rmap_find_left_neighbor( xfs_rmap_find_left_neighbor(
struct xfs_btree_cur *cur, struct xfs_btree_cur *cur,
xfs_agblock_t bno, xfs_agblock_t bno,
...@@ -310,6 +308,7 @@ xfs_rmap_find_left_neighbor( ...@@ -310,6 +308,7 @@ xfs_rmap_find_left_neighbor(
int *stat) int *stat)
{ {
struct xfs_find_left_neighbor_info info; struct xfs_find_left_neighbor_info info;
int found = 0;
int error; int error;
*stat = 0; *stat = 0;
...@@ -327,21 +326,44 @@ xfs_rmap_find_left_neighbor( ...@@ -327,21 +326,44 @@ xfs_rmap_find_left_neighbor(
info.high.rm_flags = flags; info.high.rm_flags = flags;
info.high.rm_blockcount = 0; info.high.rm_blockcount = 0;
info.irec = irec; info.irec = irec;
info.stat = stat;
trace_xfs_rmap_find_left_neighbor_query(cur->bc_mp, trace_xfs_rmap_find_left_neighbor_query(cur->bc_mp,
cur->bc_ag.pag->pag_agno, bno, 0, owner, offset, flags); cur->bc_ag.pag->pag_agno, bno, 0, owner, offset, flags);
/*
* Historically, we always used the range query to walk every reverse
* mapping that could possibly overlap the key that the caller asked
* for, and filter out the ones that don't. That is very slow when
* there are a lot of records.
*
* However, there are two scenarios where the classic btree search can
* produce correct results -- if the index contains a record that is an
* exact match for the lookup key; and if there are no other records
* between the record we want and the key we supplied.
*
* As an optimization, try a non-overlapped lookup first. This makes
* extent conversion and remap operations run a bit faster if the
* physical extents aren't being shared. If we don't find what we
* want, we fall back to the overlapped query.
*/
error = xfs_rmap_lookup_le(cur, bno, owner, offset, flags, irec,
&found);
if (error)
return error;
if (found)
error = xfs_rmap_find_left_neighbor_helper(cur, irec, &info);
if (!error)
error = xfs_rmap_query_range(cur, &info.high, &info.high, error = xfs_rmap_query_range(cur, &info.high, &info.high,
xfs_rmap_find_left_neighbor_helper, &info); xfs_rmap_find_left_neighbor_helper, &info);
if (error == -ECANCELED) if (error != -ECANCELED)
error = 0; return error;
if (*stat)
*stat = 1;
trace_xfs_rmap_find_left_neighbor_result(cur->bc_mp, trace_xfs_rmap_find_left_neighbor_result(cur->bc_mp,
cur->bc_ag.pag->pag_agno, irec->rm_startblock, cur->bc_ag.pag->pag_agno, irec->rm_startblock,
irec->rm_blockcount, irec->rm_owner, irec->rm_blockcount, irec->rm_owner, irec->rm_offset,
irec->rm_offset, irec->rm_flags); irec->rm_flags);
return error; return 0;
} }
/* For each rmap given, figure out if it matches the key we want. */ /* For each rmap given, figure out if it matches the key we want. */
......
...@@ -184,9 +184,6 @@ int xfs_rmap_finish_one(struct xfs_trans *tp, enum xfs_rmap_intent_type type, ...@@ -184,9 +184,6 @@ int xfs_rmap_finish_one(struct xfs_trans *tp, enum xfs_rmap_intent_type type,
xfs_fsblock_t startblock, xfs_filblks_t blockcount, xfs_fsblock_t startblock, xfs_filblks_t blockcount,
xfs_exntst_t state, struct xfs_btree_cur **pcur); xfs_exntst_t state, struct xfs_btree_cur **pcur);
int xfs_rmap_find_left_neighbor(struct xfs_btree_cur *cur, xfs_agblock_t bno,
uint64_t owner, uint64_t offset, unsigned int flags,
struct xfs_rmap_irec *irec, int *stat);
int xfs_rmap_lookup_le_range(struct xfs_btree_cur *cur, xfs_agblock_t bno, int xfs_rmap_lookup_le_range(struct xfs_btree_cur *cur, xfs_agblock_t bno,
uint64_t owner, uint64_t offset, unsigned int flags, uint64_t owner, uint64_t offset, unsigned int flags,
struct xfs_rmap_irec *irec, int *stat); struct xfs_rmap_irec *irec, int *stat);
......
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