Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 59c84ed0 authored by Jan Kara's avatar Jan Kara Committed by Ben Myers
Browse files

xfs: Fix overallocation in xfs_buf_allocate_memory()



Commit de1cbee4 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 <dchinner@redhat.com>
Signed-off-by: default avatarJan Kara <jack@suse.cz>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarDave Chinner <dchinner@redhat.com>
Signed-off-by: default avatarBen Myers <bpm@sgi.com>
parent 76d09538
Loading
Loading
Loading
Loading
+2 −14
Original line number Diff line number Diff line
@@ -201,14 +201,7 @@ xfs_buf_alloc(
	bp->b_length = numblks;
	bp->b_io_length = numblks;
	bp->b_flags = flags;

	/*
	 * We do not set the block number here in the buffer because we have not
	 * finished initialising the buffer. We insert the buffer into the cache
	 * in this state, so this ensures that we are unable to do IO on a
	 * buffer that hasn't been fully initialised.
	 */
	bp->b_bn = XFS_BUF_DADDR_NULL;
	bp->b_bn = blkno;
	atomic_set(&bp->b_pin_count, 0);
	init_waitqueue_head(&bp->b_waiters);

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

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

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

	bp = xfs_buf_alloc(target, 0, numblks, 0);
	bp = xfs_buf_alloc(target, XFS_BUF_DADDR_NULL, numblks, 0);
	if (unlikely(bp == NULL))
		goto fail;