1 From: Tao Ma <tao.ma@oracle.com>
2 Subject: [PATCH 13/16] ocfs2: Optionally limit extent size in ocfs2_insert_extent()
3 Patch-mainline: 2.6.28?
6 In xattr bucket, we want to limit the maximum size of a btree leaf,
7 otherwise we'll lose the benefits of hashing because we'll have to search
10 So add a new field in ocfs2_extent_tree which indicates the maximum leaf cluster
11 size we want so that we can prevent ocfs2_insert_extent() from merging the leaf
12 record even if it is contiguous with an adjacent record.
14 Other btree types are not affected by this change.
16 Signed-off-by: Tao Ma <tao.ma@oracle.com>
17 Signed-off-by: Mark Fasheh <mfasheh@suse.com>
19 fs/ocfs2/alloc.c | 39 ++++++++++++++++++++++++++++++---------
20 fs/ocfs2/alloc.h | 5 +++++
21 2 files changed, 35 insertions(+), 9 deletions(-)
23 diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c
24 index 47cdea6..16879bd 100644
25 --- a/fs/ocfs2/alloc.c
26 +++ b/fs/ocfs2/alloc.c
27 @@ -79,6 +79,7 @@ struct ocfs2_extent_tree {
28 struct buffer_head *root_bh;
29 struct ocfs2_extent_list *root_el;
31 + unsigned int max_leaf_clusters;
34 static void ocfs2_dinode_set_last_eb_blk(struct ocfs2_extent_tree *et,
35 @@ -220,7 +221,8 @@ static struct ocfs2_extent_tree_operations ocfs2_xattr_tree_et_ops = {
38 static struct ocfs2_extent_tree*
39 - ocfs2_new_extent_tree(struct buffer_head *bh,
40 + ocfs2_new_extent_tree(struct inode *inode,
41 + struct buffer_head *bh,
42 enum ocfs2_extent_tree_type et_type,
45 @@ -248,6 +250,8 @@ static struct ocfs2_extent_tree*
46 (struct ocfs2_xattr_block *)bh->b_data;
47 et->root_el = &xb->xb_attrs.xb_root.xt_list;
48 et->eops = &ocfs2_xattr_tree_et_ops;
49 + et->max_leaf_clusters = ocfs2_clusters_for_bytes(inode->i_sb,
50 + OCFS2_MAX_XATTR_TREE_LEAF_SIZE);
54 @@ -4118,7 +4122,8 @@ out:
55 static void ocfs2_figure_contig_type(struct inode *inode,
56 struct ocfs2_insert_type *insert,
57 struct ocfs2_extent_list *el,
58 - struct ocfs2_extent_rec *insert_rec)
59 + struct ocfs2_extent_rec *insert_rec,
60 + struct ocfs2_extent_tree *et)
63 enum ocfs2_contig_type contig_type = CONTIG_NONE;
64 @@ -4134,6 +4139,20 @@ static void ocfs2_figure_contig_type(struct inode *inode,
67 insert->ins_contig = contig_type;
69 + if (insert->ins_contig != CONTIG_NONE) {
70 + struct ocfs2_extent_rec *rec =
71 + &el->l_recs[insert->ins_contig_index];
72 + unsigned int len = le16_to_cpu(rec->e_leaf_clusters) +
73 + le16_to_cpu(insert_rec->e_leaf_clusters);
76 + * Caller might want us to limit the size of extents, don't
77 + * calculate contiguousness if we might exceed that limit.
79 + if (et->max_leaf_clusters && len > et->max_leaf_clusters)
80 + insert->ins_contig = CONTIG_NONE;
85 @@ -4241,7 +4260,7 @@ static int ocfs2_figure_insert_type(struct inode *inode,
86 le16_to_cpu(el->l_next_free_rec);
88 if (!insert->ins_tree_depth) {
89 - ocfs2_figure_contig_type(inode, insert, el, insert_rec);
90 + ocfs2_figure_contig_type(inode, insert, el, insert_rec, et);
91 ocfs2_figure_appending_type(insert, el, insert_rec);
94 @@ -4275,7 +4294,7 @@ static int ocfs2_figure_insert_type(struct inode *inode,
95 * into two types of appends: simple record append, or a
96 * rotate inside the tail leaf.
98 - ocfs2_figure_contig_type(inode, insert, el, insert_rec);
99 + ocfs2_figure_contig_type(inode, insert, el, insert_rec, et);
102 * The insert code isn't quite ready to deal with all cases of
103 @@ -4411,7 +4430,7 @@ int ocfs2_dinode_insert_extent(struct ocfs2_super *osb,
105 struct ocfs2_extent_tree *et = NULL;
107 - et = ocfs2_new_extent_tree(root_bh, OCFS2_DINODE_EXTENT, NULL);
108 + et = ocfs2_new_extent_tree(inode, root_bh, OCFS2_DINODE_EXTENT, NULL);
112 @@ -4442,7 +4461,8 @@ int ocfs2_xattr_value_insert_extent(struct ocfs2_super *osb,
114 struct ocfs2_extent_tree *et = NULL;
116 - et = ocfs2_new_extent_tree(root_bh, OCFS2_XATTR_VALUE_EXTENT, private);
117 + et = ocfs2_new_extent_tree(inode, root_bh,
118 + OCFS2_XATTR_VALUE_EXTENT, private);
122 @@ -4472,7 +4492,8 @@ int ocfs2_xattr_tree_insert_extent(struct ocfs2_super *osb,
124 struct ocfs2_extent_tree *et = NULL;
126 - et = ocfs2_new_extent_tree(root_bh, OCFS2_XATTR_TREE_EXTENT, NULL);
127 + et = ocfs2_new_extent_tree(inode, root_bh, OCFS2_XATTR_TREE_EXTENT,
132 @@ -4888,7 +4909,7 @@ int ocfs2_mark_extent_written(struct inode *inode, struct buffer_head *root_bh,
136 - et = ocfs2_new_extent_tree(root_bh, et_type, private);
137 + et = ocfs2_new_extent_tree(inode, root_bh, et_type, private);
141 @@ -5186,7 +5207,7 @@ int ocfs2_remove_extent(struct inode *inode, struct buffer_head *root_bh,
142 struct ocfs2_path *path = NULL;
143 struct ocfs2_extent_tree *et = NULL;
145 - et = ocfs2_new_extent_tree(root_bh, et_type, private);
146 + et = ocfs2_new_extent_tree(inode, root_bh, et_type, private);
150 diff --git a/fs/ocfs2/alloc.h b/fs/ocfs2/alloc.h
151 index b8cfc53..ff40c8f 100644
152 --- a/fs/ocfs2/alloc.h
153 +++ b/fs/ocfs2/alloc.h
154 @@ -32,6 +32,11 @@ enum ocfs2_extent_tree_type {
155 OCFS2_XATTR_TREE_EXTENT,
159 + * For xattr tree leaf, we limit the leaf byte size to be 64K.
161 +#define OCFS2_MAX_XATTR_TREE_LEAF_SIZE 65536
163 struct ocfs2_alloc_context;
164 int ocfs2_dinode_insert_extent(struct ocfs2_super *osb,