# \[PATCH -next v4\] bcache: Use DEFINE\_MUTEX() for mutex lock

- Subsystems: BCACHE (BLOCK LAYER CACHE), THE REST
- Maintainers: Coly Li, Kent Overstreet, Linus Torvalds
- List: linux-bcache
- 3 messages, 2 authors
- Page: https://ratatoskr.run/linux-bcache/2021/05/6358193/t

## \[PATCH -next v4\] bcache: Use DEFINE\_MUTEX() for mutex lock

- From: Zheng Yongjun \<hidden\>
- Date: 2021-05-05 10:53:15 
- Message: https://ratatoskr.run/linux-bcache/2021/05/6358193.md

```text
Mutex lock can be initialized automatically with DEFINE_MUTEX() rather
than explicitly calling mutex_init().

This patch will reduce the size of bcache.ko about 16 bytes, the
reason as follows:

Though this patch will increase the size of .data segment about 32
bytes, it will also reduce the size of .init.text and
.rodata.str1.1(at x86_64), .rodata_str1.8(at arm64) total about 48
bytes which reduce the size more than .data segment;

Here is the statistics:
Sections: (arm64 platform)
Idx name                size
-.init.text             00000240
+.init.text             00000228

-.rodata.str1.8	000012cd
+.rodata.str1.8	000012b5

-.data                  00000c60
+.data                  00000c80

Sections: (x86 platform)
Idx name                size
-.init.text             000001d9
+.init.text             000001bf

-.rodata.str1.1	00000c80
+.rodata.str1.1	00000c6d

-.data                  00000cc0
+.data                  00000ce0

Reported-by: Hulk Robot <redacted>
Signed-off-by: Zheng Yongjun <redacted>
---

v4:
- change commit log, delete bss information at commit description.
v3:
- change commit log, delete statistic about .bss segment.
v2:
- add commit log about the reason why bcache.ko size reduced.
---
 drivers/md/bcache/super.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
index 03e1fe4de53d..3635f454309e 100644
--- a/drivers/md/bcache/super.c
+++ b/drivers/md/bcache/super.c
@@ -40,7 +40,7 @@ static const char invalid_uuid[] = {
 };
 
 static struct kobject *bcache_kobj;
-struct mutex bch_register_lock;
+DEFINE_MUTEX(bch_register_lock);
 bool bcache_is_reboot;
 LIST_HEAD(bch_cache_sets);
 static LIST_HEAD(uncached_devices);
@@ -2869,7 +2869,6 @@ static int __init bcache_init(void)
 
 	check_module_parameters();
 
-	mutex_init(&bch_register_lock);
 	init_waitqueue_head(&unregister_wait);
 	register_reboot_notifier(&reboot);
 
-- 
2.25.1

```

## Re: \[PATCH -next v4\] bcache: Use DEFINE\_MUTEX() for mutex lock

- From: Coly Li \<hidden\>
- Date: 2021-05-06 03:27:12 
- Message: https://ratatoskr.run/linux-bcache/2021/05/6359492.md

```text
On 5/5/21 7:06 PM, Zheng Yongjun wrote:
> Mutex lock can be initialized automatically with DEFINE_MUTEX() rather
> than explicitly calling mutex_init().
> 
> This patch will reduce the size of bcache.ko about 16 bytes, the
> reason as follows:
> 
> Though this patch will increase the size of .data segment about 32
> bytes, it will also reduce the size of .init.text and
> .rodata.str1.1(at x86_64), .rodata_str1.8(at arm64) total about 48
> bytes which reduce the size more than .data segment;
> 
> Here is the statistics:
> Sections: (arm64 platform)
> Idx name                size
> -.init.text             00000240
> +.init.text             00000228
> 
> -.rodata.str1.8	000012cd
> +.rodata.str1.8	000012b5
> 
> -.data                  00000c60
> +.data                  00000c80
> 
> Sections: (x86 platform)
> Idx name                size
> -.init.text             000001d9
> +.init.text             000001bf
> 
> -.rodata.str1.1	00000c80
> +.rodata.str1.1	00000c6d
> 
> -.data                  00000cc0
> +.data                  00000ce0
> 
> Reported-by: Hulk Robot <redacted>
> Signed-off-by: Zheng Yongjun <redacted>

Added in my for-test queue.

Thanks.

Coly Li

[snipped]
```

## 答复: \[PATCH -next v4\] bcache: Use DEFINE\_MUTEX() for mutex lock

- From: zhengyongjun \<hidden\>
- Date: 2021-05-06 08:33:21 
- Message: https://ratatoskr.run/linux-bcache/2021/05/6359654.md

```text
I've been on a business trip some time ago and didn't do upstream work. Thanks for your patience:)

-----邮件原件-----
发件人: Coly Li [mailto:colyli@suse.de] 
发送时间: 2021年5月6日 11:27
收件人: zhengyongjun [ref]
抄送: pmail_hulkci [ref]; kent.overstreet@gmail.com; linux-bcache@vger.kernel.org; linux-kernel@vger.kernel.org
主题: Re: [PATCH -next v4] bcache: Use DEFINE_MUTEX() for mutex lock

On 5/5/21 7:06 PM, Zheng Yongjun wrote:
> Mutex lock can be initialized automatically with DEFINE_MUTEX() rather 
> than explicitly calling mutex_init().
> 
> This patch will reduce the size of bcache.ko about 16 bytes, the 
> reason as follows:
> 
> Though this patch will increase the size of .data segment about 32 
> bytes, it will also reduce the size of .init.text and 
> .rodata.str1.1(at x86_64), .rodata_str1.8(at arm64) total about 48 
> bytes which reduce the size more than .data segment;
> 
> Here is the statistics:
> Sections: (arm64 platform)
> Idx name                size
> -.init.text             00000240
> +.init.text             00000228
> 
> -.rodata.str1.8	000012cd
> +.rodata.str1.8	000012b5
> 
> -.data                  00000c60
> +.data                  00000c80
> 
> Sections: (x86 platform)
> Idx name                size
> -.init.text             000001d9
> +.init.text             000001bf
> 
> -.rodata.str1.1	00000c80
> +.rodata.str1.1	00000c6d
> 
> -.data                  00000cc0
> +.data                  00000ce0
> 
> Reported-by: Hulk Robot <redacted>
> Signed-off-by: Zheng Yongjun <redacted>

Added in my for-test queue.

Thanks.

Coly Li

[snipped]
```
