Skip to contentSkip to conversation

misc cleanup patches

PATCH In review Anand Jain 4 participants 9 messages Jul 4, 2021 – Jul 7, 2021 Btrfs file system

lore
Share & tools
lore

Anand Jain

author
#0 lore raw

cover misc cleanup patches

These patches are independent, not related.
They are miscellaneous cleanup patches.

Anand Jain (2):
btrfs: cleanup fs_devices pointer usage in btrfs_trim_fs
btrfs: change btrfs_io_bio_init inline function to macro

 fs/btrfs/extent-tree.c | 10 +++++-----
 fs/btrfs/extent_io.c   |  5 +----
 2 files changed, 6 insertions(+), 9 deletions(-)
Signature · 1 line
2.31.1
author
#1 lore raw

PATCH 1/2 btrfs: cleanup fs_devices pointer usage in btrfs_trim_fs

Drop variable
struct list_head *devices
and add new variable
struct btrfs_fs_devices *fs_devices = fs_info->fs_devices;

so that fs_devices is used at two locations within btrfs_trim_fs() function and also helps to access fs_devices->devices.

---
 fs/btrfs/extent-tree.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
fs/btrfs/extent-tree.c +5 -5
index 268ce58d4569..d5925bebd379 100644
@@ -5950,9 +5950,9 @@ static int btrfs_trim_free_extents(struct btrfs_device *device, u64 *trimmed)
  */
 int btrfs_trim_fs(struct btrfs_fs_info *fs_info, struct fstrim_range *range)
 {
+	struct btrfs_fs_devices *fs_devices = fs_info->fs_devices;
 	struct btrfs_block_group *cache = NULL;
 	struct btrfs_device *device;
-	struct list_head *devices;
 	u64 group_trimmed;
 	u64 range_end = U64_MAX;
 	u64 start;
@@ -6016,9 +6016,9 @@ int btrfs_trim_fs(struct btrfs_fs_info *fs_info, struct fstrim_range *range)
 		btrfs_warn(fs_info,
 			"failed to trim %llu block group(s), last error %d",
 			bg_failed, bg_ret);
-	mutex_lock(&fs_info->fs_devices->device_list_mutex);
-	devices = &fs_info->fs_devices->devices;
-	list_for_each_entry(device, devices, dev_list) {
+
+	mutex_lock(&fs_devices->device_list_mutex);
+	list_for_each_entry(device, &fs_devices->devices, dev_list) {
 		if (test_bit(BTRFS_DEV_STATE_MISSING, &device->dev_state))
 			continue;
 
@@ -6031,7 +6031,7 @@ int btrfs_trim_fs(struct btrfs_fs_info *fs_info, struct fstrim_range *range)
 
 		trimmed += group_trimmed;
 	}
-	mutex_unlock(&fs_info->fs_devices->device_list_mutex);
+	mutex_unlock(&fs_devices->device_list_mutex);
 
 	if (dev_failed)
 		btrfs_warn(fs_info,
Signature · 1 line
2.31.1
author
#3 lore raw

PATCH 2/2 btrfs: change btrfs_io_bio_init inline function to macro

In reply to Anand Jain

btrfs_io_bio_init() is a single line static inline function and initializes part of allocated struct btrfs_io_bio. Make it macro so that preprocessor handles it and preserve the original comments of the function.

---
 fs/btrfs/extent_io.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
fs/btrfs/extent_io.c +1 -4
index 9e81d25dea70..8ed07cffb4a4 100644
@@ -3110,10 +3110,7 @@ static void end_bio_extent_readpage(struct bio *bio)
  * new bio by bio_alloc_bioset as it does not initialize the bytes outside of
  * 'bio' because use of __GFP_ZERO is not supported.
  */
-static inline void btrfs_io_bio_init(struct btrfs_io_bio *btrfs_bio)
-{
-	memset(btrfs_bio, 0, offsetof(struct btrfs_io_bio, bio));
-}
+#define btrfs_io_bio_init(bbio)	memset(bbio, 0, offsetof(struct btrfs_io_bio, bio))
 
 /*
  * The following helpers allocate a bio. As it's backed by a bioset, it'll
Signature · 1 line
2.31.1
#4 lore raw

Re: [PATCH 2/2] btrfs: change btrfs_io_bio_init inline function to macro

Quoted 16 lines · Anand Jain

btrfs_io_bio_init() is a single line static inline function and initializes part of allocated struct btrfs_io_bio. Make it macro so that preprocessor handles it and preserve the original comments of the function.

---
 fs/btrfs/extent_io.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
fs/btrfs/extent_io.c +0 -0
index 9e81d25dea70..8ed07cffb4a4 100644
@@ -3110,10 +3110,7 @@ static void end_bio_extent_readpage(struct bio *bio)
  * new bio by bio_alloc_bioset as it does not initialize the bytes outside of

fs/btrfs/extent_io.c static void end_bio_extent_readpage(struct bio *bio) · line 3116

Quoted 10 lines
fs/btrfs/extent_io.c +1 -4
  * 'bio' because use of __GFP_ZERO is not supported.
  */
-static inline void btrfs_io_bio_init(struct btrfs_io_bio *btrfs_bio)
-{
-	memset(btrfs_bio, 0, offsetof(struct btrfs_io_bio, bio));
-}
+#define btrfs_io_bio_init(bbio)	memset(bbio, 0, offsetof(struct btrfs_io_bio, bio))
 
 /*
  * The following helpers allocate a bio. As it's backed by a bioset, it'll

What do we gain by this change? The compiler is perfectly able to inline btrfs_io_bio_init.

author
#5 lore raw

Re: [PATCH 2/2] btrfs: change btrfs_io_bio_init inline function to macro

Quoted 26 lines · Nikolay Borisov
Quoted 23 lines · Anand Jain

btrfs_io_bio_init() is a single line static inline function and initializes part of allocated struct btrfs_io_bio. Make it macro so that preprocessor handles it and preserve the original comments of the function.

---
  fs/btrfs/extent_io.c | 5 +----
  1 file changed, 1 insertion(+), 4 deletions(-)
fs/btrfs/extent_io.c +1 -4
index 9e81d25dea70..8ed07cffb4a4 100644
@@ -3110,10 +3110,7 @@ static void end_bio_extent_readpage(struct bio *bio)
   * new bio by bio_alloc_bioset as it does not initialize the bytes outside of
   * 'bio' because use of __GFP_ZERO is not supported.
   */
-static inline void btrfs_io_bio_init(struct btrfs_io_bio *btrfs_bio)
-{
-	memset(btrfs_bio, 0, offsetof(struct btrfs_io_bio, bio));
-}
+#define btrfs_io_bio_init(bbio)	memset(bbio, 0, offsetof(struct btrfs_io_bio, bio))
 
Quoted 8 lines

fs/btrfs/extent_io.c static void end_bio_extent_readpage(struct bio *bio) · line 3116

Quoted 3 lines
fs/btrfs/extent_io.c +0 -0
  /*
   * The following helpers allocate a bio. As it's backed by a bioset, it'll

What do we gain by this change? The compiler is perfectly able to inline btrfs_io_bio_init.

The gain is macro is guaranteed to be inline-ed. A function with the inline prefix isn't.

#6 lore raw

Re: [PATCH 2/2] btrfs: change btrfs_io_bio_init inline function to macro

Quoted 43 lines · Anand Jain
Quoted 30 lines · Nikolay Borisov
Quoted 27 lines · Anand Jain

btrfs_io_bio_init() is a single line static inline function and initializes
part of allocated struct btrfs_io_bio. Make it macro so that preprocessor
handles it and preserve the original comments of the function.

---
  fs/btrfs/extent_io.c | 5 +----

  1 file changed, 1 insertion(+), 4 deletions(-)
fs/btrfs/extent_io.c +0 -0
index 9e81d25dea70..8ed07cffb4a4 100644
@@ -3110,10 +3110,7 @@ static void end_bio_extent_readpage(struct bio
 *bio)
    * new bio by bio_alloc_bioset as it does not initialize the bytes

outside of
   * 'bio' because use of __GFP_ZERO is not supported. */

fs/btrfs/extent_io.c +1 -4
-static inline void btrfs_io_bio_init(struct btrfs_io_bio *btrfs_bio)
-{
-    memset(btrfs_bio, 0, offsetof(struct btrfs_io_bio, bio));
-}
+#define btrfs_io_bio_init(bbio)    memset(bbio, 0, offsetof(struct

btrfs_io_bio, bio))

Quoted 9 lines
Quoted 4 lines

    /*
   * The following helpers allocate a bio. As it's backed by a bioset, it'll

What do we gain by this change? The compiler is perfectly able to inline btrfs_io_bio_init.

Quoted 3 lines

The gain is macro is guaranteed to be inline-ed. A function with the inline prefix isn't.

In this particular case it's guaranteed that the function will be inlined.

#7 lore raw

Re: [PATCH 2/2] btrfs: change btrfs_io_bio_init inline function to macro

Quoted 5 lines · Nikolay Borisov
Quoted 3 lines

The gain is macro is guaranteed to be inline-ed. A function with the inline prefix isn't.

In this particular case it's guaranteed that the function will be inlined.

And we also get additional type safety from the function, which the macro doesn't provide.

#8 lore raw

Re: [PATCH 2/2] btrfs: change btrfs_io_bio_init inline function to macro

Quoted 9 lines · Johannes Thumshirn
Quoted 5 lines · Nikolay Borisov
Quoted 3 lines

The gain is macro is guaranteed to be inline-ed. A function with the inline prefix isn't.

In this particular case it's guaranteed that the function will be inlined.

And we also get additional type safety from the function, which the macro doesn't provide.

Yeah, using static inlines instead of macros is preferred when they're reasonably simple, like in this case.

#2 lore raw

Re: [PATCH 1/2] btrfs: cleanup fs_devices pointer usage in btrfs_trim_fs

In reply to Anand Jain
Quoted 9 lines · Anand Jain

Drop variable
struct list_head *devices
and add new variable
struct btrfs_fs_devices *fs_devices = fs_info->fs_devices;

so that fs_devices is used at two locations within btrfs_trim_fs() function and also helps to access fs_devices->devices.

Added to misc-next, thanks.