aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/ctree.h
diff options
context:
space:
mode:
authorMiao Xie <miaox@cn.fujitsu.com>2011-04-22 06:12:22 -0400
committerChris Mason <chris.mason@oracle.com>2011-05-21 09:30:56 -0400
commit16cdcec736cd214350cdb591bf1091f8beedefa0 (patch)
tree5598d4561660c4d7a1d4de8b3703d6dd3cc7f9e7 /fs/btrfs/ctree.h
parent61c4f2c81c61f73549928dfd9f3e8f26aa36a8cf (diff)
btrfs: implement delayed inode items operation
Changelog V5 -> V6: - Fix oom when the memory load is high, by storing the delayed nodes into the root's radix tree, and letting btrfs inodes go. Changelog V4 -> V5: - Fix the race on adding the delayed node to the inode, which is spotted by Chris Mason. - Merge Chris Mason's incremental patch into this patch. - Fix deadlock between readdir() and memory fault, which is reported by Itaru Kitayama. Changelog V3 -> V4: - Fix nested lock, which is reported by Itaru Kitayama, by updating space cache inode in time. Changelog V2 -> V3: - Fix the race between the delayed worker and the task which does delayed items balance, which is reported by Tsutomu Itoh. - Modify the patch address David Sterba's comment. - Fix the bug of the cpu recursion spinlock, reported by Chris Mason Changelog V1 -> V2: - break up the global rb-tree, use a list to manage the delayed nodes, which is created for every directory and file, and used to manage the delayed directory name index items and the delayed inode item. - introduce a worker to deal with the delayed nodes. Compare with Ext3/4, the performance of file creation and deletion on btrfs is very poor. the reason is that btrfs must do a lot of b+ tree insertions, such as inode item, directory name item, directory name index and so on. If we can do some delayed b+ tree insertion or deletion, we can improve the performance, so we made this patch which implemented delayed directory name index insertion/deletion and delayed inode update. Implementation: - introduce a delayed root object into the filesystem, that use two lists to manage the delayed nodes which are created for every file/directory. One is used to manage all the delayed nodes that have delayed items. And the other is used to manage the delayed nodes which is waiting to be dealt with by the work thread. - Every delayed node has two rb-tree, one is used to manage the directory name index which is going to be inserted into b+ tree, and the other is used to manage the directory name index which is going to be deleted from b+ tree. - introduce a worker to deal with the delayed operation. This worker is used to deal with the works of the delayed directory name index items insertion and deletion and the delayed inode update. When the delayed items is beyond the lower limit, we create works for some delayed nodes and insert them into the work queue of the worker, and then go back. When the delayed items is beyond the upper bound, we create works for all the delayed nodes that haven't been dealt with, and insert them into the work queue of the worker, and then wait for that the untreated items is below some threshold value. - When we want to insert a directory name index into b+ tree, we just add the information into the delayed inserting rb-tree. And then we check the number of the delayed items and do delayed items balance. (The balance policy is above.) - When we want to delete a directory name index from the b+ tree, we search it in the inserting rb-tree at first. If we look it up, just drop it. If not, add the key of it into the delayed deleting rb-tree. Similar to the delayed inserting rb-tree, we also check the number of the delayed items and do delayed items balance. (The same to inserting manipulation) - When we want to update the metadata of some inode, we cached the data of the inode into the delayed node. the worker will flush it into the b+ tree after dealing with the delayed insertion and deletion. - We will move the delayed node to the tail of the list after we access the delayed node, By this way, we can cache more delayed items and merge more inode updates. - If we want to commit transaction, we will deal with all the delayed node. - the delayed node will be freed when we free the btrfs inode. - Before we log the inode items, we commit all the directory name index items and the delayed inode update. I did a quick test by the benchmark tool[1] and found we can improve the performance of file creation by ~15%, and file deletion by ~20%. Before applying this patch: Create files: Total files: 50000 Total time: 1.096108 Average time: 0.000022 Delete files: Total files: 50000 Total time: 1.510403 Average time: 0.000030 After applying this patch: Create files: Total files: 50000 Total time: 0.932899 Average time: 0.000019 Delete files: Total files: 50000 Total time: 1.215732 Average time: 0.000024 [1] http://marc.info/?l=linux-btrfs&m=128212635122920&q=p3 Many thanks for Kitayama-san's help! Signed-off-by: Miao Xie <miaox@cn.fujitsu.com> Reviewed-by: David Sterba <dave@jikos.cz> Tested-by: Tsutomu Itoh <t-itoh@jp.fujitsu.com> Tested-by: Itaru Kitayama <kitayama@cl.bb4u.ne.jp> Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/ctree.h')
-rw-r--r--fs/btrfs/ctree.h29
1 files changed, 27 insertions, 2 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 8f4b81de3ae..5d25129d011 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -869,6 +869,7 @@ struct btrfs_block_group_cache {
869struct reloc_control; 869struct reloc_control;
870struct btrfs_device; 870struct btrfs_device;
871struct btrfs_fs_devices; 871struct btrfs_fs_devices;
872struct btrfs_delayed_root;
872struct btrfs_fs_info { 873struct btrfs_fs_info {
873 u8 fsid[BTRFS_FSID_SIZE]; 874 u8 fsid[BTRFS_FSID_SIZE];
874 u8 chunk_tree_uuid[BTRFS_UUID_SIZE]; 875 u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
@@ -895,7 +896,10 @@ struct btrfs_fs_info {
895 /* logical->physical extent mapping */ 896 /* logical->physical extent mapping */
896 struct btrfs_mapping_tree mapping_tree; 897 struct btrfs_mapping_tree mapping_tree;
897 898
898 /* block reservation for extent, checksum and root tree */ 899 /*
900 * block reservation for extent, checksum, root tree and
901 * delayed dir index item
902 */
899 struct btrfs_block_rsv global_block_rsv; 903 struct btrfs_block_rsv global_block_rsv;
900 /* block reservation for delay allocation */ 904 /* block reservation for delay allocation */
901 struct btrfs_block_rsv delalloc_block_rsv; 905 struct btrfs_block_rsv delalloc_block_rsv;
@@ -1022,6 +1026,7 @@ struct btrfs_fs_info {
1022 * for the sys_munmap function call path 1026 * for the sys_munmap function call path
1023 */ 1027 */
1024 struct btrfs_workers fixup_workers; 1028 struct btrfs_workers fixup_workers;
1029 struct btrfs_workers delayed_workers;
1025 struct task_struct *transaction_kthread; 1030 struct task_struct *transaction_kthread;
1026 struct task_struct *cleaner_kthread; 1031 struct task_struct *cleaner_kthread;
1027 int thread_pool_size; 1032 int thread_pool_size;
@@ -1079,6 +1084,8 @@ struct btrfs_fs_info {
1079 1084
1080 /* filesystem state */ 1085 /* filesystem state */
1081 u64 fs_state; 1086 u64 fs_state;
1087
1088 struct btrfs_delayed_root *delayed_root;
1082}; 1089};
1083 1090
1084/* 1091/*
@@ -1162,6 +1169,11 @@ struct btrfs_root {
1162 struct rb_root inode_tree; 1169 struct rb_root inode_tree;
1163 1170
1164 /* 1171 /*
1172 * radix tree that keeps track of delayed nodes of every inode,
1173 * protected by inode_lock
1174 */
1175 struct radix_tree_root delayed_nodes_tree;
1176 /*
1165 * right now this just gets used so that a root has its own devid 1177 * right now this just gets used so that a root has its own devid
1166 * for stat. It may be used for more later 1178 * for stat. It may be used for more later
1167 */ 1179 */
@@ -2099,6 +2111,13 @@ static inline bool btrfs_mixed_space_info(struct btrfs_space_info *space_info)
2099} 2111}
2100 2112
2101/* extent-tree.c */ 2113/* extent-tree.c */
2114static inline u64 btrfs_calc_trans_metadata_size(struct btrfs_root *root,
2115 int num_items)
2116{
2117 return (root->leafsize + root->nodesize * (BTRFS_MAX_LEVEL - 1)) *
2118 3 * num_items;
2119}
2120
2102void btrfs_put_block_group(struct btrfs_block_group_cache *cache); 2121void btrfs_put_block_group(struct btrfs_block_group_cache *cache);
2103int btrfs_run_delayed_refs(struct btrfs_trans_handle *trans, 2122int btrfs_run_delayed_refs(struct btrfs_trans_handle *trans,
2104 struct btrfs_root *root, unsigned long count); 2123 struct btrfs_root *root, unsigned long count);
@@ -2294,6 +2313,8 @@ void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p);
2294struct btrfs_path *btrfs_alloc_path(void); 2313struct btrfs_path *btrfs_alloc_path(void);
2295void btrfs_free_path(struct btrfs_path *p); 2314void btrfs_free_path(struct btrfs_path *p);
2296void btrfs_set_path_blocking(struct btrfs_path *p); 2315void btrfs_set_path_blocking(struct btrfs_path *p);
2316void btrfs_clear_path_blocking(struct btrfs_path *p,
2317 struct extent_buffer *held);
2297void btrfs_unlock_up_safe(struct btrfs_path *p, int level); 2318void btrfs_unlock_up_safe(struct btrfs_path *p, int level);
2298 2319
2299int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root, 2320int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root,
@@ -2305,6 +2326,10 @@ static inline int btrfs_del_item(struct btrfs_trans_handle *trans,
2305 return btrfs_del_items(trans, root, path, path->slots[0], 1); 2326 return btrfs_del_items(trans, root, path, path->slots[0], 1);
2306} 2327}
2307 2328
2329int setup_items_for_insert(struct btrfs_trans_handle *trans,
2330 struct btrfs_root *root, struct btrfs_path *path,
2331 struct btrfs_key *cpu_key, u32 *data_size,
2332 u32 total_data, u32 total_size, int nr);
2308int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root 2333int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root
2309 *root, struct btrfs_key *key, void *data, u32 data_size); 2334 *root, struct btrfs_key *key, void *data, u32 data_size);
2310int btrfs_insert_some_items(struct btrfs_trans_handle *trans, 2335int btrfs_insert_some_items(struct btrfs_trans_handle *trans,
@@ -2368,7 +2393,7 @@ void btrfs_check_and_init_root_item(struct btrfs_root_item *item);
2368/* dir-item.c */ 2393/* dir-item.c */
2369int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, 2394int btrfs_insert_dir_item(struct btrfs_trans_handle *trans,
2370 struct btrfs_root *root, const char *name, 2395 struct btrfs_root *root, const char *name,
2371 int name_len, u64 dir, 2396 int name_len, struct inode *dir,
2372 struct btrfs_key *location, u8 type, u64 index); 2397 struct btrfs_key *location, u8 type, u64 index);
2373struct btrfs_dir_item *btrfs_lookup_dir_item(struct btrfs_trans_handle *trans, 2398struct btrfs_dir_item *btrfs_lookup_dir_item(struct btrfs_trans_handle *trans,
2374 struct btrfs_root *root, 2399 struct btrfs_root *root,