Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
cloud-kernel
提交
86479a04
cloud-kernel
项目概览
openanolis
/
cloud-kernel
1 年多 前同步成功
通知
160
Star
36
Fork
7
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
10
列表
看板
标记
里程碑
合并请求
2
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
cloud-kernel
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
10
Issue
10
列表
看板
标记
里程碑
合并请求
2
合并请求
2
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
86479a04
编写于
9月 10, 2007
作者:
C
Chris Mason
提交者:
David Woodhouse
9月 10, 2007
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add support for defragging files via btrfsctl -d. Avoid OOM on extent tree
defrag. Signed-off-by:
N
Chris Mason
<
chris.mason@oracle.com
>
上级
8e21528f
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
100 addition
and
18 deletion
+100
-18
fs/btrfs/ctree.c
fs/btrfs/ctree.c
+4
-0
fs/btrfs/disk-io.h
fs/btrfs/disk-io.h
+2
-0
fs/btrfs/extent_map.c
fs/btrfs/extent_map.c
+10
-6
fs/btrfs/inode.c
fs/btrfs/inode.c
+81
-12
fs/btrfs/tree-defrag.c
fs/btrfs/tree-defrag.c
+3
-0
未找到文件。
fs/btrfs/ctree.c
浏览文件 @
86479a04
...
...
@@ -217,6 +217,9 @@ int btrfs_realloc_node(struct btrfs_trans_handle *trans,
root
->
fs_info
->
generation
);
WARN_ON
(
1
);
}
if
(
buffer_defrag_done
(
parent
))
return
0
;
parent_node
=
btrfs_buffer_node
(
parent
);
parent_nritems
=
btrfs_header_nritems
(
&
parent_node
->
header
);
parent_level
=
btrfs_header_level
(
&
parent_node
->
header
);
...
...
@@ -274,6 +277,7 @@ int btrfs_realloc_node(struct btrfs_trans_handle *trans,
*
last_ret
=
search_start
;
if
(
parent_level
==
1
)
clear_buffer_defrag
(
tmp_bh
);
set_buffer_defrag_done
(
tmp_bh
);
brelse
(
tmp_bh
);
}
return
err
;
...
...
fs/btrfs/disk-io.h
浏览文件 @
86479a04
...
...
@@ -26,9 +26,11 @@
enum
btrfs_bh_state_bits
{
BH_Checked
=
BH_PrivateStart
,
BH_Defrag
,
BH_DefragDone
,
};
BUFFER_FNS
(
Checked
,
checked
);
BUFFER_FNS
(
Defrag
,
defrag
);
BUFFER_FNS
(
DefragDone
,
defrag_done
);
static
inline
struct
btrfs_node
*
btrfs_buffer_node
(
struct
buffer_head
*
bh
)
{
...
...
fs/btrfs/extent_map.c
浏览文件 @
86479a04
...
...
@@ -10,6 +10,12 @@
#include <linux/blkdev.h>
#include "extent_map.h"
/* temporary define until extent_map moves out of btrfs */
struct
kmem_cache
*
btrfs_cache_create
(
const
char
*
name
,
size_t
size
,
unsigned
long
extra_flags
,
void
(
*
ctor
)(
void
*
,
struct
kmem_cache
*
,
unsigned
long
));
static
struct
kmem_cache
*
extent_map_cache
;
static
struct
kmem_cache
*
extent_state_cache
;
...
...
@@ -32,14 +38,12 @@ struct tree_entry {
void
__init
extent_map_init
(
void
)
{
extent_map_cache
=
kmem_cache_create
(
"extent_map"
,
sizeof
(
struct
extent_map
),
0
,
SLAB_RECLAIM_ACCOUNT
|
extent_map_cache
=
btrfs_cache_create
(
"extent_map"
,
sizeof
(
struct
extent_map
),
SLAB_DESTROY_BY_RCU
,
NULL
);
extent_state_cache
=
kmem_cache_create
(
"extent_state"
,
sizeof
(
struct
extent_state
),
0
,
SLAB_RECLAIM_ACCOUNT
|
extent_state_cache
=
btrfs_cache_create
(
"extent_state"
,
sizeof
(
struct
extent_state
),
SLAB_DESTROY_BY_RCU
,
NULL
);
}
...
...
fs/btrfs/inode.c
浏览文件 @
86479a04
...
...
@@ -1904,6 +1904,70 @@ static int create_snapshot(struct btrfs_root *root, char *name, int namelen)
return
ret
;
}
static
unsigned
long
force_ra
(
struct
address_space
*
mapping
,
struct
file_ra_state
*
ra
,
struct
file
*
file
,
pgoff_t
offset
,
pgoff_t
last_index
)
{
pgoff_t
req_size
;
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
req_size
=
last_index
-
offset
+
1
;
offset
=
page_cache_readahead
(
mapping
,
ra
,
file
,
offset
,
req_size
);
return
offset
;
#else
req_size
=
min
(
last_index
-
offset
+
1
,
(
pgoff_t
)
128
);
page_cache_sync_readahead
(
mapping
,
ra
,
file
,
offset
,
req_size
);
return
offset
+
req_size
;
#endif
}
int
btrfs_defrag_file
(
struct
file
*
file
)
{
struct
inode
*
inode
=
file
->
f_path
.
dentry
->
d_inode
;
struct
extent_map_tree
*
em_tree
=
&
BTRFS_I
(
inode
)
->
extent_tree
;
struct
page
*
page
;
unsigned
long
last_index
;
unsigned
long
ra_index
=
0
;
u64
page_start
;
u64
page_end
;
unsigned
long
i
;
mutex_lock
(
&
inode
->
i_mutex
);
last_index
=
inode
->
i_size
>>
PAGE_CACHE_SHIFT
;
for
(
i
=
0
;
i
<=
last_index
;
i
++
)
{
if
(
i
==
ra_index
)
{
ra_index
=
force_ra
(
inode
->
i_mapping
,
&
file
->
f_ra
,
file
,
ra_index
,
last_index
);
}
page
=
grab_cache_page
(
inode
->
i_mapping
,
i
);
if
(
!
page
)
goto
out_unlock
;
if
(
!
PageUptodate
(
page
))
{
btrfs_readpage
(
NULL
,
page
);
lock_page
(
page
);
if
(
!
PageUptodate
(
page
))
{
unlock_page
(
page
);
page_cache_release
(
page
);
goto
out_unlock
;
}
}
page_start
=
page
->
index
<<
PAGE_CACHE_SHIFT
;
page_end
=
page_start
+
PAGE_CACHE_SIZE
-
1
;
lock_extent
(
em_tree
,
page_start
,
page_end
,
GFP_NOFS
);
set_extent_delalloc
(
em_tree
,
page_start
,
page_end
,
GFP_NOFS
);
unlock_extent
(
em_tree
,
page_start
,
page_end
,
GFP_NOFS
);
set_page_dirty
(
page
);
unlock_page
(
page
);
page_cache_release
(
page
);
balance_dirty_pages_ratelimited_nr
(
inode
->
i_mapping
,
1
);
}
out_unlock:
mutex_unlock
(
&
inode
->
i_mutex
);
return
0
;
}
int
btrfs_ioctl
(
struct
inode
*
inode
,
struct
file
*
filp
,
unsigned
int
cmd
,
unsigned
long
arg
)
{
...
...
@@ -1948,10 +2012,14 @@ int btrfs_ioctl(struct inode *inode, struct file *filp, unsigned int
break
;
case
BTRFS_IOC_DEFRAG
:
mutex_lock
(
&
root
->
fs_info
->
fs_mutex
);
btrfs_defrag_root
(
root
,
0
);
btrfs_defrag_root
(
root
->
fs_info
->
extent_root
,
0
);
mutex_unlock
(
&
root
->
fs_info
->
fs_mutex
);
if
(
S_ISDIR
(
inode
->
i_mode
))
{
mutex_lock
(
&
root
->
fs_info
->
fs_mutex
);
btrfs_defrag_root
(
root
,
0
);
btrfs_defrag_root
(
root
->
fs_info
->
extent_root
,
0
);
mutex_unlock
(
&
root
->
fs_info
->
fs_mutex
);
}
else
if
(
S_ISREG
(
inode
->
i_mode
))
{
btrfs_defrag_file
(
filp
);
}
ret
=
0
;
break
;
default:
...
...
@@ -2018,7 +2086,7 @@ void btrfs_destroy_cachep(void)
kmem_cache_destroy
(
btrfs_path_cachep
);
}
st
atic
struct
kmem_cache
*
cache_create
(
const
char
*
name
,
size_t
size
,
st
ruct
kmem_cache
*
btrfs_
cache_create
(
const
char
*
name
,
size_t
size
,
unsigned
long
extra_flags
,
void
(
*
ctor
)(
void
*
,
struct
kmem_cache
*
,
unsigned
long
))
...
...
@@ -2033,27 +2101,28 @@ static struct kmem_cache *cache_create(const char *name, size_t size,
int
btrfs_init_cachep
(
void
)
{
btrfs_inode_cachep
=
cache_create
(
"btrfs_inode_cache"
,
btrfs_inode_cachep
=
btrfs_
cache_create
(
"btrfs_inode_cache"
,
sizeof
(
struct
btrfs_inode
),
0
,
init_once
);
if
(
!
btrfs_inode_cachep
)
goto
fail
;
btrfs_trans_handle_cachep
=
cache_create
(
"btrfs_trans_handle_cache"
,
sizeof
(
struct
btrfs_trans_handle
),
0
,
NULL
);
btrfs_trans_handle_cachep
=
btrfs_cache_create
(
"btrfs_trans_handle_cache"
,
sizeof
(
struct
btrfs_trans_handle
),
0
,
NULL
);
if
(
!
btrfs_trans_handle_cachep
)
goto
fail
;
btrfs_transaction_cachep
=
cache_create
(
"btrfs_transaction_cache"
,
btrfs_transaction_cachep
=
btrfs_
cache_create
(
"btrfs_transaction_cache"
,
sizeof
(
struct
btrfs_transaction
),
0
,
NULL
);
if
(
!
btrfs_transaction_cachep
)
goto
fail
;
btrfs_path_cachep
=
cache_create
(
"btrfs_path_cache"
,
btrfs_path_cachep
=
btrfs_
cache_create
(
"btrfs_path_cache"
,
sizeof
(
struct
btrfs_transaction
),
0
,
NULL
);
if
(
!
btrfs_path_cachep
)
goto
fail
;
btrfs_bit_radix_cachep
=
cache_create
(
"btrfs_radix"
,
256
,
btrfs_bit_radix_cachep
=
btrfs_
cache_create
(
"btrfs_radix"
,
256
,
SLAB_DESTROY_BY_RCU
,
NULL
);
if
(
!
btrfs_bit_radix_cachep
)
goto
fail
;
...
...
fs/btrfs/tree-defrag.c
浏览文件 @
86479a04
...
...
@@ -113,6 +113,8 @@ static int defrag_walk_down(struct btrfs_trans_handle *trans,
}
WARN_ON
(
*
level
<
0
);
WARN_ON
(
*
level
>=
BTRFS_MAX_LEVEL
);
clear_buffer_defrag
(
path
->
nodes
[
*
level
]);
clear_buffer_defrag_done
(
path
->
nodes
[
*
level
]);
btrfs_block_release
(
root
,
path
->
nodes
[
*
level
]);
path
->
nodes
[
*
level
]
=
NULL
;
*
level
+=
1
;
...
...
@@ -143,6 +145,7 @@ static int defrag_walk_up(struct btrfs_trans_handle *trans,
return
0
;
}
else
{
clear_buffer_defrag
(
path
->
nodes
[
*
level
]);
clear_buffer_defrag_done
(
path
->
nodes
[
*
level
]);
btrfs_block_release
(
root
,
path
->
nodes
[
*
level
]);
path
->
nodes
[
*
level
]
=
NULL
;
*
level
=
i
+
1
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录