Btrfs: be smarter about dropping things from the tree log
PATCH 1/1 Btrfs: be smarter about dropping things from the tree log
When we truncate existing items in the tree log we've been searching for each individual item and removing them. This is unnecessary churn and searching, just keep track of the slot we are on and how many items we need to delete and delete them all at once. Thanks,
--- fs/btrfs/tree-log.c | 16 ++++++++++++++-- 1 files changed, 14 insertions(+), 2 deletions(-)
fs/btrfs/tree-log.c +14 -2
@@ -2872,12 +2872,15 @@ static int drop_objectid_items(struct btrfs_trans_handle *trans,int ret;struct btrfs_key key;struct btrfs_key found_key; +int start_slot; +int del_nr =0 ; key.objectid = objectid; key.type = max_key_type; key.offset = (u64)-1 ;while (1 ) { + del_nr =0 ; ret =btrfs_search_slot (trans, log, &key, path,-1 ,1 );BUG_ON (ret ==0 );if (ret <0 )
@@ -2885,20 +2888,29 @@ static int drop_objectid_items(struct btrfs_trans_handle *trans,if (path->slots[0 ] ==0 )break ; - +next_slot: path->slots[0 ]--; +btrfs_item_key_to_cpu (path->nodes[0 ], &found_key, path->slots[0 ]);if (found_key.objectid != objectid)break ; - ret =btrfs_del_item (trans, log, path); + start_slot = path->slots[0 ]; + del_nr++; +if (start_slot) + goto next_slot; + + ret =btrfs_del_items (trans, log, path, start_slot, del_nr);if (ret)break ;btrfs_release_path (path); } +if (!ret && del_nr) + ret =btrfs_del_items (trans, log, path, start_slot, del_nr);btrfs_release_path (path); +if (ret >0 ) ret =0 ;return ret;
Signature · 1 line
1.7.7.6
Quoted 4 lines
When we truncate existing items in the tree log we've been searching for each individual item and removing them. This is unnecessary churn and searching, just keep track of the slot we are on and how many items we need to delete and delete them all at once. Thanks,
(speaking of unnecessary churn :))
Quoted 4 lines
fs/btrfs/tree-log.c +2
-0+next_slot: path->slots[0 ]--; + btrfs_item_key_to_cpu(path->nodes[0], &found_key,
fs/btrfs/tree-log.c static int drop_objectid_items(struct btrfs_trans_handle *trans, · line 2903
Quoted 10 lines
fs/btrfs/tree-log.c +4
-1path->slots[0]);if (found_key.objectid != objectid)break ; - ret =btrfs_del_item (trans, log, path); + start_slot = path->slots[0 ]; + del_nr++; +if (start_slot) + goto next_slot;
A linear backwards scan? Of potentially 64k leaves?
Can you use bin_search() to look for the first key >= [objectid,0,0] in the leaf? And probably a single comparison of slot 0 to fast path the case where the whole leaf contains the object id?
fs/btrfs/tree-log.c static int drop_objectid_items(struct btrfs_trans_handle *trans, · line 2912
Quoted 8 lines
fs/btrfs/tree-log.c +3
-0+ ret =btrfs_del_items (trans, log, path, start_slot, del_nr);if (ret)break ;btrfs_release_path (path); } +if (!ret && del_nr) + ret =btrfs_del_items (trans, log, path, start_slot, del_nr);btrfs_release_path (path);
You shouldn't have to duplicate deletion and releasing the path if you wrap the calculation of start_slot and nr in a helper. Something like:
nr = find_nr_and_slot_doo_de_doo(, &start_slot); if (nr > 0) btrfs_del_items(, start_slot, nr);
- z
Quoted 24 lines · Zach Brown
Quoted 4 lines
When we truncate existing items in the tree log we've been searching for each individual item and removing them. This is unnecessary churn and searching, just keep track of the slot we are on and how many items we need to delete and delete them all at once. Thanks,
(speaking of unnecessary churn :))
Quoted 4 lines
fs/btrfs/tree-log.c +2
-0+next_slot: path->slots[0 ]--; + btrfs_item_key_to_cpu(path->nodes[0], &found_key,fs/btrfs/tree-log.c static int drop_objectid_items(struct btrfs_trans_handle *trans, · line 2903
Quoted 10 lines
fs/btrfs/tree-log.c +4
-1path->slots[0]);if (found_key.objectid != objectid)break ; - ret =btrfs_del_item (trans, log, path); + start_slot = path->slots[0 ]; + del_nr++; +if (start_slot) + goto next_slot;A linear backwards scan? Of potentially 64k leaves?
Quoted 4 lines
Can you use
bin_search()to look for the first key >= [objectid,0,0] in the leaf? And probably a single comparison of slot 0 to fast path the case where the whole leaf contains the object id?
Yeah I can do that.
Quoted 12 lines
fs/btrfs/tree-log.c static int drop_objectid_items(struct btrfs_trans_handle *trans, · line 2912
Quoted 8 lines
fs/btrfs/tree-log.c +3
-0+ ret =btrfs_del_items (trans, log, path, start_slot, del_nr);if (ret)break ;btrfs_release_path (path); } +if (!ret && del_nr) + ret =btrfs_del_items (trans, log, path, start_slot, del_nr);btrfs_release_path (path);You shouldn't have to duplicate deletion and releasing the path if you wrap the calculation of
start_slotand nr in a helper. Something like:
Quoted 3 lines
nr = find_nr_and_slot_doo_de_doo(, &start_slot); if (nr > 0) btrfs_del_items(, start_slot, nr);
K, I'll fix that up, thanks.
Josef