提交 4347b9d7 编写于 作者: C Christoph Hellwig 提交者: Alex Elder

xfs: clean up buffer allocation

Change _xfs_buf_initialize to allocate the buffer directly and rename it to
xfs_buf_alloc now that is the only buffer allocation routine.  Also remove
the xfs_buf_deallocate wrapper around the kmem_zone_free calls for buffers.
Signed-off-by: NChristoph Hellwig <hch@lst.de>
Reviewed-by: NDave Chinner <dchinner@redhat.com>
Signed-off-by: NAlex Elder <aelder@sgi.com>
上级 af5c4bee
...@@ -65,10 +65,6 @@ struct workqueue_struct *xfsconvertd_workqueue; ...@@ -65,10 +65,6 @@ struct workqueue_struct *xfsconvertd_workqueue;
#define xb_to_km(flags) \ #define xb_to_km(flags) \
(((flags) & XBF_DONT_BLOCK) ? KM_NOFS : KM_SLEEP) (((flags) & XBF_DONT_BLOCK) ? KM_NOFS : KM_SLEEP)
#define xfs_buf_allocate(flags) \
kmem_zone_alloc(xfs_buf_zone, xb_to_km(flags))
#define xfs_buf_deallocate(bp) \
kmem_zone_free(xfs_buf_zone, (bp));
static inline int static inline int
xfs_buf_is_vmapped( xfs_buf_is_vmapped(
...@@ -167,14 +163,19 @@ xfs_buf_stale( ...@@ -167,14 +163,19 @@ xfs_buf_stale(
ASSERT(atomic_read(&bp->b_hold) >= 1); ASSERT(atomic_read(&bp->b_hold) >= 1);
} }
STATIC void struct xfs_buf *
_xfs_buf_initialize( xfs_buf_alloc(
xfs_buf_t *bp, struct xfs_buftarg *target,
xfs_buftarg_t *target,
xfs_off_t range_base, xfs_off_t range_base,
size_t range_length, size_t range_length,
xfs_buf_flags_t flags) xfs_buf_flags_t flags)
{ {
struct xfs_buf *bp;
bp = kmem_zone_alloc(xfs_buf_zone, xb_to_km(flags));
if (unlikely(!bp))
return NULL;
/* /*
* We don't want certain flags to appear in b_flags. * We don't want certain flags to appear in b_flags.
*/ */
...@@ -203,8 +204,9 @@ _xfs_buf_initialize( ...@@ -203,8 +204,9 @@ _xfs_buf_initialize(
init_waitqueue_head(&bp->b_waiters); init_waitqueue_head(&bp->b_waiters);
XFS_STATS_INC(xb_create); XFS_STATS_INC(xb_create);
trace_xfs_buf_init(bp, _RET_IP_); trace_xfs_buf_init(bp, _RET_IP_);
return bp;
} }
/* /*
...@@ -277,7 +279,7 @@ xfs_buf_free( ...@@ -277,7 +279,7 @@ xfs_buf_free(
} else if (bp->b_flags & _XBF_KMEM) } else if (bp->b_flags & _XBF_KMEM)
kmem_free(bp->b_addr); kmem_free(bp->b_addr);
_xfs_buf_free_pages(bp); _xfs_buf_free_pages(bp);
xfs_buf_deallocate(bp); kmem_zone_free(xfs_buf_zone, bp);
} }
/* /*
...@@ -539,16 +541,14 @@ xfs_buf_get( ...@@ -539,16 +541,14 @@ xfs_buf_get(
if (likely(bp)) if (likely(bp))
goto found; goto found;
new_bp = xfs_buf_allocate(flags); new_bp = xfs_buf_alloc(target, ioff << BBSHIFT, isize << BBSHIFT,
flags);
if (unlikely(!new_bp)) if (unlikely(!new_bp))
return NULL; return NULL;
_xfs_buf_initialize(new_bp, target,
ioff << BBSHIFT, isize << BBSHIFT, flags);
bp = _xfs_buf_find(target, ioff, isize, flags, new_bp); bp = _xfs_buf_find(target, ioff, isize, flags, new_bp);
if (!bp) { if (!bp) {
xfs_buf_deallocate(new_bp); kmem_zone_free(xfs_buf_zone, new_bp);
return NULL; return NULL;
} }
...@@ -557,7 +557,7 @@ xfs_buf_get( ...@@ -557,7 +557,7 @@ xfs_buf_get(
if (error) if (error)
goto no_buffer; goto no_buffer;
} else } else
xfs_buf_deallocate(new_bp); kmem_zone_free(xfs_buf_zone, new_bp);
/* /*
* Now we have a workable buffer, fill in the block number so * Now we have a workable buffer, fill in the block number so
...@@ -694,19 +694,6 @@ xfs_buf_read_uncached( ...@@ -694,19 +694,6 @@ xfs_buf_read_uncached(
return bp; return bp;
} }
xfs_buf_t *
xfs_buf_get_empty(
size_t len,
xfs_buftarg_t *target)
{
xfs_buf_t *bp;
bp = xfs_buf_allocate(0);
if (bp)
_xfs_buf_initialize(bp, target, 0, len, 0);
return bp;
}
/* /*
* Return a buffer allocated as an empty buffer and associated to external * Return a buffer allocated as an empty buffer and associated to external
* memory via xfs_buf_associate_memory() back to it's empty state. * memory via xfs_buf_associate_memory() back to it's empty state.
...@@ -792,10 +779,9 @@ xfs_buf_get_uncached( ...@@ -792,10 +779,9 @@ xfs_buf_get_uncached(
int error, i; int error, i;
xfs_buf_t *bp; xfs_buf_t *bp;
bp = xfs_buf_allocate(0); bp = xfs_buf_alloc(target, 0, len, 0);
if (unlikely(bp == NULL)) if (unlikely(bp == NULL))
goto fail; goto fail;
_xfs_buf_initialize(bp, target, 0, len, 0);
error = _xfs_buf_get_pages(bp, page_count, 0); error = _xfs_buf_get_pages(bp, page_count, 0);
if (error) if (error)
...@@ -823,7 +809,7 @@ xfs_buf_get_uncached( ...@@ -823,7 +809,7 @@ xfs_buf_get_uncached(
__free_page(bp->b_pages[i]); __free_page(bp->b_pages[i]);
_xfs_buf_free_pages(bp); _xfs_buf_free_pages(bp);
fail_free_buf: fail_free_buf:
xfs_buf_deallocate(bp); kmem_zone_free(xfs_buf_zone, bp);
fail: fail:
return NULL; return NULL;
} }
......
...@@ -175,7 +175,8 @@ extern xfs_buf_t *xfs_buf_get(xfs_buftarg_t *, xfs_off_t, size_t, ...@@ -175,7 +175,8 @@ extern xfs_buf_t *xfs_buf_get(xfs_buftarg_t *, xfs_off_t, size_t,
extern xfs_buf_t *xfs_buf_read(xfs_buftarg_t *, xfs_off_t, size_t, extern xfs_buf_t *xfs_buf_read(xfs_buftarg_t *, xfs_off_t, size_t,
xfs_buf_flags_t); xfs_buf_flags_t);
extern xfs_buf_t *xfs_buf_get_empty(size_t, xfs_buftarg_t *); struct xfs_buf *xfs_buf_alloc(struct xfs_buftarg *, xfs_off_t, size_t,
xfs_buf_flags_t);
extern void xfs_buf_set_empty(struct xfs_buf *bp, size_t len); extern void xfs_buf_set_empty(struct xfs_buf *bp, size_t len);
extern xfs_buf_t *xfs_buf_get_uncached(struct xfs_buftarg *, size_t, int); extern xfs_buf_t *xfs_buf_get_uncached(struct xfs_buftarg *, size_t, int);
extern int xfs_buf_associate_memory(xfs_buf_t *, void *, size_t); extern int xfs_buf_associate_memory(xfs_buf_t *, void *, size_t);
......
...@@ -1047,7 +1047,7 @@ xlog_alloc_log(xfs_mount_t *mp, ...@@ -1047,7 +1047,7 @@ xlog_alloc_log(xfs_mount_t *mp,
xlog_get_iclog_buffer_size(mp, log); xlog_get_iclog_buffer_size(mp, log);
error = ENOMEM; error = ENOMEM;
bp = xfs_buf_get_empty(log->l_iclog_size, mp->m_logdev_targp); bp = xfs_buf_alloc(mp->m_logdev_targp, 0, log->l_iclog_size, 0);
if (!bp) if (!bp)
goto out_free_log; goto out_free_log;
bp->b_iodone = xlog_iodone; bp->b_iodone = xlog_iodone;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册