Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Linux-御风守护者
linux
提交
f2458e1d
L
linux
项目概览
Linux-御风守护者
/
linux
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
L
linux
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f2458e1d
编写于
4月 25, 2007
作者:
C
Chris Mason
提交者:
David Woodhouse
4月 25, 2007
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Btrfs: change around extent-tree prealloc
Signed-off-by:
N
Chris Mason
<
chris.mason@oracle.com
>
上级
f68cad0f
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
87 addition
and
27 deletion
+87
-27
fs/btrfs/ctree.h
fs/btrfs/ctree.h
+7
-3
fs/btrfs/disk-io.c
fs/btrfs/disk-io.c
+2
-1
fs/btrfs/extent-tree.c
fs/btrfs/extent-tree.c
+78
-23
未找到文件。
fs/btrfs/ctree.h
浏览文件 @
f2458e1d
...
...
@@ -244,12 +244,17 @@ struct btrfs_fs_info {
struct
btrfs_root
*
extent_root
;
struct
btrfs_root
*
tree_root
;
struct
btrfs_root
*
dev_root
;
struct
btrfs_key
current_insert
;
struct
btrfs_key
last_insert
;
struct
radix_tree_root
fs_roots_radix
;
struct
radix_tree_root
pending_del_radix
;
struct
radix_tree_root
pinned_radix
;
struct
radix_tree_root
dev_radix
;
u64
extent_tree_insert
[
BTRFS_MAX_LEVEL
*
3
];
int
extent_tree_insert_nr
;
u64
extent_tree_prealloc
[
BTRFS_MAX_LEVEL
*
3
];
int
extent_tree_prealloc_nr
;
u64
generation
;
struct
btrfs_transaction
*
running_transaction
;
struct
btrfs_super_block
*
disk_super
;
...
...
@@ -267,8 +272,7 @@ struct btrfs_fs_info {
/*
* in ram representation of the tree. extent_root is used for all allocations
* and for the extent tree extent_root root. current_insert is used
* only for the extent tree.
* and for the extent tree extent_root root.
*/
struct
btrfs_root
{
struct
buffer_head
*
node
;
...
...
fs/btrfs/disk-io.c
浏览文件 @
f2458e1d
...
...
@@ -542,6 +542,8 @@ struct btrfs_root *open_ctree(struct super_block *sb)
fs_info
->
btree_inode
->
i_size
=
sb
->
s_bdev
->
bd_inode
->
i_size
;
fs_info
->
btree_inode
->
i_mapping
->
a_ops
=
&
btree_aops
;
fs_info
->
do_barriers
=
1
;
fs_info
->
extent_tree_insert_nr
=
0
;
fs_info
->
extent_tree_prealloc_nr
=
0
;
BTRFS_I
(
fs_info
->
btree_inode
)
->
root
=
tree_root
;
memset
(
&
BTRFS_I
(
fs_info
->
btree_inode
)
->
location
,
0
,
sizeof
(
struct
btrfs_key
));
...
...
@@ -555,7 +557,6 @@ struct btrfs_root *open_ctree(struct super_block *sb)
}
mutex_init
(
&
fs_info
->
trans_mutex
);
mutex_init
(
&
fs_info
->
fs_mutex
);
memset
(
&
fs_info
->
current_insert
,
0
,
sizeof
(
fs_info
->
current_insert
));
memset
(
&
fs_info
->
last_insert
,
0
,
sizeof
(
fs_info
->
last_insert
));
__setup_root
(
sb
->
s_blocksize
,
dev_root
,
...
...
fs/btrfs/extent-tree.c
浏览文件 @
f2458e1d
...
...
@@ -169,9 +169,8 @@ static int finish_current_insert(struct btrfs_trans_handle *trans, struct
btrfs_set_key_type
(
&
ins
,
BTRFS_EXTENT_ITEM_KEY
);
btrfs_set_extent_owner
(
&
extent_item
,
extent_root
->
root_key
.
objectid
);
for
(
i
=
0
;
i
<
extent_root
->
fs_info
->
current_insert
.
flags
;
i
++
)
{
ins
.
objectid
=
extent_root
->
fs_info
->
current_insert
.
objectid
+
i
;
for
(
i
=
0
;
i
<
extent_root
->
fs_info
->
extent_tree_insert_nr
;
i
++
)
{
ins
.
objectid
=
extent_root
->
fs_info
->
extent_tree_insert
[
i
];
super_blocks_used
=
btrfs_super_blocks_used
(
info
->
disk_super
);
btrfs_set_super_blocks_used
(
info
->
disk_super
,
super_blocks_used
+
1
);
...
...
@@ -179,7 +178,8 @@ static int finish_current_insert(struct btrfs_trans_handle *trans, struct
sizeof
(
extent_item
));
BUG_ON
(
ret
);
}
extent_root
->
fs_info
->
current_insert
.
offset
=
0
;
extent_root
->
fs_info
->
extent_tree_insert_nr
=
0
;
extent_root
->
fs_info
->
extent_tree_prealloc_nr
=
0
;
return
0
;
}
...
...
@@ -349,7 +349,10 @@ static int find_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
int
start_found
;
struct
btrfs_leaf
*
l
;
struct
btrfs_root
*
root
=
orig_root
->
fs_info
->
extent_root
;
struct
btrfs_fs_info
*
info
=
root
->
fs_info
;
int
total_needed
=
num_blocks
;
int
total_found
=
0
;
int
fill_prealloc
=
0
;
int
level
;
path
=
btrfs_alloc_path
();
...
...
@@ -357,8 +360,12 @@ static int find_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
btrfs_set_key_type
(
ins
,
BTRFS_EXTENT_ITEM_KEY
);
level
=
btrfs_header_level
(
btrfs_buffer_header
(
root
->
node
));
total_needed
+=
(
level
+
2
)
*
3
;
if
(
root
->
fs_info
->
last_insert
.
objectid
==
0
&&
search_end
==
(
u64
)
-
1
)
{
if
(
num_blocks
==
0
)
{
fill_prealloc
=
1
;
num_blocks
=
1
;
total_needed
=
min
(
level
+
2
,
BTRFS_MAX_LEVEL
)
*
3
;
}
if
(
info
->
last_insert
.
objectid
==
0
&&
search_end
==
(
u64
)
-
1
)
{
struct
btrfs_disk_key
*
last_key
;
btrfs_init_path
(
path
);
ins
->
objectid
=
(
u64
)
-
1
;
...
...
@@ -373,8 +380,8 @@ static int find_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
last_key
=
&
l
->
items
[
path
->
slots
[
0
]].
key
;
search_start
=
btrfs_disk_key_objectid
(
last_key
);
}
if
(
root
->
fs_
info
->
last_insert
.
objectid
>
search_start
)
search_start
=
root
->
fs_
info
->
last_insert
.
objectid
;
if
(
info
->
last_insert
.
objectid
>
search_start
)
search_start
=
info
->
last_insert
.
objectid
;
check_failed:
btrfs_init_path
(
path
);
...
...
@@ -392,6 +399,10 @@ static int find_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
l
=
btrfs_buffer_leaf
(
path
->
nodes
[
0
]);
slot
=
path
->
slots
[
0
];
if
(
slot
>=
btrfs_header_nritems
(
&
l
->
header
))
{
if
(
fill_prealloc
)
{
info
->
extent_tree_prealloc_nr
=
0
;
total_found
=
0
;
}
ret
=
btrfs_next_leaf
(
root
,
path
);
if
(
ret
==
0
)
continue
;
...
...
@@ -399,13 +410,13 @@ static int find_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
goto
error
;
if
(
!
start_found
)
{
ins
->
objectid
=
search_start
;
ins
->
offset
=
(
u64
)
-
1
;
ins
->
offset
=
(
u64
)
-
1
-
search_start
;
start_found
=
1
;
goto
check_pending
;
}
ins
->
objectid
=
last_block
>
search_start
?
last_block
:
search_start
;
ins
->
offset
=
(
u64
)
-
1
;
ins
->
offset
=
(
u64
)
-
1
-
ins
->
objectid
;
goto
check_pending
;
}
btrfs_disk_key_to_cpu
(
&
key
,
&
l
->
items
[
slot
].
key
);
...
...
@@ -414,7 +425,7 @@ static int find_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
if
(
last_block
<
search_start
)
last_block
=
search_start
;
hole_size
=
key
.
objectid
-
last_block
;
if
(
hole_size
>
total_needed
)
{
if
(
hole_size
>
num_blocks
)
{
ins
->
objectid
=
last_block
;
ins
->
offset
=
hole_size
;
goto
check_pending
;
...
...
@@ -433,17 +444,51 @@ static int find_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
btrfs_release_path
(
root
,
path
);
BUG_ON
(
ins
->
objectid
<
search_start
);
for
(
test_block
=
ins
->
objectid
;
test_block
<
ins
->
objectid
+
total_needed
;
test_block
++
)
{
if
(
test_radix_bit
(
&
root
->
fs_info
->
pinned_radix
,
test_block
))
{
test_block
<
ins
->
objectid
+
num_blocks
;
test_block
++
)
{
if
(
test_radix_bit
(
&
info
->
pinned_radix
,
test_block
))
{
search_start
=
test_block
+
1
;
goto
check_failed
;
}
}
BUG_ON
(
root
->
fs_info
->
current_insert
.
offset
);
root
->
fs_info
->
current_insert
.
offset
=
total_needed
-
num_blocks
;
root
->
fs_info
->
current_insert
.
objectid
=
ins
->
objectid
+
num_blocks
;
root
->
fs_info
->
current_insert
.
flags
=
0
;
if
(
!
fill_prealloc
&&
info
->
extent_tree_insert_nr
)
{
u64
last
=
info
->
extent_tree_insert
[
info
->
extent_tree_insert_nr
-
1
];
if
(
ins
->
objectid
+
num_blocks
>
info
->
extent_tree_insert
[
0
]
&&
ins
->
objectid
<=
last
)
{
search_start
=
last
+
1
;
WARN_ON
(
1
);
goto
check_failed
;
}
}
if
(
!
fill_prealloc
&&
info
->
extent_tree_prealloc_nr
)
{
u64
first
=
info
->
extent_tree_prealloc
[
info
->
extent_tree_prealloc_nr
-
1
];
if
(
ins
->
objectid
+
num_blocks
>
first
&&
ins
->
objectid
<=
info
->
extent_tree_prealloc
[
0
])
{
search_start
=
info
->
extent_tree_prealloc
[
0
]
+
1
;
WARN_ON
(
1
);
goto
check_failed
;
}
}
if
(
fill_prealloc
)
{
int
nr
;
test_block
=
ins
->
objectid
;
while
(
test_block
<
ins
->
objectid
+
ins
->
offset
&&
total_found
<
total_needed
)
{
nr
=
total_needed
-
total_found
-
1
;
BUG_ON
(
nr
<
0
);
root
->
fs_info
->
extent_tree_prealloc
[
nr
]
=
test_block
;
total_found
++
;
test_block
++
;
}
if
(
total_found
<
total_needed
)
{
search_start
=
test_block
;
goto
check_failed
;
}
root
->
fs_info
->
extent_tree_prealloc_nr
=
total_found
;
}
root
->
fs_info
->
last_insert
.
objectid
=
ins
->
objectid
;
ins
->
offset
=
num_blocks
;
btrfs_free_path
(
path
);
...
...
@@ -472,25 +517,35 @@ int btrfs_alloc_extent(struct btrfs_trans_handle *trans,
struct
btrfs_fs_info
*
info
=
root
->
fs_info
;
struct
btrfs_root
*
extent_root
=
info
->
extent_root
;
struct
btrfs_extent_item
extent_item
;
struct
btrfs_key
prealloc_key
;
btrfs_set_extent_refs
(
&
extent_item
,
1
);
btrfs_set_extent_owner
(
&
extent_item
,
owner
);
if
(
root
==
extent_root
)
{
BUG_ON
(
extent_root
->
fs_info
->
current_insert
.
offset
==
0
);
int
nr
;
BUG_ON
(
info
->
extent_tree_prealloc_nr
==
0
);
BUG_ON
(
num_blocks
!=
1
);
BUG_ON
(
extent_root
->
fs_info
->
current_insert
.
flags
==
extent_root
->
fs_info
->
current_insert
.
offset
);
ins
->
offset
=
1
;
ins
->
objectid
=
extent_root
->
fs_info
->
current_insert
.
objectid
+
extent_root
->
fs_info
->
current_insert
.
flags
++
;
info
->
extent_tree_prealloc_nr
--
;
nr
=
info
->
extent_tree_prealloc_nr
;
ins
->
objectid
=
info
->
extent_tree_prealloc
[
nr
];
info
->
extent_tree_insert
[
info
->
extent_tree_insert_nr
++
]
=
ins
->
objectid
;
return
0
;
}
/* do the real allocation */
ret
=
find_free_extent
(
trans
,
root
,
num_blocks
,
search_start
,
search_end
,
ins
);
if
(
ret
)
return
ret
;
/* then do prealloc for the extent tree */
ret
=
find_free_extent
(
trans
,
root
,
0
,
ins
->
objectid
+
ins
->
offset
,
search_end
,
&
prealloc_key
);
if
(
ret
)
return
ret
;
super_blocks_used
=
btrfs_super_blocks_used
(
info
->
disk_super
);
btrfs_set_super_blocks_used
(
info
->
disk_super
,
super_blocks_used
+
num_blocks
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录