btrfs: reada: avoid undone reada extents in btrfs_reada_wait
authorZhao Lei <zhaolei@cn.fujitsu.com>
Tue, 26 Jan 2016 10:42:40 +0000 (18:42 +0800)
committerDavid Sterba <dsterba@suse.com>
Thu, 18 Feb 2016 09:27:23 +0000 (10:27 +0100)
Reada background works is not designed to finish all jobs
completely, it will break in following case:
1: When a device reaches workload limit (MAX_IN_FLIGHT)
2: Total reads reach max limit (10000)
3: All devices don't have queued more jobs, often happened in DUP case

And if all background works exit with remaining jobs,
btrfs_reada_wait() will wait indefinetelly.

Above problem is rarely happened in old code, because:
1: Every work queues 2x new works
   So many works reduced chances of undone jobs.
2: One work will continue 10000 times loop in case of no-jobs
   It reduced no-thread window time.

But after we fixed above case, the "undone reada extents" frequently
happened.

Fix:
 Check to ensure we have at least one thread if there are undone jobs
 in btrfs_reada_wait().

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/reada.c

index e97bc8eb01e22eb184c276d8c90f4ccedd9689c1..5bcd567f48278089ecb7b26f2abc1578b65571b0 100644 (file)
@@ -953,8 +953,11 @@ struct reada_control *btrfs_reada_add(struct btrfs_root *root,
 int btrfs_reada_wait(void *handle)
 {
        struct reada_control *rc = handle;
+       struct btrfs_fs_info *fs_info = rc->root->fs_info;
 
        while (atomic_read(&rc->elems)) {
+               if (!atomic_read(&fs_info->reada_works_cnt))
+                       reada_start_machine(fs_info);
                wait_event_timeout(rc->wait, atomic_read(&rc->elems) == 0,
                                   5 * HZ);
                dump_devs(rc->root->fs_info,
@@ -971,9 +974,13 @@ int btrfs_reada_wait(void *handle)
 int btrfs_reada_wait(void *handle)
 {
        struct reada_control *rc = handle;
+       struct btrfs_fs_info *fs_info = rc->root->fs_info;
 
        while (atomic_read(&rc->elems)) {
-               wait_event(rc->wait, atomic_read(&rc->elems) == 0);
+               if (!atomic_read(&fs_info->reada_works_cnt))
+                       reada_start_machine(fs_info);
+               wait_event_timeout(rc->wait, atomic_read(&rc->elems) == 0,
+                                  (HZ + 9) / 10);
        }
 
        kref_put(&rc->refcnt, reada_control_release);
This page took 0.038867 seconds and 5 git commands to generate.