Message ID | 20191120104425.407213-3-cmaiolino@redhat.com (mailing list archive) |
---|---|
State | Deferred, archived |
Headers | show |
Series | Remove/convert more kmem_* wrappers | expand |
On Wed, Nov 20, 2019 at 11:44:22AM +0100, Carlos Maiolino wrote: > __GFP_NOFAIL can be used for an infinite retry + congestion_wait, so we > can use kmem_cache_alloc() directly. > > Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com> Looks ok, Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com> --D > --- > V2: > - Rephrase commit log to explain why it's ok to remove the retry > loop from kmem_zone_alloc(). > > fs/xfs/kmem.c | 21 --------------------- > fs/xfs/kmem.h | 2 -- > fs/xfs/libxfs/xfs_alloc.c | 3 ++- > fs/xfs/libxfs/xfs_bmap.c | 3 ++- > fs/xfs/xfs_icache.c | 2 +- > fs/xfs/xfs_trace.h | 1 - > 6 files changed, 5 insertions(+), 27 deletions(-) > > diff --git a/fs/xfs/kmem.c b/fs/xfs/kmem.c > index 1da94237a8cf..2644fdaa0549 100644 > --- a/fs/xfs/kmem.c > +++ b/fs/xfs/kmem.c > @@ -115,24 +115,3 @@ kmem_realloc(const void *old, size_t newsize, xfs_km_flags_t flags) > congestion_wait(BLK_RW_ASYNC, HZ/50); > } while (1); > } > - > -void * > -kmem_zone_alloc(kmem_zone_t *zone, xfs_km_flags_t flags) > -{ > - int retries = 0; > - gfp_t lflags = kmem_flags_convert(flags); > - void *ptr; > - > - trace_kmem_zone_alloc(kmem_cache_size(zone), flags, _RET_IP_); > - do { > - ptr = kmem_cache_alloc(zone, lflags); > - if (ptr || (flags & KM_MAYFAIL)) > - return ptr; > - if (!(++retries % 100)) > - xfs_err(NULL, > - "%s(%u) possible memory allocation deadlock in %s (mode:0x%x)", > - current->comm, current->pid, > - __func__, lflags); > - congestion_wait(BLK_RW_ASYNC, HZ/50); > - } while (1); > -} > diff --git a/fs/xfs/kmem.h b/fs/xfs/kmem.h > index 3242de676808..7e4ad73771ce 100644 > --- a/fs/xfs/kmem.h > +++ b/fs/xfs/kmem.h > @@ -76,8 +76,6 @@ kmem_zalloc_large(size_t size, xfs_km_flags_t flags) > #define kmem_zone kmem_cache > #define kmem_zone_t struct kmem_cache > > -extern void *kmem_zone_alloc(kmem_zone_t *, xfs_km_flags_t); > - > static inline struct page * > kmem_to_page(void *addr) > { > diff --git a/fs/xfs/libxfs/xfs_alloc.c b/fs/xfs/libxfs/xfs_alloc.c > index 675613c7bacb..42cae87bdd2d 100644 > --- a/fs/xfs/libxfs/xfs_alloc.c > +++ b/fs/xfs/libxfs/xfs_alloc.c > @@ -2351,7 +2351,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; > diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c > index 9fbdca183465..37596e49b92e 100644 > --- a/fs/xfs/libxfs/xfs_bmap.c > +++ b/fs/xfs/libxfs/xfs_bmap.c > @@ -554,7 +554,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) > diff --git a/fs/xfs/xfs_icache.c b/fs/xfs/xfs_icache.c > index 950e8a51ec66..985f48e3795f 100644 > --- a/fs/xfs/xfs_icache.c > +++ b/fs/xfs/xfs_icache.c > @@ -40,7 +40,7 @@ xfs_inode_alloc( > * KM_MAYFAIL and return NULL here on ENOMEM. Set the > * code up to do this anyway. > */ > - ip = kmem_zone_alloc(xfs_inode_zone, 0); > + ip = kmem_cache_alloc(xfs_inode_zone, GFP_KERNEL | __GFP_NOFAIL); > if (!ip) > return NULL; > if (inode_init_always(mp->m_super, VFS_I(ip))) { > diff --git a/fs/xfs/xfs_trace.h b/fs/xfs/xfs_trace.h > index c13bb3655e48..192f499ccd7e 100644 > --- a/fs/xfs/xfs_trace.h > +++ b/fs/xfs/xfs_trace.h > @@ -3571,7 +3571,6 @@ DEFINE_KMEM_EVENT(kmem_alloc); > DEFINE_KMEM_EVENT(kmem_alloc_io); > DEFINE_KMEM_EVENT(kmem_alloc_large); > DEFINE_KMEM_EVENT(kmem_realloc); > -DEFINE_KMEM_EVENT(kmem_zone_alloc); > > #endif /* _TRACE_XFS_H */ > > -- > 2.23.0 >
diff --git a/fs/xfs/kmem.c b/fs/xfs/kmem.c index 1da94237a8cf..2644fdaa0549 100644 --- a/fs/xfs/kmem.c +++ b/fs/xfs/kmem.c @@ -115,24 +115,3 @@ kmem_realloc(const void *old, size_t newsize, xfs_km_flags_t flags) congestion_wait(BLK_RW_ASYNC, HZ/50); } while (1); } - -void * -kmem_zone_alloc(kmem_zone_t *zone, xfs_km_flags_t flags) -{ - int retries = 0; - gfp_t lflags = kmem_flags_convert(flags); - void *ptr; - - trace_kmem_zone_alloc(kmem_cache_size(zone), flags, _RET_IP_); - do { - ptr = kmem_cache_alloc(zone, lflags); - if (ptr || (flags & KM_MAYFAIL)) - return ptr; - if (!(++retries % 100)) - xfs_err(NULL, - "%s(%u) possible memory allocation deadlock in %s (mode:0x%x)", - current->comm, current->pid, - __func__, lflags); - congestion_wait(BLK_RW_ASYNC, HZ/50); - } while (1); -} diff --git a/fs/xfs/kmem.h b/fs/xfs/kmem.h index 3242de676808..7e4ad73771ce 100644 --- a/fs/xfs/kmem.h +++ b/fs/xfs/kmem.h @@ -76,8 +76,6 @@ kmem_zalloc_large(size_t size, xfs_km_flags_t flags) #define kmem_zone kmem_cache #define kmem_zone_t struct kmem_cache -extern void *kmem_zone_alloc(kmem_zone_t *, xfs_km_flags_t); - static inline struct page * kmem_to_page(void *addr) { diff --git a/fs/xfs/libxfs/xfs_alloc.c b/fs/xfs/libxfs/xfs_alloc.c index 675613c7bacb..42cae87bdd2d 100644 --- a/fs/xfs/libxfs/xfs_alloc.c +++ b/fs/xfs/libxfs/xfs_alloc.c @@ -2351,7 +2351,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; diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index 9fbdca183465..37596e49b92e 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -554,7 +554,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) diff --git a/fs/xfs/xfs_icache.c b/fs/xfs/xfs_icache.c index 950e8a51ec66..985f48e3795f 100644 --- a/fs/xfs/xfs_icache.c +++ b/fs/xfs/xfs_icache.c @@ -40,7 +40,7 @@ xfs_inode_alloc( * KM_MAYFAIL and return NULL here on ENOMEM. Set the * code up to do this anyway. */ - ip = kmem_zone_alloc(xfs_inode_zone, 0); + ip = kmem_cache_alloc(xfs_inode_zone, GFP_KERNEL | __GFP_NOFAIL); if (!ip) return NULL; if (inode_init_always(mp->m_super, VFS_I(ip))) { diff --git a/fs/xfs/xfs_trace.h b/fs/xfs/xfs_trace.h index c13bb3655e48..192f499ccd7e 100644 --- a/fs/xfs/xfs_trace.h +++ b/fs/xfs/xfs_trace.h @@ -3571,7 +3571,6 @@ DEFINE_KMEM_EVENT(kmem_alloc); DEFINE_KMEM_EVENT(kmem_alloc_io); DEFINE_KMEM_EVENT(kmem_alloc_large); DEFINE_KMEM_EVENT(kmem_realloc); -DEFINE_KMEM_EVENT(kmem_zone_alloc); #endif /* _TRACE_XFS_H */
__GFP_NOFAIL can be used for an infinite retry + congestion_wait, so we can use kmem_cache_alloc() directly. Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com> --- V2: - Rephrase commit log to explain why it's ok to remove the retry loop from kmem_zone_alloc(). fs/xfs/kmem.c | 21 --------------------- fs/xfs/kmem.h | 2 -- fs/xfs/libxfs/xfs_alloc.c | 3 ++- fs/xfs/libxfs/xfs_bmap.c | 3 ++- fs/xfs/xfs_icache.c | 2 +- fs/xfs/xfs_trace.h | 1 - 6 files changed, 5 insertions(+), 27 deletions(-)