struct btrfs_stripe_hash *h;
unsigned int num_entries = 1U << BTRFS_STRIPE_HASH_TABLE_BITS;
+#ifdef CONFIG_BTRFS_DEBUG
+ WRITE_ONCE(info->rbio_cache_size, RBIO_CACHE_SIZE);
+#endif
if (info->stripe_hash_table)
return 0;
spin_unlock(&table->cache_lock);
}
+#ifdef CONFIG_BTRFS_DEBUG
+/*
+ * Test knob (debug/rbio_cache_size): with a small or zero limit, a
+ * read-modify-write cannot take its stripe from the cache and must read it,
+ * which is what a fault-injecting test needs to see. Lowering it empties the
+ * cache, so the new limit holds from the next rbio on.
+ */
+void btrfs_set_rbio_cache_size(struct btrfs_fs_info *info, unsigned int size)
+{
+ unsigned int old = READ_ONCE(info->rbio_cache_size);
+
+ WRITE_ONCE(info->rbio_cache_size, size);
+ if (size < old && info->stripe_hash_table)
+ btrfs_clear_rbio_cache(info);
+}
+#endif
+
/*
* Send every parked rbio down and stop the park timer, before the raid56
* workqueue is destroyed: the timer queues its expired rbios there. By
* If the size of the rbio cache is too big, we
* prune an item.
*/
+/* How many rbios the stripe cache keeps (0: none). */
+static unsigned int rbio_cache_limit(const struct btrfs_fs_info *fs_info)
+{
+#ifdef CONFIG_BTRFS_DEBUG
+ return READ_ONCE(fs_info->rbio_cache_size);
+#else
+ return RBIO_CACHE_SIZE;
+#endif
+}
+
static void cache_rbio(struct btrfs_raid_bio *rbio)
{
struct btrfs_stripe_hash_table *table;
+ const unsigned int limit = rbio_cache_limit(rbio->bioc->fs_info);
bool pin;
if (!test_bit(RBIO_CACHE_READY_BIT, &rbio->flags))
return;
-
pin = rbio_needs_pin(rbio);
+ /* Even a disabled cache keeps a stripe its run has not finished. */
+ if (!limit && !pin)
+ return;
+
table = rbio->bioc->fs_info->stripe_hash_table;
spin_lock(&table->cache_lock);
spin_unlock(&rbio->bio_list_lock);
- rbio_cache_prune(table, rbio, RBIO_CACHE_SIZE);
+ /* Prunes as far as needed: the limit can have been lowered. */
+ rbio_cache_prune(table, rbio, limit);
spin_unlock(&table->cache_lock);
}
#ifdef CONFIG_BTRFS_DEBUG
+/* The raid56 stripe cache limit (raid56.c), 0 to disable the cache. */
+static ssize_t btrfs_rbio_cache_size_show(struct kobject *kobj,
+ struct kobj_attribute *a, char *buf)
+{
+ struct btrfs_fs_info *fs_info = to_fs_info(get_btrfs_kobj(kobj));
+
+ return sysfs_emit(buf, "%u\n", READ_ONCE(fs_info->rbio_cache_size));
+}
+
+static ssize_t btrfs_rbio_cache_size_store(struct kobject *kobj,
+ struct kobj_attribute *a,
+ const char *buf, size_t len)
+{
+ struct btrfs_fs_info *fs_info = to_fs_info(get_btrfs_kobj(kobj));
+ unsigned int val;
+ int ret;
+
+ ret = kstrtouint(buf, 10, &val);
+ if (ret)
+ return ret;
+ btrfs_set_rbio_cache_size(fs_info, val);
+ return len;
+}
+BTRFS_ATTR_RW(debug_mount, rbio_cache_size, btrfs_rbio_cache_size_show,
+ btrfs_rbio_cache_size_store);
+
/*
* Audit every data read-modify-write against the committed extent tree
* (raid56.c): a tree search per RMW, so off by default.
static const struct attribute *btrfs_debug_mount_attrs[] = {
BTRFS_ATTR_PTR(debug_mount, stripe_rmw_audit),
BTRFS_ATTR_PTR(debug_mount, stripe_rmw_audit_stats),
+ BTRFS_ATTR_PTR(debug_mount, rbio_cache_size),
NULL,
};