* [PATCH v2] btrfs: print-tree: Add locking status output for debug build
@ 2018-04-24 5:03 Qu Wenruo
2018-04-24 14:44 ` David Sterba
0 siblings, 1 reply; 3+ messages in thread
From: Qu Wenruo @ 2018-04-24 5:03 UTC (permalink / raw)
To: linux-btrfs
It's pretty handy if we can get debug output for locking status of an
extent buffer, specially for race related debugging.
So add the following output for btrfs_print_tree() and
btrfs_print_leaf():
- refs
- write_locks (as w:%d)
- read_locks (as r:%d)
- blocking_writers (as bw:%d)
- blocking_readers (as br:%d)
- spinning_writers (as sw:%d)
- spinning_readers (as sr:%d)
- lock_owner
- current->pid
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
changelog:
v2:
Use correct specifier for int (both atomic_t and pid_t, no special
specifier found in Documentation/core-api/printk-formats.rst)
---
fs/btrfs/print-tree.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/fs/btrfs/print-tree.c b/fs/btrfs/print-tree.c
index 9904cf741e1c..7f0ada51e5fe 100644
--- a/fs/btrfs/print-tree.c
+++ b/fs/btrfs/print-tree.c
@@ -179,6 +179,26 @@ static void print_uuid_item(struct extent_buffer *l, unsigned long offset,
}
}
+/*
+ * Helper to output refs and locking status.
+ *
+ * Useful to debug race related problem
+ */
+static void print_eb_refs_lock(struct extent_buffer *eb)
+{
+#ifdef CONFIG_BTRFS_DEBUG
+ btrfs_info(eb->fs_info,
+"refs %u lock(w:%u r:%u bw:%u br:%u sw:%u sr:%u) lock_owner %u current %u",
+ atomic_read(&eb->refs), atomic_read(&eb->write_locks),
+ atomic_read(&eb->read_locks),
+ atomic_read(&eb->blocking_writers),
+ atomic_read(&eb->blocking_readers),
+ atomic_read(&eb->spinning_writers),
+ atomic_read(&eb->spinning_readers),
+ eb->lock_owner, current->pid);
+#endif
+}
+
void btrfs_print_leaf(struct extent_buffer *l)
{
struct btrfs_fs_info *fs_info;
@@ -206,6 +226,7 @@ void btrfs_print_leaf(struct extent_buffer *l)
"leaf %llu gen %llu total ptrs %d free space %d owner %llu",
btrfs_header_bytenr(l), btrfs_header_generation(l), nr,
btrfs_leaf_free_space(fs_info, l), btrfs_header_owner(l));
+ print_eb_refs_lock(l);
for (i = 0 ; i < nr ; i++) {
item = btrfs_item_nr(i);
btrfs_item_key_to_cpu(l, &key, i);
@@ -360,6 +381,7 @@ void btrfs_print_tree(struct extent_buffer *c, bool follow)
btrfs_header_bytenr(c), level, btrfs_header_generation(c),
nr, (u32)BTRFS_NODEPTRS_PER_BLOCK(fs_info) - nr,
btrfs_header_owner(c));
+ print_eb_refs_lock(c);
for (i = 0; i < nr; i++) {
btrfs_node_key_to_cpu(c, &key, i);
pr_info("\tkey %d (%llu %u %llu) block %llu gen %llu\n",
--
2.17.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] btrfs: print-tree: Add locking status output for debug build
2018-04-24 5:03 [PATCH v2] btrfs: print-tree: Add locking status output for debug build Qu Wenruo
@ 2018-04-24 14:44 ` David Sterba
2018-04-24 23:44 ` Qu Wenruo
0 siblings, 1 reply; 3+ messages in thread
From: David Sterba @ 2018-04-24 14:44 UTC (permalink / raw)
To: Qu Wenruo; +Cc: linux-btrfs
On Tue, Apr 24, 2018 at 01:03:13PM +0800, Qu Wenruo wrote:
> It's pretty handy if we can get debug output for locking status of an
> extent buffer, specially for race related debugging.
>
> So add the following output for btrfs_print_tree() and
> btrfs_print_leaf():
> - refs
> - write_locks (as w:%d)
> - read_locks (as r:%d)
> - blocking_writers (as bw:%d)
> - blocking_readers (as br:%d)
> - spinning_writers (as sw:%d)
> - spinning_readers (as sr:%d)
> - lock_owner
> - current->pid
This is fine
> + btrfs_info(eb->fs_info,
I'd rather make that btrfs_debug, but info is fine as long as it's under
CONFIG_BTRFS_DEBUG.
> +"refs %u lock(w:%u r:%u bw:%u br:%u sw:%u sr:%u) lock_owner %u current %u",
This is not :) but I'll fix that according to the above.
Reviewed-by: David Sterba <dsterba@suse.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] btrfs: print-tree: Add locking status output for debug build
2018-04-24 14:44 ` David Sterba
@ 2018-04-24 23:44 ` Qu Wenruo
0 siblings, 0 replies; 3+ messages in thread
From: Qu Wenruo @ 2018-04-24 23:44 UTC (permalink / raw)
To: dsterba, Qu Wenruo, linux-btrfs
[-- Attachment #1.1: Type: text/plain, Size: 1316 bytes --]
On 2018年04月24日 22:44, David Sterba wrote:
> On Tue, Apr 24, 2018 at 01:03:13PM +0800, Qu Wenruo wrote:
>> It's pretty handy if we can get debug output for locking status of an
>> extent buffer, specially for race related debugging.
>>
>> So add the following output for btrfs_print_tree() and
>> btrfs_print_leaf():
>> - refs
>> - write_locks (as w:%d)
>> - read_locks (as r:%d)
>> - blocking_writers (as bw:%d)
>> - blocking_readers (as br:%d)
>> - spinning_writers (as sw:%d)
>> - spinning_readers (as sr:%d)
>> - lock_owner
>> - current->pid
>
> This is fine
>
>> + btrfs_info(eb->fs_info,
>
> I'd rather make that btrfs_debug, but info is fine as long as it's under
> CONFIG_BTRFS_DEBUG.
>
>> +"refs %u lock(w:%u r:%u bw:%u br:%u sw:%u sr:%u) lock_owner %u current %u",
>
> This is not :) but I'll fix that according to the above.
Not again...
I forgot to commit the change, no wonder everything is the same and need
to modify the patch commit message.
Sorry for the inconvenience.
Thanks,
Qu
>
> Reviewed-by: David Sterba <dsterba@suse.com>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-04-24 23:44 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-24 5:03 [PATCH v2] btrfs: print-tree: Add locking status output for debug build Qu Wenruo
2018-04-24 14:44 ` David Sterba
2018-04-24 23:44 ` Qu Wenruo
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.