xfs: Remove kmem_zalloc_large()
PATCH 1/1 xfs: Remove kmem_zalloc_large()
This patch aims to replace kmem_zalloc_large() with global kernel memory API. So, all its callers are now using kvzalloc() directly, so kmalloc() fallsback to vmalloc() automatically.
__GFP_RETRY_MAYFAIL has been set because according to memory documentation, it should be used in case kmalloc() is preferred over vmalloc().
Patch survives xfstests with large (32GiB) and small (4GiB) RAM memory amounts.
--- fs/xfs/kmem.h | 6 ------ fs/xfs/scrub/symlink.c | 4 +++- fs/xfs/xfs_acl.c | 3 ++- fs/xfs/xfs_ioctl.c | 5 +++-- fs/xfs/xfs_rtalloc.c | 3 ++- 5 files changed, 10 insertions(+), 11 deletions(-)
I'm not entirely sure passing __GFP_RETRY_MAYFAIL is the right thing to do here, but since current api attempts a kmalloc before falling back to vmalloc, it seems to be correct to pass it.
Comments? Cheers
fs/xfs/kmem.h +0 -6
@@ -71,12 +71,6 @@ 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/scrub/symlink.c +3 -1
@@ -22,11 +22,13 @@ xchk_setup_symlink( struct xfs_inode *ip) {/* Allocate the buffer without the inode lock held. */ - sc->buf =kmem_zalloc_large (XFS_SYMLINK_MAXLEN +1 ,0 ); + sc->buf =kvzalloc (XFS_SYMLINK_MAXLEN +1 , +GFP_KERNEL | __GFP_RETRY_MAYFAIL);if (!sc->buf)return -ENOMEM ;return xchk_setup_inode_contents (sc, ip,0 ); + }/* Symbolic links. */
fs/xfs/xfs_acl.c +2 -1
@@ -192,7 +192,8 @@ __xfs_set_acl(struct inode *inode, struct posix_acl *acl, int type)if (acl) { args.valuelen =XFS_ACL_SIZE (acl->a_count); - args.value =kmem_zalloc_large (args.valuelen,0 ); + args.value =kvzalloc (args.valuelen, +GFP_KERNEL | __GFP_RETRY_MAYFAIL);if (!args.value)return -ENOMEM ;xfs_acl_to_disk (args.value, acl);
fs/xfs/xfs_ioctl.c +3 -2
@@ -404,7 +404,7 @@ xfs_ioc_attr_list( context.cursor.offset))return -EINVAL ; - buffer =kmem_zalloc_large (bufsize,0 ); + buffer =kvzalloc (bufsize,GFP_KERNEL | __GFP_RETRY_MAYFAIL);if (!buffer)return -ENOMEM ;
@@ -1690,7 +1690,8 @@ xfs_ioc_getbmap(if (bmx.bmv_count >ULONG_MAX / recsize)return -ENOMEM ; - buf =kmem_zalloc_large (bmx.bmv_count *sizeof (*buf),0 ); + buf =kvzalloc (bmx.bmv_count *sizeof (*buf), +GFP_KERNEL | __GFP_RETRY_MAYFAIL);if (!buf)return -ENOMEM ;
fs/xfs/xfs_rtalloc.c +2 -1
@@ -862,7 +862,8 @@ xfs_alloc_rsum_cache(* lower bound on the minimum level with any free extents. We can * continue without the cache if it couldn't be allocated. */ - mp->m_rsum_cache =kmem_zalloc_large (rbmblocks,0 ); + mp->m_rsum_cache =kvzalloc (rbmblocks, +GFP_KERNEL | __GFP_RETRY_MAYFAIL);if (!mp->m_rsum_cache)xfs_warn (mp,"could not allocate realtime summary cache" ); }
Signature · 1 line
2.26.2
Quoted 18 lines · Carlos Maiolino
This patch aims to replace
kmem_zalloc_large()with global kernel memory API. So, all its callers are now usingkvzalloc()directly, sokmalloc()fallsback tovmalloc()automatically.
__GFP_RETRY_MAYFAILhas been set because according to memory documentation, it should be used in casekmalloc()is preferred overvmalloc().Patch survives xfstests with large (32GiB) and small (4GiB) RAM memory amounts.
Signed-off-by Carlos Maiolino <[email protected]>--- fs/xfs/kmem.h | 6 ------ fs/xfs/scrub/symlink.c | 4 +++- fs/xfs/xfs_acl.c | 3 ++- fs/xfs/xfs_ioctl.c | 5 +++-- fs/xfs/xfs_rtalloc.c | 3 ++- 5 files changed, 10 insertions(+), 11 deletions(-)
Quoted 3 lines
I'm not entirely sure passing
__GFP_RETRY_MAYFAILis the right thing to do here, but since current api attempts a kmalloc before falling back to vmalloc, it seems to be correct to pass it.
I don't think __GFP_RETRY_MAYFAIL is necessary. If the allocation is larger than ALLOC_ORDER_COSTLY (8 pages, I think) then kmalloc() will fail rather than retry forever and then it falls back to vmalloc. Hence I don't think we need to tell the kmalloc() it needs to fail large allocations if it can't make progress...
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Quoted 23 lines · Dave Chinner
Quoted 18 lines · Carlos Maiolino
This patch aims to replace
kmem_zalloc_large()with global kernel memory API. So, all its callers are now usingkvzalloc()directly, sokmalloc()fallsback tovmalloc()automatically.
__GFP_RETRY_MAYFAILhas been set because according to memory documentation, it should be used in casekmalloc()is preferred overvmalloc().Patch survives xfstests with large (32GiB) and small (4GiB) RAM memory amounts.
Signed-off-by Carlos Maiolino <[email protected]>--- fs/xfs/kmem.h | 6 ------ fs/xfs/scrub/symlink.c | 4 +++- fs/xfs/xfs_acl.c | 3 ++- fs/xfs/xfs_ioctl.c | 5 +++-- fs/xfs/xfs_rtalloc.c | 3 ++- 5 files changed, 10 insertions(+), 11 deletions(-)Quoted 3 lines
I'm not entirely sure passing
__GFP_RETRY_MAYFAILis the right thing to do here, but since current api attempts a kmalloc before falling back to vmalloc, it seems to be correct to pass it.
Quoted 7 lines
I don't think
__GFP_RETRY_MAYFAILis necessary. If the allocation is larger thanALLOC_ORDER_COSTLY(8 pages, I think) thenkmalloc()will fail rather than retry forever and then it falls back to vmalloc. Hence I don't think we need to tell thekmalloc()it needs to fail large allocations if it can't make progress...Cheers,
Thanks Dave!
If nobody has any other comment, I'll submit a version without RETRY_MAYFAIL later today.
cheers.
Quoted 6 lines
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Signature · 1 line
Carlos