提交 d3c2fdcf 编写于 作者: C Chris Mason

Btrfs: Use balance_dirty_pages_nr on btree blocks

btrfs_btree_balance_dirty is changed to pass the number of pages dirtied
for more accurate dirty throttling.  This lets the VM make better decisions
about when to force some writeback.
Signed-off-by: NChris Mason <chris.mason@oracle.com>
上级 7d7d6068
...@@ -666,7 +666,8 @@ void btrfs_block_release(struct btrfs_root *root, struct buffer_head *buf) ...@@ -666,7 +666,8 @@ void btrfs_block_release(struct btrfs_root *root, struct buffer_head *buf)
brelse(buf); brelse(buf);
} }
void btrfs_btree_balance_dirty(struct btrfs_root *root) void btrfs_btree_balance_dirty(struct btrfs_root *root, unsigned long nr)
{ {
balance_dirty_pages_ratelimited(root->fs_info->btree_inode->i_mapping); balance_dirty_pages_ratelimited_nr(
root->fs_info->btree_inode->i_mapping, nr);
} }
...@@ -80,7 +80,7 @@ int btrfs_insert_dev_radix(struct btrfs_root *root, ...@@ -80,7 +80,7 @@ int btrfs_insert_dev_radix(struct btrfs_root *root,
u64 num_blocks); u64 num_blocks);
int btrfs_map_bh_to_logical(struct btrfs_root *root, struct buffer_head *bh, int btrfs_map_bh_to_logical(struct btrfs_root *root, struct buffer_head *bh,
u64 logical); u64 logical);
void btrfs_btree_balance_dirty(struct btrfs_root *root); void btrfs_btree_balance_dirty(struct btrfs_root *root, unsigned long nr);
int btrfs_free_fs_root(struct btrfs_fs_info *fs_info, struct btrfs_root *root); int btrfs_free_fs_root(struct btrfs_fs_info *fs_info, struct btrfs_root *root);
void btrfs_mark_buffer_dirty(struct buffer_head *bh); void btrfs_mark_buffer_dirty(struct buffer_head *bh);
#endif #endif
...@@ -1275,6 +1275,7 @@ struct buffer_head *btrfs_alloc_free_block(struct btrfs_trans_handle *trans, ...@@ -1275,6 +1275,7 @@ struct buffer_head *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
set_buffer_checked(buf); set_buffer_checked(buf);
set_buffer_defrag(buf); set_buffer_defrag(buf);
set_radix_bit(&trans->transaction->dirty_pages, buf->b_page->index); set_radix_bit(&trans->transaction->dirty_pages, buf->b_page->index);
trans->blocks_used++;
return buf; return buf;
} }
......
...@@ -655,7 +655,7 @@ static ssize_t btrfs_file_write(struct file *file, const char __user *buf, ...@@ -655,7 +655,7 @@ static ssize_t btrfs_file_write(struct file *file, const char __user *buf,
num_written += write_bytes; num_written += write_bytes;
balance_dirty_pages_ratelimited_nr(inode->i_mapping, num_pages); balance_dirty_pages_ratelimited_nr(inode->i_mapping, num_pages);
btrfs_btree_balance_dirty(root); btrfs_btree_balance_dirty(root, 1);
cond_resched(); cond_resched();
} }
mutex_unlock(&inode->i_mutex); mutex_unlock(&inode->i_mutex);
......
...@@ -387,15 +387,17 @@ static int btrfs_unlink(struct inode *dir, struct dentry *dentry) ...@@ -387,15 +387,17 @@ static int btrfs_unlink(struct inode *dir, struct dentry *dentry)
struct btrfs_root *root; struct btrfs_root *root;
struct btrfs_trans_handle *trans; struct btrfs_trans_handle *trans;
int ret; int ret;
unsigned long nr;
root = BTRFS_I(dir)->root; root = BTRFS_I(dir)->root;
mutex_lock(&root->fs_info->fs_mutex); mutex_lock(&root->fs_info->fs_mutex);
trans = btrfs_start_transaction(root, 1); trans = btrfs_start_transaction(root, 1);
btrfs_set_trans_block_group(trans, dir); btrfs_set_trans_block_group(trans, dir);
ret = btrfs_unlink_trans(trans, root, dir, dentry); ret = btrfs_unlink_trans(trans, root, dir, dentry);
nr = trans->blocks_used;
btrfs_end_transaction(trans, root); btrfs_end_transaction(trans, root);
mutex_unlock(&root->fs_info->fs_mutex); mutex_unlock(&root->fs_info->fs_mutex);
btrfs_btree_balance_dirty(root); btrfs_btree_balance_dirty(root, nr);
return ret; return ret;
} }
...@@ -412,6 +414,7 @@ static int btrfs_rmdir(struct inode *dir, struct dentry *dentry) ...@@ -412,6 +414,7 @@ static int btrfs_rmdir(struct inode *dir, struct dentry *dentry)
int found_type; int found_type;
struct btrfs_leaf *leaf; struct btrfs_leaf *leaf;
char *goodnames = ".."; char *goodnames = "..";
unsigned long nr;
path = btrfs_alloc_path(); path = btrfs_alloc_path();
BUG_ON(!path); BUG_ON(!path);
...@@ -467,8 +470,9 @@ static int btrfs_rmdir(struct inode *dir, struct dentry *dentry) ...@@ -467,8 +470,9 @@ static int btrfs_rmdir(struct inode *dir, struct dentry *dentry)
btrfs_release_path(root, path); btrfs_release_path(root, path);
btrfs_free_path(path); btrfs_free_path(path);
mutex_unlock(&root->fs_info->fs_mutex); mutex_unlock(&root->fs_info->fs_mutex);
nr = trans->blocks_used;
ret = btrfs_end_transaction(trans, root); ret = btrfs_end_transaction(trans, root);
btrfs_btree_balance_dirty(root); btrfs_btree_balance_dirty(root, nr);
if (ret && !err) if (ret && !err)
err = ret; err = ret;
return err; return err;
...@@ -764,6 +768,7 @@ void btrfs_delete_inode(struct inode *inode) ...@@ -764,6 +768,7 @@ void btrfs_delete_inode(struct inode *inode)
{ {
struct btrfs_trans_handle *trans; struct btrfs_trans_handle *trans;
struct btrfs_root *root = BTRFS_I(inode)->root; struct btrfs_root *root = BTRFS_I(inode)->root;
unsigned long nr;
int ret; int ret;
truncate_inode_pages(&inode->i_data, 0); truncate_inode_pages(&inode->i_data, 0);
...@@ -780,15 +785,17 @@ void btrfs_delete_inode(struct inode *inode) ...@@ -780,15 +785,17 @@ void btrfs_delete_inode(struct inode *inode)
ret = btrfs_free_inode(trans, root, inode); ret = btrfs_free_inode(trans, root, inode);
if (ret) if (ret)
goto no_delete_lock; goto no_delete_lock;
nr = trans->blocks_used;
btrfs_end_transaction(trans, root); btrfs_end_transaction(trans, root);
mutex_unlock(&root->fs_info->fs_mutex); mutex_unlock(&root->fs_info->fs_mutex);
btrfs_btree_balance_dirty(root); btrfs_btree_balance_dirty(root, nr);
return; return;
no_delete_lock: no_delete_lock:
nr = trans->blocks_used;
btrfs_end_transaction(trans, root); btrfs_end_transaction(trans, root);
mutex_unlock(&root->fs_info->fs_mutex); mutex_unlock(&root->fs_info->fs_mutex);
btrfs_btree_balance_dirty(root); btrfs_btree_balance_dirty(root, nr);
no_delete: no_delete:
clear_inode(inode); clear_inode(inode);
} }
...@@ -1165,6 +1172,7 @@ static int btrfs_mknod(struct inode *dir, struct dentry *dentry, ...@@ -1165,6 +1172,7 @@ static int btrfs_mknod(struct inode *dir, struct dentry *dentry,
int err; int err;
int drop_inode = 0; int drop_inode = 0;
u64 objectid; u64 objectid;
unsigned long nr;
if (!new_valid_dev(rdev)) if (!new_valid_dev(rdev))
return -EINVAL; return -EINVAL;
...@@ -1198,6 +1206,7 @@ static int btrfs_mknod(struct inode *dir, struct dentry *dentry, ...@@ -1198,6 +1206,7 @@ static int btrfs_mknod(struct inode *dir, struct dentry *dentry,
btrfs_update_inode_block_group(trans, inode); btrfs_update_inode_block_group(trans, inode);
btrfs_update_inode_block_group(trans, dir); btrfs_update_inode_block_group(trans, dir);
out_unlock: out_unlock:
nr = trans->blocks_used;
btrfs_end_transaction(trans, root); btrfs_end_transaction(trans, root);
mutex_unlock(&root->fs_info->fs_mutex); mutex_unlock(&root->fs_info->fs_mutex);
...@@ -1205,7 +1214,7 @@ static int btrfs_mknod(struct inode *dir, struct dentry *dentry, ...@@ -1205,7 +1214,7 @@ static int btrfs_mknod(struct inode *dir, struct dentry *dentry,
inode_dec_link_count(inode); inode_dec_link_count(inode);
iput(inode); iput(inode);
} }
btrfs_btree_balance_dirty(root); btrfs_btree_balance_dirty(root, nr);
return err; return err;
} }
...@@ -1217,6 +1226,7 @@ static int btrfs_create(struct inode *dir, struct dentry *dentry, ...@@ -1217,6 +1226,7 @@ static int btrfs_create(struct inode *dir, struct dentry *dentry,
struct inode *inode; struct inode *inode;
int err; int err;
int drop_inode = 0; int drop_inode = 0;
unsigned long nr;
u64 objectid; u64 objectid;
mutex_lock(&root->fs_info->fs_mutex); mutex_lock(&root->fs_info->fs_mutex);
...@@ -1251,6 +1261,7 @@ static int btrfs_create(struct inode *dir, struct dentry *dentry, ...@@ -1251,6 +1261,7 @@ static int btrfs_create(struct inode *dir, struct dentry *dentry,
btrfs_update_inode_block_group(trans, inode); btrfs_update_inode_block_group(trans, inode);
btrfs_update_inode_block_group(trans, dir); btrfs_update_inode_block_group(trans, dir);
out_unlock: out_unlock:
nr = trans->blocks_used;
btrfs_end_transaction(trans, root); btrfs_end_transaction(trans, root);
mutex_unlock(&root->fs_info->fs_mutex); mutex_unlock(&root->fs_info->fs_mutex);
...@@ -1258,7 +1269,7 @@ static int btrfs_create(struct inode *dir, struct dentry *dentry, ...@@ -1258,7 +1269,7 @@ static int btrfs_create(struct inode *dir, struct dentry *dentry,
inode_dec_link_count(inode); inode_dec_link_count(inode);
iput(inode); iput(inode);
} }
btrfs_btree_balance_dirty(root); btrfs_btree_balance_dirty(root, nr);
return err; return err;
} }
...@@ -1268,6 +1279,7 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir, ...@@ -1268,6 +1279,7 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir,
struct btrfs_trans_handle *trans; struct btrfs_trans_handle *trans;
struct btrfs_root *root = BTRFS_I(dir)->root; struct btrfs_root *root = BTRFS_I(dir)->root;
struct inode *inode = old_dentry->d_inode; struct inode *inode = old_dentry->d_inode;
unsigned long nr;
int err; int err;
int drop_inode = 0; int drop_inode = 0;
...@@ -1288,6 +1300,7 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir, ...@@ -1288,6 +1300,7 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir,
if (err) if (err)
drop_inode = 1; drop_inode = 1;
nr = trans->blocks_used;
btrfs_end_transaction(trans, root); btrfs_end_transaction(trans, root);
mutex_unlock(&root->fs_info->fs_mutex); mutex_unlock(&root->fs_info->fs_mutex);
...@@ -1295,7 +1308,7 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir, ...@@ -1295,7 +1308,7 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir,
inode_dec_link_count(inode); inode_dec_link_count(inode);
iput(inode); iput(inode);
} }
btrfs_btree_balance_dirty(root); btrfs_btree_balance_dirty(root, nr);
return err; return err;
} }
...@@ -1336,6 +1349,7 @@ static int btrfs_mkdir(struct inode *dir, struct dentry *dentry, int mode) ...@@ -1336,6 +1349,7 @@ static int btrfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
int err = 0; int err = 0;
int drop_on_err = 0; int drop_on_err = 0;
u64 objectid; u64 objectid;
unsigned long nr = 1;
mutex_lock(&root->fs_info->fs_mutex); mutex_lock(&root->fs_info->fs_mutex);
trans = btrfs_start_transaction(root, 1); trans = btrfs_start_transaction(root, 1);
...@@ -1380,12 +1394,13 @@ static int btrfs_mkdir(struct inode *dir, struct dentry *dentry, int mode) ...@@ -1380,12 +1394,13 @@ static int btrfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
btrfs_update_inode_block_group(trans, dir); btrfs_update_inode_block_group(trans, dir);
out_fail: out_fail:
nr = trans->blocks_used;
btrfs_end_transaction(trans, root); btrfs_end_transaction(trans, root);
out_unlock: out_unlock:
mutex_unlock(&root->fs_info->fs_mutex); mutex_unlock(&root->fs_info->fs_mutex);
if (drop_on_err) if (drop_on_err)
iput(inode); iput(inode);
btrfs_btree_balance_dirty(root); btrfs_btree_balance_dirty(root, nr);
return err; return err;
} }
...@@ -1682,6 +1697,7 @@ static void btrfs_truncate(struct inode *inode) ...@@ -1682,6 +1697,7 @@ static void btrfs_truncate(struct inode *inode)
struct btrfs_root *root = BTRFS_I(inode)->root; struct btrfs_root *root = BTRFS_I(inode)->root;
int ret; int ret;
struct btrfs_trans_handle *trans; struct btrfs_trans_handle *trans;
unsigned long nr;
if (!S_ISREG(inode->i_mode)) if (!S_ISREG(inode->i_mode))
return; return;
...@@ -1697,10 +1713,11 @@ static void btrfs_truncate(struct inode *inode) ...@@ -1697,10 +1713,11 @@ static void btrfs_truncate(struct inode *inode)
/* FIXME, add redo link to tree so we don't leak on crash */ /* FIXME, add redo link to tree so we don't leak on crash */
ret = btrfs_truncate_in_trans(trans, root, inode); ret = btrfs_truncate_in_trans(trans, root, inode);
btrfs_update_inode(trans, root, inode); btrfs_update_inode(trans, root, inode);
nr = trans->blocks_used;
ret = btrfs_end_transaction(trans, root); ret = btrfs_end_transaction(trans, root);
BUG_ON(ret); BUG_ON(ret);
mutex_unlock(&root->fs_info->fs_mutex); mutex_unlock(&root->fs_info->fs_mutex);
btrfs_btree_balance_dirty(root); btrfs_btree_balance_dirty(root, nr);
} }
int btrfs_commit_write(struct file *file, struct page *page, int btrfs_commit_write(struct file *file, struct page *page,
...@@ -1725,6 +1742,7 @@ static int create_subvol(struct btrfs_root *root, char *name, int namelen) ...@@ -1725,6 +1742,7 @@ static int create_subvol(struct btrfs_root *root, char *name, int namelen)
int err; int err;
u64 objectid; u64 objectid;
u64 new_dirid = BTRFS_FIRST_FREE_OBJECTID; u64 new_dirid = BTRFS_FIRST_FREE_OBJECTID;
unsigned long nr = 1;
mutex_lock(&root->fs_info->fs_mutex); mutex_lock(&root->fs_info->fs_mutex);
trans = btrfs_start_transaction(root, 1); trans = btrfs_start_transaction(root, 1);
...@@ -1814,12 +1832,13 @@ static int create_subvol(struct btrfs_root *root, char *name, int namelen) ...@@ -1814,12 +1832,13 @@ static int create_subvol(struct btrfs_root *root, char *name, int namelen)
if (ret) if (ret)
goto fail; goto fail;
fail: fail:
nr = trans->blocks_used;
err = btrfs_commit_transaction(trans, root); err = btrfs_commit_transaction(trans, root);
if (err && !ret) if (err && !ret)
ret = err; ret = err;
fail_commit: fail_commit:
mutex_unlock(&root->fs_info->fs_mutex); mutex_unlock(&root->fs_info->fs_mutex);
btrfs_btree_balance_dirty(root); btrfs_btree_balance_dirty(root, nr);
return ret; return ret;
} }
...@@ -1832,6 +1851,7 @@ static int create_snapshot(struct btrfs_root *root, char *name, int namelen) ...@@ -1832,6 +1851,7 @@ static int create_snapshot(struct btrfs_root *root, char *name, int namelen)
int ret; int ret;
int err; int err;
u64 objectid; u64 objectid;
unsigned long nr;
if (!root->ref_cows) if (!root->ref_cows)
return -EINVAL; return -EINVAL;
...@@ -1884,12 +1904,13 @@ static int create_snapshot(struct btrfs_root *root, char *name, int namelen) ...@@ -1884,12 +1904,13 @@ static int create_snapshot(struct btrfs_root *root, char *name, int namelen)
if (ret) if (ret)
goto fail; goto fail;
fail: fail:
nr = trans->blocks_used;
err = btrfs_commit_transaction(trans, root); err = btrfs_commit_transaction(trans, root);
if (err && !ret) if (err && !ret)
ret = err; ret = err;
mutex_unlock(&root->fs_info->fs_mutex); mutex_unlock(&root->fs_info->fs_mutex);
up_write(&root->snap_sem); up_write(&root->snap_sem);
btrfs_btree_balance_dirty(root); btrfs_btree_balance_dirty(root, nr);
return ret; return ret;
} }
...@@ -2240,6 +2261,7 @@ static int btrfs_symlink(struct inode *dir, struct dentry *dentry, ...@@ -2240,6 +2261,7 @@ static int btrfs_symlink(struct inode *dir, struct dentry *dentry,
int datasize; int datasize;
char *ptr; char *ptr;
struct btrfs_file_extent_item *ei; struct btrfs_file_extent_item *ei;
unsigned long nr;
name_len = strlen(symname) + 1; name_len = strlen(symname) + 1;
if (name_len > BTRFS_MAX_INLINE_DATA_SIZE(root)) if (name_len > BTRFS_MAX_INLINE_DATA_SIZE(root))
...@@ -2309,13 +2331,14 @@ static int btrfs_symlink(struct inode *dir, struct dentry *dentry, ...@@ -2309,13 +2331,14 @@ static int btrfs_symlink(struct inode *dir, struct dentry *dentry,
drop_inode = 1; drop_inode = 1;
out_unlock: out_unlock:
nr = trans->blocks_used;
btrfs_end_transaction(trans, root); btrfs_end_transaction(trans, root);
mutex_unlock(&root->fs_info->fs_mutex); mutex_unlock(&root->fs_info->fs_mutex);
if (drop_inode) { if (drop_inode) {
inode_dec_link_count(inode); inode_dec_link_count(inode);
iput(inode); iput(inode);
} }
btrfs_btree_balance_dirty(root); btrfs_btree_balance_dirty(root, nr);
return err; return err;
} }
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/writeback.h>
#include "ctree.h" #include "ctree.h"
#include "disk-io.h" #include "disk-io.h"
#include "transaction.h" #include "transaction.h"
...@@ -340,6 +341,7 @@ int btrfs_defrag_root(struct btrfs_root *root, int cacheonly) ...@@ -340,6 +341,7 @@ int btrfs_defrag_root(struct btrfs_root *root, int cacheonly)
struct btrfs_fs_info *info = root->fs_info; struct btrfs_fs_info *info = root->fs_info;
int ret; int ret;
struct btrfs_trans_handle *trans; struct btrfs_trans_handle *trans;
unsigned long nr;
if (root->defrag_running) if (root->defrag_running)
return 0; return 0;
...@@ -348,10 +350,11 @@ int btrfs_defrag_root(struct btrfs_root *root, int cacheonly) ...@@ -348,10 +350,11 @@ int btrfs_defrag_root(struct btrfs_root *root, int cacheonly)
while (1) { while (1) {
root->defrag_running = 1; root->defrag_running = 1;
ret = btrfs_defrag_leaves(trans, root, cacheonly); ret = btrfs_defrag_leaves(trans, root, cacheonly);
nr = trans->blocks_used;
btrfs_end_transaction(trans, root); btrfs_end_transaction(trans, root);
mutex_unlock(&info->fs_mutex); mutex_unlock(&info->fs_mutex);
btrfs_btree_balance_dirty(root); btrfs_btree_balance_dirty(info->tree_root, nr);
cond_resched(); cond_resched();
mutex_lock(&info->fs_mutex); mutex_lock(&info->fs_mutex);
...@@ -398,6 +401,7 @@ static int drop_dirty_roots(struct btrfs_root *tree_root, ...@@ -398,6 +401,7 @@ static int drop_dirty_roots(struct btrfs_root *tree_root,
{ {
struct dirty_root *dirty; struct dirty_root *dirty;
struct btrfs_trans_handle *trans; struct btrfs_trans_handle *trans;
unsigned long nr;
u64 num_blocks; u64 num_blocks;
u64 blocks_used; u64 blocks_used;
int ret = 0; int ret = 0;
...@@ -426,11 +430,11 @@ static int drop_dirty_roots(struct btrfs_root *tree_root, ...@@ -426,11 +430,11 @@ static int drop_dirty_roots(struct btrfs_root *tree_root,
&dirty->root->root_item); &dirty->root->root_item);
if (err) if (err)
ret = err; ret = err;
nr = trans->blocks_used;
ret = btrfs_end_transaction(trans, tree_root); ret = btrfs_end_transaction(trans, tree_root);
BUG_ON(ret); BUG_ON(ret);
mutex_unlock(&tree_root->fs_info->fs_mutex); mutex_unlock(&tree_root->fs_info->fs_mutex);
btrfs_btree_balance_dirty(tree_root, nr);
btrfs_btree_balance_dirty(tree_root);
schedule(); schedule();
mutex_lock(&tree_root->fs_info->fs_mutex); mutex_lock(&tree_root->fs_info->fs_mutex);
...@@ -449,13 +453,15 @@ static int drop_dirty_roots(struct btrfs_root *tree_root, ...@@ -449,13 +453,15 @@ static int drop_dirty_roots(struct btrfs_root *tree_root,
BUG(); BUG();
break; break;
} }
nr = trans->blocks_used;
ret = btrfs_end_transaction(trans, tree_root); ret = btrfs_end_transaction(trans, tree_root);
BUG_ON(ret); BUG_ON(ret);
kfree(dirty->root); kfree(dirty->root);
kfree(dirty); kfree(dirty);
mutex_unlock(&tree_root->fs_info->fs_mutex); mutex_unlock(&tree_root->fs_info->fs_mutex);
btrfs_btree_balance_dirty(tree_root);
btrfs_btree_balance_dirty(tree_root, nr);
schedule(); schedule();
} }
return ret; return ret;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册