Add roundrobin raid1 read policy
cover Add roundrobin raid1 read policy
From: Michal Rostecki <[email protected]>
This patch series adds a new raid1 read policy - roundrobin. For each request, it selects the mirror which has lower load than queue depth. Load is defined as the number of inflight requests + a penalty value (if the scheduled request is not local to the last processed request for a rotational disk).
The series consists of preparational changes which add necessary information to the btrfs_device struct and the change with the policy.
This policy was tested with fio and compared with the default pid policy.
The singlethreaded test has the following parameters:
[global]
name=btrfs-raid1-seqread
filename=btrfs-raid1-seqread
rw=read
bs=64k
direct=0
numjobs=1
time_based=0
[file1]
size=10G
ioengine=libaio
and shows the following results:
- raid1c3 with 3 HDDs:
3 x Segate Barracuda ST2000DM008 (2TB)
* pid policy
READ: bw=217MiB/s (228MB/s), 217MiB/s-217MiB/s (228MB/s-228MB/s),
io=10.0GiB (10.7GB), run=47082-47082msec
* roundrobin policy
READ: bw=409MiB/s (429MB/s), 409MiB/s-409MiB/s (429MB/s-429MB/s),
io=10.0GiB (10.7GB), run=25028-25028mse- raid1c3 with 2 HDDs and 1 SSD:
2 x Segate Barracuda ST2000DM008 (2TB)
1 x Crucial CT256M550SSD1 (256GB)
* pid policy (the worst case when only HDDs were chosen)
READ: bw=220MiB/s (231MB/s), 220MiB/s-220MiB/s (231MB/s-231MB/s),
io=10.0GiB (10.7GB), run=46577-46577mse
* pid policy (the best case when SSD was used as well)
READ: bw=513MiB/s (538MB/s), 513MiB/s-513MiB/s (538MB/s-538MB/s),
io=10.0GiB (10.7GB), run=19954-19954msec
* roundrobin (there are no noticeable differences when testing multiple
times)
READ: bw=541MiB/s (567MB/s), 541MiB/s-541MiB/s (567MB/s-567MB/s),
io=10.0GiB (10.7GB), run=18933-18933msecThe multithreaded test has the following parameters:
[global]
name=btrfs-raid1-seqread
filename=btrfs-raid1-seqread
rw=read
bs=64k
direct=0
numjobs=8
time_based=0
[file1]
size=10G
ioengine=libaio
and shows the following results:
- raid1c3 with 3 HDDs: 3 x Segate Barracuda ST2000DM008 (2TB) 3 x Segate Barracuda ST2000DM008 (2TB)
* pid policy
READ: bw=1569MiB/s (1645MB/s), 196MiB/s-196MiB/s (206MB/s-206MB/s),
io=80.0GiB (85.9GB), run=52210-52211msec
* roundrobin
READ: bw=1733MiB/s (1817MB/s), 217MiB/s-217MiB/s (227MB/s-227MB/s),
io=80.0GiB (85.9GB), run=47269-47271msec- raid1c3 with 2 HDDs and 1 SSD:
2 x Segate Barracuda ST2000DM008 (2TB)
1 x Crucial CT256M550SSD1 (256GB)
* pid policy
READ: bw=1843MiB/s (1932MB/s), 230MiB/s-230MiB/s (242MB/s-242MB/s),
io=80.0GiB (85.9GB), run=44449-44450msec
* roundrobin
READ: bw=2485MiB/s (2605MB/s), 311MiB/s-311MiB/s (326MB/s-326MB/s),
io=80.0GiB (85.9GB), run=32969-32970msecTo measure the performance of each policy and find optimal penalty values, I created scripts which are available here:
https://gitlab.com/vadorovsky/btrfs-perf
https://github.com/mrostecki/btrfs-perf
Michal Rostecki (6):
btrfs: Add inflight BIO request counter
btrfs: Store the last device I/O offset
btrfs: Add stripe_physical function
btrfs: Check if the filesystem is has mixed type of devices
btrfs: sysfs: Add directory for read policies
btrfs: Add roundrobin raid1 read policy
fs/btrfs/ctree.h | 3 + fs/btrfs/disk-io.c | 3 + fs/btrfs/sysfs.c | 144 ++++++++++++++++++++++++++---- fs/btrfs/volumes.c | 218 +++++++++++++++++++++++++++++++++++++++++++-- fs/btrfs/volumes.h | 22 +++++ 5 files changed, 366 insertions(+), 24 deletions(-)
Signature · 1 line
2.30.0
RFC PATCH 1/6 btrfs: Add inflight BIO request counter
From: Michal Rostecki <[email protected]>
Add a per-CPU inflight BIO counter to btrfs_device which stores the number of requests currently processed by the device. This information is going to be used in roundrobin raid1 read policy.
--- fs/btrfs/volumes.c | 11 +++++++++-- fs/btrfs/volumes.h | 3 +++ 2 files changed, 12 insertions(+), 2 deletions(-)
fs/btrfs/volumes.c +9 -2
@@ -376,6 +376,7 @@ void btrfs_free_device(struct btrfs_device *device)extent_io_tree_release (&device->alloc_state);bio_put (device->flush_bio);btrfs_destroy_dev_zone_info (device); +percpu_counter_destroy (&device->inflight);kfree (device); }
@@ -439,6 +440,11 @@ static struct btrfs_device *__alloc_device(struct btrfs_fs_info *fs_info)extent_io_tree_init (fs_info, &dev->alloc_state,IO_TREE_DEVICE_ALLOC_STATE ,NULL ); +if (percpu_counter_init (&dev->inflight,0 ,GFP_KERNEL )) { +kfree (dev); +return ERR_PTR (-ENOMEM ); + } +return dev; }
@@ -6305,6 +6311,7 @@ static inline void btrfs_end_bbio(struct btrfs_bio *bbio, struct bio *bio)static void btrfs_end_bio (struct bio *bio) { +struct btrfs_device *dev =btrfs_io_bio (bio)->device;struct btrfs_bio *bbio = bio->bi_private;int is_orig_bio =0 ;
@@ -6312,8 +6319,6 @@ static void btrfs_end_bio(struct bio *bio)atomic_inc (&bbio->error);if (bio->bi_status ==BLK_STS_IOERR || bio->bi_status ==BLK_STS_TARGET ) { -struct btrfs_device *dev =btrfs_io_bio (bio)->device; -ASSERT (dev->bdev);if (bio_op (bio) ==REQ_OP_WRITE ) btrfs_dev_stat_inc_and_print(dev,
@@ -6331,6 +6336,7 @@ static void btrfs_end_bio(struct bio *bio) is_orig_bio =1 ;btrfs_bio_counter_dec (bbio->fs_info); +percpu_counter_dec (&dev->inflight);if (atomic_dec_and_test (&bbio->stripes_pending)) {if (!is_orig_bio) {
@@ -6375,6 +6381,7 @@ static void submit_stripe_bio(struct btrfs_bio *bbio, struct bio *bio,bio_set_dev (bio, dev->bdev);btrfs_bio_counter_inc_noblocked (fs_info); +percpu_counter_inc (&dev->inflight);btrfsic_submit_bio (bio); }
fs/btrfs/volumes.h +3 -0
@@ -143,6 +143,9 @@ struct btrfs_device {struct completion kobj_unregister;/* For sysfs/FSID/devinfo/devid/ */ struct kobject devid_kobj; + +/* I/O stats for raid1 mirror selection */ +struct percpu_counter inflight; };/*
Signature · 1 line
2.30.0
RFC PATCH 2/6 btrfs: Store the last device I/O offset
In reply to Michal RosteckiFrom: Michal Rostecki <[email protected]>
Add an atomic field which stores the physical offset of the last I/O operation scheduled to the device. This information is going to be used to measure the locality of I/O requests.
--- fs/btrfs/volumes.c | 4 ++++ fs/btrfs/volumes.h | 1 + 2 files changed, 5 insertions(+)
fs/btrfs/volumes.c +4 -0
@@ -444,6 +444,7 @@ static struct btrfs_device *__alloc_device(struct btrfs_fs_info *fs_info)kfree (dev);return ERR_PTR (-ENOMEM ); } +atomic_set (&dev->last_offset,0 );return dev; }
@@ -6368,11 +6369,13 @@ static void submit_stripe_bio(struct btrfs_bio *bbio, struct bio *bio, u64 physical, struct btrfs_device *dev) { struct btrfs_fs_info *fs_info = bbio->fs_info; +u64 length; bio->bi_private = bbio;btrfs_io_bio (bio)->device = dev; bio->bi_end_io = btrfs_end_bio; bio->bi_iter.bi_sector = physical >>9 ; + length = bio->bi_iter.bi_size; btrfs_debug_in_rcu(fs_info, "btrfs_map_bio: rw %d 0x%x, sector=%llu, dev=%lu (%s id %llu), size=%u", bio_op(bio), bio->bi_opf, bio->bi_iter.bi_sector,
@@ -6382,6 +6385,7 @@ static void submit_stripe_bio(struct btrfs_bio *bbio, struct bio *bio,btrfs_bio_counter_inc_noblocked (fs_info);percpu_counter_inc (&dev->inflight); +atomic_set (&dev->last_offset, physical + length);btrfsic_submit_bio (bio); }
fs/btrfs/volumes.h +1 -0
@@ -146,6 +146,7 @@ struct btrfs_device {/* I/O stats for raid1 mirror selection */ struct percpu_counter inflight; +atomic_t last_offset; };/*
Signature · 1 line
2.30.0
RFC PATCH 3/6 btrfs: Add stripe_physical function
In reply to Michal RosteckiFrom: Michal Rostecki <[email protected]>
Move the calculation of the physical address for a stripe to the new function - stripe_physical(). It can be used by raid1 read policies to calculate the offset and select mirrors based on I/O locality.
--- fs/btrfs/volumes.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-)
fs/btrfs/volumes.c +20 -2
@@ -5498,6 +5498,23 @@ int btrfs_is_parity_mirror(struct btrfs_fs_info *fs_info, u64 logical, u64 len)return ret; } +/* +* Calculates the physical location for the given stripe and I/O geometry. +* +* @map: mapping containing the logical extent +* @stripe_index: index of the stripe to make a calculation for +* @stripe_offset: offset of the block in its stripe +* @stripe_nr: index of the stripe whete the block falls in +* +* Returns the physical location. +*/ +static u64 stripe_physical (struct map_lookup *map,u32 stripe_index, +u64 stripe_offset,u64 stripe_nr) +{ +return map->stripes[stripe_index].physical + stripe_offset + + stripe_nr * map->stripe_len; +} +static int find_live_mirror (struct btrfs_fs_info *fs_info,struct map_lookup *map,int first,int dev_replace_is_ongoing)
@@ -6216,8 +6233,9 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, }for (i =0 ; i < num_stripes; i++) { - bbio->stripes[i].physical = map->stripes[stripe_index].physical + - stripe_offset + stripe_nr * map->stripe_len; + bbio->stripes[i].physical =stripe_physical (map, stripe_index, + stripe_offset, + stripe_nr); bbio->stripes[i].dev = map->stripes[stripe_index].dev; stripe_index++; }
Signature · 1 line
2.30.0
RFC PATCH 4/6 btrfs: Check if the filesystem is has mixed type of devices
In reply to Michal RosteckiFrom: Michal Rostecki <[email protected]>
Add the btrfs_check_mixed() function which checks if the filesystem has the mixed type of devices (non-rotational and rotational). This information is going to be used in roundrobin raid1 read policy.
--- fs/btrfs/volumes.c | 44 ++++++++++++++++++++++++++++++++++++++++++-- fs/btrfs/volumes.h | 7 +++++++ 2 files changed, 49 insertions(+), 2 deletions(-)
fs/btrfs/volumes.c +42 -2
@@ -617,6 +617,35 @@ static int btrfs_free_stale_devices(const char *path,return ret; } +/* +* Checks if after adding the new device the filesystem is going to have mixed +* types of devices (non-rotational and rotational). +* +* @fs_devices: list of devices +* @new_device_rotating: if the new device is rotational +* +* Returns true if there are mixed types of devices, otherwise returns false. +*/ +static bool btrfs_check_mixed (struct btrfs_fs_devices *fs_devices, +bool new_device_rotating) +{ +struct btrfs_device *device, *prev_device; + +list_for_each_entry (device, &fs_devices->devices, dev_list) { +if (prev_device ==NULL && + device->rotating != new_device_rotating) +return true; +if (prev_device !=NULL && + (device->rotating != prev_device->rotating || + device->rotating != new_device_rotating)) +return true; + + prev_device = device; + } + +return false; +} +/* * This is only used on mount, and we are protected from competing things * messing with our fs_devices by the uuid_mutex, thus we do not need the
@@ -629,6 +658,7 @@ static int btrfs_open_one_device(struct btrfs_fs_devices *fs_devices,struct request_queue *q;struct block_device *bdev;struct btrfs_super_block *disk_super; +bool rotating;u64 devid;int ret;
@@ -669,8 +699,12 @@ static int btrfs_open_one_device(struct btrfs_fs_devices *fs_devices, } q =bdev_get_queue (bdev); -if (!blk_queue_nonrot (q)) + rotating = !blk_queue_nonrot (q); + device->rotating = rotating; +if (rotating) fs_devices->rotating = true; +if (!fs_devices->mixed) + fs_devices->mixed =btrfs_check_mixed (fs_devices, rotating); device->bdev = bdev;clear_bit (BTRFS_DEV_STATE_IN_FS_METADATA , &device->dev_state);
@@ -2418,6 +2452,7 @@ static int btrfs_prepare_sprout(struct btrfs_fs_info *fs_info) fs_devices->open_devices =0 ; fs_devices->missing_devices =0 ; fs_devices->rotating = false; + fs_devices->mixed = false;list_add (&seed_devices->seed_list, &fs_devices->seed_list);generate_random_uuid (fs_devices->fsid);
@@ -2522,6 +2557,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_pathint seeding_dev =0 ;int ret =0 ;bool locked = false; +bool rotating;if (sb_rdonly (sb) && !fs_devices->seeding)return -EROFS ;
@@ -2621,8 +2657,12 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_pathatomic64_add (device->total_bytes, &fs_info->free_chunk_space); -if (!blk_queue_nonrot (q)) + rotating = !blk_queue_nonrot (q); + device->rotating = rotating; +if (rotating) fs_devices->rotating = true; +if (!fs_devices->mixed) + fs_devices->mixed =btrfs_check_mixed (fs_devices, rotating); orig_super_total_bytes =btrfs_super_total_bytes (fs_info->super_copy); btrfs_set_super_total_bytes(fs_info->super_copy,
fs/btrfs/volumes.h +7 -0
@@ -147,6 +147,9 @@ struct btrfs_device {/* I/O stats for raid1 mirror selection */ struct percpu_counter inflight;atomic_t last_offset; + +/* If the device is rotational */ +bool rotating; };/*
@@ -274,6 +277,10 @@ struct btrfs_fs_devices {* nonrot flag set */ bool rotating; +/* Set when we find or add both nonrot and rot disks in the +* filesystem +*/ +bool mixed;struct btrfs_fs_info *fs_info;/* sysfs kobjects */
Signature · 1 line
2.30.0
Re: [PATCH RFC 4/6] btrfs: Check if the filesystem is has mixed type of devices
Quoted 5 lines · Michal Rostecki
From: Michal Rostecki <[email protected]>
Add the
btrfs_check_mixed()function which checks if the filesystem has the mixed type of devices (non-rotational and rotational). This information is going to be used in roundrobin raid1 read policy.a
[...]
fs/btrfs/volumes.c static int btrfs_open_one_device(struct btrfs_fs_devices *fs_devices, · line 707
Quoted 11 lines
fs/btrfs/volumes.c +5
-1@@ -669,8 +699,12 @@ static int btrfs_open_one_device(struct btrfs_fs_devices *fs_devices, } q =bdev_get_queue (bdev); -if (!blk_queue_nonrot (q)) + rotating = !blk_queue_nonrot (q); + device->rotating = rotating; +if (rotating) fs_devices->rotating = true; +if (!fs_devices->mixed) + fs_devices->mixed =btrfs_check_mixed (fs_devices, rotating);
[...]
Since this is adding to a set, a faster way is:
if (fs_devices->rotating != rotating)
fs_devices->mixed = true;
The scan might be necessary on device removal, though.
fs/btrfs/volumes.c static int btrfs_open_one_device(struct btrfs_fs_devices *fs_devices, · line 707
Quoted 7 lines
fs/btrfs/volumes.c +5
-1-if (!blk_queue_nonrot (q)) + rotating = !blk_queue_nonrot (q); + device->rotating = rotating; +if (rotating) fs_devices->rotating = true; +if (!fs_devices->mixed) + fs_devices->mixed =btrfs_check_mixed (fs_devices, rotating);
Duplication. Maybe pull all this into a function?
Best Regards,
Michał Mirosław
Re: [PATCH RFC 4/6] btrfs: Check if the filesystem is has mixed type of devices
Quoted 20 lines · Michał Mirosław
Quoted 5 lines · Michal Rostecki
From: Michal Rostecki <[email protected]>
Add the
btrfs_check_mixed()function which checks if the filesystem has the mixed type of devices (non-rotational and rotational). This information is going to be used in roundrobin raid1 read policy.a[...]
Quoted 11 lines
fs/btrfs/volumes.c +5
-1@@ -669,8 +699,12 @@ static int btrfs_open_one_device(struct btrfs_fs_devices *fs_devices, } q =bdev_get_queue (bdev); -if (!blk_queue_nonrot (q)) + rotating = !blk_queue_nonrot (q); + device->rotating = rotating; +if (rotating) fs_devices->rotating = true; +if (!fs_devices->mixed) + fs_devices->mixed =btrfs_check_mixed (fs_devices, rotating);[...]
Quoted 5 lines
Since this is adding to a set, a faster way is:
if (
fs_devices->rotating!= rotating)fs_devices->mixed = true;
Good idea.
Quoted 2 lines
The scan might be necessary on device removal, though.
And good point. I didn't address the case of device removal at all.
Quoted 10 lines
fs/btrfs/volumes.c static int btrfs_open_one_device(struct btrfs_fs_devices *fs_devices, · line 707
Quoted 7 lines
fs/btrfs/volumes.c +5
-1-if (!blk_queue_nonrot (q)) + rotating = !blk_queue_nonrot (q); + device->rotating = rotating; +if (rotating) fs_devices->rotating = true; +if (!fs_devices->mixed) + fs_devices->mixed =btrfs_check_mixed (fs_devices, rotating);Duplication. Maybe pull all this into a function?
Will do that as well.
Quoted 2 lines
Best Regards,
Michał Mirosław
Regards,
Michal
Re: [PATCH RFC 4/6] btrfs: Check if the filesystem is has mixed type of devices
In reply to Michał MirosławQuoted 20 lines · Michał Mirosław
Quoted 5 lines · Michal Rostecki
From: Michal Rostecki <[email protected]>
Add the
btrfs_check_mixed()function which checks if the filesystem has the mixed type of devices (non-rotational and rotational). This information is going to be used in roundrobin raid1 read policy.a[...]
Quoted 11 lines
fs/btrfs/volumes.c +5
-1@@ -669,8 +699,12 @@ static int btrfs_open_one_device(struct btrfs_fs_devices *fs_devices, } q =bdev_get_queue (bdev); -if (!blk_queue_nonrot (q)) + rotating = !blk_queue_nonrot (q); + device->rotating = rotating; +if (rotating) fs_devices->rotating = true; +if (!fs_devices->mixed) + fs_devices->mixed =btrfs_check_mixed (fs_devices, rotating);[...]
Quoted 7 lines
Since this is adding to a set, a faster way is:
if (
fs_devices->rotating!= rotating)fs_devices->mixed = true;The scan might be necessary on device removal, though.
Actually, that's not going to work in case of appenging a rotational device when all previous devices are non-rotational.
if (rotating)
fs_devices->rotating = true;
if (fs_devices->rotating != rotating)
fs_devices->mixed = true;If all devices are non-rotational, we start with the following attributes:
fs_devices->rotating: falsefs_devices->mixed: false
Then, while appending a rotational disk, we have:
rotating = true;
if (rotating) // if (true)
fs_devices->rotating = true; // overriding with `true`
if (fs_devices->rotating != rotating) // if (true != true), which is false
fs_devices->mixed = true; // NOT EXECUTEDSo we end up fs_devices->mixed being false, despite having a mixed array.
Inverting the order of those if checks would break the other permuitations which start with rotational disks.
Therefore, to cover all cases, I think we need a full check, always.
Regards,
Michal
Re: [PATCH RFC 4/6] btrfs: Check if the filesystem is has mixed type of devices
Quoted 29 lines · Michal Rostecki
Quoted 20 lines · Michał Mirosław
Quoted 5 lines · Michal Rostecki
From: Michal Rostecki <[email protected]>
Add the
btrfs_check_mixed()function which checks if the filesystem has the mixed type of devices (non-rotational and rotational). This information is going to be used in roundrobin raid1 read policy.a[...]
Quoted 11 lines
fs/btrfs/volumes.c +5
-1@@ -669,8 +699,12 @@ static int btrfs_open_one_device(struct btrfs_fs_devices *fs_devices, } q =bdev_get_queue (bdev); -if (!blk_queue_nonrot (q)) + rotating = !blk_queue_nonrot (q); + device->rotating = rotating; +if (rotating) fs_devices->rotating = true; +if (!fs_devices->mixed) + fs_devices->mixed =btrfs_check_mixed (fs_devices, rotating);[...]
Quoted 6 lines
Since this is adding to a set, a faster way is:
if (
fs_devices->rotating!= rotating)fs_devices->mixed = true;The scan might be necessary on device removal, though.
Actually, that's not going to work in case of appenging a rotational device when all previous devices are non-rotational.
[...]
Quoted 2 lines
Inverting the order of those
ifchecks would break the other permuitations which start with rotational disks.
But not if you would add:
if (adding first device)
fs_devices->rotating = rotating;
before the checks.
But them, there is a simpler way: count how many rotating vs non-rotating devices there are while adding them. Like:
rotating ? ++n_rotating : ++n_fixed;
And then on remove you'd have it covered.
Best Regards
Michał Mirosław
Re: [PATCH RFC 4/6] btrfs: Check if the filesystem is has mixed type of devices
Quoted 39 lines · Michał Mirosław
Quoted 29 lines · Michal Rostecki
Quoted 20 lines · Michał Mirosław
Quoted 5 lines · Michal Rostecki
From: Michal Rostecki <[email protected]>
Add the
btrfs_check_mixed()function which checks if the filesystem has the mixed type of devices (non-rotational and rotational). This information is going to be used in roundrobin raid1 read policy.a[...]
Quoted 11 lines
fs/btrfs/volumes.c +5
-1@@ -669,8 +699,12 @@ static int btrfs_open_one_device(struct btrfs_fs_devices *fs_devices, } q =bdev_get_queue (bdev); -if (!blk_queue_nonrot (q)) + rotating = !blk_queue_nonrot (q); + device->rotating = rotating; +if (rotating) fs_devices->rotating = true; +if (!fs_devices->mixed) + fs_devices->mixed =btrfs_check_mixed (fs_devices, rotating);[...]
Quoted 6 lines
Since this is adding to a set, a faster way is:
if (
fs_devices->rotating!= rotating)fs_devices->mixed = true;The scan might be necessary on device removal, though.
Actually, that's not going to work in case of appenging a rotational device when all previous devices are non-rotational.
[...]
Quoted 2 lines
Inverting the order of those
ifchecks would break the other permuitations which start with rotational disks.But not if you would add:
if (adding first device)
fs_devices->rotating = rotating;
Quoted 8 lines
before the checks.
But them, there is a simpler way: count how many rotating vs non-rotating devices there are while adding them. Like:
rotating ? ++n_rotating : ++n_fixed;
And then on remove you'd have it covered.
I like the idea of storing numbers and simply checking them. I use it in v2 - though probably in a different form, and I will most likely move the whole logic around checking device types to separate functions, to not bloat btrfs_open_one_device() and the others too much.
Re: [PATCH RFC 4/6] btrfs: Check if the filesystem is has mixed type of devices
In reply to Michal RosteckiHi Michal,
url: https://github.com/0day-ci/linux/commits/Michal-Rostecki/Add-roundrobin-raid1-read-policy/20210210-053511 base: 92bf22614b21a2706f4993b278017e437f7785b3 config: i386-randconfig-m021-20210209 (attached as .config) compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
If you fix the issue, kindly add following tag as appropriate
New smatch warnings:fs/btrfs/volumes.c:635 btrfs_check_mixed() error: uninitialized symbol 'prev_device'.
Old smatch warnings:fs/btrfs/volumes.c:1264 open_fs_devices() error: we previously assumed 'latest_dev' could be null (see line 1252)
vim +/prev_device +635 fs/btrfs/volumes.c
bd7608b9a9bbf6 Michal Rostecki 2021-02-09 629 static bool btrfs_check_mixed(struct btrfs_fs_devices *fs_devices,
bd7608b9a9bbf6 Michal Rostecki 2021-02-09 630 bool new_device_rotating)
bd7608b9a9bbf6 Michal Rostecki 2021-02-09 631 {
bd7608b9a9bbf6 Michal Rostecki 2021-02-09 632 struct btrfs_device *device, *prev_device;
bd7608b9a9bbf6 Michal Rostecki 2021-02-09 633
bd7608b9a9bbf6 Michal Rostecki 2021-02-09 634 list_for_each_entry(device, &fs_devices->devices, dev_list) {
bd7608b9a9bbf6 Michal Rostecki 2021-02-09 @635 if (prev_device == NULL &&
^^^^^^^^^^^^^^^^^^^Uninitialized.
bd7608b9a9bbf6 Michal Rostecki 2021-02-09 636 device->rotating != new_device_rotating) bd7608b9a9bbf6 Michal Rostecki 2021-02-09 637 return true; bd7608b9a9bbf6 Michal Rostecki 2021-02-09 638 if (prev_device != NULL && bd7608b9a9bbf6 Michal Rostecki 2021-02-09 639 (device->rotating != prev_device->rotating || bd7608b9a9bbf6 Michal Rostecki 2021-02-09 640 device->rotating != new_device_rotating)) bd7608b9a9bbf6 Michal Rostecki 2021-02-09 641 return true; bd7608b9a9bbf6 Michal Rostecki 2021-02-09 642 bd7608b9a9bbf6 Michal Rostecki 2021-02-09 643 prev_device = device; bd7608b9a9bbf6 Michal Rostecki 2021-02-09 644 } bd7608b9a9bbf6 Michal Rostecki 2021-02-09 645 bd7608b9a9bbf6 Michal Rostecki 2021-02-09 646 return false; bd7608b9a9bbf6 Michal Rostecki 2021-02-09 647 }
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Re: [PATCH RFC 4/6] btrfs: Check if the filesystem is has mixed type of devices
In reply to Michal RosteckiQuoted 27 lines · Michal Rostecki
From: Michal Rostecki <[email protected]>
Add the
btrfs_check_mixed()function which checks if the filesystem has the mixed type of devices (non-rotational and rotational). This information is going to be used in roundrobin raid1 read policy.Signed-off-by Michal Rostecki <[email protected]>--- fs/btrfs/volumes.c | 44 ++++++++++++++++++++++++++++++++++++++++++-- fs/btrfs/volumes.h | 7 +++++++ 2 files changed, 49 insertions(+), 2 deletions(-)fs/btrfs/volumes.c +6
-0@@ -617,6 +617,35 @@ static int btrfs_free_stale_devices(const char *path,return ret; } +/* +* Checks if after adding the new device the filesystem is going to have mixed +* types of devices (non-rotational and rotational). +* +* @fs_devices: list of devices +* @new_device_rotating: if the new device is rotational
fs/btrfs/volumes.c static int btrfs_free_stale_devices(const char *path, · line 635
Quoted 10 lines
fs/btrfs/volumes.c +10
-0+* +* Returns true if there are mixed types of devices, otherwise returns false. +*/ +static bool btrfs_check_mixed (struct btrfs_fs_devices *fs_devices, +bool new_device_rotating) +{ +struct btrfs_device *device, *prev_device; + +list_for_each_entry (device, &fs_devices->devices, dev_list) { + if (prev_device == NULL &&
Hum, prev_device is not initialized when we enter the first iteration of the loop.
fs/btrfs/volumes.c static int btrfs_free_stale_devices(const char *path, · line 639
Quoted 4 lines
fs/btrfs/volumes.c +4
-0+ device->rotating != new_device_rotating) +return true; + if (prev_device != NULL && + (device->rotating != prev_device->rotating ||
Here it's more dangerous, dereferencing an uninitialized pointer can result in a crash.
With this fixed, it would be better to redo the benchmarks when using mixed device types.
Thanks.
Quoted 92 lines
fs/btrfs/volumes.c +22
-2+ device->rotating != new_device_rotating)) +return true; + + prev_device = device; + } + +return false; +} +/* * This is only used on mount, and we are protected from competing things * messing with our fs_devices by the uuid_mutex, thus we do not need the @@ -629,6 +658,7 @@ static int btrfs_open_one_device(struct btrfs_fs_devices *fs_devices,struct request_queue *q;struct block_device *bdev;struct btrfs_super_block *disk_super; +bool rotating;u64 devid;int ret;@@ -669,8 +699,12 @@ static int btrfs_open_one_device(struct btrfs_fs_devices *fs_devices, } q =bdev_get_queue (bdev); -if (!blk_queue_nonrot (q)) + rotating = !blk_queue_nonrot (q); + device->rotating = rotating; +if (rotating) fs_devices->rotating = true; +if (!fs_devices->mixed) + fs_devices->mixed =btrfs_check_mixed (fs_devices, rotating); device->bdev = bdev;clear_bit (BTRFS_DEV_STATE_IN_FS_METADATA , &device->dev_state);@@ -2418,6 +2452,7 @@ static int btrfs_prepare_sprout(struct btrfs_fs_info *fs_info) fs_devices->open_devices =0 ; fs_devices->missing_devices =0 ; fs_devices->rotating = false; + fs_devices->mixed = false;list_add (&seed_devices->seed_list, &fs_devices->seed_list);generate_random_uuid (fs_devices->fsid);@@ -2522,6 +2557,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_pathint seeding_dev =0 ;int ret =0 ;bool locked = false; +bool rotating;if (sb_rdonly (sb) && !fs_devices->seeding)return -EROFS ;@@ -2621,8 +2657,12 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_pathatomic64_add (device->total_bytes, &fs_info->free_chunk_space); -if (!blk_queue_nonrot (q)) + rotating = !blk_queue_nonrot (q); + device->rotating = rotating; +if (rotating) fs_devices->rotating = true; +if (!fs_devices->mixed) + fs_devices->mixed =btrfs_check_mixed (fs_devices, rotating); orig_super_total_bytes =btrfs_super_total_bytes (fs_info->super_copy); btrfs_set_super_total_bytes(fs_info->super_copy,fs/btrfs/volumes.h +7
-1@@ -147,6 +147,9 @@ struct btrfs_device {/* I/O stats for raid1 mirror selection */ struct percpu_counter inflight;atomic_t last_offset; + +/* If the device is rotational */ +bool rotating; };/* @@ -274,6 +277,10 @@ struct btrfs_fs_devices {* nonrot flag set */ bool rotating; +/* Set when we find or add both nonrot and rot disks in the +* filesystem +*/ +bool mixed;struct btrfs_fs_info *fs_info;/* sysfs kobjects */ --2.30.0
Signature · 3 lines
Filipe David Manana, “Whether you think you can, or you think you can't — you're right.”
Re: [PATCH RFC 4/6] btrfs: Check if the filesystem is has mixed type of devices
Quoted 47 lines · Filipe Manana
Quoted 27 lines · Michal Rostecki
From: Michal Rostecki <[email protected]>
Add the
btrfs_check_mixed()function which checks if the filesystem has the mixed type of devices (non-rotational and rotational). This information is going to be used in roundrobin raid1 read policy.Signed-off-by Michal Rostecki <[email protected]>--- fs/btrfs/volumes.c | 44 ++++++++++++++++++++++++++++++++++++++++++-- fs/btrfs/volumes.h | 7 +++++++ 2 files changed, 49 insertions(+), 2 deletions(-)fs/btrfs/volumes.c +6
-0@@ -617,6 +617,35 @@ static int btrfs_free_stale_devices(const char *path,return ret; } +/* +* Checks if after adding the new device the filesystem is going to have mixed +* types of devices (non-rotational and rotational). +* +* @fs_devices: list of devices +* @new_device_rotating: if the new device is rotational fs/btrfs/volumes.c static int btrfs_free_stale_devices(const char *path, · line 635
Quoted 10 lines
fs/btrfs/volumes.c +10
-0+* +* Returns true if there are mixed types of devices, otherwise returns false. +*/ +static bool btrfs_check_mixed (struct btrfs_fs_devices *fs_devices, +bool new_device_rotating) +{ +struct btrfs_device *device, *prev_device; + +list_for_each_entry (device, &fs_devices->devices, dev_list) { + if (prev_device == NULL &&Hum,
prev_deviceis not initialized when we enter the first iteration of the loop.fs/btrfs/volumes.c static int btrfs_free_stale_devices(const char *path, · line 639
Quoted 4 lines
fs/btrfs/volumes.c +4
-0+ device->rotating != new_device_rotating) +return true; + if (prev_device != NULL && + (device->rotating != prev_device->rotating ||
Quoted 8 lines
Here it's more dangerous, dereferencing an uninitialized pointer can result in a crash.
With this fixed, it would be better to redo the benchmarks when using mixed device types.
Thanks.
Thanks for pointing that out. Will fix and redo benchmarks for v2.
Quoted 98 lines
Quoted 92 lines
fs/btrfs/volumes.c +22
-2+ device->rotating != new_device_rotating)) +return true; + + prev_device = device; + } + +return false; +} +/* * This is only used on mount, and we are protected from competing things * messing with our fs_devices by the uuid_mutex, thus we do not need the @@ -629,6 +658,7 @@ static int btrfs_open_one_device(struct btrfs_fs_devices *fs_devices,struct request_queue *q;struct block_device *bdev;struct btrfs_super_block *disk_super; +bool rotating;u64 devid;int ret;@@ -669,8 +699,12 @@ static int btrfs_open_one_device(struct btrfs_fs_devices *fs_devices, } q =bdev_get_queue (bdev); -if (!blk_queue_nonrot (q)) + rotating = !blk_queue_nonrot (q); + device->rotating = rotating; +if (rotating) fs_devices->rotating = true; +if (!fs_devices->mixed) + fs_devices->mixed =btrfs_check_mixed (fs_devices, rotating); device->bdev = bdev;clear_bit (BTRFS_DEV_STATE_IN_FS_METADATA , &device->dev_state);@@ -2418,6 +2452,7 @@ static int btrfs_prepare_sprout(struct btrfs_fs_info *fs_info) fs_devices->open_devices =0 ; fs_devices->missing_devices =0 ; fs_devices->rotating = false; + fs_devices->mixed = false;list_add (&seed_devices->seed_list, &fs_devices->seed_list);generate_random_uuid (fs_devices->fsid);@@ -2522,6 +2557,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_pathint seeding_dev =0 ;int ret =0 ;bool locked = false; +bool rotating;if (sb_rdonly (sb) && !fs_devices->seeding)return -EROFS ;@@ -2621,8 +2657,12 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_pathatomic64_add (device->total_bytes, &fs_info->free_chunk_space); -if (!blk_queue_nonrot (q)) + rotating = !blk_queue_nonrot (q); + device->rotating = rotating; +if (rotating) fs_devices->rotating = true; +if (!fs_devices->mixed) + fs_devices->mixed =btrfs_check_mixed (fs_devices, rotating); orig_super_total_bytes =btrfs_super_total_bytes (fs_info->super_copy); btrfs_set_super_total_bytes(fs_info->super_copy,fs/btrfs/volumes.h +7
-1@@ -147,6 +147,9 @@ struct btrfs_device {/* I/O stats for raid1 mirror selection */ struct percpu_counter inflight;atomic_t last_offset; + +/* If the device is rotational */ +bool rotating; };/* @@ -274,6 +277,10 @@ struct btrfs_fs_devices {* nonrot flag set */ bool rotating; +/* Set when we find or add both nonrot and rot disks in the +* filesystem +*/ +bool mixed;struct btrfs_fs_info *fs_info;/* sysfs kobjects */ --2.30.0
Signature · 3 lines
Filipe David Manana, “Whether you think you can, or you think you can't — you're right.”
RFC PATCH 5/6 btrfs: sysfs: Add directory for read policies
In reply to Michal RosteckiFrom: Michal Rostecki <[email protected]>
Before this change, raid1 read policy could be selected by using the /sys/fs/btrfs/[fsid]/read_policy file.
Change it to /sys/fs/btrfs/[fsid]/read_policies/policy.
The motivation behing creating the read_policies directory is that the next changes and new read policies are going to intruduce settings specific to read policies.
--- fs/btrfs/sysfs.c | 51 +++++++++++++++++++++++++++++++++------------- fs/btrfs/volumes.h | 1 + 2 files changed, 38 insertions(+), 14 deletions(-)
fs/btrfs/sysfs.c +37 -14
@@ -896,6 +896,19 @@ static ssize_t btrfs_generation_show(struct kobject *kobj, } BTRFS_ATTR(, generation, btrfs_generation_show); +static const struct attribute *btrfs_attrs[] = { + BTRFS_ATTR_PTR(, label), + BTRFS_ATTR_PTR(, nodesize), + BTRFS_ATTR_PTR(, sectorsize), + BTRFS_ATTR_PTR(, clone_alignment), + BTRFS_ATTR_PTR(, quota_override), + BTRFS_ATTR_PTR(, metadata_uuid), + BTRFS_ATTR_PTR(, checksum), + BTRFS_ATTR_PTR(, exclusive_operation), + BTRFS_ATTR_PTR(, generation), +NULL , +}; +/* * Look for an exact string @string in @buffer with possible leading or * trailing whitespace
@@ -920,7 +933,7 @@ static const char * const btrfs_read_policy_name[] = { "pid" };static ssize_t btrfs_read_policy_show (struct kobject *kobj,struct kobj_attribute *a,char *buf) { -struct btrfs_fs_devices *fs_devices =to_fs_devs (kobj); +struct btrfs_fs_devices *fs_devices =to_fs_devs (kobj->parent);ssize_t ret =0 ;int i;
@@ -944,7 +957,7 @@ static ssize_t btrfs_read_policy_store(struct kobject *kobj,struct kobj_attribute *a, const char *buf, size_t len) { - struct btrfs_fs_devices *fs_devices = to_fs_devs(kobj); + struct btrfs_fs_devices *fs_devices = to_fs_devs(kobj->parent);int i;for (i =0 ; i <BTRFS_NR_READ_POLICY ; i++) {
@@ -961,19 +974,10 @@ static ssize_t btrfs_read_policy_store(struct kobject *kobj,return -EINVAL ; } -BTRFS_ATTR_RW(, read_policy, btrfs_read_policy_show, btrfs_read_policy_store); +BTRFS_ATTR_RW (read_policies, policy, btrfs_read_policy_show, btrfs_read_policy_store); -static const struct attribute *btrfs_attrs[] = { - BTRFS_ATTR_PTR(, label), - BTRFS_ATTR_PTR(, nodesize), - BTRFS_ATTR_PTR(, sectorsize), - BTRFS_ATTR_PTR(, clone_alignment), - BTRFS_ATTR_PTR(, quota_override), - BTRFS_ATTR_PTR(, metadata_uuid), - BTRFS_ATTR_PTR(, checksum), - BTRFS_ATTR_PTR(, exclusive_operation), - BTRFS_ATTR_PTR(, generation), - BTRFS_ATTR_PTR(, read_policy), +static const struct attribute *read_policies_attrs[] = { +BTRFS_ATTR_PTR (read_policies, policy),NULL , };
@@ -1112,6 +1116,12 @@ void btrfs_sysfs_remove_mounted(struct btrfs_fs_info *fs_info)sysfs_remove_link (fsid_kobj,"bdi" ); +if (fs_info->fs_devices->read_policies_kobj) { +sysfs_remove_files (fs_info->fs_devices->read_policies_kobj, + read_policies_attrs); +kobject_del (fs_info->fs_devices->read_policies_kobj); +kobject_put (fs_info->fs_devices->read_policies_kobj); + }if (fs_info->space_info_kobj) {sysfs_remove_files (fs_info->space_info_kobj, allocation_attrs);kobject_del (fs_info->space_info_kobj);
@@ -1658,6 +1668,19 @@ int btrfs_sysfs_add_mounted(struct btrfs_fs_info *fs_info)if (error) goto failure; + fs_devs->read_policies_kobj =kobject_create_and_add ("read_policies" , + fsid_kobj); + +if (!fs_devs->read_policies_kobj) { + error = -ENOMEM ; + goto failure; + } + + error =sysfs_create_files (fs_devs->read_policies_kobj, + read_policies_attrs); +if (error) + goto failure; +return 0 ; failure:btrfs_sysfs_remove_mounted (fs_info);
fs/btrfs/volumes.h +1 -0
@@ -287,6 +287,7 @@ struct btrfs_fs_devices {struct kobject fsid_kobj;struct kobject *devices_kobj;struct kobject *devinfo_kobj; +struct kobject *read_policies_kobj;struct completion kobj_unregister;enum btrfs_chunk_allocation_policy chunk_alloc_policy;
Signature · 1 line
2.30.0
Re: [PATCH RFC 5/6] btrfs: sysfs: Add directory for read policies
Quoted 10 lines · Michal Rostecki
From: Michal Rostecki <[email protected]>
Before this change, raid1 read policy could be selected by using the /sys/fs/btrfs/[fsid]/read_policy file.
Change it to /sys/fs/btrfs/[fsid]/read_policies/policy.
The motivation behing creating the
read_policiesdirectory is that the next changes and new read policies are going to intruduce settings specific to read policies.
No Documentation/ABI/ update for this change?
Re: [PATCH RFC 5/6] btrfs: sysfs: Add directory for read policies
Quoted 6 lines · Greg KH
Quoted 5 lines · Michal Rostecki
From: Michal Rostecki <[email protected]>
Before this change, raid1 read policy could be selected by using the /sys/fs/btrfs/[fsid]/read_policy file.
Quoted 8 lines
Quoted 5 lines
Change it to /sys/fs/btrfs/[fsid]/read_policies/policy.
The motivation behing creating the
read_policiesdirectory is that the next changes and new read policies are going to intruduce settings specific to read policies.No
Documentation/ABI/update for this change?
Good point. As far as I see, we have no btrfs-related file there. I will add it to Documentation/ABI/testing in v2.
I guess we also need to document all the options from btrfs that are unaffected by this particular patchset? Would it make sense to cover them in a separate patch?
Re: [PATCH RFC 5/6] btrfs: sysfs: Add directory for read policies
Quoted 16 lines · Michal Rostecki
Quoted 6 lines · Greg KH
Quoted 5 lines · Michal Rostecki
From: Michal Rostecki <[email protected]>
Before this change, raid1 read policy could be selected by using the /sys/fs/btrfs/[fsid]/read_policy file.
Quoted 8 lines
Quoted 5 lines
Change it to /sys/fs/btrfs/[fsid]/read_policies/policy.
The motivation behing creating the
read_policiesdirectory is that the next changes and new read policies are going to intruduce settings specific to read policies.No
Documentation/ABI/update for this change?
Quoted 6 lines
Good point. As far as I see, we have no btrfs-related file there. I will add it to
Documentation/ABI/testingin v2.I guess we also need to document all the options from btrfs that are unaffected by this particular patchset? Would it make sense to cover them in a separate patch?
That would be a good idea to do as a separate and new patch, yes.
thanks,
greg k-h
RFC PATCH 6/6 btrfs: Add roundrobin raid1 read policy
In reply to Michal RosteckiFrom: Michal Rostecki <[email protected]>
Add a new raid1 read policy roundrobin. For each read request, it selects the mirror which has lower load than queue depth and it starts iterating from the last used mirror (by the current CPU). Load is defined as the number of inflight requests + a potential penalty value.
The policy can be enabled through sysfs:
# echo roundrobin > /sys/fs/btrfs/[fsid]/read_policies/policy
This policy was tested with fio and compared with the default pid policy.
The singlethreaded test has the following parameters:
[global]
name=btrfs-raid1-seqread
filename=btrfs-raid1-seqread
rw=read
bs=64k
direct=0
numjobs=1
time_based=0
[file1]
size=10G
ioengine=libaio
and shows the following results:
- raid1c3 with 3 HDDs:
3 x Segate Barracuda ST2000DM008 (2TB)
* pid policy
READ: bw=217MiB/s (228MB/s), 217MiB/s-217MiB/s (228MB/s-228MB/s),
io=10.0GiB (10.7GB), run=47082-47082msec
* roundrobin policy
READ: bw=409MiB/s (429MB/s), 409MiB/s-409MiB/s (429MB/s-429MB/s),
io=10.0GiB (10.7GB), run=25028-25028mse- raid1c3 with 2 HDDs and 1 SSD:
2 x Segate Barracuda ST2000DM008 (2TB)
1 x Crucial CT256M550SSD1 (256GB)
* pid policy (the worst case when only HDDs were chosen)
READ: bw=220MiB/s (231MB/s), 220MiB/s-220MiB/s (231MB/s-231MB/s),
io=10.0GiB (10.7GB), run=46577-46577mse
* pid policy (the best case when SSD was used as well)
READ: bw=513MiB/s (538MB/s), 513MiB/s-513MiB/s (538MB/s-538MB/s),
io=10.0GiB (10.7GB), run=19954-19954msec
* roundrobin (there are no noticeable differences when testing multiple
times)
READ: bw=541MiB/s (567MB/s), 541MiB/s-541MiB/s (567MB/s-567MB/s),
io=10.0GiB (10.7GB), run=18933-18933msecThe multithreaded test has the following parameters:
[global]
name=btrfs-raid1-seqread
filename=btrfs-raid1-seqread
rw=read
bs=64k
direct=0
numjobs=8
time_based=0
[file1]
size=10G
ioengine=libaio
and shows the following results:
- raid1c3 with 3 HDDs: 3 x Segate Barracuda ST2000DM008 (2TB) 3 x Segate Barracuda ST2000DM008 (2TB)
* pid policy
READ: bw=1569MiB/s (1645MB/s), 196MiB/s-196MiB/s (206MB/s-206MB/s),
io=80.0GiB (85.9GB), run=52210-52211msec
* roundrobin
READ: bw=1733MiB/s (1817MB/s), 217MiB/s-217MiB/s (227MB/s-227MB/s),
io=80.0GiB (85.9GB), run=47269-47271msec- raid1c3 with 2 HDDs and 1 SSD:
2 x Segate Barracuda ST2000DM008 (2TB)
1 x Crucial CT256M550SSD1 (256GB)
* pid policy
READ: bw=1843MiB/s (1932MB/s), 230MiB/s-230MiB/s (242MB/s-242MB/s),
io=80.0GiB (85.9GB), run=44449-44450msec
* roundrobin
READ: bw=2485MiB/s (2605MB/s), 311MiB/s-311MiB/s (326MB/s-326MB/s),
io=80.0GiB (85.9GB), run=32969-32970msecThe penalty value is an additional value added to the number of inflight requests when a scheduled request is non-local (which means it would start from the different physical location than the physical location of the last request processed by the given device). By default, it's applied only in filesystems which have mixed types of devices (non-rotational and rotational), but it can be configured to be applied without that condition.
The configuration is done through sysfs:
- /sys/fs/btrfs/[fsid]/read_policies/roundrobin_nonlocal_inc_mixed_only
where 1 (the default) value means applying penalty only in mixed arrays, 0 means applying it unconditionally.
The exact penalty value is defined separately for non-rotational and rotational devices. By default, it's 0 for non-rotational devices and 1 for rotational devices. Both values are configurable through sysfs:
- /sys/fs/btrfs/[fsid]/read_policies/roundrobin_nonrot_nonlocal_inc
- /sys/fs/btrfs/[fsid]/read_policies/roundrobin_rot_nonlocal_inc
To sum it up - the default case is applying the penalty under the following conditions:
- the raid1 array consists of mixed types of devices
- the scheduled request is going to be non-local for the given disk
- the device is rotational
That default case is based on a slight preference towards non-rotational disks in mixed arrays and has proven to give the best performance in tested arrays.
For the array with 3 HDDs, not adding any penalty resulted in 409MiB/s (429MB/s) performance. Adding the penalty value 1 resulted in a performance drop to 404MiB/s (424MB/s). Increasing the value towards 10 was making the performance even worse.
For the array with 2 HDDs and 1 SSD, adding penalty value 1 to rotational disks resulted in the best performance - 541MiB/s (567MB/s). Not adding any value and increasing the value was making the performance worse.
Adding penalty value to non-rotational disks was always decreasing the performance, which motivated setting it as 0 by default. For the purpose of testing, it's still configurable.
To measure the performance of each policy and find optimal penalty values, I created scripts which are available here:
https://gitlab.com/vadorovsky/btrfs-perf
https://github.com/mrostecki/btrfs-perf
--- fs/btrfs/ctree.h | 3 + fs/btrfs/disk-io.c | 3 + fs/btrfs/sysfs.c | 93 +++++++++++++++++++++++++++++- fs/btrfs/volumes.c | 137 ++++++++++++++++++++++++++++++++++++++++++++- fs/btrfs/volumes.h | 10 ++++ 5 files changed, 242 insertions(+), 4 deletions(-)
fs/btrfs/ctree.h +3 -0
@@ -976,6 +976,9 @@ struct btrfs_fs_info {/* Max size to emit ZONE_APPEND write command */ u64 max_zone_append_size; +/* Last mirror picked in round-robin selection */ +int __percpu *last_mirror; +#ifdef CONFIG_BTRFS_FS_REF_VERIFY spinlock_t ref_verify_lock;struct rb_root block_tree;
fs/btrfs/disk-io.c +3 -0
@@ -1547,6 +1547,7 @@ void btrfs_free_fs_info(struct btrfs_fs_info *fs_info)btrfs_extent_buffer_leak_debug_check (fs_info);kfree (fs_info->super_copy);kfree (fs_info->super_for_commit); +free_percpu (fs_info->last_mirror);kvfree (fs_info); }
@@ -2857,6 +2858,8 @@ void btrfs_init_fs_info(struct btrfs_fs_info *fs_info) fs_info->swapfile_pins =RB_ROOT ; fs_info->send_in_progress =0 ; + + fs_info->last_mirror =__alloc_percpu (sizeof (int ), __alignof__(int )); }static int init_mount_fs_info (struct btrfs_fs_info *fs_info,struct super_block *sb)
fs/btrfs/sysfs.c +92 -1
107 lines not on this page · raw message
fs/btrfs/volumes.c +134 -3
169 lines not on this page · raw message
fs/btrfs/volumes.h +10 -0
@@ -230,9 +230,15 @@ enum btrfs_chunk_allocation_policy {enum btrfs_read_policy {/* Use process PID to choose the stripe */ BTRFS_READ_POLICY_PID , +/* Round robin */ +BTRFS_READ_POLICY_ROUNDROBIN ,BTRFS_NR_READ_POLICY , }; +/* Default raid1 policies config */ +#define BTRFS_DEFAULT_ROUNDROBIN_NONROT_NONLOCAL_INC 0 +#define BTRFS_DEFAULT_ROUNDROBIN_ROT_NONLOCAL_INC 1 +struct btrfs_fs_devices {u8 fsid[BTRFS_FSID_SIZE ];/* FS specific uuid */ u8 metadata_uuid[BTRFS_FSID_SIZE ];
@@ -294,6 +300,10 @@ struct btrfs_fs_devices {/* Policy used to read the mirrored stripes */ enum btrfs_read_policy read_policy; +/* Policies config */ +bool roundrobin_nonlocal_inc_mixed_only; +u32 roundrobin_nonrot_nonlocal_inc; +u32 roundrobin_rot_nonlocal_inc; };#define BTRFS_BIO_INLINE_CSUM_SIZE 64
Signature · 1 line
2.30.0
Re: [PATCH RFC 6/6] btrfs: Add roundrobin raid1 read policy
On Tue, Feb 09, 2021 at 09:30:40PM +0100, Michal Rostecki wrote:
[...]
Quoted 13 lines
For the array with 3 HDDs, not adding any penalty resulted in 409MiB/s (429MB/s) performance. Adding the penalty value 1 resulted in a performance drop to 404MiB/s (424MB/s). Increasing the value towards 10 was making the performance even worse.
For the array with 2 HDDs and 1 SSD, adding penalty value 1 to rotational disks resulted in the best performance - 541MiB/s (567MB/s). Not adding any value and increasing the value was making the performance worse.
Adding penalty value to non-rotational disks was always decreasing the performance, which motivated setting it as 0 by default. For the purpose of testing, it's still configurable.
[...]
Quoted 6 lines
fs/btrfs/volumes.c +6
-0+ bdev = map->stripes[mirror_index].dev->bdev; + inflight =mirror_load (fs_info, map, mirror_index, stripe_offset, + stripe_nr); + queue_depth =blk_queue_depth (bdev->bd_disk->queue); + +return inflight < queue_depth;
[...]
Quoted 1 line
fs/btrfs/volumes.c +1
-0+ last_mirror =this_cpu_read (*fs_info->last_mirror);
[...]
Quoted 10 lines
fs/btrfs/volumes.c +10
-0+for (i = last_mirror; i < first + num_stripes; i++) { +if (mirror_queue_not_filled (fs_info, map, i, stripe_offset, + stripe_nr)) { + preferred_mirror = i; + goto out; + } + } + +for (i = first; i < last_mirror; i++) { + if (mirror_queue_not_filled(fs_info, map, i, stripe_offset,
fs/btrfs/volumes.c static u64 stripe_physical(struct map_lookup *map, u32 stripe_index, · line 5675
Quoted 10 lines
fs/btrfs/volumes.c +10
-0+ stripe_nr)) { + preferred_mirror = i; + goto out; + } + } + + preferred_mirror = last_mirror; + +out: +this_cpu_write (*fs_info->last_mirror, preferred_mirror);
This looks like it effectively decreases queue depth for non-last device. After all devices are filled to queue_depth-penalty, only a single mirror will be selected for next reads (until a read on some other one completes).
Have you tried testing with much more jobs / non-sequential accesses?
Best Reagrds,
Michał Mirosław
Re: [PATCH RFC 6/6] btrfs: Add roundrobin raid1 read policy
Quoted 42 lines · Michał Mirosław
On Tue, Feb 09, 2021 at 09:30:40PM +0100, Michal Rostecki wrote:
[...]Quoted 13 lines
For the array with 3 HDDs, not adding any penalty resulted in 409MiB/s (429MB/s) performance. Adding the penalty value 1 resulted in a performance drop to 404MiB/s (424MB/s). Increasing the value towards 10 was making the performance even worse.
For the array with 2 HDDs and 1 SSD, adding penalty value 1 to rotational disks resulted in the best performance - 541MiB/s (567MB/s). Not adding any value and increasing the value was making the performance worse.
Adding penalty value to non-rotational disks was always decreasing the performance, which motivated setting it as 0 by default. For the purpose of testing, it's still configurable.
[...]
Quoted 6 lines
fs/btrfs/volumes.c +6
-0+ bdev = map->stripes[mirror_index].dev->bdev; + inflight =mirror_load (fs_info, map, mirror_index, stripe_offset, + stripe_nr); + queue_depth =blk_queue_depth (bdev->bd_disk->queue); + +return inflight < queue_depth;[...]
Quoted 1 line
fs/btrfs/volumes.c +1
-0+ last_mirror =this_cpu_read (*fs_info->last_mirror);[...]
Quoted 17 lines
fs/btrfs/volumes.c +17
-0+for (i = last_mirror; i < first + num_stripes; i++) { +if (mirror_queue_not_filled (fs_info, map, i, stripe_offset, + stripe_nr)) { + preferred_mirror = i; + goto out; + } + } + +for (i = first; i < last_mirror; i++) { +if (mirror_queue_not_filled (fs_info, map, i, stripe_offset, + stripe_nr)) { + preferred_mirror = i; + goto out; + } + } + + preferred_mirror = last_mirror;
Quoted 9 lines
fs/btrfs/volumes.c static u64 stripe_physical(struct map_lookup *map, u32 stripe_index, · line 5675
Quoted 3 lines
fs/btrfs/volumes.c +3
-0+ +out: +this_cpu_write (*fs_info->last_mirror, preferred_mirror);This looks like it effectively decreases queue depth for non-last device. After all devices are filled to queue_depth-penalty, only a single mirror will be selected for next reads (until a read on some other one completes).
Good point. And if all devices are going to be filled for longer time, this function will keep selecting the last one. Maybe I should select last+1 in that case. Would that address your concern or did you have any other solution in mind?
Thanks for pointing that out.
Quoted 2 lines
Have you tried testing with much more jobs / non-sequential accesses?
I didn't try with non-sequential accesses. Will do that before respinning v2.
Quoted 2 lines
Best Reagrds,
Michał Mirosław
Regards,
Michal
Re: [PATCH RFC 6/6] btrfs: Add roundrobin raid1 read policy
Quoted 53 lines · Michal Rostecki
Quoted 42 lines · Michał Mirosław
On Tue, Feb 09, 2021 at 09:30:40PM +0100, Michal Rostecki wrote:
[...]Quoted 13 lines
For the array with 3 HDDs, not adding any penalty resulted in 409MiB/s (429MB/s) performance. Adding the penalty value 1 resulted in a performance drop to 404MiB/s (424MB/s). Increasing the value towards 10 was making the performance even worse.
For the array with 2 HDDs and 1 SSD, adding penalty value 1 to rotational disks resulted in the best performance - 541MiB/s (567MB/s). Not adding any value and increasing the value was making the performance worse.
Adding penalty value to non-rotational disks was always decreasing the performance, which motivated setting it as 0 by default. For the purpose of testing, it's still configurable.
[...]
Quoted 6 lines
fs/btrfs/volumes.c +6
-0+ bdev = map->stripes[mirror_index].dev->bdev; + inflight =mirror_load (fs_info, map, mirror_index, stripe_offset, + stripe_nr); + queue_depth =blk_queue_depth (bdev->bd_disk->queue); + +return inflight < queue_depth;[...]
Quoted 1 line
fs/btrfs/volumes.c +1
-0+ last_mirror =this_cpu_read (*fs_info->last_mirror);[...]
Quoted 17 lines
fs/btrfs/volumes.c +17
-0+for (i = last_mirror; i < first + num_stripes; i++) { +if (mirror_queue_not_filled (fs_info, map, i, stripe_offset, + stripe_nr)) { + preferred_mirror = i; + goto out; + } + } + +for (i = first; i < last_mirror; i++) { +if (mirror_queue_not_filled (fs_info, map, i, stripe_offset, + stripe_nr)) { + preferred_mirror = i; + goto out; + } + } + + preferred_mirror = last_mirror;Quoted 9 lines
fs/btrfs/volumes.c static u64 stripe_physical(struct map_lookup *map, u32 stripe_index, · line 5675
Quoted 3 lines
fs/btrfs/volumes.c +3
-0+ +out: +this_cpu_write (*fs_info->last_mirror, preferred_mirror);This looks like it effectively decreases queue depth for non-last device. After all devices are filled to queue_depth-penalty, only a single mirror will be selected for next reads (until a read on some other one completes).
Quoted 4 lines
Good point. And if all devices are going to be filled for longer time, this function will keep selecting the last one. Maybe I should select last+1 in that case. Would that address your concern or did you have any other solution in mind?
The best would be to postpone the selection until one device becomes free again. But if that's not doable, then yes, you could make sure it stays round-robin after filling the queues (the scheduling will loose the "penalty"-driven adjustment though).
Best Reagrds,
Michał Mirosław
Re: [PATCH RFC 6/6] btrfs: Add roundrobin raid1 read policy
Quoted 13 lines · Michał Mirosław
Quoted 11 lines · Michal Rostecki
Quoted 5 lines · Michał Mirosław
This looks like it effectively decreases queue depth for non-last device. After all devices are filled to queue_depth-penalty, only a single mirror will be selected for next reads (until a read on some other one completes).
Good point. And if all devices are going to be filled for longer time, this function will keep selecting the last one. Maybe I should select last+1 in that case. Would that address your concern or did you have any other solution in mind?
Quoted 4 lines
The best would be to postpone the selection until one device becomes free again. But if that's not doable, then yes, you could make sure it stays round-robin after filling the queues (the scheduling will loose the "penalty"-driven adjustment though).
Or another idea - when all the queues are filled, return the mirror which has the lowest load (inflight + penalty), even though it's greater than queue depth. In that case the scheduling will not lose the penalty adjustment and the load is going to be spreaded more fair.
I'm not sure if postponing the selection is that good idea. I think it's better if the request is added to the iosched queue anyway, even if the disks' queues are filled, and let the I/O scheduler handle that. The length of the iosched queue (nr_requests, attribute of the iosched) is usually greater than queue depth (attribute of the devide), which means that it's fine to schedule more requests for iosched to handle.
IMO btrfs should use the information given by iosched only for heuristic mirror selection, rather than implement its own throttling logic.
Does it make sense to you?
An another idea could be an additional iteration in regard to nr_requests, if all load values are greater than queue depths, though it might be an overkill. I would prefer to stick to my first idea if everyone agrees.
Regards,
Michal
Re: [PATCH RFC 6/6] btrfs: Add roundrobin raid1 read policy
Quoted 34 lines · Michal Rostecki
Quoted 13 lines · Michał Mirosław
Quoted 11 lines · Michal Rostecki
Quoted 5 lines · Michał Mirosław
This looks like it effectively decreases queue depth for non-last device. After all devices are filled to queue_depth-penalty, only a single mirror will be selected for next reads (until a read on some other one completes).
Good point. And if all devices are going to be filled for longer time, this function will keep selecting the last one. Maybe I should select last+1 in that case. Would that address your concern or did you have any other solution in mind?
Quoted 4 lines
The best would be to postpone the selection until one device becomes free again. But if that's not doable, then yes, you could make sure it stays round-robin after filling the queues (the scheduling will loose the "penalty"-driven adjustment though).
Or another idea - when all the queues are filled, return the mirror which has the lowest load (inflight + penalty), even though it's greater than queue depth. In that case the scheduling will not lose the penalty adjustment and the load is going to be spreaded more fair.
I'm not sure if postponing the selection is that good idea. I think it's better if the request is added to the iosched queue anyway, even if the disks' queues are filled, and let the I/O scheduler handle that. The length of the iosched queue (
nr_requests, attribute of the iosched) is usually greater than queue depth (attribute of the devide), which means that it's fine to schedule more requests for iosched to handle.IMO btrfs should use the information given by iosched only for heuristic mirror selection, rather than implement its own throttling logic.
Quoted 6 lines
Does it make sense to you?
An another idea could be an additional iteration in regard to
nr_requests, if all load values are greater than queue depths, though it might be an overkill. I would prefer to stick to my first idea if everyone agrees.
What if iosched could provide an estimate of request's latency? Then btrfs could always select the lowest. For reads from NVME/SSD I would normally expect something simple: speed_factor * (pending_bytes + req_bytes). For HDDs this could do more computation like looking into what is there in the queue already.
This would deviate from simple round-robin scheme, though.
Best Regards
Michał Mirosław
Re: [PATCH RFC 6/6] btrfs: Add roundrobin raid1 read policy
Quoted 42 lines · Michał Mirosław
Quoted 34 lines · Michal Rostecki
Quoted 13 lines · Michał Mirosław
Quoted 11 lines · Michal Rostecki
Quoted 5 lines · Michał Mirosław
This looks like it effectively decreases queue depth for non-last device. After all devices are filled to queue_depth-penalty, only a single mirror will be selected for next reads (until a read on some other one completes).
Good point. And if all devices are going to be filled for longer time, this function will keep selecting the last one. Maybe I should select last+1 in that case. Would that address your concern or did you have any other solution in mind?
Quoted 4 lines
The best would be to postpone the selection until one device becomes free again. But if that's not doable, then yes, you could make sure it stays round-robin after filling the queues (the scheduling will loose the "penalty"-driven adjustment though).
Or another idea - when all the queues are filled, return the mirror which has the lowest load (inflight + penalty), even though it's greater than queue depth. In that case the scheduling will not lose the penalty adjustment and the load is going to be spreaded more fair.
I'm not sure if postponing the selection is that good idea. I think it's better if the request is added to the iosched queue anyway, even if the disks' queues are filled, and let the I/O scheduler handle that. The length of the iosched queue (
nr_requests, attribute of the iosched) is usually greater than queue depth (attribute of the devide), which means that it's fine to schedule more requests for iosched to handle.IMO btrfs should use the information given by iosched only for heuristic mirror selection, rather than implement its own throttling logic.
Quoted 6 lines
Does it make sense to you?
An another idea could be an additional iteration in regard to
nr_requests, if all load values are greater than queue depths, though it might be an overkill. I would prefer to stick to my first idea if everyone agrees.
Quoted 7 lines
What if iosched could provide an estimate of request's latency? Then btrfs could always select the lowest. For reads from NVME/SSD I would normally expect something simple:
speed_factor* (pending_bytes+req_bytes). For HDDs this could do more computation like looking into what is there in the queue already.This would deviate from simple round-robin scheme, though.
I think that idea is close to what Anand Jain did in his latency policy, though instead of trying to predict the latency of the currently scheduled request, it uses stats about previous read operations:
Indeed your idea would deviate from the simple round-robin, so maybe it would be good to try it, but as a separate policy in a separate patch(set).
Regards,
Michal
Re: [PATCH RFC 6/6] btrfs: Add roundrobin raid1 read policy
In reply to Michal RosteckiQuoted 131 lines · Michal Rostecki
From: Michal Rostecki <[email protected]>
Add a new raid1 read policy
roundrobin. For each read request, it selects the mirror which has lower load than queue depth and it starts iterating from the last used mirror (by the current CPU). Load is defined as the number of inflight requests + a potential penalty value.The policy can be enabled through sysfs:
# echo roundrobin > /sys/fs/btrfs/[fsid]/read_policies/policyThis policy was tested with fio and compared with the default
pidpolicy.The singlethreaded test has the following parameters:
[global] name=btrfs-raid1-seqread filename=btrfs-raid1-seqread rw=read bs=64k direct=0 numjobs=1 time_based=0 [file1] size=10G ioengine=libaioand shows the following results:
- raid1c3 with 3 HDDs:
3 x Segate Barracuda ST2000DM008 (2TB) * pid policy READ: bw=217MiB/s (228MB/s), 217MiB/s-217MiB/s (228MB/s-228MB/s), io=10.0GiB (10.7GB), run=47082-47082msec * roundrobin policy READ: bw=409MiB/s (429MB/s), 409MiB/s-409MiB/s (429MB/s-429MB/s), io=10.0GiB (10.7GB), run=25028-25028mse - raid1c3 with 2 HDDs and 1 SSD: 2 x Segate Barracuda ST2000DM008 (2TB) 1 x Crucial CT256M550SSD1 (256GB) * pid policy (the worst case when only HDDs were chosen) READ: bw=220MiB/s (231MB/s), 220MiB/s-220MiB/s (231MB/s-231MB/s), io=10.0GiB (10.7GB), run=46577-46577mse * pid policy (the best case when SSD was used as well) READ: bw=513MiB/s (538MB/s), 513MiB/s-513MiB/s (538MB/s-538MB/s), io=10.0GiB (10.7GB), run=19954-19954msec * roundrobin (there are no noticeable differences when testing multiple times) READ: bw=541MiB/s (567MB/s), 541MiB/s-541MiB/s (567MB/s-567MB/s), io=10.0GiB (10.7GB), run=18933-18933msecThe multithreaded test has the following parameters:
[global] name=btrfs-raid1-seqread filename=btrfs-raid1-seqread rw=read bs=64k direct=0 numjobs=8 time_based=0 [file1] size=10G ioengine=libaioand shows the following results:
- raid1c3 with 3 HDDs: 3 x Segate Barracuda ST2000DM008 (2TB) 3 x Segate Barracuda ST2000DM008 (2TB)
* pid policyREAD: bw=1569MiB/s (1645MB/s), 196MiB/s-196MiB/s (206MB/s-206MB/s), io=80.0GiB (85.9GB), run=52210-52211msec * roundrobin READ: bw=1733MiB/s (1817MB/s), 217MiB/s-217MiB/s (227MB/s-227MB/s), io=80.0GiB (85.9GB), run=47269-47271msec - raid1c3 with 2 HDDs and 1 SSD: 2 x Segate Barracuda ST2000DM008 (2TB) 1 x Crucial CT256M550SSD1 (256GB) * pid policy READ: bw=1843MiB/s (1932MB/s), 230MiB/s-230MiB/s (242MB/s-242MB/s), io=80.0GiB (85.9GB), run=44449-44450msec * roundrobin READ: bw=2485MiB/s (2605MB/s), 311MiB/s-311MiB/s (326MB/s-326MB/s), io=80.0GiB (85.9GB), run=32969-32970msecThe penalty value is an additional value added to the number of inflight requests when a scheduled request is non-local (which means it would start from the different physical location than the physical location of the last request processed by the given device). By default, it's applied only in filesystems which have mixed types of devices (non-rotational and rotational), but it can be configured to be applied without that condition.
The configuration is done through sysfs:
Quoted 1 line
- /sys/fs/btrfs/[fsid]/read_policies/roundrobin_nonlocal_inc_mixed_only
where 1 (the default) value means applying penalty only in mixed arrays, 0 means applying it unconditionally.
The exact penalty value is defined separately for non-rotational and rotational devices. By default, it's 0 for non-rotational devices and 1 for rotational devices. Both values are configurable through sysfs:
- /sys/fs/btrfs/[fsid]/read_policies/roundrobin_nonrot_nonlocal_inc
- /sys/fs/btrfs/[fsid]/read_policies/roundrobin_rot_nonlocal_incTo sum it up - the default case is applying the penalty under the following conditions:
- the raid1 array consists of mixed types of devices
- the scheduled request is going to be non-local for the given disk
- the device is rotationalThat default case is based on a slight preference towards non-rotational disks in mixed arrays and has proven to give the best performance in tested arrays.
Quoted 1 line
For the array with 3 HDDs, not adding any penalty resulted in 409MiB/s
(429MB/s) performance. Adding the penalty value 1 resulted in a performance drop to 404MiB/s (424MB/s). Increasing the value towards 10 was making the performance even worse.
For the array with 2 HDDs and 1 SSD, adding penalty value 1 to rotational disks resulted in the best performance - 541MiB/s (567MB/s). Not adding any value and increasing the value was making the performance worse.
Quoted 7 lines
Quoted 1 line
Adding penalty value to non-rotational disks was always decreasing the
performance, which motivated setting it as 0 by default. For the purpose of testing, it's still configurable.
To measure the performance of each policy and find optimal penalty values, I created scripts which are available here:
So in summary
rotational + non-rotational: penalty = 1
all-rotational and homo : penalty = 0
all-non-rotational and homo: penalty = 0
I can't find any non-deterministic in your findings above. It is not very clear to me if we need the configurable parameters here.
It is better to have random workloads in the above three categories of configs.
Apart from the above three configs, there is also
all-non-rotational with hetero
For example, ssd and nvme together both are non-rotational. And,
all-rotational with hetero
For example, rotational disks with different speeds.
The inflight calculation is local to btrfs. If the device is busy due to external factors, it would not switch to the better performing device.
Thanks, Anand
Quoted 370 lines
https://gitlab.com/vadorovsky/btrfs-perf
https://github.com/mrostecki/btrfs-perfSigned-off-by Michal Rostecki <[email protected]>--- fs/btrfs/ctree.h | 3 + fs/btrfs/disk-io.c | 3 + fs/btrfs/sysfs.c | 93 +++++++++++++++++++++++++++++- fs/btrfs/volumes.c | 137 ++++++++++++++++++++++++++++++++++++++++++++- fs/btrfs/volumes.h | 10 ++++ 5 files changed, 242 insertions(+), 4 deletions(-)fs/btrfs/ctree.h +3
-0@@ -976,6 +976,9 @@ struct btrfs_fs_info {/* Max size to emit ZONE_APPEND write command */ u64 max_zone_append_size; +/* Last mirror picked in round-robin selection */ +int __percpu *last_mirror; +#ifdef CONFIG_BTRFS_FS_REF_VERIFY spinlock_t ref_verify_lock;struct rb_root block_tree;fs/btrfs/disk-io.c +3
-0@@ -1547,6 +1547,7 @@ void btrfs_free_fs_info(struct btrfs_fs_info *fs_info)btrfs_extent_buffer_leak_debug_check (fs_info);kfree (fs_info->super_copy);kfree (fs_info->super_for_commit); +free_percpu (fs_info->last_mirror);kvfree (fs_info); }@@ -2857,6 +2858,8 @@ void btrfs_init_fs_info(struct btrfs_fs_info *fs_info) fs_info->swapfile_pins =RB_ROOT ; fs_info->send_in_progress =0 ; + + fs_info->last_mirror =__alloc_percpu (sizeof (int ), __alignof__(int )); }static int init_mount_fs_info (struct btrfs_fs_info *fs_info,struct super_block *sb)fs/btrfs/sysfs.c +92
-1@@ -928,7 +928,7 @@ static bool strmatch(const char *buffer, const char *string)return false; } -static const char *const btrfs_read_policy_name[] = {"pid" }; +static const char *const btrfs_read_policy_name[] = {"pid" ,"roundrobin" };static ssize_t btrfs_read_policy_show (struct kobject *kobj,struct kobj_attribute *a,char *buf)@@ -976,8 +976,99 @@ static ssize_t btrfs_read_policy_store(struct kobject *kobj, }BTRFS_ATTR_RW (read_policies, policy, btrfs_read_policy_show, btrfs_read_policy_store); +static ssize_t btrfs_roundrobin_nonlocal_inc_mixed_only_show ( +struct kobject *kobj,struct kobj_attribute *a,char *buf) +{ +struct btrfs_fs_devices *fs_devices =to_fs_devs (kobj->parent); + +return scnprintf (buf,PAGE_SIZE ,"%d\n" , +READ_ONCE (fs_devices->roundrobin_nonlocal_inc_mixed_only)); +} + +static ssize_t btrfs_roundrobin_nonlocal_inc_mixed_only_store ( +struct kobject *kobj,struct kobj_attribute *a,const char *buf, +size_t len) +{ +struct btrfs_fs_devices *fs_devices =to_fs_devs (kobj->parent); +bool val; +int ret; + + ret =kstrtobool (buf, &val); +if (ret) +return -EINVAL ; + +WRITE_ONCE (fs_devices->roundrobin_nonlocal_inc_mixed_only, val); +return len; +} +BTRFS_ATTR_RW (read_policies, roundrobin_nonlocal_inc_mixed_only, + btrfs_roundrobin_nonlocal_inc_mixed_only_show, + btrfs_roundrobin_nonlocal_inc_mixed_only_store); + +static ssize_t btrfs_roundrobin_nonrot_nonlocal_inc_show (struct kobject *kobj, +struct kobj_attribute *a, +char *buf) +{ +struct btrfs_fs_devices *fs_devices =to_fs_devs (kobj->parent); + +return scnprintf (buf,PAGE_SIZE ,"%d\n" , +READ_ONCE (fs_devices->roundrobin_nonrot_nonlocal_inc)); +} + +static ssize_t btrfs_roundrobin_nonrot_nonlocal_inc_store (struct kobject *kobj, +struct kobj_attribute *a, +const char *buf, +size_t len) +{ +struct btrfs_fs_devices *fs_devices =to_fs_devs (kobj->parent); +u32 val; +int ret; + + ret =kstrtou32 (buf,10 , &val); +if (ret) +return -EINVAL ; + +WRITE_ONCE (fs_devices->roundrobin_nonrot_nonlocal_inc, val); +return len; +} +BTRFS_ATTR_RW (read_policies, roundrobin_nonrot_nonlocal_inc, + btrfs_roundrobin_nonrot_nonlocal_inc_show, + btrfs_roundrobin_nonrot_nonlocal_inc_store); + +static ssize_t btrfs_roundrobin_rot_nonlocal_inc_show (struct kobject *kobj, +struct kobj_attribute *a, +char *buf) +{ +struct btrfs_fs_devices *fs_devices =to_fs_devs (kobj->parent); + +return scnprintf (buf,PAGE_SIZE ,"%d\n" , +READ_ONCE (fs_devices->roundrobin_rot_nonlocal_inc)); +} + +static ssize_t btrfs_roundrobin_rot_nonlocal_inc_store (struct kobject *kobj, +struct kobj_attribute *a, +const char *buf, +size_t len) +{ +struct btrfs_fs_devices *fs_devices =to_fs_devs (kobj->parent); +u32 val; +int ret; + + ret =kstrtou32 (buf,10 , &val); +if (ret) +return -EINVAL ; + +WRITE_ONCE (fs_devices->roundrobin_rot_nonlocal_inc, val); +return len; +} +BTRFS_ATTR_RW (read_policies, roundrobin_rot_nonlocal_inc, + btrfs_roundrobin_rot_nonlocal_inc_show, + btrfs_roundrobin_rot_nonlocal_inc_store); +static const struct attribute *read_policies_attrs[] = {BTRFS_ATTR_PTR (read_policies, policy), +BTRFS_ATTR_PTR (read_policies, roundrobin_nonlocal_inc_mixed_only), +BTRFS_ATTR_PTR (read_policies, roundrobin_nonrot_nonlocal_inc), +BTRFS_ATTR_PTR (read_policies, roundrobin_rot_nonlocal_inc),NULL , };fs/btrfs/volumes.c +134
-3@@ -1265,6 +1265,11 @@ static int open_fs_devices(struct btrfs_fs_devices *fs_devices, fs_devices->total_rw_bytes =0 ; fs_devices->chunk_alloc_policy =BTRFS_CHUNK_ALLOC_REGULAR ; fs_devices->read_policy =BTRFS_READ_POLICY_PID ; + fs_devices->roundrobin_nonlocal_inc_mixed_only = true; + fs_devices->roundrobin_nonrot_nonlocal_inc = +BTRFS_DEFAULT_ROUNDROBIN_NONROT_NONLOCAL_INC ; + fs_devices->roundrobin_rot_nonlocal_inc = +BTRFS_DEFAULT_ROUNDROBIN_ROT_NONLOCAL_INC ;return 0 ; }@@ -5555,8 +5560,125 @@ static u64 stripe_physical(struct map_lookup *map, u32 stripe_index, stripe_nr * map->stripe_len; } +/* +* Calculates the load of the given mirror. Load is defines as the number of +* inflight requests + potential penalty value. +* +* @fs_info: the filesystem +* @map: mapping containing the logical extent +* @mirror_index: number of mirror to check +* @stripe_offset: offset of the block in its stripe +* @stripe_nr: index of the stripe whete the block falls in +*/ +static int mirror_load (struct btrfs_fs_info *fs_info,struct map_lookup *map, +int mirror_index,u64 stripe_offset,u64 stripe_nr) +{ +struct btrfs_fs_devices *fs_devices; +struct btrfs_device *dev; +int last_offset; +u64 physical; +int load; + + dev = map->stripes[mirror_index].dev; + load =percpu_counter_sum (&dev->inflight); + last_offset =atomic_read (&dev->last_offset); + physical =stripe_physical (map, mirror_index, stripe_offset, stripe_nr); + + fs_devices = fs_info->fs_devices; + +/* +* If the filesystem has mixed type of devices (or we enable adding a +* penalty value regardless) and the request is non-local, add a +* penalty value. +*/ +if ((!fs_devices->roundrobin_nonlocal_inc_mixed_only || + fs_devices->mixed) && last_offset != physical) { +if (dev->rotating) +return load + fs_devices->roundrobin_rot_nonlocal_inc; +return load + fs_devices->roundrobin_nonrot_nonlocal_inc; + } + +return load; +} + +/* +* Checks if the given mirror can process more requests. +* +* @fs_info: the filesystem +* @map: mapping containing the logical extent +* @mirror_index: index of the mirror to check +* @stripe_offset: offset of the block in its stripe +* @stripe_nr: index of the stripe whete the block falls in +* +* Returns true if more requests can be processes, otherwise returns false. +*/ +static bool mirror_queue_not_filled (struct btrfs_fs_info *fs_info, +struct map_lookup *map,int mirror_index, +u64 stripe_offset,u64 stripe_nr) +{ +struct block_device *bdev; +unsigned int queue_depth; +int inflight; + + bdev = map->stripes[mirror_index].dev->bdev; + inflight =mirror_load (fs_info, map, mirror_index, stripe_offset, + stripe_nr); + queue_depth =blk_queue_depth (bdev->bd_disk->queue); + +return inflight < queue_depth; +} + +/* +* Find a mirror using the round-robin technique which has lower load than +* queue depth. Load is defined as the number of inflight requests + potential +* penalty value. +* +* @fs_info: the filesystem +* @map: mapping containing the logical extent +* @first: index of the first device in the stripes array +* @num_stripes: number of stripes in the stripes array +* @stripe_offset: offset of the block in its stripe +* @stripe_nr: index of the stripe whete the block falls in +* +* Returns the index of selected mirror. +*/ +static int find_live_mirror_roundrobin (struct btrfs_fs_info *fs_info, +struct map_lookup *map,int first, +int num_stripes,u64 stripe_offset, +u64 stripe_nr) +{ +int preferred_mirror; +int last_mirror; +int i; + + last_mirror =this_cpu_read (*fs_info->last_mirror); + +for (i = last_mirror; i < first + num_stripes; i++) { +if (mirror_queue_not_filled (fs_info, map, i, stripe_offset, + stripe_nr)) { + preferred_mirror = i; + goto out; + } + } + +for (i = first; i < last_mirror; i++) { +if (mirror_queue_not_filled (fs_info, map, i, stripe_offset, + stripe_nr)) { + preferred_mirror = i; + goto out; + } + } + + preferred_mirror = last_mirror; + +out: +this_cpu_write (*fs_info->last_mirror, preferred_mirror); +return preferred_mirror; +} +static int find_live_mirror (struct btrfs_fs_info *fs_info,struct map_lookup *map,int first, +u64 stripe_offset,u64 stripe_nr,int dev_replace_is_ongoing) {int i;@@ -5584,6 +5706,11 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,case BTRFS_READ_POLICY_PID : preferred_mirror = first + (current->pid % num_stripes);break ; +case BTRFS_READ_POLICY_ROUNDROBIN : + preferred_mirror =find_live_mirror_roundrobin ( + fs_info, map, first, num_stripes, stripe_offset, + stripe_nr); +break ; } if (dev_replace_is_ongoing &&@@ -6178,7 +6305,9 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, stripe_index = mirror_num -1 ; else { stripe_index =find_live_mirror (fs_info, map,0 , - dev_replace_is_ongoing); + stripe_offset, + stripe_nr, + dev_replace_is_ongoing); mirror_num = stripe_index +1 ; }@@ -6204,8 +6333,10 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info,else {int old_stripe_index = stripe_index; stripe_index =find_live_mirror (fs_info, map, - stripe_index, - dev_replace_is_ongoing); + stripe_index, + stripe_offset, + stripe_nr, + dev_replace_is_ongoing); mirror_num = stripe_index - old_stripe_index +1 ; }fs/btrfs/volumes.h +10
-0@@ -230,9 +230,15 @@ enum btrfs_chunk_allocation_policy {enum btrfs_read_policy {/* Use process PID to choose the stripe */ BTRFS_READ_POLICY_PID , +/* Round robin */ +BTRFS_READ_POLICY_ROUNDROBIN ,BTRFS_NR_READ_POLICY , }; +/* Default raid1 policies config */ +#define BTRFS_DEFAULT_ROUNDROBIN_NONROT_NONLOCAL_INC 0 +#define BTRFS_DEFAULT_ROUNDROBIN_ROT_NONLOCAL_INC 1 +struct btrfs_fs_devices {u8 fsid[BTRFS_FSID_SIZE ];/* FS specific uuid */ u8 metadata_uuid[BTRFS_FSID_SIZE ];@@ -294,6 +300,10 @@ struct btrfs_fs_devices {/* Policy used to read the mirrored stripes */ enum btrfs_read_policy read_policy; +/* Policies config */ +bool roundrobin_nonlocal_inc_mixed_only; +u32 roundrobin_nonrot_nonlocal_inc; +u32 roundrobin_rot_nonlocal_inc; };#define BTRFS_BIO_INLINE_CSUM_SIZE 64
Re: [PATCH RFC 6/6] btrfs: Add roundrobin raid1 read policy
Quoted 49 lines · Anand Jain
Quoted 40 lines · Michal Rostecki
The penalty value is an additional value added to the number of inflight requests when a scheduled request is non-local (which means it would start from the different physical location than the physical location of the last request processed by the given device). By default, it's applied only in filesystems which have mixed types of devices (non-rotational and rotational), but it can be configured to be applied without that condition.
The configuration is done through sysfs:
Quoted 1 line
- /sys/fs/btrfs/[fsid]/read_policies/roundrobin_nonlocal_inc_mixed_only
where 1 (the default) value means applying penalty only in mixed arrays, 0 means applying it unconditionally.
The exact penalty value is defined separately for non-rotational and rotational devices. By default, it's 0 for non-rotational devices and 1 for rotational devices. Both values are configurable through sysfs:
- /sys/fs/btrfs/[fsid]/read_policies/roundrobin_nonrot_nonlocal_inc
- /sys/fs/btrfs/[fsid]/read_policies/roundrobin_rot_nonlocal_incTo sum it up - the default case is applying the penalty under the following conditions:
- the raid1 array consists of mixed types of devices
- the scheduled request is going to be non-local for the given disk
- the device is rotationalThat default case is based on a slight preference towards non-rotational disks in mixed arrays and has proven to give the best performance in tested arrays.
Quoted 1 line
For the array with 3 HDDs, not adding any penalty resulted in 409MiB/s
(429MB/s) performance. Adding the penalty value 1 resulted in a performance drop to 404MiB/s (424MB/s). Increasing the value towards 10 was making the performance even worse.
For the array with 2 HDDs and 1 SSD, adding penalty value 1 to rotational disks resulted in the best performance - 541MiB/s (567MB/s). Not adding any value and increasing the value was making the performance worse.
Quoted 7 lines
Quoted 1 line
Adding penalty value to non-rotational disks was always decreasing the
performance, which motivated setting it as 0 by default. For the purpose of testing, it's still configurable.
To measure the performance of each policy and find optimal penalty values, I created scripts which are available here:
Quoted 9 lines
So in summary
rotational + non-rotational: penalty = 1
all-rotational and homo : penalty = 0
all-non-rotational and homo: penalty = 0I can't find any non-deterministic in your findings above. It is not very clear to me if we need the configurable parameters here.
Honestly, the main reason why I made it configurable is to check the performance of different values without editing and recompiling the kernel. I was trying to find the best set of values with my simple Python script which tries all values from 0 to 9 and runs fio. I left those partameters to be configurable in my patches just in case someone else would like to try to tune them on their environments.
The script is here:
https://github.com/mrostecki/btrfs-perf/blob/main/roundrobin-tune.py
But on the other hand, as I mentioned in the other mail - I'm getting skeptical about having the whole penalty mechanism in general. As I wrote and as you pointed, it improves the performance only for mixed arrays. And since the roundrobin policy doesn't perform on mixed as good as policies you proposed, but it performs good on homogeneous arays, maybe it's better if I just focus on homogeneous case, and save some CPU cycles by not storing physical locations.
Quoted 11 lines
It is better to have random workloads in the above three categories of configs.
Apart from the above three configs, there is also
all-non-rotational with hetero
For example, ssd and nvme together both are non-rotational. And,
all-rotational with hetero
For example, rotational disks with different speeds.
Quoted 3 lines
The inflight calculation is local to btrfs. If the device is busy due to external factors, it would not switch to the better performing device.
Good point. Maybe I should try to use the part stats instead of storing inflight locally in btrfs.
Re: [PATCH RFC 6/6] btrfs: Add roundrobin raid1 read policy
Hi Anand,
re: inflight calculation
Quoted 11 lines · Michal Rostecki
Quoted 11 lines
It is better to have random workloads in the above three categories of configs.
Apart from the above three configs, there is also
all-non-rotational with hetero
For example, ssd and nvme together both are non-rotational. And,
all-rotational with hetero
For example, rotational disks with different speeds.
Quoted 6 lines
Quoted 3 lines
The inflight calculation is local to btrfs. If the device is busy due to external factors, it would not switch to the better performing device.
Good point. Maybe I should try to use the part stats instead of storing inflight locally in btrfs.
I tried today to reuse the inflight calculation which is done for iostat. And I came to conclusion that it's impossible without exporting some methods from the block/ subsystem.
The thing is that there are two methods of calculating inflight. Which one of them is used, depends on queue_is_mq():
And if that condition is true, I noticed that part_stats return 0, even though there are processed requests (I checked with fio inside VM).
In general, those two methods of checking inflight are:
1) part_stats - which would be trivial to reuse, just a matter of one simple for_each_possible_cpu() loop with part_stat_local_read_cpu()
2) blk_mq_in_flight() - which has a lot of code and unexported structs inside the block/ directory, double function callback; definitely not easy to reimplement easily in btrfs without copying dozens of lines
Well, I tried copying the whole blk_mq_in_flight() function with all dependencies anyway, hard to do without causing modpost errors.
So, to sum it up, I think that making 2) possible to reuse in btrfs would require at lest exporting the blk_mq_in_flight() function, therefore the change would have to go through linux-block tree. Which maybe would be a good thing to do in long term, not sure if it should block my patchset entirely.
The question is if we are fine with inflight stats inside btrfs. Personally I think we sholdn't be concerned too much about it. The inflight counter in my patches is a percpu counted, used in places which already do some atomic operations.
Thanks,
Michal
Quoted 75 lines · Michal Rostecki
From: Michal Rostecki <[email protected]>
This patch series adds a new raid1 read policy - roundrobin. For each request, it selects the mirror which has lower load than queue depth. Load is defined as the number of inflight requests + a penalty value (if the scheduled request is not local to the last processed request for a rotational disk).
The series consists of preparational changes which add necessary information to the
btrfs_devicestruct and the change with the policy.This policy was tested with fio and compared with the default
pidpolicy.The singlethreaded test has the following parameters:
[global] name=btrfs-raid1-seqread filename=btrfs-raid1-seqread rw=read bs=64k direct=0 numjobs=1 time_based=0 [file1] size=10G ioengine=libaioand shows the following results:
- raid1c3 with 3 HDDs:
3 x Segate Barracuda ST2000DM008 (2TB) * pid policy READ: bw=217MiB/s (228MB/s), 217MiB/s-217MiB/s (228MB/s-228MB/s), io=10.0GiB (10.7GB), run=47082-47082msec * roundrobin policy READ: bw=409MiB/s (429MB/s), 409MiB/s-409MiB/s (429MB/s-429MB/s), io=10.0GiB (10.7GB), run=25028-25028mse- raid1c3 with 2 HDDs and 1 SSD:
2 x Segate Barracuda ST2000DM008 (2TB) 1 x Crucial CT256M550SSD1 (256GB) * pid policy (the worst case when only HDDs were chosen) READ: bw=220MiB/s (231MB/s), 220MiB/s-220MiB/s (231MB/s-231MB/s), io=10.0GiB (10.7GB), run=46577-46577mse * pid policy (the best case when SSD was used as well) READ: bw=513MiB/s (538MB/s), 513MiB/s-513MiB/s (538MB/s-538MB/s), io=10.0GiB (10.7GB), run=19954-19954msec * roundrobin (there are no noticeable differences when testing multiple times) READ: bw=541MiB/s (567MB/s), 541MiB/s-541MiB/s (567MB/s-567MB/s), io=10.0GiB (10.7GB), run=18933-18933msecThe multithreaded test has the following parameters:
[global] name=btrfs-raid1-seqread filename=btrfs-raid1-seqread rw=read bs=64k direct=0 numjobs=8 time_based=0 [file1] size=10G ioengine=libaioand shows the following results:
- raid1c3 with 3 HDDs: 3 x Segate Barracuda ST2000DM008 (2TB) 3 x Segate Barracuda ST2000DM008 (2TB)
* pid policy
Quoted 15 lines
READ: bw=1569MiB/s (1645MB/s), 196MiB/s-196MiB/s (206MB/s-206MB/s),
io=80.0GiB (85.9GB), run=52210-52211msec
* roundrobin
READ: bw=1733MiB/s (1817MB/s), 217MiB/s-217MiB/s (227MB/s-227MB/s),
io=80.0GiB (85.9GB), run=47269-47271msec
- raid1c3 with 2 HDDs and 1 SSD:
2 x Segate Barracuda ST2000DM008 (2TB)
1 x Crucial CT256M550SSD1 (256GB)
* pid policy
READ: bw=1843MiB/s (1932MB/s), 230MiB/s-230MiB/s (242MB/s-242MB/s),
io=80.0GiB (85.9GB), run=44449-44450msec
* roundrobin
READ: bw=2485MiB/s (2605MB/s), 311MiB/s-311MiB/s (326MB/s-326MB/s),
io=80.0GiB (85.9GB), run=32969-32970msecBoth of the above test cases are sequential. How about some random IO workload?
Also, the seek time for non-rotational devices does not exist. So it is a good idea to test with ssd + nvme and all nvme or all ssd.
Quoted 11 lines
To measure the performance of each policy and find optimal penalty values, I created scripts which are available here:
https://gitlab.com/vadorovsky/btrfs-perf
https://github.com/mrostecki/btrfs-perfMichal Rostecki (6):
btrfs: Add inflight BIO request counter
btrfs: Store the last device I/O offset
These patches look good. But as only round-robin policy requires to monitor the inflight and last-offset. Could you bring them under if policy=roundrobin? Otherwise, it is just a waste of CPU cycles if the policy != roundrobin.
Quoted 2 lines
btrfs: Add
stripe_physicalfunction
btrfs: Check if the filesystem is has mixed type of devices
Thanks, Anand
Quoted 10 lines
btrfs: sysfs: Add directory for read policies
btrfs: Add roundrobin raid1 read policyfs/btrfs/ctree.h | 3 + fs/btrfs/disk-io.c | 3 + fs/btrfs/sysfs.c | 144 ++++++++++++++++++++++++++---- fs/btrfs/volumes.c | 218 +++++++++++++++++++++++++++++++++++++++++++-- fs/btrfs/volumes.h | 22 +++++ 5 files changed, 366 insertions(+), 24 deletions(-)
Quoted 92 lines · Anand Jain
Quoted 75 lines · Michal Rostecki
From: Michal Rostecki <[email protected]>
This patch series adds a new raid1 read policy - roundrobin. For each request, it selects the mirror which has lower load than queue depth. Load is defined as the number of inflight requests + a penalty value (if the scheduled request is not local to the last processed request for a rotational disk).
The series consists of preparational changes which add necessary information to the
btrfs_devicestruct and the change with the policy.This policy was tested with fio and compared with the default
pidpolicy.The singlethreaded test has the following parameters:
[global] name=btrfs-raid1-seqread filename=btrfs-raid1-seqread rw=read bs=64k direct=0 numjobs=1 time_based=0 [file1] size=10G ioengine=libaioand shows the following results:
- raid1c3 with 3 HDDs:
3 x Segate Barracuda ST2000DM008 (2TB) * pid policy READ: bw=217MiB/s (228MB/s), 217MiB/s-217MiB/s (228MB/s-228MB/s), io=10.0GiB (10.7GB), run=47082-47082msec * roundrobin policy READ: bw=409MiB/s (429MB/s), 409MiB/s-409MiB/s (429MB/s-429MB/s), io=10.0GiB (10.7GB), run=25028-25028mse- raid1c3 with 2 HDDs and 1 SSD:
2 x Segate Barracuda ST2000DM008 (2TB) 1 x Crucial CT256M550SSD1 (256GB) * pid policy (the worst case when only HDDs were chosen) READ: bw=220MiB/s (231MB/s), 220MiB/s-220MiB/s (231MB/s-231MB/s), io=10.0GiB (10.7GB), run=46577-46577mse * pid policy (the best case when SSD was used as well) READ: bw=513MiB/s (538MB/s), 513MiB/s-513MiB/s (538MB/s-538MB/s), io=10.0GiB (10.7GB), run=19954-19954msec * roundrobin (there are no noticeable differences when testing multiple times) READ: bw=541MiB/s (567MB/s), 541MiB/s-541MiB/s (567MB/s-567MB/s), io=10.0GiB (10.7GB), run=18933-18933msecThe multithreaded test has the following parameters:
[global] name=btrfs-raid1-seqread filename=btrfs-raid1-seqread rw=read bs=64k direct=0 numjobs=8 time_based=0 [file1] size=10G ioengine=libaioand shows the following results:
- raid1c3 with 3 HDDs: 3 x Segate Barracuda ST2000DM008 (2TB) 3 x Segate Barracuda ST2000DM008 (2TB)
* pid policyQuoted 15 lines
READ: bw=1569MiB/s (1645MB/s), 196MiB/s-196MiB/s (206MB/s-206MB/s), io=80.0GiB (85.9GB), run=52210-52211msec * roundrobin READ: bw=1733MiB/s (1817MB/s), 217MiB/s-217MiB/s (227MB/s-227MB/s), io=80.0GiB (85.9GB), run=47269-47271msec - raid1c3 with 2 HDDs and 1 SSD: 2 x Segate Barracuda ST2000DM008 (2TB) 1 x Crucial CT256M550SSD1 (256GB) * pid policy READ: bw=1843MiB/s (1932MB/s), 230MiB/s-230MiB/s (242MB/s-242MB/s), io=80.0GiB (85.9GB), run=44449-44450msec * roundrobin READ: bw=2485MiB/s (2605MB/s), 311MiB/s-311MiB/s (326MB/s-326MB/s), io=80.0GiB (85.9GB), run=32969-32970msec
Quoted 6 lines
Both of the above test cases are sequential. How about some random IO workload?
Also, the seek time for non-rotational devices does not exist. So it is a good idea to test with ssd + nvme and all nvme or all ssd.
Good idea. I will test random I/O and will try to test all-nvme / all-ssd and mixed nonrot.
Quoted 9 lines
Quoted 7 lines
To measure the performance of each policy and find optimal penalty values, I created scripts which are available here:
https://gitlab.com/vadorovsky/btrfs-perf
https://github.com/mrostecki/btrfs-perfMichal Rostecki (6):
Quoted 8 lines
Quoted 2 lines
btrfs: Add inflight BIO request counter
btrfs: Store the last device I/O offsetThese patches look good. But as only round-robin policy requires to monitor the inflight and last-offset. Could you bring them under if policy=roundrobin? Otherwise, it is just a waste of CPU cycles if the policy != roundrobin.
If I bring those stats under if policy=roundrobin, they are going to be inaccurate if someone switches policies on the running system, after doing any I/O in that filesystem.
I'm open to suggestions how can I make those stats as lightweight as possible. Unfortunately, I don't think I can store the last physical location without atomic_t.
The BIO percpu counter is probably the least to be worried about, though I could maybe get rid of it entirely in favor of using part_stat_read().
Quoted 16 lines
Quoted 2 lines
btrfs: Add
stripe_physicalfunction
btrfs: Check if the filesystem is has mixed type of devicesThanks, Anand
Quoted 10 lines
btrfs: sysfs: Add directory for read policies
btrfs: Add roundrobin raid1 read policyfs/btrfs/ctree.h | 3 + fs/btrfs/disk-io.c | 3 + fs/btrfs/sysfs.c | 144 ++++++++++++++++++++++++++---- fs/btrfs/volumes.c | 218 +++++++++++++++++++++++++++++++++++++++++++-- fs/btrfs/volumes.h | 22 +++++ 5 files changed, 366 insertions(+), 24 deletions(-)
Thanks for review,
Michal
Quoted 10 lines · Michal Rostecki
Quoted 5 lines
These patches look good. But as only round-robin policy requires to monitor the inflight and last-offset. Could you bring them under if policy=roundrobin? Otherwise, it is just a waste of CPU cycles if the policy != roundrobin.
If I bring those stats under if policy=roundrobin, they are going to be inaccurate if someone switches policies on the running system, after doing any I/O in that filesystem.
Quoted 7 lines
I'm open to suggestions how can I make those stats as lightweight as possible. Unfortunately, I don't think I can store the last physical location without
atomic_t.The BIO percpu counter is probably the least to be worried about, though I could maybe get rid of it entirely in favor of using
part_stat_read().
Actually, after thinking about that more, I'm wondering if I should just drop the last-offset stat and penalty mechanism entirely. They seem to improve performance slightly only on mixed workloads (thought I need to check if that's the case in all-SDD od all NVMe arrays), but still perform worse than policies that you proposed.
Maybe it'd be better if I just focus on getting the best performance on non-mixed environments in my policy and thus stick to the simple inflight < queue_depth check...
Thanks,
Michal