btrfs: use assertion helpers for spinning readers
authorDavid Sterba <dsterba@suse.com>
Fri, 24 Aug 2018 13:57:38 +0000 (15:57 +0200)
committerDavid Sterba <dsterba@suse.com>
Mon, 29 Apr 2019 17:02:21 +0000 (19:02 +0200)
Use the helpers where open coded. On non-debug builds, the warnings will
not trigger and extent_buffer::spining_readers become unused and can be
moved to the appropriate section, saving a few bytes.

Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/extent_io.c
fs/btrfs/extent_io.h
fs/btrfs/locking.c

index fc0451c3e24e485cb3be0779eb0448cbf8a68c8c..f010475f74fdfeda95d85cd8df4963ab458ed740 100644 (file)
@@ -4681,7 +4681,6 @@ __alloc_extent_buffer(struct btrfs_fs_info *fs_info, u64 start,
        atomic_set(&eb->read_locks, 0);
        atomic_set(&eb->blocking_readers, 0);
        atomic_set(&eb->blocking_writers, 0);
        atomic_set(&eb->read_locks, 0);
        atomic_set(&eb->blocking_readers, 0);
        atomic_set(&eb->blocking_writers, 0);
-       atomic_set(&eb->spinning_readers, 0);
        eb->lock_nested = 0;
        init_waitqueue_head(&eb->write_lock_wq);
        init_waitqueue_head(&eb->read_lock_wq);
        eb->lock_nested = 0;
        init_waitqueue_head(&eb->write_lock_wq);
        init_waitqueue_head(&eb->read_lock_wq);
@@ -4701,6 +4700,7 @@ __alloc_extent_buffer(struct btrfs_fs_info *fs_info, u64 start,
 
 #ifdef CONFIG_BTRFS_DEBUG
        atomic_set(&eb->spinning_writers, 0);
 
 #ifdef CONFIG_BTRFS_DEBUG
        atomic_set(&eb->spinning_writers, 0);
+       atomic_set(&eb->spinning_readers, 0);
 #endif
 
        return eb;
 #endif
 
        return eb;
index 3577ef33bc36761e4bedc4c106259ee045a2d619..89e56df64d6cc7b9c0935865919d54fcbca6018c 100644 (file)
@@ -165,7 +165,6 @@ struct extent_buffer {
        atomic_t read_locks;
        atomic_t blocking_writers;
        atomic_t blocking_readers;
        atomic_t read_locks;
        atomic_t blocking_writers;
        atomic_t blocking_readers;
-       atomic_t spinning_readers;
        short lock_nested;
        /* >= 0 if eb belongs to a log tree, -1 otherwise */
        short log_index;
        short lock_nested;
        /* >= 0 if eb belongs to a log tree, -1 otherwise */
        short log_index;
@@ -185,6 +184,7 @@ struct extent_buffer {
        struct page *pages[INLINE_EXTENT_BUFFER_PAGES];
 #ifdef CONFIG_BTRFS_DEBUG
        atomic_t spinning_writers;
        struct page *pages[INLINE_EXTENT_BUFFER_PAGES];
 #ifdef CONFIG_BTRFS_DEBUG
        atomic_t spinning_writers;
+       atomic_t spinning_readers;
        struct list_head leak_list;
 #endif
 };
        struct list_head leak_list;
 #endif
 };
index 2dd3ae524aa31fd9e2bdf0057978fc1ab9265f21..47bcd288977de78bd41697254106704907d90734 100644 (file)
@@ -62,8 +62,7 @@ void btrfs_set_lock_blocking_read(struct extent_buffer *eb)
                return;
        btrfs_assert_tree_read_locked(eb);
        atomic_inc(&eb->blocking_readers);
                return;
        btrfs_assert_tree_read_locked(eb);
        atomic_inc(&eb->blocking_readers);
-       WARN_ON(atomic_read(&eb->spinning_readers) == 0);
-       atomic_dec(&eb->spinning_readers);
+       btrfs_assert_spinning_readers_put(eb);
        read_unlock(&eb->lock);
 }
 
        read_unlock(&eb->lock);
 }
 
@@ -95,7 +94,7 @@ void btrfs_clear_lock_blocking_read(struct extent_buffer *eb)
                return;
        BUG_ON(atomic_read(&eb->blocking_readers) == 0);
        read_lock(&eb->lock);
                return;
        BUG_ON(atomic_read(&eb->blocking_readers) == 0);
        read_lock(&eb->lock);
-       atomic_inc(&eb->spinning_readers);
+       btrfs_assert_spinning_readers_get(eb);
        /* atomic_dec_and_test implies a barrier */
        if (atomic_dec_and_test(&eb->blocking_readers))
                cond_wake_up_nomb(&eb->read_lock_wq);
        /* atomic_dec_and_test implies a barrier */
        if (atomic_dec_and_test(&eb->blocking_readers))
                cond_wake_up_nomb(&eb->read_lock_wq);
@@ -150,7 +149,7 @@ again:
                goto again;
        }
        atomic_inc(&eb->read_locks);
                goto again;
        }
        atomic_inc(&eb->read_locks);
-       atomic_inc(&eb->spinning_readers);
+       btrfs_assert_spinning_readers_get(eb);
 }
 
 /*
 }
 
 /*
@@ -169,7 +168,7 @@ int btrfs_tree_read_lock_atomic(struct extent_buffer *eb)
                return 0;
        }
        atomic_inc(&eb->read_locks);
                return 0;
        }
        atomic_inc(&eb->read_locks);
-       atomic_inc(&eb->spinning_readers);
+       btrfs_assert_spinning_readers_get(eb);
        return 1;
 }
 
        return 1;
 }
 
@@ -190,7 +189,7 @@ int btrfs_try_tree_read_lock(struct extent_buffer *eb)
                return 0;
        }
        atomic_inc(&eb->read_locks);
                return 0;
        }
        atomic_inc(&eb->read_locks);
-       atomic_inc(&eb->spinning_readers);
+       btrfs_assert_spinning_readers_get(eb);
        return 1;
 }
 
        return 1;
 }
 
@@ -232,8 +231,7 @@ void btrfs_tree_read_unlock(struct extent_buffer *eb)
                return;
        }
        btrfs_assert_tree_read_locked(eb);
                return;
        }
        btrfs_assert_tree_read_locked(eb);
-       WARN_ON(atomic_read(&eb->spinning_readers) == 0);
-       atomic_dec(&eb->spinning_readers);
+       btrfs_assert_spinning_readers_put(eb);
        atomic_dec(&eb->read_locks);
        read_unlock(&eb->lock);
 }
        atomic_dec(&eb->read_locks);
        read_unlock(&eb->lock);
 }