]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: improve kmem_realloc
authorChristoph Hellwig <hch@lst.de>
Tue, 21 Jun 2016 23:32:42 +0000 (09:32 +1000)
committerDave Chinner <david@fromorbit.com>
Tue, 21 Jun 2016 23:32:42 +0000 (09:32 +1000)
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 <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
include/kmem.h
libxfs/kmem.c
libxfs/xfs_inode_fork.c
libxlog/xfs_log_recover.c

index 5484d32ab741e6b2d3795480dc540082a7f6ac6e..65f0aded6ca66489939b536b0990ad2081e7f919 100644 (file)
@@ -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
index 4f3cd7e2fd0e9451b753ee7ebf5618523e024d5e..c8bcb50861a988ad5153085dd40c7bec9833200d 100644 (file)
@@ -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) {
index 8a59e2575b471e81fff3b672de0f7b8492e19e7e..519253e181f68a2588ff94ab6ce6f41ea53d5371 100644 (file)
@@ -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);
        }
 }
 
index 6116ecd03899723ec2ca1fae0dc72e5b172bc908..6cd77d5e268c3f3fb5202613db4d5db9b5c625c4 100644 (file)
@@ -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;