Skip to content

Commit c44245b

Browse files
osandovdjwong
authored andcommitted
xfs: fix inobt inode allocation search optimization
When we try to allocate a free inode by searching the inobt, we try to find the inode nearest the parent inode by searching chunks both left and right of the chunk containing the parent. As an optimization, we cache the leftmost and rightmost records that we previously searched; if we do another allocation with the same parent inode, we'll pick up the search where it last left off. There's a bug in the case where we found a free inode to the left of the parent's chunk: we need to update the cached left and right records, but because we already reassigned the right record to point to the left, we end up assigning the left record to both the cached left and right records. This isn't a correctness problem strictly, but it can result in the next allocation rechecking chunks unnecessarily or allocating inodes further away from the parent than it needs to. Fix it by swapping the record pointer after we update the cached left and right records. Fixes: bd16956 ("xfs: speed up free inode search") Signed-off-by: Omar Sandoval <osandov@fb.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
1 parent 56bdf85 commit c44245b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

fs/xfs/libxfs/xfs_ialloc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1246,13 +1246,13 @@ xfs_dialloc_ag_inobt(
12461246

12471247
/* free inodes to the left? */
12481248
if (useleft && trec.ir_freecount) {
1249-
rec = trec;
12501249
xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR);
12511250
cur = tcur;
12521251

12531252
pag->pagl_leftrec = trec.ir_startino;
12541253
pag->pagl_rightrec = rec.ir_startino;
12551254
pag->pagl_pagino = pagino;
1255+
rec = trec;
12561256
goto alloc_inode;
12571257
}
12581258

0 commit comments

Comments
 (0)