@@ -278,15 +278,14 @@ _xfs_buf_alloc(
*/
STATIC int
_xfs_buf_get_pages(
- struct xfs_buf *bp,
- int page_count)
+ struct xfs_buf *bp)
{
ASSERT(bp->b_pages == NULL);
- bp->b_page_count = page_count;
- if (page_count > XB_PAGES) {
- bp->b_pages = kmem_zalloc(sizeof(struct page *) * page_count,
- KM_NOFS);
+ bp->b_page_count = DIV_ROUND_UP(BBTOB(bp->b_length), PAGE_SIZE);
+ if (bp->b_page_count > XB_PAGES) {
+ bp->b_pages = kmem_zalloc(sizeof(struct page *) *
+ bp->b_page_count, KM_NOFS);
if (!bp->b_pages)
return -ENOMEM;
} else {
@@ -384,8 +383,7 @@ xfs_buf_alloc_pages(
uint flags)
{
gfp_t gfp_mask = xb_to_gfp(flags);
- unsigned short page_count, i;
- xfs_off_t start, end;
+ unsigned short i;
int error;
/*
@@ -394,11 +392,7 @@ xfs_buf_alloc_pages(
if (!(flags & XBF_READ))
gfp_mask |= __GFP_ZERO;
- start = BBTOB(bp->b_maps[0].bm_bn) >> PAGE_SHIFT;
- end = (BBTOB(bp->b_maps[0].bm_bn + bp->b_length) + PAGE_SIZE - 1)
- >> PAGE_SHIFT;
- page_count = end - start;
- error = _xfs_buf_get_pages(bp, page_count);
+ error = _xfs_buf_get_pages(bp);
if (unlikely(error))
return error;
@@ -942,7 +936,6 @@ xfs_buf_get_uncached(
int flags,
struct xfs_buf **bpp)
{
- unsigned long page_count;
int error, i;
struct xfs_buf *bp;
DEFINE_SINGLE_BUF_MAP(map, XFS_BUF_DADDR_NULL, numblks);
@@ -954,12 +947,11 @@ xfs_buf_get_uncached(
if (error)
goto fail;
- page_count = PAGE_ALIGN(numblks << BBSHIFT) >> PAGE_SHIFT;
- error = _xfs_buf_get_pages(bp, page_count);
+ error = _xfs_buf_get_pages(bp);
if (error)
goto fail_free_buf;
- for (i = 0; i < page_count; i++) {
+ for (i = 0; i < bp->b_page_count; i++) {
bp->b_pages[i] = alloc_page(xb_to_gfp(flags));
if (!bp->b_pages[i]) {
error = -ENOMEM;
Ever since we stopped using the Linux page cache to back XFS buffes there is no need to take the start sector into account for calculating the number of pages in a buffer, as the data always start from the beginning of the buffer. Signed-off-by: Christoph Hellwig <hch@lst.de> --- fs/xfs/xfs_buf.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-)