From: Christoph Hellwig Date: Tue, 21 Jun 2016 23:32:42 +0000 (+1000) Subject: xfs: improve kmem_realloc X-Git-Tag: v4.7.0-rc1~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=408c66dd2e03bddd30b6bc7288ee9196561105dd;p=thirdparty%2Fxfsprogs-dev.git xfs: improve kmem_realloc Source kernel commit 664b60f6babc98ee03c2ff15b9482cc8c5e15a83 Use krealloc to implement our realloc function. This helps to avoid new allocations if we are still in the slab bucket. At least for the bmap btree root that's actually the common case. This also allows removing the now unused oldsize argument. Signed-off-by: Christoph Hellwig Reviewed-by: Brian Foster Signed-off-by: Dave Chinner --- diff --git a/include/kmem.h b/include/kmem.h index 5484d32ab..65f0aded6 100644 --- a/include/kmem.h +++ b/include/kmem.h @@ -49,6 +49,6 @@ kmem_free(void *ptr) { free(ptr); } -extern void *kmem_realloc(void *, size_t, size_t, int); +extern void *kmem_realloc(void *, size_t, int); #endif diff --git a/libxfs/kmem.c b/libxfs/kmem.c index 4f3cd7e2f..c8bcb5086 100644 --- a/libxfs/kmem.c +++ b/libxfs/kmem.c @@ -70,7 +70,7 @@ kmem_zalloc(size_t size, int flags) } void * -kmem_realloc(void *ptr, size_t new_size, size_t old_size, int flags) +kmem_realloc(void *ptr, size_t new_size, int flags) { ptr = realloc(ptr, new_size); if (ptr == NULL) { diff --git a/libxfs/xfs_inode_fork.c b/libxfs/xfs_inode_fork.c index 8a59e2575..519253e18 100644 --- a/libxfs/xfs_inode_fork.c +++ b/libxfs/xfs_inode_fork.c @@ -538,7 +538,6 @@ xfs_iroot_realloc( new_max = cur_max + rec_diff; new_size = XFS_BMAP_BROOT_SPACE_CALC(mp, new_max); ifp->if_broot = kmem_realloc(ifp->if_broot, new_size, - XFS_BMAP_BROOT_SPACE_CALC(mp, cur_max), KM_SLEEP | KM_NOFS); op = (char *)XFS_BMAP_BROOT_PTR_ADDR(mp, ifp->if_broot, 1, ifp->if_broot_bytes); @@ -682,7 +681,6 @@ xfs_idata_realloc( ifp->if_u1.if_data = kmem_realloc(ifp->if_u1.if_data, real_size, - ifp->if_real_bytes, KM_SLEEP | KM_NOFS); } } else { @@ -1398,8 +1396,7 @@ xfs_iext_realloc_direct( if (rnew_size != ifp->if_real_bytes) { ifp->if_u1.if_extents = kmem_realloc(ifp->if_u1.if_extents, - rnew_size, - ifp->if_real_bytes, KM_NOFS); + rnew_size, KM_NOFS); } if (rnew_size > ifp->if_real_bytes) { memset(&ifp->if_u1.if_extents[ifp->if_bytes / @@ -1472,6 +1469,7 @@ xfs_iext_realloc_indirect( xfs_ifork_t *ifp, /* inode fork pointer */ int new_size) /* new indirection array size */ { +#ifdef DEBUG int nlists; /* number of irec's (ex lists) */ int size; /* current indirection array size */ @@ -1480,12 +1478,12 @@ xfs_iext_realloc_indirect( size = nlists * sizeof(xfs_ext_irec_t); ASSERT(ifp->if_real_bytes); ASSERT((new_size >= 0) && (new_size != size)); +#endif if (new_size == 0) { xfs_iext_destroy(ifp); } else { - ifp->if_u1.if_ext_irec = (xfs_ext_irec_t *) - kmem_realloc(ifp->if_u1.if_ext_irec, - new_size, size, KM_NOFS); + ifp->if_u1.if_ext_irec = + kmem_realloc(ifp->if_u1.if_ext_irec, new_size, KM_NOFS); } } diff --git a/libxlog/xfs_log_recover.c b/libxlog/xfs_log_recover.c index 6116ecd03..6cd77d5e2 100644 --- a/libxlog/xfs_log_recover.c +++ b/libxlog/xfs_log_recover.c @@ -1062,7 +1062,7 @@ xlog_recover_add_to_cont_trans( old_ptr = item->ri_buf[item->ri_cnt-1].i_addr; old_len = item->ri_buf[item->ri_cnt-1].i_len; - ptr = kmem_realloc(old_ptr, len+old_len, old_len, KM_SLEEP); + ptr = kmem_realloc(old_ptr, len+old_len, KM_SLEEP); memcpy(&ptr[old_len], dp, len); /* d, s, l */ item->ri_buf[item->ri_cnt-1].i_len += len; item->ri_buf[item->ri_cnt-1].i_addr = ptr;