@@ -609,8 +609,14 @@ static void run_one_async_done(struct btrfs_work *work, bool do_free)
static bool should_async_write(struct btrfs_bio *bbio)
{
+ struct btrfs_fs_devices *fs_devices = bbio->fs_info->fs_devices;
+
+ if (fs_devices->inline_csum_mode == BTRFS_INLINE_CSUM_FORCE_ON)
+ return false;
+
/* Submit synchronously if the checksum implementation is fast. */
- if (test_bit(BTRFS_FS_CSUM_IMPL_FAST, &bbio->fs_info->flags))
+ if (fs_devices->inline_csum_mode == BTRFS_INLINE_CSUM_AUTO &&
+ test_bit(BTRFS_FS_CSUM_IMPL_FAST, &bbio->fs_info->flags))
return false;
/*
@@ -1306,6 +1306,44 @@ static ssize_t btrfs_bg_reclaim_threshold_store(struct kobject *kobj,
BTRFS_ATTR_RW(, bg_reclaim_threshold, btrfs_bg_reclaim_threshold_show,
btrfs_bg_reclaim_threshold_store);
+static ssize_t btrfs_inline_csum_show(struct kobject *kobj,
+ struct kobj_attribute *a,
+ char *buf)
+{
+ struct btrfs_fs_devices *fs_devices = to_fs_devs(kobj);
+
+ switch (fs_devices->inline_csum_mode) {
+ case BTRFS_INLINE_CSUM_AUTO:
+ return sysfs_emit(buf, "auto\n");
+ case BTRFS_INLINE_CSUM_FORCE_ON:
+ return sysfs_emit(buf, "on\n");
+ case BTRFS_INLINE_CSUM_FORCE_OFF:
+ return sysfs_emit(buf, "off\n");
+ default:
+ WARN_ON(1);
+ return -EINVAL;
+ }
+}
+
+static ssize_t btrfs_inline_csum_store(struct kobject *kobj,
+ struct kobj_attribute *a,
+ const char *buf, size_t len)
+{
+ struct btrfs_fs_devices *fs_devices = to_fs_devs(kobj);
+
+ if (sysfs_streq(buf, "auto"))
+ fs_devices->inline_csum_mode = BTRFS_INLINE_CSUM_AUTO;
+ else if (sysfs_streq(buf, "on"))
+ fs_devices->inline_csum_mode = BTRFS_INLINE_CSUM_FORCE_ON;
+ else if (sysfs_streq(buf, "off"))
+ fs_devices->inline_csum_mode = BTRFS_INLINE_CSUM_FORCE_OFF;
+ else
+ return -EINVAL;
+
+ return len;
+}
+BTRFS_ATTR_RW(, inline_csum, btrfs_inline_csum_show, btrfs_inline_csum_store);
+
/*
* Per-filesystem information and stats.
*
@@ -1325,6 +1363,7 @@ static const struct attribute *btrfs_attrs[] = {
BTRFS_ATTR_PTR(, bg_reclaim_threshold),
BTRFS_ATTR_PTR(, commit_stats),
BTRFS_ATTR_PTR(, temp_fsid),
+ BTRFS_ATTR_PTR(, inline_csum),
NULL,
};
@@ -276,6 +276,22 @@ enum btrfs_read_policy {
BTRFS_NR_READ_POLICY,
};
+/*
+ * Checksum mode - do it in btrfs_submit_chunk() or offload it.
+ */
+enum btrfs_inline_csum_mode {
+ /*
+ * Choose inline checksum or offloading automatically. Do it
+ * inline if the checksum is fast, or offload to workqueues
+ * otherwise.
+ */
+ BTRFS_INLINE_CSUM_AUTO,
+ /* Never offload checksum to workqueues. */
+ BTRFS_INLINE_CSUM_FORCE_ON,
+ /* Always offload checksum to workqueues. */
+ BTRFS_INLINE_CSUM_FORCE_OFF,
+};
+
struct btrfs_fs_devices {
u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
@@ -380,6 +396,9 @@ struct btrfs_fs_devices {
/* Policy used to read the mirrored stripes. */
enum btrfs_read_policy read_policy;
+
+ /* Checksum mode - do it inline or offload it. */
+ enum btrfs_inline_csum_mode inline_csum_mode;
};
#define BTRFS_MAX_DEVS(info) ((BTRFS_MAX_ITEM_SIZE(info) \
We disable offloading checksum to workqueues and do it inline when the checksum algorithm is fast. However, as reported in the link below, RAID0 with multiple devices may suffer from the inline checksum, because "fast checksum" is still not fast enough to catch up RAID0 writing. To measure the effectiveness of inline checksum, it would be better to have a switch for inline checksum. This commit introduces fs_devices->inline_csum_mode, so that a FS user can change the behavior by writing to /sys/fs/btrfs/<uuid>/inline_csum. The default is "auto" which is the same as the previous behavior. Or, you can set "on" or "off" to always/never use inline checksum. Link: https://lore.kernel.org/linux-btrfs/20230731152223.4EFB.409509F4@e16-tech.com/ Link: https://lore.kernel.org/linux-btrfs/p3vo3g7pqn664mhmdhlotu5dzcna6vjtcoc2hb2lsgo2fwct7k@xzaxclba5tae/ Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com> --- fs/btrfs/bio.c | 8 +++++++- fs/btrfs/sysfs.c | 39 +++++++++++++++++++++++++++++++++++++++ fs/btrfs/volumes.h | 19 +++++++++++++++++++ 3 files changed, 65 insertions(+), 1 deletion(-)