diff options
author | Chris Mason <chris.mason@oracle.com> | 2011-05-24 15:35:30 -0400 |
---|---|---|
committer | Chris Mason <chris.mason@oracle.com> | 2011-05-26 17:52:15 -0400 |
commit | 4cb5300bc839b8a943eb19c9f27f25470e22d0ca (patch) | |
tree | ac0f2fb481c7aa6af08a624d276fa6d580c94c9b /fs/btrfs/disk-io.c | |
parent | d6c0cb379c5198487e4ac124728cbb2346d63b1f (diff) |
Btrfs: add mount -o auto_defrag
This will detect small random writes into files and
queue the up for an auto defrag process. It isn't well suited to
database workloads yet, but works for smaller files such as rpm, sqlite
or bdb databases.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/disk-io.c')
-rw-r--r-- | fs/btrfs/disk-io.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 16d335b342a2..b2588a552658 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c | |||
@@ -1475,6 +1475,7 @@ static int cleaner_kthread(void *arg) | |||
1475 | btrfs_run_delayed_iputs(root); | 1475 | btrfs_run_delayed_iputs(root); |
1476 | btrfs_clean_old_snapshots(root); | 1476 | btrfs_clean_old_snapshots(root); |
1477 | mutex_unlock(&root->fs_info->cleaner_mutex); | 1477 | mutex_unlock(&root->fs_info->cleaner_mutex); |
1478 | btrfs_run_defrag_inodes(root->fs_info); | ||
1478 | } | 1479 | } |
1479 | 1480 | ||
1480 | if (freezing(current)) { | 1481 | if (freezing(current)) { |
@@ -1616,6 +1617,7 @@ struct btrfs_root *open_ctree(struct super_block *sb, | |||
1616 | spin_lock_init(&fs_info->ref_cache_lock); | 1617 | spin_lock_init(&fs_info->ref_cache_lock); |
1617 | spin_lock_init(&fs_info->fs_roots_radix_lock); | 1618 | spin_lock_init(&fs_info->fs_roots_radix_lock); |
1618 | spin_lock_init(&fs_info->delayed_iput_lock); | 1619 | spin_lock_init(&fs_info->delayed_iput_lock); |
1620 | spin_lock_init(&fs_info->defrag_inodes_lock); | ||
1619 | 1621 | ||
1620 | init_completion(&fs_info->kobj_unregister); | 1622 | init_completion(&fs_info->kobj_unregister); |
1621 | fs_info->tree_root = tree_root; | 1623 | fs_info->tree_root = tree_root; |
@@ -1638,9 +1640,11 @@ struct btrfs_root *open_ctree(struct super_block *sb, | |||
1638 | atomic_set(&fs_info->async_delalloc_pages, 0); | 1640 | atomic_set(&fs_info->async_delalloc_pages, 0); |
1639 | atomic_set(&fs_info->async_submit_draining, 0); | 1641 | atomic_set(&fs_info->async_submit_draining, 0); |
1640 | atomic_set(&fs_info->nr_async_bios, 0); | 1642 | atomic_set(&fs_info->nr_async_bios, 0); |
1643 | atomic_set(&fs_info->defrag_running, 0); | ||
1641 | fs_info->sb = sb; | 1644 | fs_info->sb = sb; |
1642 | fs_info->max_inline = 8192 * 1024; | 1645 | fs_info->max_inline = 8192 * 1024; |
1643 | fs_info->metadata_ratio = 0; | 1646 | fs_info->metadata_ratio = 0; |
1647 | fs_info->defrag_inodes = RB_ROOT; | ||
1644 | 1648 | ||
1645 | fs_info->thread_pool_size = min_t(unsigned long, | 1649 | fs_info->thread_pool_size = min_t(unsigned long, |
1646 | num_online_cpus() + 2, 8); | 1650 | num_online_cpus() + 2, 8); |
@@ -2501,6 +2505,14 @@ int close_ctree(struct btrfs_root *root) | |||
2501 | smp_mb(); | 2505 | smp_mb(); |
2502 | 2506 | ||
2503 | btrfs_scrub_cancel(root); | 2507 | btrfs_scrub_cancel(root); |
2508 | |||
2509 | /* wait for any defraggers to finish */ | ||
2510 | wait_event(fs_info->transaction_wait, | ||
2511 | (atomic_read(&fs_info->defrag_running) == 0)); | ||
2512 | |||
2513 | /* clear out the rbtree of defraggable inodes */ | ||
2514 | btrfs_run_defrag_inodes(root->fs_info); | ||
2515 | |||
2504 | btrfs_put_block_group_cache(fs_info); | 2516 | btrfs_put_block_group_cache(fs_info); |
2505 | 2517 | ||
2506 | /* | 2518 | /* |