Commit ca12b7c4 authored by Tao Ma's avatar Tao Ma Committed by Mark Fasheh

ocfs2: Optionally limit extent size in ocfs2_insert_extent()

In xattr bucket, we want to limit the maximum size of a btree leaf,
otherwise we'll lose the benefits of hashing because we'll have to search
large leaves.

So add a new field in ocfs2_extent_tree which indicates the maximum leaf cluster
size we want so that we can prevent ocfs2_insert_extent() from merging the leaf
record even if it is contiguous with an adjacent record.

Other btree types are not affected by this change.
Signed-off-by: default avatarTao Ma <tao.ma@oracle.com>
Signed-off-by: default avatarMark Fasheh <mfasheh@suse.com>
parent 589dc260
...@@ -79,6 +79,7 @@ struct ocfs2_extent_tree { ...@@ -79,6 +79,7 @@ struct ocfs2_extent_tree {
struct buffer_head *root_bh; struct buffer_head *root_bh;
struct ocfs2_extent_list *root_el; struct ocfs2_extent_list *root_el;
void *private; void *private;
unsigned int max_leaf_clusters;
}; };
static void ocfs2_dinode_set_last_eb_blk(struct ocfs2_extent_tree *et, static void ocfs2_dinode_set_last_eb_blk(struct ocfs2_extent_tree *et,
...@@ -220,7 +221,8 @@ static struct ocfs2_extent_tree_operations ocfs2_xattr_tree_et_ops = { ...@@ -220,7 +221,8 @@ static struct ocfs2_extent_tree_operations ocfs2_xattr_tree_et_ops = {
}; };
static struct ocfs2_extent_tree* static struct ocfs2_extent_tree*
ocfs2_new_extent_tree(struct buffer_head *bh, ocfs2_new_extent_tree(struct inode *inode,
struct buffer_head *bh,
enum ocfs2_extent_tree_type et_type, enum ocfs2_extent_tree_type et_type,
void *private) void *private)
{ {
...@@ -248,6 +250,8 @@ static struct ocfs2_extent_tree* ...@@ -248,6 +250,8 @@ static struct ocfs2_extent_tree*
(struct ocfs2_xattr_block *)bh->b_data; (struct ocfs2_xattr_block *)bh->b_data;
et->root_el = &xb->xb_attrs.xb_root.xt_list; et->root_el = &xb->xb_attrs.xb_root.xt_list;
et->eops = &ocfs2_xattr_tree_et_ops; et->eops = &ocfs2_xattr_tree_et_ops;
et->max_leaf_clusters = ocfs2_clusters_for_bytes(inode->i_sb,
OCFS2_MAX_XATTR_TREE_LEAF_SIZE);
} }
return et; return et;
...@@ -4109,7 +4113,8 @@ out: ...@@ -4109,7 +4113,8 @@ out:
static void ocfs2_figure_contig_type(struct inode *inode, static void ocfs2_figure_contig_type(struct inode *inode,
struct ocfs2_insert_type *insert, struct ocfs2_insert_type *insert,
struct ocfs2_extent_list *el, struct ocfs2_extent_list *el,
struct ocfs2_extent_rec *insert_rec) struct ocfs2_extent_rec *insert_rec,
struct ocfs2_extent_tree *et)
{ {
int i; int i;
enum ocfs2_contig_type contig_type = CONTIG_NONE; enum ocfs2_contig_type contig_type = CONTIG_NONE;
...@@ -4125,6 +4130,20 @@ static void ocfs2_figure_contig_type(struct inode *inode, ...@@ -4125,6 +4130,20 @@ static void ocfs2_figure_contig_type(struct inode *inode,
} }
} }
insert->ins_contig = contig_type; insert->ins_contig = contig_type;
if (insert->ins_contig != CONTIG_NONE) {
struct ocfs2_extent_rec *rec =
&el->l_recs[insert->ins_contig_index];
unsigned int len = le16_to_cpu(rec->e_leaf_clusters) +
le16_to_cpu(insert_rec->e_leaf_clusters);
/*
* Caller might want us to limit the size of extents, don't
* calculate contiguousness if we might exceed that limit.
*/
if (et->max_leaf_clusters && len > et->max_leaf_clusters)
insert->ins_contig = CONTIG_NONE;
}
} }
/* /*
...@@ -4232,7 +4251,7 @@ static int ocfs2_figure_insert_type(struct inode *inode, ...@@ -4232,7 +4251,7 @@ static int ocfs2_figure_insert_type(struct inode *inode,
le16_to_cpu(el->l_next_free_rec); le16_to_cpu(el->l_next_free_rec);
if (!insert->ins_tree_depth) { if (!insert->ins_tree_depth) {
ocfs2_figure_contig_type(inode, insert, el, insert_rec); ocfs2_figure_contig_type(inode, insert, el, insert_rec, et);
ocfs2_figure_appending_type(insert, el, insert_rec); ocfs2_figure_appending_type(insert, el, insert_rec);
return 0; return 0;
} }
...@@ -4266,7 +4285,7 @@ static int ocfs2_figure_insert_type(struct inode *inode, ...@@ -4266,7 +4285,7 @@ static int ocfs2_figure_insert_type(struct inode *inode,
* into two types of appends: simple record append, or a * into two types of appends: simple record append, or a
* rotate inside the tail leaf. * rotate inside the tail leaf.
*/ */
ocfs2_figure_contig_type(inode, insert, el, insert_rec); ocfs2_figure_contig_type(inode, insert, el, insert_rec, et);
/* /*
* The insert code isn't quite ready to deal with all cases of * The insert code isn't quite ready to deal with all cases of
...@@ -4402,7 +4421,7 @@ int ocfs2_dinode_insert_extent(struct ocfs2_super *osb, ...@@ -4402,7 +4421,7 @@ int ocfs2_dinode_insert_extent(struct ocfs2_super *osb,
int status; int status;
struct ocfs2_extent_tree *et = NULL; struct ocfs2_extent_tree *et = NULL;
et = ocfs2_new_extent_tree(root_bh, OCFS2_DINODE_EXTENT, NULL); et = ocfs2_new_extent_tree(inode, root_bh, OCFS2_DINODE_EXTENT, NULL);
if (!et) { if (!et) {
status = -ENOMEM; status = -ENOMEM;
mlog_errno(status); mlog_errno(status);
...@@ -4433,7 +4452,8 @@ int ocfs2_xattr_value_insert_extent(struct ocfs2_super *osb, ...@@ -4433,7 +4452,8 @@ int ocfs2_xattr_value_insert_extent(struct ocfs2_super *osb,
int status; int status;
struct ocfs2_extent_tree *et = NULL; struct ocfs2_extent_tree *et = NULL;
et = ocfs2_new_extent_tree(root_bh, OCFS2_XATTR_VALUE_EXTENT, private); et = ocfs2_new_extent_tree(inode, root_bh,
OCFS2_XATTR_VALUE_EXTENT, private);
if (!et) { if (!et) {
status = -ENOMEM; status = -ENOMEM;
mlog_errno(status); mlog_errno(status);
...@@ -4463,7 +4483,8 @@ int ocfs2_xattr_tree_insert_extent(struct ocfs2_super *osb, ...@@ -4463,7 +4483,8 @@ int ocfs2_xattr_tree_insert_extent(struct ocfs2_super *osb,
int status; int status;
struct ocfs2_extent_tree *et = NULL; struct ocfs2_extent_tree *et = NULL;
et = ocfs2_new_extent_tree(root_bh, OCFS2_XATTR_TREE_EXTENT, NULL); et = ocfs2_new_extent_tree(inode, root_bh, OCFS2_XATTR_TREE_EXTENT,
NULL);
if (!et) { if (!et) {
status = -ENOMEM; status = -ENOMEM;
mlog_errno(status); mlog_errno(status);
...@@ -4879,7 +4900,7 @@ int ocfs2_mark_extent_written(struct inode *inode, struct buffer_head *root_bh, ...@@ -4879,7 +4900,7 @@ int ocfs2_mark_extent_written(struct inode *inode, struct buffer_head *root_bh,
goto out; goto out;
} }
et = ocfs2_new_extent_tree(root_bh, et_type, private); et = ocfs2_new_extent_tree(inode, root_bh, et_type, private);
if (!et) { if (!et) {
ret = -ENOMEM; ret = -ENOMEM;
mlog_errno(ret); mlog_errno(ret);
...@@ -5177,7 +5198,7 @@ int ocfs2_remove_extent(struct inode *inode, struct buffer_head *root_bh, ...@@ -5177,7 +5198,7 @@ int ocfs2_remove_extent(struct inode *inode, struct buffer_head *root_bh,
struct ocfs2_path *path = NULL; struct ocfs2_path *path = NULL;
struct ocfs2_extent_tree *et = NULL; struct ocfs2_extent_tree *et = NULL;
et = ocfs2_new_extent_tree(root_bh, et_type, private); et = ocfs2_new_extent_tree(inode, root_bh, et_type, private);
if (!et) { if (!et) {
ret = -ENOMEM; ret = -ENOMEM;
mlog_errno(ret); mlog_errno(ret);
......
...@@ -32,6 +32,11 @@ enum ocfs2_extent_tree_type { ...@@ -32,6 +32,11 @@ enum ocfs2_extent_tree_type {
OCFS2_XATTR_TREE_EXTENT, OCFS2_XATTR_TREE_EXTENT,
}; };
/*
* For xattr tree leaf, we limit the leaf byte size to be 64K.
*/
#define OCFS2_MAX_XATTR_TREE_LEAF_SIZE 65536
struct ocfs2_alloc_context; struct ocfs2_alloc_context;
int ocfs2_dinode_insert_extent(struct ocfs2_super *osb, int ocfs2_dinode_insert_extent(struct ocfs2_super *osb,
handle_t *handle, handle_t *handle,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment