Skip to content

Commit 1edf805

Browse files
author
Darrick J. Wong
committed
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: Darrick J. Wong <[email protected]> Reviewed-by: Dave Chinner <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]>
1 parent 75d893d commit 1edf805

File tree

2 files changed

+36
-17
lines changed

2 files changed

+36
-17
lines changed

fs/xfs/libxfs/xfs_rmap.c

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,6 @@ xfs_rmap_get_rec(
265265
struct xfs_find_left_neighbor_info {
266266
struct xfs_rmap_irec high;
267267
struct xfs_rmap_irec *irec;
268-
int *stat;
269268
};
270269

271270
/* For each rmap given, figure out if it matches the key we want. */
@@ -290,7 +289,6 @@ xfs_rmap_find_left_neighbor_helper(
290289
return 0;
291290

292291
*info->irec = *rec;
293-
*info->stat = 1;
294292
return -ECANCELED;
295293
}
296294

@@ -299,7 +297,7 @@ xfs_rmap_find_left_neighbor_helper(
299297
* return a match with the same owner and adjacent physical and logical
300298
* block ranges.
301299
*/
302-
int
300+
STATIC int
303301
xfs_rmap_find_left_neighbor(
304302
struct xfs_btree_cur *cur,
305303
xfs_agblock_t bno,
@@ -310,6 +308,7 @@ xfs_rmap_find_left_neighbor(
310308
int *stat)
311309
{
312310
struct xfs_find_left_neighbor_info info;
311+
int found = 0;
313312
int error;
314313

315314
*stat = 0;
@@ -327,21 +326,44 @@ xfs_rmap_find_left_neighbor(
327326
info.high.rm_flags = flags;
328327
info.high.rm_blockcount = 0;
329328
info.irec = irec;
330-
info.stat = stat;
331329

332330
trace_xfs_rmap_find_left_neighbor_query(cur->bc_mp,
333331
cur->bc_ag.pag->pag_agno, bno, 0, owner, offset, flags);
334332

335-
error = xfs_rmap_query_range(cur, &info.high, &info.high,
336-
xfs_rmap_find_left_neighbor_helper, &info);
337-
if (error == -ECANCELED)
338-
error = 0;
339-
if (*stat)
340-
trace_xfs_rmap_find_left_neighbor_result(cur->bc_mp,
341-
cur->bc_ag.pag->pag_agno, irec->rm_startblock,
342-
irec->rm_blockcount, irec->rm_owner,
343-
irec->rm_offset, irec->rm_flags);
344-
return error;
333+
/*
334+
* Historically, we always used the range query to walk every reverse
335+
* mapping that could possibly overlap the key that the caller asked
336+
* for, and filter out the ones that don't. That is very slow when
337+
* there are a lot of records.
338+
*
339+
* However, there are two scenarios where the classic btree search can
340+
* produce correct results -- if the index contains a record that is an
341+
* exact match for the lookup key; and if there are no other records
342+
* between the record we want and the key we supplied.
343+
*
344+
* As an optimization, try a non-overlapped lookup first. This makes
345+
* extent conversion and remap operations run a bit faster if the
346+
* physical extents aren't being shared. If we don't find what we
347+
* want, we fall back to the overlapped query.
348+
*/
349+
error = xfs_rmap_lookup_le(cur, bno, owner, offset, flags, irec,
350+
&found);
351+
if (error)
352+
return error;
353+
if (found)
354+
error = xfs_rmap_find_left_neighbor_helper(cur, irec, &info);
355+
if (!error)
356+
error = xfs_rmap_query_range(cur, &info.high, &info.high,
357+
xfs_rmap_find_left_neighbor_helper, &info);
358+
if (error != -ECANCELED)
359+
return error;
360+
361+
*stat = 1;
362+
trace_xfs_rmap_find_left_neighbor_result(cur->bc_mp,
363+
cur->bc_ag.pag->pag_agno, irec->rm_startblock,
364+
irec->rm_blockcount, irec->rm_owner, irec->rm_offset,
365+
irec->rm_flags);
366+
return 0;
345367
}
346368

347369
/* For each rmap given, figure out if it matches the key we want. */

fs/xfs/libxfs/xfs_rmap.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,6 @@ int xfs_rmap_finish_one(struct xfs_trans *tp, enum xfs_rmap_intent_type type,
184184
xfs_fsblock_t startblock, xfs_filblks_t blockcount,
185185
xfs_exntst_t state, struct xfs_btree_cur **pcur);
186186

187-
int xfs_rmap_find_left_neighbor(struct xfs_btree_cur *cur, xfs_agblock_t bno,
188-
uint64_t owner, uint64_t offset, unsigned int flags,
189-
struct xfs_rmap_irec *irec, int *stat);
190187
int xfs_rmap_lookup_le_range(struct xfs_btree_cur *cur, xfs_agblock_t bno,
191188
uint64_t owner, uint64_t offset, unsigned int flags,
192189
struct xfs_rmap_irec *irec, int *stat);

0 commit comments

Comments
 (0)