Skip to contentSkip to conversation

xfs: replace kvmalloc_array with kvzalloc_objs

PATCH NAK Lalit Shankar Chowdhury 3 participants 6 messages Sep 17 – Sep 18 XFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs: replace kvmalloc_array with kvzalloc_objs

Replace kvmalloc_array() with the more concise kvzalloc_objs() implementation.

---
 fs/xfs/xfs_zone_alloc.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/xfs/xfs_zone_alloc.c +1 -2
index 28c1e48909fa..82615045aa4c 100644
@@ -1238,8 +1238,7 @@ static unsigned long *
 xfs_alloc_bucket_bitmap(
 	struct xfs_mount	*mp)
 {
-	return kvmalloc_array(BITS_TO_LONGS(mp->m_sb.sb_rgcount),
-			sizeof(unsigned long), GFP_KERNEL | __GFP_ZERO);
+	return kvzalloc_objs(unsigned long, BITS_TO_LONGS(mp->m_sb.sb_rgcount));
 }
 
 static struct xfs_zone_info *
Signature · 1 line
2.53.0
maintainer NAK
#1 lore raw
Quoted 4 lines · Lalit Shankar Chowdhury

Replace kvmalloc_array() with the more concise kvzalloc_objs() implementation.

NAK...

This is used to allocate composite objects managed through a slab cache. This is not for fundamental basic data types....

Quoted 21 lines
---
 fs/xfs/xfs_zone_alloc.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/xfs/xfs_zone_alloc.c +1 -2
index 28c1e48909fa..82615045aa4c 100644
@@ -1238,8 +1238,7 @@ static unsigned long *
 xfs_alloc_bucket_bitmap(
 	struct xfs_mount	*mp)
 {
-	return kvmalloc_array(BITS_TO_LONGS(mp->m_sb.sb_rgcount),
-			sizeof(unsigned long), GFP_KERNEL | __GFP_ZERO);
+	return kvzalloc_objs(unsigned long, BITS_TO_LONGS(mp->m_sb.sb_rgcount));
 }
 
 static struct xfs_zone_info *
Signature · 1 line
2.53.0
#2 lore raw
Quoted 10 lines · Carlos Maiolino
Quoted 4 lines · Lalit Shankar Chowdhury

Replace kvmalloc_array() with the more concise kvzalloc_objs() implementation.

NAK...

This is used to allocate composite objects managed through a slab cache. This is not for fundamental basic data types....

I don't think so. While the naming of the helper is a bit unfortunate, it is intended for allocating arrays.

But this function really should not exist, instead bitmap_alloc/free should be switched to th kvmalloc family so that it will just work for large allocations and we can kill the wrappers in XFS.

maintainer
#3 lore raw
Quoted 7 lines · Christoph Hellwig
Quoted 6 lines · Carlos Maiolino
Quoted 4 lines · Lalit Shankar Chowdhury

Replace kvmalloc_array() with the more concise kvzalloc_objs() implementation.

Quoted 7 lines
Quoted 4 lines

NAK...

This is used to allocate composite objects managed through a slab cache. This is not for fundamental basic data types....

I don't think so. While the naming of the helper is a bit unfortunate, it is intended for allocating arrays.

I see your point, but what kv(z)alloc_objs() do is essentially

kmalloc(sizeof(object type) * count, GFP)...

While I see why it's useful for composite types, I don't see the much the point of doing kvzalloc_objs(int, count)..
And still kvmalloc_array() looks a better fit in this case IMO than kvmalloc_objs().

Quoted 5 lines

But this function really should not exist, instead bitmap_alloc/free should be switched to th kvmalloc family so that it will just work for large allocations and we can kill the wrappers in XFS.

+1

maintainer
#4 lore raw
In reply to Christoph Hellwig
Quoted 12 lines · Christoph Hellwig
Quoted 10 lines · Carlos Maiolino
Quoted 4 lines · Lalit Shankar Chowdhury

Replace kvmalloc_array() with the more concise kvzalloc_objs() implementation.

NAK...

This is used to allocate composite objects managed through a slab cache. This is not for fundamental basic data types....

Quoted 7 lines

I don't think so. While the naming of the helper is a bit unfortunate, it is intended for allocating arrays.

But this function really should not exist, instead bitmap_alloc/free should be switched to th kvmalloc family so that it will just work for large allocations and we can kill the wrappers in XFS.

You meant something like this? Leaving xfs_alloc_bucket_bitmap() looks a bit better for me, to avoid overly long indentation.
I don't think there are free_bitmap_bucket though, buckets are straight kvfree()'ed.

fs/xfs/xfs_zone_alloc.c +4 -9
index 28c1e48909fa..864020603dfb 100644
@@ -1234,14 +1234,6 @@ xfs_calc_open_zones(
 	return 0;
 }
 
-static unsigned long *
-xfs_alloc_bucket_bitmap(
-	struct xfs_mount	*mp)
-{
-	return kvmalloc_array(BITS_TO_LONGS(mp->m_sb.sb_rgcount),
-			sizeof(unsigned long), GFP_KERNEL | __GFP_ZERO);
-}
-
 static struct xfs_zone_info *
 xfs_alloc_zone_info(
 	struct xfs_mount	*mp)
@@ -1260,7 +1252,10 @@ xfs_alloc_zone_info(
 	init_waitqueue_head(&zi->zi_zone_wait);
 	spin_lock_init(&zi->zi_used_buckets_lock);
 	for (i = 0; i < XFS_ZONE_USED_BUCKETS; i++) {
-		zi->zi_used_bucket_bitmap[i] = xfs_alloc_bucket_bitmap(mp);
+		zi->zi_used_bucket_bitmap[i] =
+			kvmalloc_array(BITS_TO_LONGS(mp->m_sb.sb_rgcount),
+					sizeof(unsigned long),
+					GFP_KERNEL | GFP_ZERO);
 		if (!zi->zi_used_bucket_bitmap[i])
 			goto out_free_bitmaps;
 	}
#5 lore raw
Quoted 4 lines · Carlos Maiolino

You meant something like this? Leaving xfs_alloc_bucket_bitmap() looks a bit better for me, to avoid overly long indentation.
I don't think there are free_bitmap_bucket though, buckets are straight kvfree()'ed.

No, I mean changing bitmap_*alloc* and bitmap_Free in lib/bitmap.c.