xfs: fall back to vmalloc when allocation log vector buffers
PATCH 1/1 xfs: fall back to vmalloc when allocation log vector buffers
From: Dave Chinner <[email protected]>
When using large directory blocks, we regularly see memory allocations of >64k being made for the shadow log vector buffer. When we are under memory pressure, kmalloc() may not be able to find contiguous memory chunks large enough to satisfy these allocations easily, and if memory is fragmented we can potentially stall here.
TO avoid this problem, switch the log vector buffer allocation to use kmem_alloc_large(). This will allow failed allocations to fall back to vmalloc and so remove the dependency on large contiguous regions of memory being available. This should prevent slowdowns and potential stalls when memory is low and/or fragmented.
--- fs/xfs/kmem.c | 6 +++--- fs/xfs/kmem.h | 8 +++++++- fs/xfs/xfs_log_cil.c | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-)
fs/xfs/kmem.c +3 -3
@@ -46,13 +46,13 @@ kmem_alloc(size_t size, xfs_km_flags_t flags) }void * -kmem_zalloc_large (size_t size,xfs_km_flags_t flags) +kmem_alloc_large (size_t size,xfs_km_flags_t flags) {unsigned nofs_flag =0 ;void *ptr;gfp_t lflags; - ptr =kmem_zalloc (size, flags |KM_MAYFAIL ); + ptr =kmem_alloc (size, flags |KM_MAYFAIL );if (ptr)return ptr;
@@ -67,7 +67,7 @@ kmem_zalloc_large(size_t size, xfs_km_flags_t flags) nofs_flag =memalloc_nofs_save (); lflags =kmem_flags_convert (flags); - ptr =__vmalloc (size, lflags | __GFP_ZERO,PAGE_KERNEL ); + ptr =__vmalloc (size, lflags,PAGE_KERNEL );if (flags &KM_NOFS )memalloc_nofs_restore (nofs_flag);
fs/xfs/kmem.h +7 -1
@@ -71,7 +71,7 @@ kmem_flags_convert(xfs_km_flags_t flags) }extern void *kmem_alloc (size_t ,xfs_km_flags_t ); -extern void *kmem_zalloc_large (size_t size,xfs_km_flags_t ); +extern void *kmem_alloc_large (size_t size,xfs_km_flags_t );extern void *kmem_realloc (const void *,size_t ,xfs_km_flags_t );static inline void kmem_free (const void *ptr) {
@@ -85,6 +85,12 @@ kmem_zalloc(size_t size, xfs_km_flags_t flags)return kmem_alloc (size, flags |KM_ZERO ); } +static inline void * +kmem_zalloc_large (size_t size,xfs_km_flags_t flags) +{ +return kmem_alloc_large (size, flags |KM_ZERO ); +} +/* * Zone interfaces */
fs/xfs/xfs_log_cil.c +1 -1
@@ -202,7 +202,7 @@ xlog_cil_alloc_shadow_bufs(*/ kmem_free (lip->li_lv_shadow); - lv =kmem_alloc (buf_size,KM_SLEEP |KM_NOFS ); + lv =kmem_alloc_large (buf_size,KM_SLEEP |KM_NOFS );memset (lv,0 ,xlog_cil_iovec_space (niovecs)); lv->lv_item = lip;
Signature · 1 line
2.15.1
Quoted 81 lines · Dave Chinner
From: Dave Chinner <[email protected]>
When using large directory blocks, we regularly see memory allocations of >64k being made for the shadow log vector buffer. When we are under memory pressure,
kmalloc()may not be able to find contiguous memory chunks large enough to satisfy these allocations easily, and if memory is fragmented we can potentially stall here.TO avoid this problem, switch the log vector buffer allocation to use
kmem_alloc_large(). This will allow failed allocations to fall back to vmalloc and so remove the dependency on large contiguous regions of memory being available. This should prevent slowdowns and potential stalls when memory is low and/or fragmented.Signed-off-by Dave Chinner <[email protected]>--- fs/xfs/kmem.c | 6 +++--- fs/xfs/kmem.h | 8 +++++++- fs/xfs/xfs_log_cil.c | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-)fs/xfs/kmem.c +3
-3@@ -46,13 +46,13 @@ kmem_alloc(size_t size, xfs_km_flags_t flags) }void * -kmem_zalloc_large (size_t size,xfs_km_flags_t flags) +kmem_alloc_large (size_t size,xfs_km_flags_t flags) {unsigned nofs_flag =0 ;void *ptr;gfp_t lflags; - ptr =kmem_zalloc (size, flags |KM_MAYFAIL ); + ptr =kmem_alloc (size, flags |KM_MAYFAIL );if (ptr)return ptr;@@ -67,7 +67,7 @@ kmem_zalloc_large(size_t size, xfs_km_flags_t flags) nofs_flag =memalloc_nofs_save (); lflags =kmem_flags_convert (flags); - ptr =__vmalloc (size, lflags | __GFP_ZERO,PAGE_KERNEL ); + ptr =__vmalloc (size, lflags,PAGE_KERNEL );if (flags &KM_NOFS )memalloc_nofs_restore (nofs_flag);fs/xfs/kmem.h +7
-1@@ -71,7 +71,7 @@ kmem_flags_convert(xfs_km_flags_t flags) }extern void *kmem_alloc (size_t ,xfs_km_flags_t ); -extern void *kmem_zalloc_large (size_t size,xfs_km_flags_t ); +extern void *kmem_alloc_large (size_t size,xfs_km_flags_t );extern void *kmem_realloc (const void *,size_t ,xfs_km_flags_t );static inline void kmem_free (const void *ptr) {@@ -85,6 +85,12 @@ kmem_zalloc(size_t size, xfs_km_flags_t flags)return kmem_alloc (size, flags |KM_ZERO ); } +static inline void * +kmem_zalloc_large (size_t size,xfs_km_flags_t flags) +{ +return kmem_alloc_large (size, flags |KM_ZERO ); +} +/* * Zone interfaces */ fs/xfs/xfs_log_cil.c +0
-0
fs/xfs/xfs_log_cil.c xlog_cil_alloc_shadow_bufs( · line 205
Quoted 5 lines
fs/xfs/xfs_log_cil.c +1
-1@@ -202,7 +202,7 @@ xlog_cil_alloc_shadow_bufs(*/ kmem_free (lip->li_lv_shadow); - lv =kmem_alloc (buf_size,KM_SLEEP |KM_NOFS ); + lv =kmem_alloc_large (buf_size,KM_SLEEP |KM_NOFS );
"KM_SLEEP | KM_NOFS", will fix it on the way in.
I wonder about expanding the uses of vmalloc space, but otoh stalling the log seems like a worse idea...
Looks ok enough to give it a spin,
--D
Quoted 10 lines
fs/xfs/xfs_log_cil.c +0
-0memset (lv,0 ,xlog_cil_iovec_space (niovecs)); lv->lv_item = lip;Signature · 6 lines
2.15.1 -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 16 lines · Darrick J. Wong
Quoted 15 lines · Dave Chinner
From: Dave Chinner <[email protected]>
When using large directory blocks, we regularly see memory allocations of >64k being made for the shadow log vector buffer. When we are under memory pressure,
kmalloc()may not be able to find contiguous memory chunks large enough to satisfy these allocations easily, and if memory is fragmented we can potentially stall here.TO avoid this problem, switch the log vector buffer allocation to use
kmem_alloc_large(). This will allow failed allocations to fall back to vmalloc and so remove the dependency on large contiguous regions of memory being available. This should prevent slowdowns and potential stalls when memory is low and/or fragmented.Signed-off-by Dave Chinner <[email protected]>
.....
Quoted 8 lines
Quoted 8 lines
fs/xfs/xfs_log_cil.c +0
-0@@ -202,7 +202,7 @@ xlog_cil_alloc_shadow_bufs(*/ kmem_free (lip->li_lv_shadow);
Quoted 4 lines
fs/xfs/xfs_log_cil.c xlog_cil_alloc_shadow_bufs( · line 205
Quoted 2 lines
fs/xfs/xfs_log_cil.c +1
-1- lv =kmem_alloc (buf_size,KM_SLEEP |KM_NOFS ); + lv =kmem_alloc_large (buf_size,KM_SLEEP |KM_NOFS );"
KM_SLEEP|KM_NOFS", will fix it on the way in.
*nod*
Quoted 2 lines
I wonder about expanding the uses of vmalloc space, but otoh stalling the log seems like a worse idea...
We'll only see this happen when memory is really low and/or fragmented, so i don't think it's a problem at all. I could trigger warnings without this patch - they disappear with this patch and the system seemed more responsive under equivalent loading. That's entirely subjective, but it's so hard to consistently drive the system into the severe memory shortages and reclaim failures that trigger this problem that's the best I was able to do...
Quoted 2 lines
Looks ok enough to give it a spin,
Reviewed-by Darrick J. Wong <[email protected]>
Thanks!
-Dave.
Signature · 2 lines
Dave Chinner [email protected]