summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2008-01-29 15:15:18 -0500
committerDavid Woodhouse <dwmw2@hera.kernel.org>2008-01-29 15:15:18 -0500
commitaa69dec31c165783f5210e423c29a50ac97b25fb (patch)
tree446165df45e3b167aacbf8527fdc4200d7fa2d3c
parentcbf87cad0752748e38bf98f1d18614e0be6dc500 (diff)
Add inode item and backref in one insert, reducing cpu usage
-rw-r--r--ctree.c39
-rw-r--r--ctree.h17
2 files changed, 39 insertions, 17 deletions
diff --git a/ctree.c b/ctree.c
index 63575809..fa3c04c4 100644
--- a/ctree.c
+++ b/ctree.c
@@ -2199,27 +2199,34 @@ int btrfs_extend_item(struct btrfs_trans_handle *trans,
* Given a key and some data, insert an item into the tree.
* This does all the path init required, making room in the tree if needed.
*/
-int btrfs_insert_empty_item(struct btrfs_trans_handle *trans,
+int btrfs_insert_empty_items(struct btrfs_trans_handle *trans,
struct btrfs_root *root,
struct btrfs_path *path,
- struct btrfs_key *cpu_key, u32 data_size)
+ struct btrfs_key *cpu_key, u32 *data_size,
+ int nr)
{
struct extent_buffer *leaf;
struct btrfs_item *item;
int ret = 0;
int slot;
int slot_orig;
+ int i;
u32 nritems;
+ u32 total_size = 0;
+ u32 total_data = 0;
unsigned int data_end;
struct btrfs_disk_key disk_key;
- btrfs_cpu_key_to_disk(&disk_key, cpu_key);
+ for (i = 0; i < nr; i++) {
+ total_data += data_size[i];
+ }
/* create a root if there isn't one */
if (!root->node)
BUG();
- ret = btrfs_search_slot(trans, root, cpu_key, path, data_size, 1);
+ total_size = total_data + (nr - 1) * sizeof(struct btrfs_item);
+ ret = btrfs_search_slot(trans, root, cpu_key, path, total_size, 1);
if (ret == 0) {
return -EEXIST;
}
@@ -2233,10 +2240,10 @@ int btrfs_insert_empty_item(struct btrfs_trans_handle *trans,
data_end = leaf_data_end(root, leaf);
if (btrfs_leaf_free_space(root, leaf) <
- sizeof(struct btrfs_item) + data_size) {
+ sizeof(struct btrfs_item) + total_size) {
btrfs_print_leaf(root, leaf);
printk("not enough freespace need %u have %d\n",
- data_size, btrfs_leaf_free_space(root, leaf));
+ total_size, btrfs_leaf_free_space(root, leaf));
BUG();
}
@@ -2262,27 +2269,31 @@ int btrfs_insert_empty_item(struct btrfs_trans_handle *trans,
item = btrfs_item_nr(leaf, i);
ioff = btrfs_item_offset(leaf, item);
- btrfs_set_item_offset(leaf, item, ioff - data_size);
+ btrfs_set_item_offset(leaf, item, ioff - total_data);
}
/* shift the items */
- memmove_extent_buffer(leaf, btrfs_item_nr_offset(slot + 1),
+ memmove_extent_buffer(leaf, btrfs_item_nr_offset(slot + nr),
btrfs_item_nr_offset(slot),
(nritems - slot) * sizeof(struct btrfs_item));
/* shift the data */
memmove_extent_buffer(leaf, btrfs_leaf_data(leaf) +
- data_end - data_size, btrfs_leaf_data(leaf) +
+ data_end - total_data, btrfs_leaf_data(leaf) +
data_end, old_data - data_end);
data_end = old_data;
}
/* setup the item for the new data */
- btrfs_set_item_key(leaf, &disk_key, slot);
- item = btrfs_item_nr(leaf, slot);
- btrfs_set_item_offset(leaf, item, data_end - data_size);
- btrfs_set_item_size(leaf, item, data_size);
- btrfs_set_header_nritems(leaf, nritems + 1);
+ for (i = 0; i < nr; i++) {
+ btrfs_cpu_key_to_disk(&disk_key, cpu_key + i);
+ btrfs_set_item_key(leaf, &disk_key, slot + i);
+ item = btrfs_item_nr(leaf, slot + i);
+ btrfs_set_item_offset(leaf, item, data_end - data_size[i]);
+ data_end -= data_size[i];
+ btrfs_set_item_size(leaf, item, data_size[i]);
+ }
+ btrfs_set_header_nritems(leaf, nritems + nr);
btrfs_mark_buffer_dirty(leaf);
ret = 0;
diff --git a/ctree.h b/ctree.h
index a219c23f..113d38f5 100644
--- a/ctree.h
+++ b/ctree.h
@@ -1009,9 +1009,20 @@ static inline int btrfs_del_item(struct btrfs_trans_handle *trans,
int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root
*root, struct btrfs_key *key, void *data, u32 data_size);
-int btrfs_insert_empty_item(struct btrfs_trans_handle *trans, struct btrfs_root
- *root, struct btrfs_path *path, struct btrfs_key
- *cpu_key, u32 data_size);
+int btrfs_insert_empty_items(struct btrfs_trans_handle *trans,
+ struct btrfs_root *root,
+ struct btrfs_path *path,
+ struct btrfs_key *cpu_key, u32 *data_size, int nr);
+
+static inline int btrfs_insert_empty_item(struct btrfs_trans_handle *trans,
+ struct btrfs_root *root,
+ struct btrfs_path *path,
+ struct btrfs_key *key,
+ u32 data_size)
+{
+ return btrfs_insert_empty_items(trans, root, path, key, &data_size, 1);
+}
+
int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path);
int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path);
int btrfs_leaf_free_space(struct btrfs_root *root, struct extent_buffer *leaf);