summaryrefslogtreecommitdiffstats
path: root/fs/xfs/kmem.c
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2016-04-05 19:47:01 -0400
committerDave Chinner <david@fromorbit.com>2016-04-05 19:47:01 -0400
commit664b60f6babc98ee03c2ff15b9482cc8c5e15a83 (patch)
tree195d42b776a4e311a912147722aa516e9e6d9048 /fs/xfs/kmem.c
parent9f27889f3a96ff356ac92688cc0c4be3935ae3af (diff)
xfs: improve kmem_realloc
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>
Diffstat (limited to 'fs/xfs/kmem.c')
-rw-r--r--fs/xfs/kmem.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/fs/xfs/kmem.c b/fs/xfs/kmem.c
index 686ba6fb20dd..339c696bbc01 100644
--- a/fs/xfs/kmem.c
+++ b/fs/xfs/kmem.c
@@ -93,19 +93,23 @@ kmem_zalloc_large(size_t size, xfs_km_flags_t flags)
93} 93}
94 94
95void * 95void *
96kmem_realloc(const void *ptr, size_t newsize, size_t oldsize, 96kmem_realloc(const void *old, size_t newsize, xfs_km_flags_t flags)
97 xfs_km_flags_t flags)
98{ 97{
99 void *new; 98 int retries = 0;
99 gfp_t lflags = kmem_flags_convert(flags);
100 void *ptr;
100 101
101 new = kmem_alloc(newsize, flags); 102 do {
102 if (ptr) { 103 ptr = krealloc(old, newsize, lflags);
103 if (new) 104 if (ptr || (flags & (KM_MAYFAIL|KM_NOSLEEP)))
104 memcpy(new, ptr, 105 return ptr;
105 ((oldsize < newsize) ? oldsize : newsize)); 106 if (!(++retries % 100))
106 kmem_free(ptr); 107 xfs_err(NULL,
107 } 108 "%s(%u) possible memory allocation deadlock size %zu in %s (mode:0x%x)",
108 return new; 109 current->comm, current->pid,
110 newsize, __func__, lflags);
111 congestion_wait(BLK_RW_ASYNC, HZ/50);
112 } while (1);
109} 113}
110 114
111void * 115void *