Linux Btrfs filesystem development
 help / color / mirror / Atom feed
* [PATCH 0/2] Extent buffer allocation helpers cleanup
@ 2025-02-26  8:22 David Sterba
  2025-02-26  8:22 ` [PATCH 1/2] btrfs: don't pass nodesize to __alloc_extent_buffer() David Sterba
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: David Sterba @ 2025-02-26  8:22 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba

There used to be a reason to have an eb allocation with arbitrary
nodesize due to selftests but this does not seem to be necessary
anymore.

David Sterba (2):
  btrfs: don't pass nodesize to __alloc_extent_buffer()
  btrfs: merge alloc_dummy_extent_buffer() helpers

 fs/btrfs/extent_io.c             | 26 +++++++++-----------------
 fs/btrfs/extent_io.h             |  2 --
 fs/btrfs/tests/extent-io-tests.c |  6 +++---
 3 files changed, 12 insertions(+), 22 deletions(-)

-- 
2.47.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] btrfs: don't pass nodesize to __alloc_extent_buffer()
  2025-02-26  8:22 [PATCH 0/2] Extent buffer allocation helpers cleanup David Sterba
@ 2025-02-26  8:22 ` David Sterba
  2025-02-26  8:22 ` [PATCH 2/2] btrfs: merge alloc_dummy_extent_buffer() helpers David Sterba
  2025-02-26 10:30 ` [PATCH 0/2] Extent buffer allocation helpers cleanup Johannes Thumshirn
  2 siblings, 0 replies; 4+ messages in thread
From: David Sterba @ 2025-02-26  8:22 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba

All callers pass a valid fs_info so we can read the nodesize from that
instead of passing it as parameter.

Signed-off-by: David Sterba <dsterba@suse.com>
---
 fs/btrfs/extent_io.c             | 20 +++++++++-----------
 fs/btrfs/extent_io.h             |  2 +-
 fs/btrfs/tests/extent-io-tests.c |  6 +++---
 3 files changed, 13 insertions(+), 15 deletions(-)

diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 7b0aa332aedc..6ba332dcb7dc 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -2652,15 +2652,14 @@ static inline void btrfs_release_extent_buffer(struct extent_buffer *eb)
 	kmem_cache_free(extent_buffer_cache, eb);
 }
 
-static struct extent_buffer *
-__alloc_extent_buffer(struct btrfs_fs_info *fs_info, u64 start,
-		      unsigned long len)
+static struct extent_buffer *__alloc_extent_buffer(struct btrfs_fs_info *fs_info,
+						   u64 start)
 {
 	struct extent_buffer *eb = NULL;
 
 	eb = kmem_cache_zalloc(extent_buffer_cache, GFP_NOFS|__GFP_NOFAIL);
 	eb->start = start;
-	eb->len = len;
+	eb->len = fs_info->nodesize;
 	eb->fs_info = fs_info;
 	init_rwsem(&eb->lock);
 
@@ -2669,7 +2668,7 @@ __alloc_extent_buffer(struct btrfs_fs_info *fs_info, u64 start,
 	spin_lock_init(&eb->refs_lock);
 	atomic_set(&eb->refs, 1);
 
-	ASSERT(len <= BTRFS_MAX_METADATA_BLOCKSIZE);
+	ASSERT(eb->len <= BTRFS_MAX_METADATA_BLOCKSIZE);
 
 	return eb;
 }
@@ -2680,7 +2679,7 @@ struct extent_buffer *btrfs_clone_extent_buffer(const struct extent_buffer *src)
 	int num_folios = num_extent_folios(src);
 	int ret;
 
-	new = __alloc_extent_buffer(src->fs_info, src->start, src->len);
+	new = __alloc_extent_buffer(src->fs_info, src->start);
 	if (new == NULL)
 		return NULL;
 
@@ -2714,13 +2713,13 @@ struct extent_buffer *btrfs_clone_extent_buffer(const struct extent_buffer *src)
 }
 
 struct extent_buffer *__alloc_dummy_extent_buffer(struct btrfs_fs_info *fs_info,
-						  u64 start, unsigned long len)
+						  u64 start)
 {
 	struct extent_buffer *eb;
 	int num_folios = 0;
 	int ret;
 
-	eb = __alloc_extent_buffer(fs_info, start, len);
+	eb = __alloc_extent_buffer(fs_info, start);
 	if (!eb)
 		return NULL;
 
@@ -2754,7 +2753,7 @@ struct extent_buffer *__alloc_dummy_extent_buffer(struct btrfs_fs_info *fs_info,
 struct extent_buffer *alloc_dummy_extent_buffer(struct btrfs_fs_info *fs_info,
 						u64 start)
 {
-	return __alloc_dummy_extent_buffer(fs_info, start, fs_info->nodesize);
+	return __alloc_dummy_extent_buffer(fs_info, start);
 }
 
 static void check_buffer_tree_ref(struct extent_buffer *eb)
@@ -3031,7 +3030,6 @@ static int attach_eb_folio_to_filemap(struct extent_buffer *eb, int i,
 struct extent_buffer *alloc_extent_buffer(struct btrfs_fs_info *fs_info,
 					  u64 start, u64 owner_root, int level)
 {
-	unsigned long len = fs_info->nodesize;
 	int num_folios;
 	int attached = 0;
 	struct extent_buffer *eb;
@@ -3060,7 +3058,7 @@ struct extent_buffer *alloc_extent_buffer(struct btrfs_fs_info *fs_info,
 	if (eb)
 		return eb;
 
-	eb = __alloc_extent_buffer(fs_info, start, len);
+	eb = __alloc_extent_buffer(fs_info, start);
 	if (!eb)
 		return ERR_PTR(-ENOMEM);
 
diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h
index 6c5328bfabc2..3413a34585c8 100644
--- a/fs/btrfs/extent_io.h
+++ b/fs/btrfs/extent_io.h
@@ -253,7 +253,7 @@ void clear_folio_extent_mapped(struct folio *folio);
 struct extent_buffer *alloc_extent_buffer(struct btrfs_fs_info *fs_info,
 					  u64 start, u64 owner_root, int level);
 struct extent_buffer *__alloc_dummy_extent_buffer(struct btrfs_fs_info *fs_info,
-						  u64 start, unsigned long len);
+						  u64 start);
 struct extent_buffer *alloc_dummy_extent_buffer(struct btrfs_fs_info *fs_info,
 						u64 start);
 struct extent_buffer *btrfs_clone_extent_buffer(const struct extent_buffer *src);
diff --git a/fs/btrfs/tests/extent-io-tests.c b/fs/btrfs/tests/extent-io-tests.c
index 0a2dbfaaf49e..5847cbdc1e90 100644
--- a/fs/btrfs/tests/extent-io-tests.c
+++ b/fs/btrfs/tests/extent-io-tests.c
@@ -525,7 +525,7 @@ static int test_eb_bitmaps(u32 sectorsize, u32 nodesize)
 		goto out;
 	}
 
-	eb = __alloc_dummy_extent_buffer(fs_info, 0, nodesize);
+	eb = __alloc_dummy_extent_buffer(fs_info, 0);
 	if (!eb) {
 		test_std_err(TEST_ALLOC_ROOT);
 		ret = -ENOMEM;
@@ -542,7 +542,7 @@ static int test_eb_bitmaps(u32 sectorsize, u32 nodesize)
 	 * Test again for case where the tree block is sectorsize aligned but
 	 * not nodesize aligned.
 	 */
-	eb = __alloc_dummy_extent_buffer(fs_info, sectorsize, nodesize);
+	eb = __alloc_dummy_extent_buffer(fs_info, sectorsize);
 	if (!eb) {
 		test_std_err(TEST_ALLOC_ROOT);
 		ret = -ENOMEM;
@@ -730,7 +730,7 @@ static int test_eb_mem_ops(u32 sectorsize, u32 nodesize)
 		goto out;
 	}
 
-	eb = __alloc_dummy_extent_buffer(fs_info, SZ_1M, nodesize);
+	eb = __alloc_dummy_extent_buffer(fs_info, SZ_1M);
 	if (!eb) {
 		test_std_err(TEST_ALLOC_EXTENT_BUFFER);
 		ret = -ENOMEM;
-- 
2.47.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] btrfs: merge alloc_dummy_extent_buffer() helpers
  2025-02-26  8:22 [PATCH 0/2] Extent buffer allocation helpers cleanup David Sterba
  2025-02-26  8:22 ` [PATCH 1/2] btrfs: don't pass nodesize to __alloc_extent_buffer() David Sterba
@ 2025-02-26  8:22 ` David Sterba
  2025-02-26 10:30 ` [PATCH 0/2] Extent buffer allocation helpers cleanup Johannes Thumshirn
  2 siblings, 0 replies; 4+ messages in thread
From: David Sterba @ 2025-02-26  8:22 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba

After previous patch removing nodesize from parameters,
__alloc_dummy_extent_buffer() and alloc_dummy_extent_buffer() are
identical so we can drop one.

Signed-off-by: David Sterba <dsterba@suse.com>
---
 fs/btrfs/extent_io.c             | 10 ++--------
 fs/btrfs/extent_io.h             |  2 --
 fs/btrfs/tests/extent-io-tests.c |  6 +++---
 3 files changed, 5 insertions(+), 13 deletions(-)

diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 6ba332dcb7dc..9cefe6030335 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -2712,8 +2712,8 @@ struct extent_buffer *btrfs_clone_extent_buffer(const struct extent_buffer *src)
 	return new;
 }
 
-struct extent_buffer *__alloc_dummy_extent_buffer(struct btrfs_fs_info *fs_info,
-						  u64 start)
+struct extent_buffer *alloc_dummy_extent_buffer(struct btrfs_fs_info *fs_info,
+						u64 start)
 {
 	struct extent_buffer *eb;
 	int num_folios = 0;
@@ -2750,12 +2750,6 @@ struct extent_buffer *__alloc_dummy_extent_buffer(struct btrfs_fs_info *fs_info,
 	return NULL;
 }
 
-struct extent_buffer *alloc_dummy_extent_buffer(struct btrfs_fs_info *fs_info,
-						u64 start)
-{
-	return __alloc_dummy_extent_buffer(fs_info, start);
-}
-
 static void check_buffer_tree_ref(struct extent_buffer *eb)
 {
 	int refs;
diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h
index 3413a34585c8..ae0c04019a7e 100644
--- a/fs/btrfs/extent_io.h
+++ b/fs/btrfs/extent_io.h
@@ -252,8 +252,6 @@ void clear_folio_extent_mapped(struct folio *folio);
 
 struct extent_buffer *alloc_extent_buffer(struct btrfs_fs_info *fs_info,
 					  u64 start, u64 owner_root, int level);
-struct extent_buffer *__alloc_dummy_extent_buffer(struct btrfs_fs_info *fs_info,
-						  u64 start);
 struct extent_buffer *alloc_dummy_extent_buffer(struct btrfs_fs_info *fs_info,
 						u64 start);
 struct extent_buffer *btrfs_clone_extent_buffer(const struct extent_buffer *src);
diff --git a/fs/btrfs/tests/extent-io-tests.c b/fs/btrfs/tests/extent-io-tests.c
index 5847cbdc1e90..74aca7180a5a 100644
--- a/fs/btrfs/tests/extent-io-tests.c
+++ b/fs/btrfs/tests/extent-io-tests.c
@@ -525,7 +525,7 @@ static int test_eb_bitmaps(u32 sectorsize, u32 nodesize)
 		goto out;
 	}
 
-	eb = __alloc_dummy_extent_buffer(fs_info, 0);
+	eb = alloc_dummy_extent_buffer(fs_info, 0);
 	if (!eb) {
 		test_std_err(TEST_ALLOC_ROOT);
 		ret = -ENOMEM;
@@ -542,7 +542,7 @@ static int test_eb_bitmaps(u32 sectorsize, u32 nodesize)
 	 * Test again for case where the tree block is sectorsize aligned but
 	 * not nodesize aligned.
 	 */
-	eb = __alloc_dummy_extent_buffer(fs_info, sectorsize);
+	eb = alloc_dummy_extent_buffer(fs_info, sectorsize);
 	if (!eb) {
 		test_std_err(TEST_ALLOC_ROOT);
 		ret = -ENOMEM;
@@ -730,7 +730,7 @@ static int test_eb_mem_ops(u32 sectorsize, u32 nodesize)
 		goto out;
 	}
 
-	eb = __alloc_dummy_extent_buffer(fs_info, SZ_1M);
+	eb = alloc_dummy_extent_buffer(fs_info, SZ_1M);
 	if (!eb) {
 		test_std_err(TEST_ALLOC_EXTENT_BUFFER);
 		ret = -ENOMEM;
-- 
2.47.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] Extent buffer allocation helpers cleanup
  2025-02-26  8:22 [PATCH 0/2] Extent buffer allocation helpers cleanup David Sterba
  2025-02-26  8:22 ` [PATCH 1/2] btrfs: don't pass nodesize to __alloc_extent_buffer() David Sterba
  2025-02-26  8:22 ` [PATCH 2/2] btrfs: merge alloc_dummy_extent_buffer() helpers David Sterba
@ 2025-02-26 10:30 ` Johannes Thumshirn
  2 siblings, 0 replies; 4+ messages in thread
From: Johannes Thumshirn @ 2025-02-26 10:30 UTC (permalink / raw)
  To: David Sterba, linux-btrfs@vger.kernel.org

Looks good to me,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-02-26 10:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-26  8:22 [PATCH 0/2] Extent buffer allocation helpers cleanup David Sterba
2025-02-26  8:22 ` [PATCH 1/2] btrfs: don't pass nodesize to __alloc_extent_buffer() David Sterba
2025-02-26  8:22 ` [PATCH 2/2] btrfs: merge alloc_dummy_extent_buffer() helpers David Sterba
2025-02-26 10:30 ` [PATCH 0/2] Extent buffer allocation helpers cleanup Johannes Thumshirn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox