xfs: Remove kmem_zone_alloc() usage
authorCarlos Maiolino <cmaiolino@redhat.com>
Wed, 22 Jul 2020 16:23:04 +0000 (09:23 -0700)
committerDarrick J. Wong <darrick.wong@oracle.com>
Wed, 29 Jul 2020 03:24:14 +0000 (20:24 -0700)
Use kmem_cache_alloc() directly.

All kmem_zone_alloc() users pass 0 as flags, which are translated into:
GFP_KERNEL | __GFP_NOWARN, and kmem_zone_alloc() loops forever until the
allocation succeeds.

We can use __GFP_NOFAIL to tell the allocator to loop forever rather
than doing it ourself, and because the allocation will never fail, we do
not need to use __GFP_NOWARN anymore. Hence, all callers can be
converted to use GFP_KERNEL | __GFP_NOFAIL

Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
[darrick: add a comment back in about nofail]
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
fs/xfs/libxfs/xfs_alloc.c
fs/xfs/libxfs/xfs_bmap.c
fs/xfs/xfs_icache.c

index bf4d07e5c73ffdbbecff52faf53d65b36b499d55..852b536551b53ef6948eee4308045b420390ff36 100644 (file)
@@ -2462,7 +2462,8 @@ xfs_defer_agfl_block(
        ASSERT(xfs_bmap_free_item_zone != NULL);
        ASSERT(oinfo != NULL);
 
-       new = kmem_zone_alloc(xfs_bmap_free_item_zone, 0);
+       new = kmem_cache_alloc(xfs_bmap_free_item_zone,
+                              GFP_KERNEL | __GFP_NOFAIL);
        new->xefi_startblock = XFS_AGB_TO_FSB(mp, agno, agbno);
        new->xefi_blockcount = 1;
        new->xefi_oinfo = *oinfo;
index 667cdd0dfdf4a3e2317025bf6c6847fc9fd34c52..fd5c0d669d0d7a0544a7179c6b198308f29a787f 100644 (file)
@@ -553,7 +553,8 @@ __xfs_bmap_add_free(
 #endif
        ASSERT(xfs_bmap_free_item_zone != NULL);
 
-       new = kmem_zone_alloc(xfs_bmap_free_item_zone, 0);
+       new = kmem_cache_alloc(xfs_bmap_free_item_zone,
+                              GFP_KERNEL | __GFP_NOFAIL);
        new->xefi_startblock = bno;
        new->xefi_blockcount = (xfs_extlen_t)len;
        if (oinfo)
index 3c6e936d2f9923ea7fa48a60a30e32607aaeba14..101028ebb571890e6ed941fb8d8767ee934f6abe 100644 (file)
@@ -37,13 +37,11 @@ xfs_inode_alloc(
        struct xfs_inode        *ip;
 
        /*
-        * if this didn't occur in transactions, we could use
-        * KM_MAYFAIL and return NULL here on ENOMEM. Set the
-        * code up to do this anyway.
+        * XXX: If this didn't occur in transactions, we could drop GFP_NOFAIL
+        * and return NULL here on ENOMEM.
         */
-       ip = kmem_zone_alloc(xfs_inode_zone, 0);
-       if (!ip)
-               return NULL;
+       ip = kmem_cache_alloc(xfs_inode_zone, GFP_KERNEL | __GFP_NOFAIL);
+
        if (inode_init_always(mp->m_super, VFS_I(ip))) {
                kmem_cache_free(xfs_inode_zone, ip);
                return NULL;