Skip to content

Commit bcf62ab

Browse files
jankaraBen Myers
authored andcommitted
xfs: Fix overallocation in xfs_buf_allocate_memory()
Commit de1cbee which removed b_file_offset in favor of b_bn introduced a bug causing xfs_buf_allocate_memory() to overestimate the number of necessary pages. The problem is that xfs_buf_alloc() sets b_bn to -1 and thus effectively every buffer is straddling a page boundary which causes xfs_buf_allocate_memory() to allocate two pages and use vmalloc() for access which is unnecessary. Dave says xfs_buf_alloc() doesn't need to set b_bn to -1 anymore since the buffer is inserted into the cache only after being fully initialized now. So just make xfs_buf_alloc() fill in proper block number from the beginning. CC: David Chinner <[email protected]> Signed-off-by: Jan Kara <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Dave Chinner <[email protected]> Signed-off-by: Ben Myers <[email protected]>
1 parent 079da28 commit bcf62ab

File tree

1 file changed

+2
-14
lines changed

1 file changed

+2
-14
lines changed

fs/xfs/xfs_buf.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,7 @@ xfs_buf_alloc(
201201
bp->b_length = numblks;
202202
bp->b_io_length = numblks;
203203
bp->b_flags = flags;
204-
205-
/*
206-
* We do not set the block number here in the buffer because we have not
207-
* finished initialising the buffer. We insert the buffer into the cache
208-
* in this state, so this ensures that we are unable to do IO on a
209-
* buffer that hasn't been fully initialised.
210-
*/
211-
bp->b_bn = XFS_BUF_DADDR_NULL;
204+
bp->b_bn = blkno;
212205
atomic_set(&bp->b_pin_count, 0);
213206
init_waitqueue_head(&bp->b_waiters);
214207

@@ -567,11 +560,6 @@ xfs_buf_get(
567560
if (bp != new_bp)
568561
xfs_buf_free(new_bp);
569562

570-
/*
571-
* Now we have a workable buffer, fill in the block number so
572-
* that we can do IO on it.
573-
*/
574-
bp->b_bn = blkno;
575563
bp->b_io_length = bp->b_length;
576564

577565
found:
@@ -772,7 +760,7 @@ xfs_buf_get_uncached(
772760
int error, i;
773761
xfs_buf_t *bp;
774762

775-
bp = xfs_buf_alloc(target, 0, numblks, 0);
763+
bp = xfs_buf_alloc(target, XFS_BUF_DADDR_NULL, numblks, 0);
776764
if (unlikely(bp == NULL))
777765
goto fail;
778766

0 commit comments

Comments
 (0)