ext4: extent status tree (step2)
Subsystems (2)
v5 cover ext4: extent status tree (step2)
Hi all,
This is my fifth try to implement the second step of extent status tree. The patch set can be divided into the following parts.
Patch 1/10
This patch refines the extent status tree
Patch 2/10-6/10
These patches try to track all extent status in extent status tree and
make it as a extent cache. In extent_status structure bit field is removed because we get some warnings from 'sparse'. Now es_pblk and es_status are manipulated by ext4_es_*_pblock and ext4_es_*_status directly. Currently when an unwritten extent is allocated, we never know it from map->m_flags because ext4_ext_map_blocks doesn't return EXT4_MAP_UNWRITTEN flag. A patch fixes it and we can determine the extent status according to m_flags.
According to Jan's feedback, we put the hole into extent cache to avoid
to access extent tree in disk as far as possible. Here if the whole file is a hole, this hole will not be cached in extent status tree because it is always splitted immediately. Meanwhile the hole will not be cached when ext4_da_map_blocks looks up a block mapping because this hole will be as a delayed extent later.
Patch 7/10-8/10
This two patches try to reclaim memory from extent status tree when we
are under a high memeory pressure.
Patch 9/10-10/10
Thses patches are picked up again from 1st version because I aware that
they could remove a bogus wait in ext4_ind_direct_IO when dioread_nolock is enabled. After applied them, the latency of dio read can be reduced.
I measure it using fio and the result shows as below.
config file
-----------
[global]
ioengine=psync
direct=1
bs=4k
threadgroup_reporting
directory=/mnt/sda1/
filename=testfile
filesize=10g
size=10g
runtime=120
iodepth=16
[fio]
rw=randrw
numjobs=4
result
------
w/ bogus wait
read : io=1508.1MB, bw=12876KB/s, iops=3218 , runt=120001msec
clat (usec): min=128 , max=268738 , avg=718.62, stdev=3703.97
lat (usec): min=128 , max=268739 , avg=718.78, stdev=3703.97
write: io=1505.2MB, bw=12843KB/s, iops=3210 , runt=120001msec
clat (usec): min=47 , max=991727 , avg=520.94, stdev=3451.63
lat (usec): min=47 , max=991727 , avg=521.31, stdev=3451.63w/o bogus wait
read : io=1576.4MB, bw=13451KB/s, iops=3362 , runt=120001msec
clat (usec): min=128 , max=283906 , avg=685.88, stdev=2762.64
lat (usec): min=128 , max=283907 , avg=686.05, stdev=2762.64
write: io=1577.9MB, bw=13458KB/s, iops=3364 , runt=120001msec
clat (usec): min=48 , max=977942 , avg=498.97, stdev=3093.08
lat (usec): min=48 , max=977943 , avg=499.33, stdev=3093.08Quoted 1 line
From the result we can see that the avg. of latency could be reduced a little.
changelog:
v5 <- v4:
- drop a patch that removes EXT4_MAP_FROM_CLUSTER flag
(I will revise it in the patch set of get_block_t refinement)
- fold original patch 3/9 into patch 4/9
- manipulate es_pblk and es_status directly
(bit field is removed because it causes some warnings from 'sparse')
- let ext4_ext_map_blocks return EXT4_MAP_UNWRITTEN flag
- rename ext4_es_find_extent with ext4_es_find_delayed_extent
- add hole status and put hole into extent status tree as a cache
- convert unwritten extents from extent status tree in ext4_ext_direct_IO and end_io callback
- remove a bogus wait in ext4_ind_direct_IO when dioread_nolock is enabled
v4 <- v3:
- register a normal shrinker to reclaim extent from extent status tree
v3 <- v2:
- use prune_super() to reclaim extents from extent status tree
- stashed es_status into es_pblk
- remove single extent cache
- rebase against 3.8-rc4
v2 <- v1:
- drop patches that try to improve unwritten extent conversion
- remove EXT4_MAP_FROM_CLUSTER flag
- add tracepoint for ext4_es_lookup_extent()
- drop a patch, which tries to fix a warning when bigalloc and delalloc are enabled
- add a shrinker to reclaim memory from extent status tree
- rebase against 3.8-rc2
v4: http://lwn.net/Articles/536037/
v3: http://lwn.net/Articles/533730/
v2: http://lwn.net/Articles/532446/
v1: http://lwn.net/Articles/531065/
As always, any comments or feedbacks are welcome.
FWIW, when I try to implement patch 3/10, I realize that get_block_t and *_map_blocks functions need to be refactored because in ext4 we already have six get_block_t functions
- ext4_get_block
- ext4_get_block_write
- ext4_get_block_write_nolock
- noalloc_get_block_write
- ext4_da_get_block_prep
- _ext4_get_block
and four *_map_blocks
- ext4_map_blocks
- ext4_da_map_blocks
- ext4_ext_map_blocks
- ext4_ind_map_blocks
So I am planning to refine them. First I will try to split ext4_map_blocks into two parts, e.g. ext4_map_blocks_read and ext4_map_blocks_write, and then try other cleanups and improvmentes.
Thanks,
- Zheng
Zheng Liu (10):
ext4: refine extent status tree
ext4: add physical block and status member into extent status tree
ext4: let ext4_ext_map_blocks return EXT4_MAP_UNWRITTEN flag
ext4: track all extent status in extent status tree
ext4: lookup block mapping in extent status tree
ext4: remove single extent cache
ext4: adjust some functions for reclaiming extents from extent status
tree
ext4: reclaim extents from extent status tree
ext4: convert unwritten extents from extent status tree in end_io
ext4: remove bogus wait for unwritten extents in ext4_ind_direct_IO
fs/ext4/ext4.h | 21 +- fs/ext4/ext4_extents.h | 6 - fs/ext4/extents.c | 211 ++++-------- fs/ext4/extents_status.c | 779 +++++++++++++++++++++++++++++++++++--------- fs/ext4/extents_status.h | 84 ++++- fs/ext4/file.c | 16 +- fs/ext4/indirect.c | 5 - fs/ext4/inode.c | 148 +++++++-- fs/ext4/move_extent.c | 3 - fs/ext4/page-io.c | 8 +- fs/ext4/super.c | 8 +- include/trace/events/ext4.h | 207 ++++++++++-- 12 files changed, 1075 insertions(+), 421 deletions(-)
Signature · 1 line
1.7.12.rc2.18.g61b472e
PATCH v5 1/10 ext4: refine extent status tree
From: Zheng Liu <[email protected]>
This commit refines the extent status tree code.
1) A prefix 'es_' is added to to the extent status tree structure members.
2) Refactored es_remove_extent() so that __es_remove_extent() can be used by es_insert_extent() to remove the old extent entry(-ies) before inserting a new one.
3) Rename extent_status_end() to ext4_es_end()
4) ext4_es_can_be_merged() is define to check whether two extents can be merged or not.
5) Update and clarified comments.
--- fs/ext4/extents.c | 21 +-- fs/ext4/extents_status.c | 318 ++++++++++++++++++++++++-------------------- fs/ext4/extents_status.h | 8 +- fs/ext4/file.c | 12 +- include/trace/events/ext4.h | 40 +++--- 5 files changed, 217 insertions(+), 182 deletions(-)
fs/ext4/extents.c +11 -10
@@ -3525,13 +3525,14 @@ static int ext4_find_delalloc_range(struct inode *inode, {struct extent_status es; - es.start = lblk_start; -ext4_es_find_extent (inode, &es); -if (es.len ==0 ) + es.es_lblk = lblk_start; + (void )ext4_es_find_extent (inode, &es); +if (es.es_len ==0 )return 0 ;/* there is no delay extent in this tree */ -else if (es.start <= lblk_start && lblk_start < es.start + es.len) +else if (es.es_lblk <= lblk_start && + lblk_start < es.es_lblk + es.es_len)return 1 ; -else if (lblk_start <= es.start && es.start <= lblk_end) +else if (lblk_start <= es.es_lblk && es.es_lblk <= lblk_end)return 1 ;else return 0 ;
@@ -4567,7 +4568,7 @@ static int ext4_find_delayed_extent(struct inode *inode,struct extent_status es;ext4_lblk_t next_del; - es.start = newex->ec_block; + es.es_lblk = newex->ec_block; next_del =ext4_es_find_extent (inode, &es);if (newex->ec_start ==0 ) {
@@ -4575,18 +4576,18 @@ static int ext4_find_delayed_extent(struct inode *inode,* No extent in extent-tree contains block @newex->ec_start, * then the block may stay in 1)a hole or 2)delayed-extent. */ -if (es.len ==0 ) +if (es.es_len ==0 )/* A hole found. */ return 0 ; -if (es.start > newex->ec_block) { +if (es.es_lblk > newex->ec_block) {/* A hole found. */ - newex->ec_len =min (es.start - newex->ec_block, + newex->ec_len =min (es.es_lblk - newex->ec_block, newex->ec_len);return 0 ; } - newex->ec_len = es.start + es.len - newex->ec_block; + newex->ec_len = es.es_lblk + es.es_len - newex->ec_block; }return next_del;
fs/ext4/extents_status.c +177 -141
561 lines not on this page · raw message
fs/ext4/extents_status.h +4 -4
@@ -22,8 +22,8 @@struct extent_status {struct rb_node rb_node; -ext4_lblk_t start;/* first block extent covers */ -ext4_lblk_t len;/* length of extent in block */ +ext4_lblk_t es_lblk;/* first logical block extent covers */ +ext4_lblk_t es_len;/* length of extent in block */ };struct ext4_es_tree {
@@ -35,9 +35,9 @@ extern int __init ext4_init_es(void);extern void ext4_exit_es (void );extern void ext4_es_init_tree (struct ext4_es_tree *tree); -extern int ext4_es_insert_extent (struct inode *inode,ext4_lblk_t start, +extern int ext4_es_insert_extent (struct inode *inode,ext4_lblk_t lblk,ext4_lblk_t len); -extern int ext4_es_remove_extent (struct inode *inode,ext4_lblk_t start, +extern int ext4_es_remove_extent (struct inode *inode,ext4_lblk_t lblk,ext4_lblk_t len);extern ext4_lblk_t ext4_es_find_extent (struct inode *inode,struct extent_status *es);
fs/ext4/file.c +5 -7
@@ -464,10 +464,9 @@ static loff_t ext4_seek_data(struct file *file, loff_t offset, loff_t maxsize)* If there is a delay extent at this offset, * it will be as a data. */ - es.start = last; + es.es_lblk = last; (void )ext4_es_find_extent (inode, &es); -if (last >= es.start && - last < es.start + es.len) { +if (last >= es.es_lblk && last < es.es_lblk + es.es_len) {if (last != start) dataoff = last << blkbits;break ;
@@ -549,11 +548,10 @@ static loff_t ext4_seek_hole(struct file *file, loff_t offset, loff_t maxsize)* If there is a delay extent at this offset, * we will skip this extent. */ - es.start = last; + es.es_lblk = last; (void )ext4_es_find_extent (inode, &es); -if (last >= es.start && - last < es.start + es.len) { - last = es.start + es.len; +if (last >= es.es_lblk && last < es.es_lblk + es.es_len) { + last = es.es_lblk + es.es_len; holeoff = last << blkbits;continue ; }
include/trace/events/ext4.h +20 -20
@@ -2068,75 +2068,75 @@ TRACE_EVENT(ext4_ext_remove_space_done, );TRACE_EVENT (ext4_es_insert_extent, - TP_PROTO(struct inode *inode, ext4_lblk_t start, ext4_lblk_t len), + TP_PROTO(struct inode *inode, ext4_lblk_t lblk, ext4_lblk_t len), -TP_ARGS (inode, start, len), +TP_ARGS (inode, lblk, len),TP_STRUCT__entry ( __field( dev_t, dev ) __field( ino_t, ino ) - __field( loff_t, start ) + __field( loff_t, lblk )__field ( loff_t, len ) ),TP_fast_assign ( __entry->dev = inode->i_sb->s_dev; __entry->ino = inode->i_ino; - __entry->start = start; + __entry->lblk = lblk; __entry->len = len; ),TP_printk ("dev %d,%d ino %lu es [%lld/%lld)" ,MAJOR (__entry->dev),MINOR (__entry->dev), (unsigned long ) __entry->ino, - __entry->start, __entry->len) + __entry->lblk, __entry->len) );TRACE_EVENT (ext4_es_remove_extent, - TP_PROTO(struct inode *inode, ext4_lblk_t start, ext4_lblk_t len), + TP_PROTO(struct inode *inode, ext4_lblk_t lblk, ext4_lblk_t len), -TP_ARGS (inode, start, len), +TP_ARGS (inode, lblk, len),TP_STRUCT__entry ( __field( dev_t, dev ) __field( ino_t, ino ) - __field( loff_t, start ) + __field( loff_t, lblk )__field ( loff_t, len ) ),TP_fast_assign ( __entry->dev = inode->i_sb->s_dev; __entry->ino = inode->i_ino; - __entry->start = start; + __entry->lblk = lblk; __entry->len = len; ),TP_printk ("dev %d,%d ino %lu es [%lld/%lld)" ,MAJOR (__entry->dev),MINOR (__entry->dev), (unsigned long ) __entry->ino, - __entry->start, __entry->len) + __entry->lblk, __entry->len) );TRACE_EVENT (ext4_es_find_extent_enter, - TP_PROTO(struct inode *inode, ext4_lblk_t start), + TP_PROTO(struct inode *inode, ext4_lblk_t lblk), -TP_ARGS (inode, start), +TP_ARGS (inode, lblk),TP_STRUCT__entry ( __field( dev_t, dev ) __field( ino_t, ino ) -__field ( ext4_lblk_t, start ) +__field ( ext4_lblk_t, lblk ) ),TP_fast_assign ( __entry->dev = inode->i_sb->s_dev; __entry->ino = inode->i_ino; - __entry->start = start; + __entry->lblk = lblk; ), -TP_printk ("dev %d,%d ino %lu start %u" , +TP_printk ("dev %d,%d ino %lu lblk %u" ,MAJOR (__entry->dev),MINOR (__entry->dev), - (unsigned long ) __entry->ino, __entry->start) + (unsigned long ) __entry->ino, __entry->lblk) ); TRACE_EVENT(ext4_es_find_extent_exit,
@@ -2148,7 +2148,7 @@ TRACE_EVENT(ext4_es_find_extent_exit,TP_STRUCT__entry (__field (dev_t ,dev )__field ( ino_t, ino ) -__field ( ext4_lblk_t, start ) +__field ( ext4_lblk_t, lblk )__field ( ext4_lblk_t, len )__field ( ext4_lblk_t, ret ) ),
@@ -2156,15 +2156,15 @@ TRACE_EVENT(ext4_es_find_extent_exit,TP_fast_assign ( __entry->dev = inode->i_sb->s_dev; __entry->ino = inode->i_ino; - __entry->start = es->start; - __entry->len = es->len; + __entry->lblk = es->es_lblk; + __entry->len = es->es_len; __entry->ret = ret; ),TP_printk ("dev %d,%d ino %lu es [%u/%u) ret %u" ,MAJOR (__entry->dev),MINOR (__entry->dev), (unsigned long ) __entry->ino, - __entry->start, __entry->len, __entry->ret) + __entry->lblk, __entry->len, __entry->ret) );#endif /* _TRACE_EXT4_H */
Signature · 1 line
1.7.12.rc2.18.g61b472e
Re: [PATCH 01/10 v5] ext4: refine extent status tree
Quoted 11 lines · Zheng Liu
From: Zheng Liu <[email protected]>
This commit refines the extent status tree code.
1) A prefix '
es_' is added to to the extent status tree structure members.2) Refactored
es_remove_extent()so that__es_remove_extent()can be used byes_insert_extent()to remove the old extent entry(-ies) before inserting a new one.
Quoted 6 lines
3) Rename
extent_status_end()toext4_es_end()4)
ext4_es_can_be_merged()is define to check whether two extents can be merged or not.5) Update and clarified comments.
Just one minor comment below. Otherwise the patch looks good (although I
admit I didn't check all the renaming changes carefully. You can add:
Honza
Quoted 14 lines
Signed-off-by Zheng Liu <[email protected]>Cc "Theodore Ts'o" <[email protected]>Cc Jan kara <[email protected]>--- fs/ext4/extents.c | 21 +-- fs/ext4/extents_status.c | 318 ++++++++++++++++++++++++-------------------- fs/ext4/extents_status.h | 8 +- fs/ext4/file.c | 12 +- include/trace/events/ext4.h | 40 +++--- 5 files changed, 217 insertions(+), 182 deletions(-)fs/ext4/extents_status.c +0
-0
...
Quoted 35 lines
fs/ext4/extents_status.c +2
-22@@ -320,60 +352,39 @@ ext4_es_try_to_merge_right(struct ext4_es_tree *tree, struct extent_status *es)return es; } -static int __es_insert_extent (struct ext4_es_tree *tree,ext4_lblk_t offset, -ext4_lblk_t len) +static int __es_insert_extent (struct ext4_es_tree *tree, +struct extent_status *newes) {struct rb_node **p = &tree->root.rb_node;struct rb_node *parent =NULL ;struct extent_status *es; -ext4_lblk_t end = offset + len -1 ; - -BUG_ON (end < offset); - es = tree->cache_es; -if (es && offset == (extent_status_end (es) +1 )) { -es_debug ("cached by [%u/%u)\n" , es->start, es->len); - es->len += len; - es =ext4_es_try_to_merge_right (tree, es); - goto out; - }else if (es && es->start == end +1 ) { -es_debug ("cached by [%u/%u)\n" , es->start, es->len); - es->start = offset; - es->len += len; - es =ext4_es_try_to_merge_left (tree, es); - goto out; - }else if (es && es->start <= offset && - end <=extent_status_end (es)) { -es_debug ("cached by [%u/%u)\n" , es->start, es->len); - goto out; - }while (*p) { parent = *p;
fs/ext4/extents_status.c ext4_es_try_to_merge_right(struct ext4_es_tree *tree, struct extent_status *es) · line 369
Quoted 10 lines
fs/ext4/extents_status.c +4
-4es = rb_entry(parent, struct extent_status, rb_node); -if (offset < es->start) { -if (es->start == end +1 ) { - es->start = offset; - es->len += len; +if (newes->es_lblk < es->es_lblk) { +if (ext4_es_can_be_merged (newes, es)) { + es->es_lblk = newes->es_lblk; + es->es_len += newes->es_len;
This is wrong, isn't it? You cannot change es->es_lblk because that can
break ordering of elements in the tree... thinking ... ah, it's OK because you have non-overlapping intervals. But it deserves a comment I guess.
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH 01/10 v5] ext4: refine extent status tree
On Fri, Feb 08, 2013 at 04:35:00PM +0100, Jan Kara wrote:
[snip]
Quoted 33 lines
Quoted 33 lines
fs/ext4/extents_status.c +2
-22-static int __es_insert_extent (struct ext4_es_tree *tree,ext4_lblk_t offset, -ext4_lblk_t len) +static int __es_insert_extent (struct ext4_es_tree *tree, +struct extent_status *newes) {struct rb_node **p = &tree->root.rb_node;struct rb_node *parent =NULL ;struct extent_status *es; -ext4_lblk_t end = offset + len -1 ; - -BUG_ON (end < offset); - es = tree->cache_es; -if (es && offset == (extent_status_end (es) +1 )) { -es_debug ("cached by [%u/%u)\n" , es->start, es->len); - es->len += len; - es =ext4_es_try_to_merge_right (tree, es); - goto out; - }else if (es && es->start == end +1 ) { -es_debug ("cached by [%u/%u)\n" , es->start, es->len); - es->start = offset; - es->len += len; - es =ext4_es_try_to_merge_left (tree, es); - goto out; - }else if (es && es->start <= offset && - end <=extent_status_end (es)) { -es_debug ("cached by [%u/%u)\n" , es->start, es->len); - goto out; - }while (*p) { parent = *p; es = rb_entry(parent, struct extent_status, rb_node);
Quoted 11 lines
fs/ext4/extents_status.c ext4_es_try_to_merge_right(struct ext4_es_tree *tree, struct extent_status *es) · line 369
Quoted 8 lines
fs/ext4/extents_status.c +4
-4-if (offset < es->start) { -if (es->start == end +1 ) { - es->start = offset; - es->len += len; +if (newes->es_lblk < es->es_lblk) { +if (ext4_es_can_be_merged (newes, es)) { + es->es_lblk = newes->es_lblk; + es->es_len += newes->es_len;This is wrong, isn't it? You cannot change
es->es_lblkbecause that can
break ordering of elements in the tree... thinking ... ah, it's OK because you have non-overlapping intervals. But it deserves a comment I guess.
Hi Jan,
Sorry for the delay reply. I will add a comment here to describe why es_lblk can be changed directly.
Thanks,
- Zheng
PATCH v5 2/10 ext4: add physical block and status member into extent status tree
In reply to Zheng LiuFrom: Zheng Liu <[email protected]>
This commit adds two members in extent_status structure to let it record physical block and extent status. Here es_pblk is used to record both of them because physical block only has 48 bits. So extent status could be stashed into it so that we can save some memory. Now written, unwritten, delayed and hole are defined as status.
Due to new member is added into extent status tree, all interfaces need to be adjusted.
--- fs/ext4/extents_status.c | 67 +++++++++++++++++++++++++++++++++++++-------- fs/ext4/extents_status.h | 64 ++++++++++++++++++++++++++++++++++++++++++- fs/ext4/inode.c | 3 +- include/trace/events/ext4.h | 34 +++++++++++++++-------- 4 files changed, 142 insertions(+), 26 deletions(-)
fs/ext4/extents_status.c +55 -12
@@ -179,7 +179,9 @@ static void ext4_es_print_tree(struct inode *inode)while (node) {struct extent_status *es; es = rb_entry(node, struct extent_status, rb_node); -printk (KERN_DEBUG " [%u/%u)" , es->es_lblk, es->es_len); +printk (KERN_DEBUG " [%u/%u) %llu %llx" , + es->es_lblk, es->es_len, +ext4_es_pblock (es),ext4_es_status (es)); node =rb_next (node); }printk (KERN_DEBUG "\n" );
@@ -234,7 +236,7 @@ static struct extent_status *__es_tree_search(struct rb_root *root,* @es: delayed extent that we found * * Returns the first block of the next extent after es, otherwise -* EXT_MAX_BLOCKS if no delay extent is found. +* EXT_MAX_BLOCKS if no extent is found. * Delayed extent is returned via @es. */ ext4_lblk_t ext4_es_find_extent (struct inode *inode,struct extent_status *es)
@@ -249,17 +251,18 @@ ext4_lblk_t ext4_es_find_extent(struct inode *inode, struct extent_status *es)read_lock (&EXT4_I (inode)->i_es_lock); tree = &EXT4_I (inode)->i_es_tree; -/* find delay extent in cache firstly */ +/* find extent in cache firstly */ + es->es_len = es->es_pblk =0 ;if (tree->cache_es) { es1 = tree->cache_es;if (in_range (es->es_lblk, es1->es_lblk, es1->es_len)) { -es_debug ("%u cached by [%u/%u)\n" , - es->es_lblk, es1->es_lblk, es1->es_len); +es_debug ("%u cached by [%u/%u) %llu %llx\n" , + es->es_lblk, es1->es_lblk, es1->es_len, +ext4_es_pblock (es1),ext4_es_status (es1)); goto out; } } - es->es_len =0 ; es1 =__es_tree_search (&tree->root, es->es_lblk); out:
@@ -267,6 +270,7 @@ out: tree->cache_es = es1; es->es_lblk = es1->es_lblk; es->es_len = es1->es_len; + es->es_pblk = es1->es_pblk; node =rb_next (&es1->rb_node);if (node) { es1 = rb_entry(node, struct extent_status, rb_node);
@@ -281,7 +285,7 @@ out: }static struct extent_status * -ext4_es_alloc_extent (ext4_lblk_t lblk,ext4_lblk_t len) +ext4_es_alloc_extent (ext4_lblk_t lblk,ext4_lblk_t len,ext4_fsblk_t pblk) {struct extent_status *es; es =kmem_cache_alloc (ext4_es_cachep,GFP_ATOMIC );
@@ -289,6 +293,7 @@ ext4_es_alloc_extent(ext4_lblk_t lblk, ext4_lblk_t len)return NULL ; es->es_lblk = lblk; es->es_len = len; + es->es_pblk = pblk;return es; }
@@ -301,6 +306,8 @@ static void ext4_es_free_extent(struct extent_status *es)* Check whether or not two extents can be merged * Condition: * - logical block number is contiguous +* - physical block number is contiguous +* - status is equal */ static int ext4_es_can_be_merged (struct extent_status *es1,struct extent_status *es2)
@@ -308,6 +315,13 @@ static int ext4_es_can_be_merged(struct extent_status *es1,if (es1->es_lblk + es1->es_len != es2->es_lblk)return 0 ; +if (ext4_es_status (es1) !=ext4_es_status (es2)) +return 0 ; + +if ((ext4_es_is_written (es1) ||ext4_es_is_unwritten (es1)) && + (ext4_es_pblock (es1) + es1->es_len !=ext4_es_pblock (es2))) +return 0 ; +return 1 ; }
@@ -367,6 +381,10 @@ static int __es_insert_extent(struct ext4_es_tree *tree,if (ext4_es_can_be_merged (newes, es)) { es->es_lblk = newes->es_lblk; es->es_len += newes->es_len; +if (ext4_es_is_written (es) || +ext4_es_is_unwritten (es)) +ext4_es_store_pblock (es, + newes->es_pblk); es =ext4_es_try_to_merge_left (tree, es); goto out; }
@@ -384,7 +402,8 @@ static int __es_insert_extent(struct ext4_es_tree *tree, } } - es =ext4_es_alloc_extent (newes->es_lblk, newes->es_len); + es =ext4_es_alloc_extent (newes->es_lblk, newes->es_len, + newes->es_pblk);if (!es)return -ENOMEM ;rb_link_node (&es->rb_node, parent, p);
@@ -404,21 +423,24 @@ out:* Return 0 on success, error code on failure. */ int ext4_es_insert_extent (struct inode *inode,ext4_lblk_t lblk, -ext4_lblk_t len) +ext4_lblk_t len,ext4_fsblk_t pblk, +unsigned long long status) {struct ext4_es_tree *tree;struct extent_status newes;ext4_lblk_t end = lblk + len -1 ;int err =0 ; -trace_ext4_es_insert_extent (inode, lblk, len); -es_debug ("add [%u/%u) to extent status tree of inode %lu\n" , - lblk, len, inode->i_ino); +es_debug ("add [%u/%u) %llu %llx to extent status tree of inode %lu\n" , + lblk, len, pblk, status, inode->i_ino);BUG_ON (end < lblk); newes.es_lblk = lblk; newes.es_len = len; +ext4_es_store_pblock (&newes, pblk); +ext4_es_store_status (&newes, status); +trace_ext4_es_insert_extent (inode, &newes);write_lock (&EXT4_I (inode)->i_es_lock); tree = &EXT4_I (inode)->i_es_tree;
@@ -442,6 +464,7 @@ static int __es_remove_extent(struct ext4_es_tree *tree, ext4_lblk_t lblk,struct extent_status *es;struct extent_status orig_es;ext4_lblk_t len1, len2; +ext4_fsblk_t block;int err =0 ; es =__es_tree_search (&tree->root, lblk);
@@ -455,6 +478,8 @@ static int __es_remove_extent(struct ext4_es_tree *tree, ext4_lblk_t lblk, orig_es.es_lblk = es->es_lblk; orig_es.es_len = es->es_len; + orig_es.es_pblk = es->es_pblk; + len1 = lblk > es->es_lblk ? lblk - es->es_lblk :0 ; len2 =ext4_es_end (es) > end ?ext4_es_end (es) - end :0 ;if (len1 >0 )
@@ -465,6 +490,13 @@ static int __es_remove_extent(struct ext4_es_tree *tree, ext4_lblk_t lblk, newes.es_lblk = end +1 ; newes.es_len = len2; +if (ext4_es_is_written (&orig_es) || +ext4_es_is_unwritten (&orig_es)) { + block =ext4_es_pblock (&orig_es) + + orig_es.es_len - len2; +ext4_es_store_pblock (&newes, block); + } +ext4_es_store_status (&newes,ext4_es_status (&orig_es)); err =__es_insert_extent (tree, &newes);if (err) { es->es_lblk = orig_es.es_lblk;
@@ -474,6 +506,11 @@ static int __es_remove_extent(struct ext4_es_tree *tree, ext4_lblk_t lblk, }else { es->es_lblk = end +1 ; es->es_len = len2; +if (ext4_es_is_written (es) || +ext4_es_is_unwritten (es)) { + block = orig_es.es_pblk + orig_es.es_len - len2; +ext4_es_store_pblock (es, block); + } } goto out; }
@@ -498,9 +535,15 @@ static int __es_remove_extent(struct ext4_es_tree *tree, ext4_lblk_t lblk, }if (es && es->es_lblk < end +1 ) { +ext4_lblk_t orig_len = es->es_len; + len1 =ext4_es_end (es) - end; es->es_lblk = end +1 ; es->es_len = len1; +if (ext4_es_is_written (es) ||ext4_es_is_unwritten (es)) { + block = es->es_pblk + orig_len - len1; +ext4_es_store_pblock (es, block); + } } out:
fs/ext4/extents_status.h +63 -1
83 lines not on this page · raw message
fs/ext4/inode.c +2 -1
@@ -1821,7 +1821,8 @@ static int ext4_da_map_blocks(struct inode *inode, sector_t iblock, goto out_unlock; } - retval =ext4_es_insert_extent (inode, map->m_lblk, map->m_len); + retval =ext4_es_insert_extent (inode, map->m_lblk, map->m_len, + ~0 ,EXTENT_STATUS_DELAYED );if (retval) goto out_unlock;
include/trace/events/ext4.h +22 -12
@@ -2068,28 +2068,33 @@ TRACE_EVENT(ext4_ext_remove_space_done, );TRACE_EVENT (ext4_es_insert_extent, - TP_PROTO(struct inode *inode, ext4_lblk_t lblk, ext4_lblk_t len), + TP_PROTO(struct inode *inode, struct extent_status *es), -TP_ARGS (inode, lblk, len), +TP_ARGS (inode, es),TP_STRUCT__entry ( - __field( dev_t, dev ) - __field( ino_t, ino ) - __field( loff_t, lblk ) -__field ( loff_t, len ) + __field( dev_t, dev ) + __field( ino_t, ino ) + __field( ext4_lblk_t, lblk ) + __field( ext4_lblk_t, len ) + __field( ext4_fsblk_t, pblk ) + __field( unsigned long long, status ) ),TP_fast_assign ( __entry->dev = inode->i_sb->s_dev; __entry->ino = inode->i_ino; - __entry->lblk = lblk; - __entry->len = len; + __entry->lblk = es->es_lblk; + __entry->len = es->es_len; + __entry->pblk = ext4_es_pblock(es); + __entry->status = ext4_es_status(es); ), -TP_printk ("dev %d,%d ino %lu es [%lld/%lld)" , +TP_printk ("dev %d,%d ino %lu es [%u/%u) mapped %llu status %llx" ,MAJOR (__entry->dev),MINOR (__entry->dev), (unsigned long ) __entry->ino, - __entry->lblk, __entry->len) + __entry->lblk, __entry->len, + __entry->pblk, __entry->status) ); TRACE_EVENT(ext4_es_remove_extent,
@@ -2150,6 +2155,8 @@ TRACE_EVENT(ext4_es_find_extent_exit, __field( ino_t, ino ) __field( ext4_lblk_t, lblk ) __field( ext4_lblk_t, len ) + __field( ext4_fsblk_t, pblk ) + __field( unsigned long long, status ) __field( ext4_lblk_t, ret ) ),
@@ -2158,13 +2165,16 @@ TRACE_EVENT(ext4_es_find_extent_exit, __entry->ino = inode->i_ino; __entry->lblk = es->es_lblk; __entry->len = es->es_len; + __entry->pblk =ext4_es_pblock (es); + __entry->status =ext4_es_status (es); __entry->ret = ret; ), -TP_printk ("dev %d,%d ino %lu es [%u/%u) ret %u" , +TP_printk ("dev %d,%d ino %lu es [%u/%u) mapped %llu status %llx ret %u" ,MAJOR (__entry->dev),MINOR (__entry->dev), (unsigned long ) __entry->ino, - __entry->lblk, __entry->len, __entry->ret) + __entry->lblk, __entry->len, + __entry->pblk, __entry->status, __entry->ret) );#endif /* _TRACE_EXT4_H */
Signature · 1 line
1.7.12.rc2.18.g61b472e
Re: [PATCH 02/10 v5] ext4: add physical block and status member into extent status tree
Quoted 10 lines · Zheng Liu
From: Zheng Liu <[email protected]>
This commit adds two members in
extent_statusstructure to let it record physical block and extent status. Herees_pblkis used to record both of them because physical block only has 48 bits. So extent status could be stashed into it so that we can save some memory. Now written, unwritten, delayed and hole are defined as status.Due to new member is added into extent status tree, all interfaces need to be adjusted.
The patch looks good. You can add:
Honza
Quoted 397 lines
Signed-off-by Zheng Liu <[email protected]>Cc "Theodore Ts'o" <[email protected]>Cc Jan kara <[email protected]>--- fs/ext4/extents_status.c | 67 +++++++++++++++++++++++++++++++++++++-------- fs/ext4/extents_status.h | 64 ++++++++++++++++++++++++++++++++++++++++++- fs/ext4/inode.c | 3 +- include/trace/events/ext4.h | 34 +++++++++++++++-------- 4 files changed, 142 insertions(+), 26 deletions(-)fs/ext4/extents_status.c +55
-12@@ -179,7 +179,9 @@ static void ext4_es_print_tree(struct inode *inode)while (node) {struct extent_status *es; es = rb_entry(node, struct extent_status, rb_node); -printk (KERN_DEBUG " [%u/%u)" , es->es_lblk, es->es_len); +printk (KERN_DEBUG " [%u/%u) %llu %llx" , + es->es_lblk, es->es_len, +ext4_es_pblock (es),ext4_es_status (es)); node =rb_next (node); }printk (KERN_DEBUG "\n" );@@ -234,7 +236,7 @@ static struct extent_status *__es_tree_search(struct rb_root *root,* @es: delayed extent that we found * * Returns the first block of the next extent after es, otherwise -* EXT_MAX_BLOCKS if no delay extent is found. +* EXT_MAX_BLOCKS if no extent is found. * Delayed extent is returned via @es. */ ext4_lblk_t ext4_es_find_extent (struct inode *inode,struct extent_status *es)@@ -249,17 +251,18 @@ ext4_lblk_t ext4_es_find_extent(struct inode *inode, struct extent_status *es)read_lock (&EXT4_I (inode)->i_es_lock); tree = &EXT4_I (inode)->i_es_tree; -/* find delay extent in cache firstly */ +/* find extent in cache firstly */ + es->es_len = es->es_pblk =0 ;if (tree->cache_es) { es1 = tree->cache_es;if (in_range (es->es_lblk, es1->es_lblk, es1->es_len)) { -es_debug ("%u cached by [%u/%u)\n" , - es->es_lblk, es1->es_lblk, es1->es_len); +es_debug ("%u cached by [%u/%u) %llu %llx\n" , + es->es_lblk, es1->es_lblk, es1->es_len, +ext4_es_pblock (es1),ext4_es_status (es1)); goto out; } } - es->es_len =0 ; es1 =__es_tree_search (&tree->root, es->es_lblk); out:@@ -267,6 +270,7 @@ out: tree->cache_es = es1; es->es_lblk = es1->es_lblk; es->es_len = es1->es_len; + es->es_pblk = es1->es_pblk; node =rb_next (&es1->rb_node);if (node) { es1 = rb_entry(node, struct extent_status, rb_node);@@ -281,7 +285,7 @@ out: }static struct extent_status * -ext4_es_alloc_extent (ext4_lblk_t lblk,ext4_lblk_t len) +ext4_es_alloc_extent (ext4_lblk_t lblk,ext4_lblk_t len,ext4_fsblk_t pblk) {struct extent_status *es; es =kmem_cache_alloc (ext4_es_cachep,GFP_ATOMIC );@@ -289,6 +293,7 @@ ext4_es_alloc_extent(ext4_lblk_t lblk, ext4_lblk_t len)return NULL ; es->es_lblk = lblk; es->es_len = len; + es->es_pblk = pblk;return es; }@@ -301,6 +306,8 @@ static void ext4_es_free_extent(struct extent_status *es)* Check whether or not two extents can be merged * Condition: * - logical block number is contiguous +* - physical block number is contiguous +* - status is equal */ static int ext4_es_can_be_merged (struct extent_status *es1,struct extent_status *es2)@@ -308,6 +315,13 @@ static int ext4_es_can_be_merged(struct extent_status *es1,if (es1->es_lblk + es1->es_len != es2->es_lblk)return 0 ; +if (ext4_es_status (es1) !=ext4_es_status (es2)) +return 0 ; + +if ((ext4_es_is_written (es1) ||ext4_es_is_unwritten (es1)) && + (ext4_es_pblock (es1) + es1->es_len !=ext4_es_pblock (es2))) +return 0 ; +return 1 ; }@@ -367,6 +381,10 @@ static int __es_insert_extent(struct ext4_es_tree *tree,if (ext4_es_can_be_merged (newes, es)) { es->es_lblk = newes->es_lblk; es->es_len += newes->es_len; +if (ext4_es_is_written (es) || +ext4_es_is_unwritten (es)) +ext4_es_store_pblock (es, + newes->es_pblk); es =ext4_es_try_to_merge_left (tree, es); goto out; }@@ -384,7 +402,8 @@ static int __es_insert_extent(struct ext4_es_tree *tree, } } - es =ext4_es_alloc_extent (newes->es_lblk, newes->es_len); + es =ext4_es_alloc_extent (newes->es_lblk, newes->es_len, + newes->es_pblk);if (!es)return -ENOMEM ;rb_link_node (&es->rb_node, parent, p);@@ -404,21 +423,24 @@ out:* Return 0 on success, error code on failure. */ int ext4_es_insert_extent (struct inode *inode,ext4_lblk_t lblk, -ext4_lblk_t len) +ext4_lblk_t len,ext4_fsblk_t pblk, +unsigned long long status) {struct ext4_es_tree *tree;struct extent_status newes;ext4_lblk_t end = lblk + len -1 ;int err =0 ; -trace_ext4_es_insert_extent (inode, lblk, len); -es_debug ("add [%u/%u) to extent status tree of inode %lu\n" , - lblk, len, inode->i_ino); +es_debug ("add [%u/%u) %llu %llx to extent status tree of inode %lu\n" , + lblk, len, pblk, status, inode->i_ino);BUG_ON (end < lblk); newes.es_lblk = lblk; newes.es_len = len; +ext4_es_store_pblock (&newes, pblk); +ext4_es_store_status (&newes, status); +trace_ext4_es_insert_extent (inode, &newes);write_lock (&EXT4_I (inode)->i_es_lock); tree = &EXT4_I (inode)->i_es_tree;@@ -442,6 +464,7 @@ static int __es_remove_extent(struct ext4_es_tree *tree, ext4_lblk_t lblk,struct extent_status *es;struct extent_status orig_es;ext4_lblk_t len1, len2; +ext4_fsblk_t block;int err =0 ; es =__es_tree_search (&tree->root, lblk);@@ -455,6 +478,8 @@ static int __es_remove_extent(struct ext4_es_tree *tree, ext4_lblk_t lblk, orig_es.es_lblk = es->es_lblk; orig_es.es_len = es->es_len; + orig_es.es_pblk = es->es_pblk; + len1 = lblk > es->es_lblk ? lblk - es->es_lblk :0 ; len2 =ext4_es_end (es) > end ?ext4_es_end (es) - end :0 ;if (len1 >0 )@@ -465,6 +490,13 @@ static int __es_remove_extent(struct ext4_es_tree *tree, ext4_lblk_t lblk, newes.es_lblk = end +1 ; newes.es_len = len2; +if (ext4_es_is_written (&orig_es) || +ext4_es_is_unwritten (&orig_es)) { + block =ext4_es_pblock (&orig_es) + + orig_es.es_len - len2; +ext4_es_store_pblock (&newes, block); + } +ext4_es_store_status (&newes,ext4_es_status (&orig_es)); err =__es_insert_extent (tree, &newes);if (err) { es->es_lblk = orig_es.es_lblk;@@ -474,6 +506,11 @@ static int __es_remove_extent(struct ext4_es_tree *tree, ext4_lblk_t lblk, }else { es->es_lblk = end +1 ; es->es_len = len2; +if (ext4_es_is_written (es) || +ext4_es_is_unwritten (es)) { + block = orig_es.es_pblk + orig_es.es_len - len2; +ext4_es_store_pblock (es, block); + } } goto out; }@@ -498,9 +535,15 @@ static int __es_remove_extent(struct ext4_es_tree *tree, ext4_lblk_t lblk, }if (es && es->es_lblk < end +1 ) { +ext4_lblk_t orig_len = es->es_len; + len1 =ext4_es_end (es) - end; es->es_lblk = end +1 ; es->es_len = len1; +if (ext4_es_is_written (es) ||ext4_es_is_unwritten (es)) { + block = es->es_pblk + orig_len - len1; +ext4_es_store_pblock (es, block); + } } out:fs/ext4/extents_status.h +63
-1@@ -20,10 +20,21 @@#define es_debug (fmt, ...) no_printk(fmt, ##__VA_ARGS__)#endif +#define EXTENT_STATUS_WRITTEN 0x10000000/* written extent */ +#define EXTENT_STATUS_UNWRITTEN 0x20000000/* unwritten extent */ +#define EXTENT_STATUS_DELAYED 0x40000000/* delayed extent */ +#define EXTENT_STATUS_HOLE 0x80000000/* hole */ + +#define EXTENT_STATUS_FLAGS (EXTENT_STATUS_WRITTEN | \ + EXTENT_STATUS_UNWRITTEN | \ + EXTENT_STATUS_DELAYED | \ + EXTENT_STATUS_HOLE) +struct extent_status {struct rb_node rb_node;ext4_lblk_t es_lblk;/* first logical block extent covers */ ext4_lblk_t es_len;/* length of extent in block */ +ext4_fsblk_t es_pblk;/* first physical block */ };struct ext4_es_tree {@@ -36,10 +47,61 @@ extern void ext4_exit_es(void);extern void ext4_es_init_tree (struct ext4_es_tree *tree);extern int ext4_es_insert_extent (struct inode *inode,ext4_lblk_t lblk, -ext4_lblk_t len); +ext4_lblk_t len,ext4_fsblk_t pblk, +unsigned long long status);extern int ext4_es_remove_extent (struct inode *inode,ext4_lblk_t lblk,ext4_lblk_t len);extern ext4_lblk_t ext4_es_find_extent (struct inode *inode,struct extent_status *es); +static inline int ext4_es_is_written (struct extent_status *es) +{ +return (es->es_pblk &EXTENT_STATUS_WRITTEN ); +} + +static inline int ext4_es_is_unwritten (struct extent_status *es) +{ +return (es->es_pblk &EXTENT_STATUS_UNWRITTEN ); +} + +static inline int ext4_es_is_delayed (struct extent_status *es) +{ +return (es->es_pblk &EXTENT_STATUS_DELAYED ); +} + +static inline int ext4_es_is_hole (struct extent_status *es) +{ +return (es->es_pblk &EXTENT_STATUS_HOLE ); +} + +static inline ext4_fsblk_t ext4_es_status (struct extent_status *es) +{ +return (es->es_pblk &EXTENT_STATUS_FLAGS ); +} + +static inline ext4_fsblk_t ext4_es_pblock (struct extent_status *es) +{ +return (es->es_pblk & ~EXTENT_STATUS_FLAGS ); +} + +static inline void ext4_es_store_pblock (struct extent_status *es, +ext4_fsblk_t pb) +{ +ext4_fsblk_t block; + + block = (pb & ~EXTENT_STATUS_FLAGS ) | + (es->es_pblk &EXTENT_STATUS_FLAGS ); + es->es_pblk = block; +} + +static inline void ext4_es_store_status (struct extent_status *es, +unsigned long long status) +{ +ext4_fsblk_t block; + + block = (status &EXTENT_STATUS_FLAGS ) | + (es->es_pblk & ~EXTENT_STATUS_FLAGS ); + es->es_pblk = block; +} +#endif /* _EXT4_EXTENTS_STATUS_H */ fs/ext4/inode.c +2
-1@@ -1821,7 +1821,8 @@ static int ext4_da_map_blocks(struct inode *inode, sector_t iblock, goto out_unlock; } - retval =ext4_es_insert_extent (inode, map->m_lblk, map->m_len); + retval =ext4_es_insert_extent (inode, map->m_lblk, map->m_len, + ~0 ,EXTENT_STATUS_DELAYED );if (retval) goto out_unlock;include/trace/events/ext4.h +22
-12@@ -2068,28 +2068,33 @@ TRACE_EVENT(ext4_ext_remove_space_done, );TRACE_EVENT (ext4_es_insert_extent, - TP_PROTO(struct inode *inode, ext4_lblk_t lblk, ext4_lblk_t len), + TP_PROTO(struct inode *inode, struct extent_status *es), -TP_ARGS (inode, lblk, len), +TP_ARGS (inode, es),TP_STRUCT__entry ( - __field( dev_t, dev ) - __field( ino_t, ino ) - __field( loff_t, lblk ) -__field ( loff_t, len ) + __field( dev_t, dev ) + __field( ino_t, ino ) + __field( ext4_lblk_t, lblk ) + __field( ext4_lblk_t, len ) + __field( ext4_fsblk_t, pblk ) + __field( unsigned long long, status ) ),TP_fast_assign ( __entry->dev = inode->i_sb->s_dev; __entry->ino = inode->i_ino; - __entry->lblk = lblk; - __entry->len = len; + __entry->lblk = es->es_lblk; + __entry->len = es->es_len; + __entry->pblk = ext4_es_pblock(es); + __entry->status = ext4_es_status(es); ), -TP_printk ("dev %d,%d ino %lu es [%lld/%lld)" , +TP_printk ("dev %d,%d ino %lu es [%u/%u) mapped %llu status %llx" ,MAJOR (__entry->dev),MINOR (__entry->dev), (unsigned long ) __entry->ino, - __entry->lblk, __entry->len) + __entry->lblk, __entry->len, + __entry->pblk, __entry->status) ); TRACE_EVENT(ext4_es_remove_extent,@@ -2150,6 +2155,8 @@ TRACE_EVENT(ext4_es_find_extent_exit, __field( ino_t, ino ) __field( ext4_lblk_t, lblk ) __field( ext4_lblk_t, len ) + __field( ext4_fsblk_t, pblk ) + __field( unsigned long long, status ) __field( ext4_lblk_t, ret ) ),@@ -2158,13 +2165,16 @@ TRACE_EVENT(ext4_es_find_extent_exit, __entry->ino = inode->i_ino; __entry->lblk = es->es_lblk; __entry->len = es->es_len; + __entry->pblk =ext4_es_pblock (es); + __entry->status =ext4_es_status (es); __entry->ret = ret; ), -TP_printk ("dev %d,%d ino %lu es [%u/%u) ret %u" , +TP_printk ("dev %d,%d ino %lu es [%u/%u) mapped %llu status %llx ret %u" ,MAJOR (__entry->dev),MINOR (__entry->dev), (unsigned long ) __entry->ino, - __entry->lblk, __entry->len, __entry->ret) + __entry->lblk, __entry->len, + __entry->pblk, __entry->status, __entry->ret) );#endif /* _TRACE_EXT4_H */ Signature · 1 line
1.7.12.rc2.18.g61b472e
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
PATCH v5 3/10 ext4: let ext4_ext_map_blocks return EXT4_MAP_UNWRITTEN flag
In reply to Zheng LiuFrom: Zheng Liu <[email protected]>
This commit lets ext4_ext_map_blocks return EXT4_MAP_UNWRITTEN flag because in later commit ext4_map_blocks needs to use this flag to determine the extent status.
--- fs/ext4/extents.c | 6 +++++- fs/ext4/inode.c | 12 +++--------- 2 files changed, 8 insertions(+), 10 deletions(-)
fs/ext4/extents.c +5 -1
@@ -3657,6 +3657,7 @@ ext4_ext_handle_uninitialized_extents(handle_t *handle, struct inode *inode,ext4_set_io_unwritten_flag (inode, io); elseext4_set_inode_state (inode ,EXT4_STATE_DIO_UNWRITTEN ); + map->m_flags |=EXT4_MAP_UNWRITTEN ;if (ext4_should_dioread_nolock (inode)) map->m_flags |=EXT4_MAP_UNINIT ; goto out;
@@ -3678,8 +3679,10 @@ ext4_ext_handle_uninitialized_extents(handle_t *handle, struct inode *inode,* repeat fallocate creation request * we already have an unwritten extent */ -if (flags &EXT4_GET_BLOCKS_UNINIT_EXT ) +if (flags &EXT4_GET_BLOCKS_UNINIT_EXT ) { + map->m_flags |=EXT4_MAP_UNWRITTEN ; goto map_out; + }/* buffered READ or buffered write_begin() lookup */ if ((flags &EXT4_GET_BLOCKS_CREATE ) ==0 ) {
@@ -4109,6 +4112,7 @@ got_allocated_blocks:/* Mark uninitialized */ if (flags &EXT4_GET_BLOCKS_UNINIT_EXT ){ext4_ext_mark_uninitialized (&newex); + map->m_flags |=EXT4_MAP_UNWRITTEN ;/* * io_end structure was created for every IO write to an * uninitialized extent. To avoid unnecessary conversion,
fs/ext4/inode.c +3 -9
@@ -560,16 +560,10 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode,return retval;/* -* When we call get_blocks without the create flag, the -* BH_Unwritten flag could have gotten set if the blocks -* requested were part of a uninitialized extent. We need to -* clear this flag now that we are committed to convert all or -* part of the uninitialized extent to be an initialized -* extent. This is because we need to avoid the combination -* of BH_Unwritten and BH_Mapped flags being simultaneously -* set on the buffer_head. +* Here we clear m_flags because after allocating an new extent, +* it will be set again. */ - map->m_flags &= ~EXT4_MAP_UNWRITTEN ; + map->m_flags &= ~EXT4_MAP_FLAGS ;/* * New blocks allocate and/or writing to uninitialized extent
Signature · 1 line
1.7.12.rc2.18.g61b472e
Re: [PATCH 03/10 v5] ext4: let ext4_ext_map_blocks return EXT4_MAP_UNWRITTEN flag
Quoted 5 lines · Zheng Liu
From: Zheng Liu <[email protected]>
This commit lets
ext4_ext_map_blocksreturnEXT4_MAP_UNWRITTENflag because in later commitext4_map_blocksneeds to use this flag to determine the extent status.
The patch looks good. You can add:
Honza
Quoted 68 lines
Signed-off-by Zheng Liu <[email protected]>Cc "Theodore Ts'o" <[email protected]>Cc Jan kara <[email protected]>--- fs/ext4/extents.c | 6 +++++- fs/ext4/inode.c | 12 +++--------- 2 files changed, 8 insertions(+), 10 deletions(-)fs/ext4/extents.c +5
-1@@ -3657,6 +3657,7 @@ ext4_ext_handle_uninitialized_extents(handle_t *handle, struct inode *inode,ext4_set_io_unwritten_flag (inode, io); elseext4_set_inode_state (inode ,EXT4_STATE_DIO_UNWRITTEN ); + map->m_flags |=EXT4_MAP_UNWRITTEN ;if (ext4_should_dioread_nolock (inode)) map->m_flags |=EXT4_MAP_UNINIT ; goto out;@@ -3678,8 +3679,10 @@ ext4_ext_handle_uninitialized_extents(handle_t *handle, struct inode *inode,* repeat fallocate creation request * we already have an unwritten extent */ -if (flags &EXT4_GET_BLOCKS_UNINIT_EXT ) +if (flags &EXT4_GET_BLOCKS_UNINIT_EXT ) { + map->m_flags |=EXT4_MAP_UNWRITTEN ; goto map_out; + }/* buffered READ or buffered write_begin() lookup */ if ((flags &EXT4_GET_BLOCKS_CREATE ) ==0 ) {@@ -4109,6 +4112,7 @@ got_allocated_blocks:/* Mark uninitialized */ if (flags &EXT4_GET_BLOCKS_UNINIT_EXT ){ext4_ext_mark_uninitialized (&newex); + map->m_flags |=EXT4_MAP_UNWRITTEN ;/* * io_end structure was created for every IO write to an * uninitialized extent. To avoid unnecessary conversion, fs/ext4/inode.c +3
-9@@ -560,16 +560,10 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode,return retval;/* -* When we call get_blocks without the create flag, the -* BH_Unwritten flag could have gotten set if the blocks -* requested were part of a uninitialized extent. We need to -* clear this flag now that we are committed to convert all or -* part of the uninitialized extent to be an initialized -* extent. This is because we need to avoid the combination -* of BH_Unwritten and BH_Mapped flags being simultaneously -* set on the buffer_head. +* Here we clear m_flags because after allocating an new extent, +* it will be set again. */ - map->m_flags &= ~EXT4_MAP_UNWRITTEN ; + map->m_flags &= ~EXT4_MAP_FLAGS ;/* * New blocks allocate and/or writing to uninitialized extent Signature · 1 line
1.7.12.rc2.18.g61b472e
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
PATCH v5 4/10 ext4: track all extent status in extent status tree
In reply to Zheng LiuFrom: Zheng Liu <[email protected]>
By recording the phycisal block and status, extent status tree is able to track the status of every extents. When we call _map_blocks functions to lookup an extent or create a new written/unwritten/delayed extent, this extent will be inserted into extent status tree. The hole extent is inserted in ext4_ext_put_gap_in_cache(). If there is no any extent, we will not insert a hole extent [0, ~0] into the extent status tree in order to reduce the complextiy of code.
We don't load all extents from disk in alloc_inode() because it costs too much memory, and if a file is opened and closed frequently it will takes too much time to load all extent information. So currently when we create/lookup an extent, this extent will be inserted into extent status tree. Hence, the extent status tree may not comprehensively contain all of the extents found in the file.
--- fs/ext4/extents.c | 4 +-- fs/ext4/extents_status.c | 27 ++++++++++++------ fs/ext4/extents_status.h | 4 +-- fs/ext4/file.c | 4 +-- fs/ext4/inode.c | 68 ++++++++++++++++++++++++++++----------------- include/trace/events/ext4.h | 4 +-- 6 files changed, 70 insertions(+), 41 deletions(-)
fs/ext4/extents.c +2 -2
@@ -3526,7 +3526,7 @@ static int ext4_find_delalloc_range(struct inode *inode,struct extent_status es; es.es_lblk = lblk_start; - (void )ext4_es_find_extent (inode, &es); + (void )ext4_es_find_delayed_extent (inode, &es);if (es.es_len ==0 )return 0 ;/* there is no delay extent in this tree */ else if (es.es_lblk <= lblk_start &&
@@ -4573,7 +4573,7 @@ static int ext4_find_delayed_extent(struct inode *inode,ext4_lblk_t next_del; es.es_lblk = newex->ec_block; - next_del =ext4_es_find_extent (inode, &es); + next_del =ext4_es_find_delayed_extent (inode, &es);if (newex->ec_start ==0 ) {/*
fs/ext4/extents_status.c +19 -8
@@ -229,7 +229,7 @@ static struct extent_status *__es_tree_search(struct rb_root *root, }/* -* ext4_es_find_extent: find the 1st delayed extent covering @es->lblk +* ext4_es_find_delayed_extent: find the 1st delayed extent covering @es->lblk * if it exists, otherwise, the next extent after @es->lblk. * * @inode: the inode which owns delayed extents
@@ -239,14 +239,15 @@ static struct extent_status *__es_tree_search(struct rb_root *root,* EXT_MAX_BLOCKS if no extent is found. * Delayed extent is returned via @es. */ -ext4_lblk_t ext4_es_find_extent (struct inode *inode,struct extent_status *es) +ext4_lblk_t ext4_es_find_delayed_extent (struct inode *inode, +struct extent_status *es) {struct ext4_es_tree *tree =NULL ;struct extent_status *es1 =NULL ;struct rb_node *node;ext4_lblk_t ret =EXT_MAX_BLOCKS ; -trace_ext4_es_find_extent_enter (inode, es->es_lblk); +trace_ext4_es_find_delayed_extent_enter (inode, es->es_lblk);read_lock (&EXT4_I (inode)->i_es_lock); tree = &EXT4_I (inode)->i_es_tree;
@@ -266,21 +267,31 @@ ext4_lblk_t ext4_es_find_extent(struct inode *inode, struct extent_status *es) es1 =__es_tree_search (&tree->root, es->es_lblk); out: -if (es1) { +if (es1 && !ext4_es_is_delayed (es1)) { +while ((node =rb_next (&es1->rb_node)) !=NULL ) { + es1 = rb_entry(node, struct extent_status, rb_node); +if (ext4_es_is_delayed (es1)) +break ; + } + } + +if (es1 &&ext4_es_is_delayed (es1)) { tree->cache_es = es1; es->es_lblk = es1->es_lblk; es->es_len = es1->es_len; es->es_pblk = es1->es_pblk; - node =rb_next (&es1->rb_node); -if (node) { +while ((node =rb_next (&es1->rb_node)) !=NULL ) { es1 = rb_entry(node, struct extent_status, rb_node); - ret = es1->es_lblk; +if (ext4_es_is_delayed (es1)) { + ret = es1->es_lblk; +break ; + } } }read_unlock (&EXT4_I (inode)->i_es_lock); -trace_ext4_es_find_extent_exit (inode, es, ret); +trace_ext4_es_find_delayed_extent_exit (inode, es, ret);return ret; }
fs/ext4/extents_status.h +2 -2
@@ -51,8 +51,8 @@ extern int ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk, unsigned long long status);extern int ext4_es_remove_extent (struct inode *inode,ext4_lblk_t lblk,ext4_lblk_t len); -extern ext4_lblk_t ext4_es_find_extent (struct inode *inode, -struct extent_status *es); +extern ext4_lblk_t ext4_es_find_delayed_extent (struct inode *inode, +struct extent_status *es);static inline int ext4_es_is_written (struct extent_status *es) {
fs/ext4/file.c +2 -2
@@ -465,7 +465,7 @@ static loff_t ext4_seek_data(struct file *file, loff_t offset, loff_t maxsize)* it will be as a data. */ es.es_lblk = last; - (void )ext4_es_find_extent (inode, &es); + (void )ext4_es_find_delayed_extent (inode, &es);if (last >= es.es_lblk && last < es.es_lblk + es.es_len) {if (last != start) dataoff = last << blkbits;
@@ -549,7 +549,7 @@ static loff_t ext4_seek_hole(struct file *file, loff_t offset, loff_t maxsize)* we will skip this extent. */ es.es_lblk = last; - (void )ext4_es_find_extent (inode, &es); + (void )ext4_es_find_delayed_extent (inode, &es);if (last >= es.es_lblk && last < es.es_lblk + es.es_len) { last = es.es_lblk + es.es_len; holeoff = last << blkbits;
fs/ext4/inode.c +43 -25
109 lines not on this page · raw message
include/trace/events/ext4.h +2 -2
@@ -2122,7 +2122,7 @@ TRACE_EVENT(ext4_es_remove_extent, __entry->lblk, __entry->len) ); -TRACE_EVENT(ext4_es_find_extent_enter, +TRACE_EVENT(ext4_es_find_delayed_extent_enter, TP_PROTO(struct inode *inode, ext4_lblk_t lblk), TP_ARGS(inode, lblk),
@@ -2144,7 +2144,7 @@ TRACE_EVENT(ext4_es_find_extent_enter, (unsigned long) __entry->ino, __entry->lblk) ); -TRACE_EVENT(ext4_es_find_extent_exit, +TRACE_EVENT(ext4_es_find_delayed_extent_exit, TP_PROTO(struct inode *inode, struct extent_status *es, ext4_lblk_t ret),
Signature · 1 line
1.7.12.rc2.18.g61b472e
Jan Kara
reviewerRe: [PATCH 04/10 v5] ext4: track all extent status in extent status tree
Quoted 29 lines · Zheng Liu
From: Zheng Liu <[email protected]>
By recording the phycisal block and status, extent status tree is able to track the status of every extents. When we call
_map_blocksfunctions to lookup an extent or create a new written/unwritten/delayed extent, this extent will be inserted into extent status tree. The hole extent is inserted inext4_ext_put_gap_in_cache(). If there is no any extent, we will not insert a hole extent [0, ~0] into the extent status tree in order to reduce the complextiy of code.We don't load all extents from disk in
alloc_inode()because it costs too much memory, and if a file is opened and closed frequently it will takes too much time to load all extent information. So currently when we create/lookup an extent, this extent will be inserted into extent status tree. Hence, the extent status tree may not comprehensively contain all of the extents found in the file.Signed-off-by Zheng Liu <[email protected]>Cc "Theodore Ts'o" <[email protected]>Cc Jan kara <[email protected]>--- fs/ext4/extents.c | 4 +-- fs/ext4/extents_status.c | 27 ++++++++++++------ fs/ext4/extents_status.h | 4 +-- fs/ext4/file.c | 4 +-- fs/ext4/inode.c | 68 ++++++++++++++++++++++++++++----------------- include/trace/events/ext4.h | 4 +-- 6 files changed, 70 insertions(+), 41 deletions(-)
...
fs/ext4/extents_status.c static struct extent_status *__es_tree_search(struct rb_root *root, · line 244
Quoted 12 lines
fs/ext4/extents_status.c +2
-1@@ -239,14 +239,15 @@ static struct extent_status *__es_tree_search(struct rb_root *root,* EXT_MAX_BLOCKS if no extent is found. * Delayed extent is returned via @es. */ -ext4_lblk_t ext4_es_find_extent (struct inode *inode,struct extent_status *es) +ext4_lblk_t ext4_es_find_delayed_extent (struct inode *inode, +struct extent_status *es) {
I have to say I'm still not very happy about this function (but it's much
better than it used to be so thanks for that!). I have two suggestions for improvement:
1) 'es' is both input and output argument where for input only es_lblk is used. That's a bit confusing so how about making the function like:
ext4_es_find_delayed_extent(struct inode *inode, ext4_lblk_t offset,
struct extent_status *out);
to separate input and output? Also you can comment that we use the 'out'
parameter instead of returning the extent_status from the tree because that can be freed once we drop the spinlock protecting status tree.
2) The returned value is somewhat surprisingly the logical offset of the *next* delalloc extent. It's used only in ext4_fill_fiemap_extents() AFAICS. It would be easier to understand if the function didn't return anything. ext4_fill_fiemap_extents() would use ext4_es_find_delayed_extent() to find both current and next delalloc extent (which would become the 'current' one in the next iteration). As a bonus you would also save some iteration of the extent status tree...
Quoted 37 lines
fs/ext4/extents_status.c +15
-5struct ext4_es_tree *tree =NULL ;struct extent_status *es1 =NULL ;struct rb_node *node;ext4_lblk_t ret =EXT_MAX_BLOCKS ; -trace_ext4_es_find_extent_enter (inode, es->es_lblk); +trace_ext4_es_find_delayed_extent_enter (inode, es->es_lblk);read_lock (&EXT4_I (inode)->i_es_lock); tree = &EXT4_I (inode)->i_es_tree;@@ -266,21 +267,31 @@ ext4_lblk_t ext4_es_find_extent(struct inode *inode, struct extent_status *es) es1 =__es_tree_search (&tree->root, es->es_lblk); out: -if (es1) { +if (es1 && !ext4_es_is_delayed (es1)) { +while ((node =rb_next (&es1->rb_node)) !=NULL ) { + es1 = rb_entry(node, struct extent_status, rb_node); +if (ext4_es_is_delayed (es1)) +break ; + } + } + +if (es1 &&ext4_es_is_delayed (es1)) { tree->cache_es = es1; es->es_lblk = es1->es_lblk; es->es_len = es1->es_len; es->es_pblk = es1->es_pblk; - node =rb_next (&es1->rb_node); -if (node) { +while ((node =rb_next (&es1->rb_node)) !=NULL ) { es1 = rb_entry(node, struct extent_status, rb_node); - ret = es1->es_lblk; +if (ext4_es_is_delayed (es1)) { + ret = es1->es_lblk; +break ; + }
fs/ext4/extents_status.c ext4_lblk_t ext4_es_find_extent(struct inode *inode, struct extent_status *es) · line 297
Quoted 10 lines
fs/ext4/extents_status.c +1
-1} }read_unlock (&EXT4_I (inode)->i_es_lock); -trace_ext4_es_find_extent_exit (inode, es, ret); +trace_ext4_es_find_delayed_extent_exit (inode, es, ret);return ret; }
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH 04/10 v5] ext4: track all extent status in extent status tree
Quoted 56 lines · Jan Kara
Quoted 29 lines · Zheng Liu
From: Zheng Liu <[email protected]>
By recording the phycisal block and status, extent status tree is able to track the status of every extents. When we call
_map_blocksfunctions to lookup an extent or create a new written/unwritten/delayed extent, this extent will be inserted into extent status tree. The hole extent is inserted inext4_ext_put_gap_in_cache(). If there is no any extent, we will not insert a hole extent [0, ~0] into the extent status tree in order to reduce the complextiy of code.We don't load all extents from disk in
alloc_inode()because it costs too much memory, and if a file is opened and closed frequently it will takes too much time to load all extent information. So currently when we create/lookup an extent, this extent will be inserted into extent status tree. Hence, the extent status tree may not comprehensively contain all of the extents found in the file.Signed-off-by Zheng Liu <[email protected]>Cc "Theodore Ts'o" <[email protected]>Cc Jan kara <[email protected]>--- fs/ext4/extents.c | 4 +-- fs/ext4/extents_status.c | 27 ++++++++++++------ fs/ext4/extents_status.h | 4 +-- fs/ext4/file.c | 4 +-- fs/ext4/inode.c | 68 ++++++++++++++++++++++++++++----------------- include/trace/events/ext4.h | 4 +-- 6 files changed, 70 insertions(+), 41 deletions(-)...
fs/ext4/extents_status.c static struct extent_status *__es_tree_search(struct rb_root *root, · line 244
Quoted 12 lines
fs/ext4/extents_status.c +2
-1@@ -239,14 +239,15 @@ static struct extent_status *__es_tree_search(struct rb_root *root,* EXT_MAX_BLOCKS if no extent is found. * Delayed extent is returned via @es. */ -ext4_lblk_t ext4_es_find_extent (struct inode *inode,struct extent_status *es) +ext4_lblk_t ext4_es_find_delayed_extent (struct inode *inode, +struct extent_status *es) {I have to say I'm still not very happy about this function (but it's much
better than it used to be so thanks for that!). I have two suggestions for improvement:
1) 'es' is both input and output argument where for input onlyes_lblkis used. That's a bit confusing so how about making the function like:ext4_es_find_delayed_extent(struct inode *inode,
ext4_lblk_toffset,struct extent_status *out);to separate input and output? Also you can comment that we use the 'out'
parameter instead of returning theextent_statusfrom the tree because that can be freed once we drop the spinlock protecting status tree.
Quoted 7 lines
2) The returned value is somewhat surprisingly the logical offset of the *next* delalloc extent. It's used only in
ext4_fill_fiemap_extents()AFAICS. It would be easier to understand if the function didn't return anything.ext4_fill_fiemap_extents()would useext4_es_find_delayed_extent()to find both current and next delalloc extent (which would become the 'current' one in the next iteration). As a bonus you would also save some iteration of the extent status tree...
I have seen that Ted has sent out two patches that split this patch. I will pick them up and polish them according to your comments. But before this, I need to fix the problem that triggers a failure of xfstests #13 with bigalloc.
Thanks,
- Zheng
Theodore Ts'o
maintainerRe: [PATCH 04/10 v5] ext4: track all extent status in extent status tree
In reply to Zheng LiuQuoted 17 lines · Zheng Liu
From: Zheng Liu <[email protected]>
By recording the phycisal block and status, extent status tree is able to track the status of every extents. When we call
_map_blocksfunctions to lookup an extent or create a new written/unwritten/delayed extent, this extent will be inserted into extent status tree. The hole extent is inserted inext4_ext_put_gap_in_cache(). If there is no any extent, we will not insert a hole extent [0, ~0] into the extent status tree in order to reduce the complextiy of code.We don't load all extents from disk in
alloc_inode()because it costs too much memory, and if a file is opened and closed frequently it will takes too much time to load all extent information. So currently when we create/lookup an extent, this extent will be inserted into extent status tree. Hence, the extent status tree may not comprehensively contain all of the extents found in the file.
Quoted 3 lines
Signed-off-by Zheng Liu <[email protected]>Cc "Theodore Ts'o" <[email protected]>Cc Jan kara <[email protected]>
Unfortunately, this commit is apparently causing test failures with bigalloc:
013.out.bad renamed from 013.out +1 -4
@@ -8,7 +8,4 @@ ----------------------------------------------- fsstress.2 : -p 20 -r ----------------------------------------------- - ------------------------------------------------ -fsstress.3 : -p 4 -z -f rmdir=10 -f link=10 -f creat=10 -f mkdir=10 -f rename=30 -f stat=30 -f unlink=30 -f truncate=20 ------------------------------------------------ +_check_generic_filesystem: filesystem on /dev/vdd is inconsistent (see 013.full)
_check_generic_filesystem: filesystem on /dev/vdd is inconsistent (see 013.full)
Ran: 013
Failures: 013
Failed 1 of 1 tests
END TEST: Ext4 4k block w/bigalloc Tue Feb 12 22:08:49 EST 2013 e2fsck 1.43-WIP (15-Jan-2013)
Pass 1: Checking inodes, blocks, and sizes
Inode 618, i_blocks is 1408, should be 1536. Fix? yes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/vdd: ***** FILE SYSTEM WAS MODIFIED *****/dev/vdd: 3969/81936 files (13.1% non-contiguous), 176208/1310720 blocks
I haven't been able to figure out what is going on here, but if we can't figure this out I may need to push off this patch series to the next merge window. I've tried splitting up this patch into two pieces to make it clearer what is going on, but I still can't see how this would be affecting the i_blocks calculation.
- Ted
Theodore Ts'o
maintainerPATCH 1/2 ext4: rename ext4_es_find_extent() to ext4_es_find_delayed_extent()
From: Zheng Liu <[email protected]>
Rename ext4_es_find_extent() to ext4_es_find_delayed_extent() to make the purpose of this function clearer.
[ This was originally part of the next commit, but I separated this
out to make it easier to review and debug the next commit. -- Ted ]
--- fs/ext4/extents.c | 4 ++-- fs/ext4/extents_status.c | 9 +++++---- fs/ext4/extents_status.h | 4 ++-- fs/ext4/file.c | 4 ++-- include/trace/events/ext4.h | 4 ++-- 5 files changed, 13 insertions(+), 12 deletions(-)
fs/ext4/extents.c +2 -2
@@ -3529,7 +3529,7 @@ static int ext4_find_delalloc_range(struct inode *inode,struct extent_status es; es.es_lblk = lblk_start; - (void )ext4_es_find_extent (inode, &es); + (void )ext4_es_find_delayed_extent (inode, &es);if (es.es_len ==0 )return 0 ;/* there is no delay extent in this tree */ else if (es.es_lblk <= lblk_start &&
@@ -4575,7 +4575,7 @@ static int ext4_find_delayed_extent(struct inode *inode,ext4_lblk_t next_del; es.es_lblk = newex->ec_block; - next_del =ext4_es_find_extent (inode, &es); + next_del =ext4_es_find_delayed_extent (inode, &es);if (newex->ec_start ==0 ) {/*
fs/ext4/extents_status.c +5 -4
@@ -229,7 +229,7 @@ static struct extent_status *__es_tree_search(struct rb_root *root, }/* -* ext4_es_find_extent: find the 1st delayed extent covering @es->lblk +* ext4_es_find_delayed_extent: find the 1st delayed extent covering @es->lblk * if it exists, otherwise, the next extent after @es->lblk. * * @inode: the inode which owns delayed extents
@@ -239,14 +239,15 @@ static struct extent_status *__es_tree_search(struct rb_root *root,* EXT_MAX_BLOCKS if no extent is found. * Delayed extent is returned via @es. */ -ext4_lblk_t ext4_es_find_extent (struct inode *inode,struct extent_status *es) +ext4_lblk_t ext4_es_find_delayed_extent (struct inode *inode, +struct extent_status *es) {struct ext4_es_tree *tree =NULL ;struct extent_status *es1 =NULL ;struct rb_node *node;ext4_lblk_t ret =EXT_MAX_BLOCKS ; -trace_ext4_es_find_extent_enter (inode, es->es_lblk); +trace_ext4_es_find_delayed_extent_enter (inode, es->es_lblk);read_lock (&EXT4_I (inode)->i_es_lock); tree = &EXT4_I (inode)->i_es_tree;
@@ -280,7 +281,7 @@ out:read_unlock (&EXT4_I (inode)->i_es_lock); -trace_ext4_es_find_extent_exit (inode, es, ret); +trace_ext4_es_find_delayed_extent_exit (inode, es, ret);return ret; }
fs/ext4/extents_status.h +2 -2
@@ -51,8 +51,8 @@ extern int ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk, unsigned long long status);extern int ext4_es_remove_extent (struct inode *inode,ext4_lblk_t lblk,ext4_lblk_t len); -extern ext4_lblk_t ext4_es_find_extent (struct inode *inode, -struct extent_status *es); +extern ext4_lblk_t ext4_es_find_delayed_extent (struct inode *inode, +struct extent_status *es);static inline int ext4_es_is_written (struct extent_status *es) {
fs/ext4/file.c +2 -2
@@ -465,7 +465,7 @@ static loff_t ext4_seek_data(struct file *file, loff_t offset, loff_t maxsize)* it will be as a data. */ es.es_lblk = last; - (void )ext4_es_find_extent (inode, &es); + (void )ext4_es_find_delayed_extent (inode, &es);if (last >= es.es_lblk && last < es.es_lblk + es.es_len) {if (last != start) dataoff = last << blkbits;
@@ -549,7 +549,7 @@ static loff_t ext4_seek_hole(struct file *file, loff_t offset, loff_t maxsize)* we will skip this extent. */ es.es_lblk = last; - (void )ext4_es_find_extent (inode, &es); + (void )ext4_es_find_delayed_extent (inode, &es);if (last >= es.es_lblk && last < es.es_lblk + es.es_len) { last = es.es_lblk + es.es_len; holeoff = last << blkbits;
include/trace/events/ext4.h +2 -2
@@ -2147,7 +2147,7 @@ TRACE_EVENT(ext4_es_remove_extent, __entry->lblk, __entry->len) ); -TRACE_EVENT(ext4_es_find_extent_enter, +TRACE_EVENT(ext4_es_find_delayed_extent_enter, TP_PROTO(struct inode *inode, ext4_lblk_t lblk), TP_ARGS(inode, lblk),
@@ -2169,7 +2169,7 @@ TRACE_EVENT(ext4_es_find_extent_enter, (unsigned long) __entry->ino, __entry->lblk) ); -TRACE_EVENT(ext4_es_find_extent_exit, +TRACE_EVENT(ext4_es_find_delayed_extent_exit, TP_PROTO(struct inode *inode, struct extent_status *es, ext4_lblk_t ret),
Signature · 1 line
1.7.12.rc0.22.gcdd159b
Theodore Ts'o
maintainerPATCH 2/2 ext4: track all extent status in extent status tree
From: Zheng Liu <[email protected]>
By recording the phycisal block and status, extent status tree is able to track the status of every extents. When we call _map_blocks functions to lookup an extent or create a new written/unwritten/delayed extent, this extent will be inserted into extent status tree. The hole extent is inserted in ext4_ext_put_gap_in_cache(). If there is no any extent, we will not insert a hole extent [0, ~0] into the extent status tree in order to reduce the complextiy of code.
We don't load all extents from disk in alloc_inode() because it costs too much memory, and if a file is opened and closed frequently it will takes too much time to load all extent information. So currently when we create/lookup an extent, this extent will be inserted into extent status tree. Hence, the extent status tree may not comprehensively contain all of the extents found in the file.
--- fs/ext4/extents_status.c | 18 ++++++++++++---- fs/ext4/inode.c | 53 ++++++++++++++++++++++++++++++------------------ 2 files changed, 47 insertions(+), 24 deletions(-)
fs/ext4/extents_status.c +14 -4
@@ -267,15 +267,25 @@ ext4_lblk_t ext4_es_find_delayed_extent(struct inode *inode, es1 =__es_tree_search (&tree->root, es->es_lblk); out: -if (es1) { +if (es1 && !ext4_es_is_delayed (es1)) { +while ((node =rb_next (&es1->rb_node)) !=NULL ) { + es1 = rb_entry(node, struct extent_status, rb_node); +if (ext4_es_is_delayed (es1)) +break ; + } + } + +if (es1 &&ext4_es_is_delayed (es1)) { tree->cache_es = es1; es->es_lblk = es1->es_lblk; es->es_len = es1->es_len; es->es_pblk = es1->es_pblk; - node =rb_next (&es1->rb_node); -if (node) { +while ((node =rb_next (&es1->rb_node)) !=NULL ) { es1 = rb_entry(node, struct extent_status, rb_node); - ret = es1->es_lblk; +if (ext4_es_is_delayed (es1)) { + ret = es1->es_lblk; +break ; + } } }
fs/ext4/inode.c +33 -20
77 lines not on this page · raw message
Signature · 1 line
1.7.12.rc0.22.gcdd159b
Re: [PATCH 04/10 v5] ext4: track all extent status in extent status tree
In reply to Theodore Ts'oQuoted 54 lines · Theodore Ts'o
Quoted 17 lines · Zheng Liu
From: Zheng Liu <[email protected]>
By recording the phycisal block and status, extent status tree is able to track the status of every extents. When we call
_map_blocksfunctions to lookup an extent or create a new written/unwritten/delayed extent, this extent will be inserted into extent status tree. The hole extent is inserted inext4_ext_put_gap_in_cache(). If there is no any extent, we will not insert a hole extent [0, ~0] into the extent status tree in order to reduce the complextiy of code.We don't load all extents from disk in
alloc_inode()because it costs too much memory, and if a file is opened and closed frequently it will takes too much time to load all extent information. So currently when we create/lookup an extent, this extent will be inserted into extent status tree. Hence, the extent status tree may not comprehensively contain all of the extents found in the file.Quoted 3 lines
Signed-off-by Zheng Liu <[email protected]>Cc "Theodore Ts'o" <[email protected]>Cc Jan kara <[email protected]>Unfortunately, this commit is apparently causing test failures with bigalloc:
013.out.bad renamed from 013.out +1
-4@@ -8,7 +8,4 @@ ----------------------------------------------- fsstress.2 : -p 20 -r ----------------------------------------------- - ------------------------------------------------ -fsstress.3 : -p 4 -z -f rmdir=10 -f link=10 -f creat=10 -f mkdir=10 -f rename=30 -f stat=30 -f unlink=30 -f truncate=20 ------------------------------------------------ +_check_generic_filesystem: filesystem on /dev/vdd is inconsistent (see 013.full)
_check_generic_filesystem: filesystem on/dev/vddis inconsistent (see 013.full)
Ran: 013
Failures: 013
Failed 1 of 1 tests
END TEST: Ext4 4k block w/bigalloc Tue Feb 12 22:08:49 EST 2013 e2fsck 1.43-WIP (15-Jan-2013)
Pass 1: Checking inodes, blocks, and sizes
Inode 618,i_blocksis 1408, should be 1536. Fix? yesPass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/vdd: ***** FILE SYSTEM WAS MODIFIED *****/dev/vdd: 3969/81936 files (13.1% non-contiguous), 176208/1310720 blocks
Quoted 5 lines
I haven't been able to figure out what is going on here, but if we can't figure this out I may need to push off this patch series to the next merge window. I've tried splitting up this patch into two pieces to make it clearer what is going on, but I still can't see how this would be affecting the
i_blockscalculation.
Hi Ted,
Oops, I run xfstests #13 serveral times and this bug can be triggered. Sorry about that. I will look at it, but I am not sure whether it can be fixed before merge window opens. Thanks for let me know.
For this bug, I guess that the problem is in ext4_da_invalidatepages() because when a file is truncated this function will be called. But it seems that the delay space reservation is the root cause. Ah, let me trace it.
Regards,
- Zheng
Re: [PATCH 04/10 v5] ext4: track all extent status in extent status tree
In reply to Theodore Ts'oQuoted 54 lines · Theodore Ts'o
Quoted 17 lines · Zheng Liu
From: Zheng Liu <[email protected]>
By recording the phycisal block and status, extent status tree is able to track the status of every extents. When we call
_map_blocksfunctions to lookup an extent or create a new written/unwritten/delayed extent, this extent will be inserted into extent status tree. The hole extent is inserted inext4_ext_put_gap_in_cache(). If there is no any extent, we will not insert a hole extent [0, ~0] into the extent status tree in order to reduce the complextiy of code.We don't load all extents from disk in
alloc_inode()because it costs too much memory, and if a file is opened and closed frequently it will takes too much time to load all extent information. So currently when we create/lookup an extent, this extent will be inserted into extent status tree. Hence, the extent status tree may not comprehensively contain all of the extents found in the file.Quoted 3 lines
Signed-off-by Zheng Liu <[email protected]>Cc "Theodore Ts'o" <[email protected]>Cc Jan kara <[email protected]>Unfortunately, this commit is apparently causing test failures with bigalloc:
013.out.bad renamed from 013.out +1
-4@@ -8,7 +8,4 @@ ----------------------------------------------- fsstress.2 : -p 20 -r ----------------------------------------------- - ------------------------------------------------ -fsstress.3 : -p 4 -z -f rmdir=10 -f link=10 -f creat=10 -f mkdir=10 -f rename=30 -f stat=30 -f unlink=30 -f truncate=20 ------------------------------------------------ +_check_generic_filesystem: filesystem on /dev/vdd is inconsistent (see 013.full)
_check_generic_filesystem: filesystem on/dev/vddis inconsistent (see 013.full)
Ran: 013
Failures: 013
Failed 1 of 1 tests
END TEST: Ext4 4k block w/bigalloc Tue Feb 12 22:08:49 EST 2013 e2fsck 1.43-WIP (15-Jan-2013)
Pass 1: Checking inodes, blocks, and sizes
Inode 618,i_blocksis 1408, should be 1536. Fix? yesPass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/vdd: ***** FILE SYSTEM WAS MODIFIED *****/dev/vdd: 3969/81936 files (13.1% non-contiguous), 176208/1310720 blocks
Quoted 5 lines
I haven't been able to figure out what is going on here, but if we can't figure this out I may need to push off this patch series to the next merge window. I've tried splitting up this patch into two pieces to make it clearer what is going on, but I still can't see how this would be affecting the
i_blockscalculation.
Hi Ted,
I have fixed this regression. The reason is that we miss to release reserved space in ext4_da_page_release_reservation(). The root cause is that when an extent is delayed allocated and later it could be allocated by fallocate. In this condition this extent need to keep as delayed extent until the extent is written out because we need to update reserved space according to these delayed extent.
I have run xfstests #13 serveral times and this regression never be triggered. Later the latest patch set will be sent out.
BTW, when I run xfstests to test the extent status tree patch sereis, I get a regression against 'dev' branch of ext4 and a bug against 3.8-rc7. I will file them in other mails.
Regards,
- Zheng
PATCH v5 5/10 ext4: lookup block mapping in extent status tree
In reply to Zheng LiuFrom: Zheng Liu <[email protected]>
After tracking all extent status, we already have a extent cache in memory. Every time we want to lookup a block mapping, we can first try to lookup it in extent status tree to avoid a potential disk I/O.
A new function called ext4_es_lookup_extent is defined to finish this work. When we try to lookup a block mapping, we always call ext4_map_blocks and/or ext4_da_map_blocks. So in these functions we first try to lookup a block mapping in extent status tree.
A new flag EXT4_GET_BLOCKS_NO_PUT_HOLE is used in ext4_da_map_blocks in order not to put a hole into extent status tree because this hole will be converted to delayed extent in the tree immediately.
--- fs/ext4/ext4.h | 2 ++ fs/ext4/extents.c | 7 ++++- fs/ext4/extents_status.c | 59 +++++++++++++++++++++++++++++++++++++++++ fs/ext4/extents_status.h | 1 + fs/ext4/inode.c | 64 +++++++++++++++++++++++++++++++++++++++++++-- include/trace/events/ext4.h | 56 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 186 insertions(+), 3 deletions(-)
fs/ext4/ext4.h +2 -0
@@ -582,6 +582,8 @@ enum {#define EXT4_GET_BLOCKS_KEEP_SIZE 0x0080/* Do not take i_data_sem locking in ext4_map_blocks */ #define EXT4_GET_BLOCKS_NO_LOCK 0x0100 +/* Do not put hole in extent cache */ +#define EXT4_GET_BLOCKS_NO_PUT_HOLE 0x0200/* * Flags used by ext4_free_blocks
fs/ext4/extents.c +6 -1
@@ -2154,6 +2154,8 @@ ext4_ext_put_gap_in_cache(struct inode *inode, struct ext4_ext_path *path, block,le32_to_cpu (ex->ee_block), ext4_ext_get_actual_len(ex)); +ext4_es_insert_extent (inode, lblock, len, ~0 , +EXTENT_STATUS_HOLE ); }else if (block >=le32_to_cpu (ex->ee_block) +ext4_ext_get_actual_len (ex)) {ext4_lblk_t next;
@@ -2167,6 +2169,8 @@ ext4_ext_put_gap_in_cache(struct inode *inode, struct ext4_ext_path *path, block);BUG_ON (next == lblock); len = next - lblock; +ext4_es_insert_extent (inode, lblock, len, ~0 , +EXTENT_STATUS_HOLE ); }else { lblock = len =0 ;BUG ();
@@ -4006,7 +4010,8 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode,* put just found gap into cache to speed up * subsequent requests */ -ext4_ext_put_gap_in_cache (inode, path, map->m_lblk); +if ((flags &EXT4_GET_BLOCKS_NO_PUT_HOLE ) ==0 ) +ext4_ext_put_gap_in_cache (inode, path, map->m_lblk); goto out2; }
fs/ext4/extents_status.c +59 -0
65 lines not on this page · raw message
fs/ext4/extents_status.h +1 -0
@@ -53,6 +53,7 @@ extern int ext4_es_remove_extent(struct inode *inode, ext4_lblk_t lblk, ext4_lblk_t len);extern ext4_lblk_t ext4_es_find_delayed_extent (struct inode *inode,struct extent_status *es); +extern int ext4_es_lookup_extent (struct inode *inode,struct extent_status *es);static inline int ext4_es_is_written (struct extent_status *es) {
fs/ext4/inode.c +62 -2
102 lines not on this page · raw message
include/trace/events/ext4.h +56 -0
62 lines not on this page · raw message
Signature · 1 line
1.7.12.rc2.18.g61b472e
Jan Kara
reviewerRe: [PATCH 05/10 v5] ext4: lookup block mapping in extent status tree
Quoted 6 lines · Zheng Liu
From: Zheng Liu <[email protected]>
After tracking all extent status, we already have a extent cache in memory. Every time we want to lookup a block mapping, we can first try to lookup it in extent status tree to avoid a potential disk I/O.
Quoted 8 lines
A new function called
ext4_es_lookup_extentis defined to finish this work. When we try to lookup a block mapping, we always callext4_map_blocksand/orext4_da_map_blocks. So in these functions we first try to lookup a block mapping in extent status tree.A new flag
EXT4_GET_BLOCKS_NO_PUT_HOLEis used inext4_da_map_blocksin order not to put a hole into extent status tree because this hole will be converted to delayed extent in the tree immediately.
It looks somewhat inconsistent that you put hole into the extent tree inext4_ext_map_blocks() but all other extent types are handled in ext4_map_blocks() or ext4_da_map_blocks(). Can we put the handling in one place?
Otherwise the patch looks OK.
Honza
Quoted 320 lines
Signed-off-by Zheng Liu <[email protected]>Cc "Theodore Ts'o" <[email protected]>Cc Jan kara <[email protected]>--- fs/ext4/ext4.h | 2 ++ fs/ext4/extents.c | 7 ++++- fs/ext4/extents_status.c | 59 +++++++++++++++++++++++++++++++++++++++++ fs/ext4/extents_status.h | 1 + fs/ext4/inode.c | 64 +++++++++++++++++++++++++++++++++++++++++++-- include/trace/events/ext4.h | 56 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 186 insertions(+), 3 deletions(-)fs/ext4/ext4.h +2
-0@@ -582,6 +582,8 @@ enum {#define EXT4_GET_BLOCKS_KEEP_SIZE 0x0080/* Do not take i_data_sem locking in ext4_map_blocks */ #define EXT4_GET_BLOCKS_NO_LOCK 0x0100 +/* Do not put hole in extent cache */ +#define EXT4_GET_BLOCKS_NO_PUT_HOLE 0x0200/* * Flags used by ext4_free_blocks fs/ext4/extents.c +6
-1@@ -2154,6 +2154,8 @@ ext4_ext_put_gap_in_cache(struct inode *inode, struct ext4_ext_path *path, block,le32_to_cpu (ex->ee_block), ext4_ext_get_actual_len(ex)); +ext4_es_insert_extent (inode, lblock, len, ~0 , +EXTENT_STATUS_HOLE ); }else if (block >=le32_to_cpu (ex->ee_block) +ext4_ext_get_actual_len (ex)) {ext4_lblk_t next;@@ -2167,6 +2169,8 @@ ext4_ext_put_gap_in_cache(struct inode *inode, struct ext4_ext_path *path, block);BUG_ON (next == lblock); len = next - lblock; +ext4_es_insert_extent (inode, lblock, len, ~0 , +EXTENT_STATUS_HOLE ); }else { lblock = len =0 ;BUG ();@@ -4006,7 +4010,8 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode,* put just found gap into cache to speed up * subsequent requests */ -ext4_ext_put_gap_in_cache (inode, path, map->m_lblk); +if ((flags &EXT4_GET_BLOCKS_NO_PUT_HOLE ) ==0 ) +ext4_ext_put_gap_in_cache (inode, path, map->m_lblk); goto out2; }fs/ext4/extents_status.c +59
-0@@ -468,6 +468,65 @@ error:return err; } +/* +* ext4_es_lookup_extent() looks up an extent in extent status tree. +* +* ext4_es_lookup_extent is called by ext4_map_blocks/ext4_da_map_blocks. +* +* Return: 1 on found, 0 on not +*/ +int ext4_es_lookup_extent (struct inode *inode,struct extent_status *es) +{ +struct ext4_es_tree *tree; +struct extent_status *es1 =NULL ; +struct rb_node *node; +int found =0 ; + +trace_ext4_es_lookup_extent_enter (inode, es->es_lblk); +es_debug ("lookup extent in block %u\n" , es->es_lblk); + + tree = &EXT4_I (inode)->i_es_tree; +read_lock (&EXT4_I (inode)->i_es_lock); + +/* find extent in cache firstly */ + es->es_len = es->es_pblk =0 ; +if (tree->cache_es) { + es1 = tree->cache_es; +if (in_range (es->es_lblk, es1->es_lblk, es1->es_len)) { +es_debug ("%u cached by [%u/%u)\n" , + es->es_lblk, es1->es_lblk, es1->es_len); + found =1 ; + goto out; + } + } + + node = tree->root.rb_node; +while (node) { + es1 = rb_entry(node, struct extent_status, rb_node); +if (es->es_lblk < es1->es_lblk) + node = node->rb_left; +else if (es->es_lblk >ext4_es_end (es1)) + node = node->rb_right; +else { + found =1 ; +break ; + } + } + +out: +if (found) { +BUG_ON (!es1); + es->es_lblk = es1->es_lblk; + es->es_len = es1->es_len; + es->es_pblk = es1->es_pblk; + } + +read_unlock (&EXT4_I (inode)->i_es_lock); + +trace_ext4_es_lookup_extent_exit (inode, es, found); +return found; +} +static int __es_remove_extent (struct ext4_es_tree *tree,ext4_lblk_t lblk,ext4_lblk_t end) {fs/ext4/extents_status.h +1
-0@@ -53,6 +53,7 @@ extern int ext4_es_remove_extent(struct inode *inode, ext4_lblk_t lblk, ext4_lblk_t len);extern ext4_lblk_t ext4_es_find_delayed_extent (struct inode *inode,struct extent_status *es); +extern int ext4_es_lookup_extent (struct inode *inode,struct extent_status *es);static inline int ext4_es_is_written (struct extent_status *es) {fs/ext4/inode.c +62
-2@@ -508,12 +508,34 @@ static pgoff_t ext4_num_dirty_pages(struct inode *inode, pgoff_t idx,int ext4_map_blocks (handle_t *handle,struct inode *inode,struct ext4_map_blocks *map,int flags) { +struct extent_status es;int retval; map->m_flags =0 ;ext_debug ("ext4_map_blocks(): inode %lu, flag %d, max_blocks %u," "logical block %lu\n" , inode->i_ino, flags, map->m_len, (unsigned long ) map->m_lblk); + +/* Lookup extent status tree firstly */ + es.es_lblk = map->m_lblk; +if (ext4_es_lookup_extent (inode, &es)) { +if (ext4_es_is_written (&es) ||ext4_es_is_unwritten (&es)) { + map->m_pblk =ext4_es_pblock (&es) + + map->m_lblk - es.es_lblk; + map->m_flags |=ext4_es_is_written (&es) ? +EXT4_MAP_MAPPED :EXT4_MAP_UNWRITTEN ; + retval = es.es_len - (map->m_lblk - es.es_lblk); +if (retval > map->m_len) + retval = map->m_len; + map->m_len = retval; + }else if (ext4_es_is_delayed (&es) ||ext4_es_is_hole (&es)) { + retval =0 ; + }else { +BUG_ON (1 ); + } + goto found; + } +/* * Try to see if we can get the block without requesting a new * file system block. @@ -541,6 +563,7 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode,if (!(flags &EXT4_GET_BLOCKS_NO_LOCK ))up_read ((&EXT4_I (inode)->i_data_sem)); +found:if (retval >0 && map->m_flags &EXT4_MAP_MAPPED ) {int ret =check_block_validity (inode, map);if (ret !=0 )@@ -1772,6 +1795,7 @@ static int ext4_da_map_blocks(struct inode *inode, sector_t iblock,struct ext4_map_blocks *map, struct buffer_head *bh) { + struct extent_status es;int retval;sector_t invalid_block = ~((sector_t )0xffff );@@ -1782,6 +1806,39 @@ static int ext4_da_map_blocks(struct inode *inode, sector_t iblock,ext_debug ("ext4_da_map_blocks(): inode %lu, max_blocks %u," "logical block %lu\n" , inode->i_ino, map->m_len, (unsigned long ) map->m_lblk); + +/* Lookup extent status tree firstly */ + es.es_lblk = iblock; +if (ext4_es_lookup_extent (inode, &es)) { + +if (ext4_es_is_hole (&es)) { + retval =0 ; +down_read ((&EXT4_I (inode)->i_data_sem)); + goto add_delayed; + } + +if (ext4_es_is_delayed (&es)) { +map_bh (bh, inode->i_sb, invalid_block); +set_buffer_new (bh); +set_buffer_delay (bh); +return 0 ; + } + + map->m_pblk =ext4_es_pblock (&es) + iblock - es.es_lblk; + retval = es.es_len - (iblock - es.es_lblk); +if (retval > map->m_len) + retval = map->m_len; + map->m_len = retval; +if (ext4_es_is_written (&es)) + map->m_flags |=EXT4_MAP_MAPPED ; +else if (ext4_es_is_unwritten (&es)) + map->m_flags |=EXT4_MAP_UNWRITTEN ; +else +BUG_ON (1 ); + +return retval; + } +/* * Try to see if we can get the block without requesting a new * file system block. @@ -1800,10 +1857,13 @@ static int ext4_da_map_blocks(struct inode *inode, sector_t iblock, map->m_flags |=EXT4_MAP_FROM_CLUSTER ; retval =0 ; }else if (ext4_test_inode_flag (inode,EXT4_INODE_EXTENTS )) - retval =ext4_ext_map_blocks (NULL , inode, map,0 ); + retval =ext4_ext_map_blocks (NULL , inode, map, +EXT4_GET_BLOCKS_NO_PUT_HOLE );else - retval =ext4_ind_map_blocks (NULL , inode, map,0 ); + retval =ext4_ind_map_blocks (NULL , inode, map, +EXT4_GET_BLOCKS_NO_PUT_HOLE ); +add_delayed:if (retval ==0 ) {int ret;/* include/trace/events/ext4.h +56
-0@@ -2177,6 +2177,62 @@ TRACE_EVENT(ext4_es_find_delayed_extent_exit, __entry->pblk, __entry->status, __entry->ret) ); +TRACE_EVENT (ext4_es_lookup_extent_enter, + TP_PROTO(struct inode *inode, ext4_lblk_t lblk), + +TP_ARGS (inode, lblk), + +TP_STRUCT__entry ( + __field( dev_t, dev ) + __field( ino_t, ino ) +__field ( ext4_lblk_t, lblk ) + ), + +TP_fast_assign ( + __entry->dev = inode->i_sb->s_dev; + __entry->ino = inode->i_ino; + __entry->lblk = lblk; + ), + +TP_printk ("dev %d,%d ino %lu lblk %u" , +MAJOR (__entry->dev),MINOR (__entry->dev), + (unsigned long ) __entry->ino, __entry->lblk) +); + +TRACE_EVENT (ext4_es_lookup_extent_exit, + TP_PROTO(struct inode *inode, struct extent_status *es, + int found), + +TP_ARGS (inode, es, found), + +TP_STRUCT__entry ( + __field( dev_t, dev ) + __field( ino_t, ino ) + __field( ext4_lblk_t, lblk ) + __field( ext4_lblk_t, len ) + __field( ext4_fsblk_t, pblk ) + __field( unsigned long long, status ) +__field ( int, found ) + ), + +TP_fast_assign ( + __entry->dev = inode->i_sb->s_dev; + __entry->ino = inode->i_ino; + __entry->lblk = es->es_lblk; + __entry->len = es->es_len; + __entry->pblk = ext4_es_pblock(es); + __entry->status = ext4_es_status(es); + __entry->found = found; + ), + +TP_printk ("dev %d,%d ino %lu found %d [%u/%u) %llu %llx" , +MAJOR (__entry->dev),MINOR (__entry->dev), + (unsigned long ) __entry->ino, __entry->found, + __entry->lblk, __entry->len, + __entry->found ? __entry->pblk :0 , + __entry->found ? __entry->status :0 ) +); +#endif /* _TRACE_EXT4_H */ /* This part must be outside protection */ Signature · 1 line
1.7.12.rc2.18.g61b472e
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH 05/10 v5] ext4: lookup block mapping in extent status tree
Quoted 12 lines · Jan Kara
Quoted 11 lines · Zheng Liu
From: Zheng Liu <[email protected]>
After tracking all extent status, we already have a extent cache in memory. Every time we want to lookup a block mapping, we can first try to lookup it in extent status tree to avoid a potential disk I/O.
A new function called
ext4_es_lookup_extentis defined to finish this work. When we try to lookup a block mapping, we always callext4_map_blocksand/orext4_da_map_blocks. So in these functions we first try to lookup a block mapping in extent status tree.
Quoted 7 lines
Quoted 3 lines
A new flag
EXT4_GET_BLOCKS_NO_PUT_HOLEis used inext4_da_map_blocksin order not to put a hole into extent status tree because this hole will be converted to delayed extent in the tree immediately.It looks somewhat inconsistent that you put hole into the extent tree in
ext4_ext_map_blocks()but all other extent types are handled inext4_map_blocks()orext4_da_map_blocks(). Can we put the handling in one place?
It seems that putting all handlings in one place is too complex because ext4_da_map_blocks() calls ext4_ext_map_blocks() and ext4_ind_map_blocks() directly. So now we put all extent except hole in ext4_map_blocks() and ext4_da_map_blocks(). For the hole, it will be inserted into the status tree in ext4_ext_put_gap_in_cache(). In this function we can get the the length of the hole. If we handle it in ext4_da_map_blocks() or ext4_map_blocks(), we only can insert a hole which the length of this hole is 1 because in these functions we couldn't know the length of the hole.
I am planning to refine the get_block_t and *map_blocks functions. At that time I will try to fix this problem.
Thanks,
- Zheng
Jan Kara
reviewerRe: [PATCH 05/10 v5] ext4: lookup block mapping in extent status tree
Quoted 21 lines · Zheng Liu
Quoted 12 lines · Jan Kara
Quoted 11 lines · Zheng Liu
From: Zheng Liu <[email protected]>
After tracking all extent status, we already have a extent cache in memory. Every time we want to lookup a block mapping, we can first try to lookup it in extent status tree to avoid a potential disk I/O.
A new function called
ext4_es_lookup_extentis defined to finish this work. When we try to lookup a block mapping, we always callext4_map_blocksand/orext4_da_map_blocks. So in these functions we first try to lookup a block mapping in extent status tree.Quoted 7 lines
Quoted 3 lines
A new flag
EXT4_GET_BLOCKS_NO_PUT_HOLEis used inext4_da_map_blocksin order not to put a hole into extent status tree because this hole will be converted to delayed extent in the tree immediately.It looks somewhat inconsistent that you put hole into the extent tree in
ext4_ext_map_blocks()but all other extent types are handled inext4_map_blocks()orext4_da_map_blocks(). Can we put the handling in one place?
Quoted 9 lines
It seems that putting all handlings in one place is too complex because
ext4_da_map_blocks()callsext4_ext_map_blocks()andext4_ind_map_blocks()directly. So now we put all extent except hole inext4_map_blocks()andext4_da_map_blocks(). For the hole, it will be inserted into the status tree inext4_ext_put_gap_in_cache(). In this function we can get the the length of the hole. If we handle it inext4_da_map_blocks()orext4_map_blocks(), we only can insert a hole which the length of this hole is 1 because in these functions we couldn't know the length of the hole.
Ah right, thanks for explanation.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Theodore Ts'o
maintainerRe: [PATCH 05/10 v5] ext4: lookup block mapping in extent status tree
In reply to Zheng LiuQuoted 3 lines · Zheng Liu
I am planning to refine the
get_block_tand*map_blocksfunctions. At that time I will try to fix this problem.
Note that get_block_t can't be changed without disrupting the Direct I/O functions which are generic VFS functions. There's been talk of trying to clean up DIO, but it will probably require building a parallel infrastructure in the generic layer, and then transitioning individual file systems over to it. It is definitely a mess, but it's going to be a very tricky problem. I suspect we'll be talking about it at LSF/MM.
One thing thing which might be an interesting thing to do that wouldn't require wholesale changes to generic code would be to transition ext4_readpages() to use fs/ext4/page-io.c. Not for this merge window, in all likelihood, but right now we are calling ext4_get_block() for every single page that we read in, while is wasteful. It would be nice if ext4_readpages() called ext4_map_blocks() for each extent, and then submitted it using the page-io.c functions so we don't end up calling into ext4_map_blocks() quite as much.
That will ease our scalability and remove locking overhead, in addition to saving CPU for the buffered I/O readpages path. Eventually it would be good to do this for DIO as well, but that's going to require a lot more work, and coordination with the developers of btrfs, xfs, etc.
- Ted
Re: [PATCH 05/10 v5] ext4: lookup block mapping in extent status tree
Quoted 23 lines · Theodore Ts'o
Quoted 3 lines · Zheng Liu
I am planning to refine the
get_block_tand*map_blocksfunctions. At that time I will try to fix this problem.Note that
get_block_tcan't be changed without disrupting the Direct I/O functions which are generic VFS functions. There's been talk of trying to clean up DIO, but it will probably require building a parallel infrastructure in the generic layer, and then transitioning individual file systems over to it. It is definitely a mess, but it's going to be a very tricky problem. I suspect we'll be talking about it at LSF/MM.One thing thing which might be an interesting thing to do that wouldn't require wholesale changes to generic code would be to transition
ext4_readpages()to usefs/ext4/page-io.c. Not for this merge window, in all likelihood, but right now we are callingext4_get_block()for every single page that we read in, while is wasteful. It would be nice ifext4_readpages()calledext4_map_blocks()for each extent, and then submitted it using thepage-io.cfunctions so we don't end up calling intoext4_map_blocks()quite as much.
Quoted 5 lines
That will ease our scalability and remove locking overhead, in addition to saving CPU for the buffered I/O readpages path. Eventually it would be good to do this for DIO as well, but that's going to require a lot more work, and coordination with the developers of btrfs, xfs, etc.
To be honest, my initial idea is only to split ext4_map_blocks into ext4_map_blocks_read and ext4_map_blocks_write, and do some cleanups. Thanks for your suggestions. I will look at it carefully after the patch series of extent status tree has been applied.
Thanks,
- Zheng
Theodore Ts'o
maintainerPossible TODO projects for the map_blocks() code path (was: Re: [PATCH 05/10 v5] ext4: lookup block mapping in extent status tree)
Quoted 5 lines · Zheng Liu
To be honest, my initial idea is only to split
ext4_map_blocksintoext4_map_blocks_readandext4_map_blocks_write, and do some cleanups. Thanks for your suggestions. I will look at it carefully after the patch series of extent status tree has been applied.
Ah, when you said get_block_t functions, I had assumed you had meant changing the function signature --- because the function signature being fixed by the generic DIO code is one of the things holding back a number of improvements in the map_blocks code paths.
For example:
1) Thanks to the DIO code, we are ab(using) a struct buffer_head data structure to pass the mapping to the DIO code. Normally the buffer_head maps only a single block's worth of data, but here b_size is repurposed to indcate the size of the logical to physical block mapping, and b_data is invalid (since it isn't a real buffer head). There are a number of other fields in the struct buffer_head which in the DIO codepath which are completely unused, which isn't just an aesthetic issue --- it's also wasting valuable (and limited) kernel stack space, since the struct buffer_head is allocated on the stack of do_blockdev_direct_IO().
2) We are currently using inode flags to pass state flags between different parts of the writepages code and the map_blocks code. This is bad because (a) it makes the code much harder to understand and maintain, and (b) it blocks us from being able to call map_blocks() in parallel. If we fix this, it would be relatively trivial to add support for parallel non-create map_block calls, and if we decide to try to use the extent status tree for range locking, it might be possible to do parallel block allocations sa well. (I believe some locking may be needed in mballoc.c for the inode-specific preallocation code, but that should be doable.)
If we have multiple interested in working on various different projects, it might be useful to start documenting some of these proposed enhancements on the wiki, and certainly these would be good things for us to discuss at the ext4 developer's workshop in April.
Regards,
- Ted
Re: Possible TODO projects for the map_blocks() code path (was: Re: [PATCH 05/10 v5] ext4: lookup block mapping in extent status tree)
Quoted 14 lines · Theodore Ts'o
Quoted 5 lines · Zheng Liu
To be honest, my initial idea is only to split
ext4_map_blocksintoext4_map_blocks_readandext4_map_blocks_write, and do some cleanups. Thanks for your suggestions. I will look at it carefully after the patch series of extent status tree has been applied.Ah, when you said
get_block_tfunctions, I had assumed you had meant changing the function signature --- because the function signature being fixed by the generic DIO code is one of the things holding back a number of improvements in themap_blockscode paths.For example:
Quoted 10 lines
1) Thanks to the DIO code, we are ab(using) a struct
buffer_headdata structure to pass the mapping to the DIO code. Normally thebuffer_headmaps only a single block's worth of data, but hereb_sizeis repurposed to indcate the size of the logical to physical block mapping, andb_datais invalid (since it isn't a real buffer head). There are a number of other fields in the structbuffer_headwhich in the DIO codepath which are completely unused, which isn't just an aesthetic issue --- it's also wasting valuable (and limited) kernel stack space, since the structbuffer_headis allocated on the stack ofdo_blockdev_direct_IO().
Yes, I also think struct buffer_head could be dropped, and get_block_t signature should be changed. But it needs to modify vfs layer. We can discuss this topic with other developers in LSF/MM summit and fsdevel@ mailing list. AFAIK, this year in LSF/MM summit there is a topic about this.
Quoted 11 lines
2) We are currently using inode flags to pass state flags between different parts of the writepages code and the
map_blockscode. This is bad because (a) it makes the code much harder to understand and maintain, and (b) it blocks us from being able to callmap_blocks()in parallel. If we fix this, it would be relatively trivial to add support for parallel non-createmap_blockcalls, and if we decide to try to use the extent status tree for range locking, it might be possible to do parallel block allocations sa well. (I believe some locking may be needed inmballoc.cfor the inode-specific preallocation code, but that should be doable.)
I think about extent-level locking when I run xfstests. It seems that we need to improve *_map_blocks() function if we want to use status tree for range locking because we always need to lookup an extent in this tree and lock this range before we do other things. That is why I want to split ext4_map_blocks function. Certainly this is only my simple idea, and I still need to consider it. But I believe an improvement and/or cleanup is a good start.
Quoted 5 lines
If we have multiple interested in working on various different projects, it might be useful to start documenting some of these proposed enhancements on the wiki, and certainly these would be good things for us to discuss at the ext4 developer's workshop in April.
Yes, there are a lot of things on ext4 wiki, which are out of date. That would be great if it can be updated.
Looking forward to discussing this topics. :-)
- Zheng
PATCH v5 6/10 ext4: remove single extent cache
In reply to Zheng LiuFrom: Zheng Liu <[email protected]>
Single extent cache could be removed because we have extent status tree as a extent cache, and it would be better.
--- fs/ext4/ext4.h | 12 ---- fs/ext4/ext4_extents.h | 6 -- fs/ext4/extents.c | 177 +++++++++++-------------------------------------- fs/ext4/move_extent.c | 3 - fs/ext4/super.c | 1 - 5 files changed, 37 insertions(+), 162 deletions(-)
fs/ext4/ext4.h +0 -12
@@ -812,17 +812,6 @@ do { \#endif /* defined(__KERNEL__) || defined(__linux__) */ -/* -* storage for cached extent -* If ec_len == 0, then the cache is invalid. -* If ec_start == 0, then the cache represents a gap (null mapping) -*/ -struct ext4_ext_cache { -ext4_fsblk_t ec_start; -ext4_lblk_t ec_block; -__u32 ec_len;/* must be 32bit to return holes */ -}; -#include "extents_status.h" /*
@@ -889,7 +878,6 @@ struct ext4_inode_info {struct inode vfs_inode;struct jbd2_inode *jinode; -struct ext4_ext_cache i_cached_extent;/* * File creation time. Its function is same as that of * struct timespec i_{a,c,m}time in the generic inode.
fs/ext4/ext4_extents.h +0 -6
@@ -193,12 +193,6 @@ static inline unsigned short ext_depth(struct inode *inode)return le16_to_cpu (ext_inode_hdr (inode)->eh_depth); } -static inline void -ext4_ext_invalidate_cache (struct inode *inode) -{ -EXT4_I (inode)->i_cached_extent.ec_len =0 ; -} -static inline void ext4_ext_mark_uninitialized (struct ext4_extent *ext) {/* We can not have an uninitialized extent of zero length! */
fs/ext4/extents.c +37 -140
324 lines not on this page · raw message
fs/ext4/move_extent.c +0 -2
@@ -761,9 +761,6 @@ out:kfree (donor_path); } -ext4_ext_invalidate_cache (orig_inode); -ext4_ext_invalidate_cache (donor_inode);
PATCH v5 7/10 ext4: adjust some functions for reclaiming extents from extent status tree
In reply to Zheng LiuFrom: Zheng Liu <[email protected]>
This commit changes some interfaces in extent status tree because we need to use inode to count the cached objects in a extent status tree.
--- fs/ext4/extents_status.c | 50 +++++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 26 deletions(-)
fs/ext4/extents_status.c +23 -24
@@ -142,9 +142,8 @@static struct kmem_cache *ext4_es_cachep; -static int __es_insert_extent (struct ext4_es_tree *tree, -struct extent_status *newes); -static int __es_remove_extent (struct ext4_es_tree *tree,ext4_lblk_t lblk, +static int __es_insert_extent (struct inode *inode,struct extent_status *newes); +static int __es_remove_extent (struct inode *inode,ext4_lblk_t lblk,ext4_lblk_t end);int __init ext4_init_es (void )
@@ -296,7 +295,8 @@ out: }static struct extent_status * -ext4_es_alloc_extent (ext4_lblk_t lblk,ext4_lblk_t len,ext4_fsblk_t pblk) +ext4_es_alloc_extent (struct inode *inode,ext4_lblk_t lblk,ext4_lblk_t len, +ext4_fsblk_t pblk) {struct extent_status *es; es =kmem_cache_alloc (ext4_es_cachep,GFP_ATOMIC );
@@ -308,7 +308,7 @@ ext4_es_alloc_extent(ext4_lblk_t lblk, ext4_lblk_t len, ext4_fsblk_t pblk)return es; } -static void ext4_es_free_extent (struct extent_status *es) +static void ext4_es_free_extent (struct inode *inode,struct extent_status *es) {kmem_cache_free (ext4_es_cachep, es); }
@@ -337,8 +337,9 @@ static int ext4_es_can_be_merged(struct extent_status *es1, }static struct extent_status * -ext4_es_try_to_merge_left (struct ext4_es_tree *tree,struct extent_status *es) +ext4_es_try_to_merge_left (struct inode *inode,struct extent_status *es) { +struct ext4_es_tree *tree = &EXT4_I (inode)->i_es_tree;struct extent_status *es1;struct rb_node *node;
@@ -350,7 +351,7 @@ ext4_es_try_to_merge_left(struct ext4_es_tree *tree, struct extent_status *es)if (ext4_es_can_be_merged (es1, es)) { es1->es_len += es->es_len;rb_erase (&es->rb_node, &tree->root); -ext4_es_free_extent (es); +ext4_es_free_extent (inode, es); es = es1; }
@@ -358,8 +359,9 @@ ext4_es_try_to_merge_left(struct ext4_es_tree *tree, struct extent_status *es) }static struct extent_status * -ext4_es_try_to_merge_right (struct ext4_es_tree *tree,struct extent_status *es) +ext4_es_try_to_merge_right (struct inode *inode,struct extent_status *es) { +struct ext4_es_tree *tree = &EXT4_I (inode)->i_es_tree;struct extent_status *es1;struct rb_node *node;
@@ -371,15 +373,15 @@ ext4_es_try_to_merge_right(struct ext4_es_tree *tree, struct extent_status *es)if (ext4_es_can_be_merged (es, es1)) { es->es_len += es1->es_len;rb_erase (node, &tree->root); -ext4_es_free_extent (es1); +ext4_es_free_extent (inode, es1); }return es; } -static int __es_insert_extent (struct ext4_es_tree *tree, -struct extent_status *newes) +static int __es_insert_extent (struct inode *inode,struct extent_status *newes) { +struct ext4_es_tree *tree = &EXT4_I (inode)->i_es_tree;struct rb_node **p = &tree->root.rb_node;struct rb_node *parent =NULL ;struct extent_status *es;
@@ -396,14 +398,14 @@ static int __es_insert_extent(struct ext4_es_tree *tree, ext4_es_is_unwritten(es))ext4_es_store_pblock (es, newes->es_pblk); - es =ext4_es_try_to_merge_left (tree, es); + es =ext4_es_try_to_merge_left (inode, es); goto out; } p = &(*p)->rb_left; }else if (newes->es_lblk >ext4_es_end (es)) {if (ext4_es_can_be_merged (es, newes)) { es->es_len += newes->es_len; - es =ext4_es_try_to_merge_right (tree, es); + es =ext4_es_try_to_merge_right (inode, es); goto out; } p = &(*p)->rb_right;
@@ -413,7 +415,7 @@ static int __es_insert_extent(struct ext4_es_tree *tree, } } - es =ext4_es_alloc_extent (newes->es_lblk, newes->es_len, + es =ext4_es_alloc_extent (inode, newes->es_lblk, newes->es_len, newes->es_pblk);if (!es)return -ENOMEM ;
@@ -437,7 +439,6 @@ int ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk, ext4_lblk_t len, ext4_fsblk_t pblk, unsigned long long status) { - struct ext4_es_tree *tree; struct extent_status newes;ext4_lblk_t end = lblk + len -1 ;int err =0 ;
@@ -454,11 +455,10 @@ int ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk,trace_ext4_es_insert_extent (inode, &newes);write_lock (&EXT4_I (inode)->i_es_lock); - tree = &EXT4_I (inode)->i_es_tree; - err =__es_remove_extent (tree, lblk, end); + err =__es_remove_extent (inode, lblk, end);if (err !=0 ) goto error; - err =__es_insert_extent (tree, &newes); + err =__es_insert_extent (inode, &newes); error:write_unlock (&EXT4_I (inode)->i_es_lock);
@@ -527,9 +527,10 @@ out:return found; } -static int __es_remove_extent (struct ext4_es_tree *tree,ext4_lblk_t lblk, -ext4_lblk_t end) +static int __es_remove_extent (struct inode *inode,ext4_lblk_t lblk, +ext4_lblk_t end) { +struct ext4_es_tree *tree = &EXT4_I (inode)->i_es_tree;struct rb_node *node;struct extent_status *es;struct extent_status orig_es;
@@ -567,7 +568,7 @@ static int __es_remove_extent(struct ext4_es_tree *tree, ext4_lblk_t lblk,ext4_es_store_pblock (&newes, block); }ext4_es_store_status (&newes,ext4_es_status (&orig_es)); - err =__es_insert_extent (tree, &newes); + err =__es_insert_extent (inode, &newes);if (err) { es->es_lblk = orig_es.es_lblk; es->es_len = orig_es.es_len;
@@ -596,7 +597,7 @@ static int __es_remove_extent(struct ext4_es_tree *tree, ext4_lblk_t lblk,while (es &&ext4_es_end (es) <= end) { node =rb_next (&es->rb_node);rb_erase (&es->rb_node, &tree->root); -ext4_es_free_extent (es); +ext4_es_free_extent (inode, es);if (!node) { es =NULL ;break ;
@@ -628,7 +629,6 @@ out:int ext4_es_remove_extent (struct inode *inode,ext4_lblk_t lblk,ext4_lblk_t len) { -struct ext4_es_tree *tree;ext4_lblk_t end;int err =0 ;
@@ -639,10 +639,8 @@ int ext4_es_remove_extent(struct inode *inode, ext4_lblk_t lblk, end = lblk + len -1 ;BUG_ON (end < lblk); - tree = &EXT4_I (inode)->i_es_tree;
PATCH v5 8/10 ext4: reclaim extents from extent status tree
In reply to Zheng LiuFrom: Zheng Liu <[email protected]>
Although extent status is loaded on-demand, we also need to reclaim extent from the tree when we are under a heavy memory pressure because in some cases fragmented extent tree causes status tree costs too much memory.
Here we maintain a lru list in super_block. When the extent status of an inode is accessed and changed, this inode will be move to the tail of the list. The inode will be dropped from this list when it is cleared. In the inode, a counter is added to count the number of cached objects in extent status tree. Here only written/unwritten extent is counted because delayed extent doesn't be reclaimed due to fiemap, bigalloc and seek_data/hole need it. The counter will be increased as a new extent is allocated, and it will be decreased as a extent is freed.
In this commit we use normal shrinker framework to reclaim memory from the status tree. ext4_es_reclaim_extents_count() traverses the lru list to count the number of reclaimable extents. ext4_es_shrink() tries to reclaim written/unwritten extents from extent status tree. The inode that has been shrunk is moved to the tail of lru list.
--- fs/ext4/ext4.h | 7 ++ fs/ext4/extents_status.c | 156 ++++++++++++++++++++++++++++++++++++++++++++ fs/ext4/extents_status.h | 5 ++ fs/ext4/super.c | 7 ++ include/trace/events/ext4.h | 60 +++++++++++++++++ 5 files changed, 235 insertions(+)
fs/ext4/ext4.h +7 -0
@@ -891,6 +891,8 @@ struct ext4_inode_info {/* extents status tree */ struct ext4_es_tree i_es_tree;rwlock_t i_es_lock; +struct list_head i_es_lru; +unsigned int i_es_lru_nr;/* protected by i_es_lock */ /* ialloc */ ext4_group_t i_last_alloc_group;
@@ -1306,6 +1308,11 @@ struct ext4_sb_info {/* Precomputed FS UUID checksum for seeding other checksums */ __u32 s_csum_seed; + +/* Reclaim extents from extent status tree */ +struct shrinker s_es_shrinker; +struct list_head s_es_lru; +spinlock_t s_es_lru_lock____cacheline_aligned_in_smp ; };static inline struct ext4_sb_info *EXT4_SB (struct super_block *sb)
fs/ext4/extents_status.c +156 -0
194 lines not on this page · raw message
fs/ext4/extents_status.h +5 -0
@@ -105,4 +105,9 @@ static inline void ext4_es_store_status(struct extent_status *es, es->es_pblk = block; } +extern void ext4_es_register_shrinker (struct super_block *sb); +extern void ext4_es_unregister_shrinker (struct super_block *sb); +extern void ext4_es_lru_add (struct inode *inode); +extern void ext4_es_lru_del (struct inode *inode); +#endif /* _EXT4_EXTENTS_STATUS_H */
fs/ext4/super.c +7 -0
@@ -858,6 +858,7 @@ static void ext4_put_super(struct super_block *sb)ext4_abort (sb,"Couldn't clean up the journal" ); } +ext4_es_unregister_shrinker (sb);del_timer (&sbi->s_err_report);ext4_release_system_zone (sb);ext4_mb_release (sb);
@@ -943,6 +944,8 @@ static struct inode *ext4_alloc_inode(struct super_block *sb)spin_lock_init (&ei->i_prealloc_lock);ext4_es_init_tree (&ei->i_es_tree);rwlock_init (&ei->i_es_lock); +INIT_LIST_HEAD (&ei->i_es_lru); + ei->i_es_lru_nr =0 ; ei->i_reserved_data_blocks =0 ; ei->i_reserved_meta_blocks =0 ; ei->i_allocated_meta_blocks =0 ;
@@ -1030,6 +1033,7 @@ void ext4_clear_inode(struct inode *inode)dquot_drop (inode);ext4_discard_preallocations (inode);ext4_es_remove_extent (inode,0 ,EXT_MAX_BLOCKS ); +ext4_es_lru_del (inode);if (EXT4_I (inode)->jinode) {jbd2_journal_release_jbd_inode (EXT4_JOURNAL (inode),EXT4_I (inode)->jinode);
@@ -3771,6 +3775,9 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) sbi->s_max_writeback_mb_bump =128 ; sbi->s_extent_max_zeroout_kb =32 ; +/* Register extent status tree shrinker */ +ext4_es_register_shrinker (sb); +/* * set up enough so that it can read an inode */
include/trace/events/ext4.h +60 -0
66 lines not on this page · raw message
Signature · 1 line
1.7.12.rc2.18.g61b472e
PATCH v5 9/10 ext4: convert unwritten extents from extent status tree in end_io
In reply to Zheng LiuFrom: Zheng Liu <[email protected]>
This commit tries to convert unwritten extents from extent status tree in end_io callback functions and ext4_ext_direct_IO.
--- fs/ext4/extents.c | 6 +- fs/ext4/extents_status.c | 180 ++++++++++++++++++++++++++++++++++++++++---- fs/ext4/extents_status.h | 2 + fs/ext4/inode.c | 5 ++ fs/ext4/page-io.c | 8 +- include/trace/events/ext4.h | 25 ++++++ 6 files changed, 208 insertions(+), 18 deletions(-)
fs/ext4/extents.c +4 -2
@@ -4443,8 +4443,10 @@ int ext4_convert_unwritten_extents(struct inode *inode, loff_t offset, ret =PTR_ERR (handle);break ; } - ret =ext4_map_blocks (handle, inode, &map, -EXT4_GET_BLOCKS_IO_CONVERT_EXT ); +down_write (&EXT4_I (inode)->i_data_sem); + ret =ext4_ext_map_blocks (handle, inode, &map, +EXT4_GET_BLOCKS_IO_CONVERT_EXT ); +up_write (&EXT4_I (inode)->i_data_sem);if (ret <=0 ) {WARN_ON (ret <=0 ); ext4_msg(inode->i_sb, KERN_ERR,
fs/ext4/extents_status.c +165 -15
276 lines not on this page · raw message
fs/ext4/extents_status.h +2 -0
@@ -54,6 +54,8 @@ extern int ext4_es_remove_extent(struct inode *inode, ext4_lblk_t lblk,extern ext4_lblk_t ext4_es_find_delayed_extent (struct inode *inode,struct extent_status *es);extern int ext4_es_lookup_extent (struct inode *inode,struct extent_status *es); +extern int ext4_es_convert_unwritten_extents (struct inode *inode,loff_t offset, +size_t size);static inline int ext4_es_is_written (struct extent_status *es) {
fs/ext4/inode.c +5 -0
@@ -3063,6 +3063,7 @@ out: io_end->result = ret; } +ext4_es_convert_unwritten_extents (inode, offset, size);ext4_add_complete_io (io_end); }
@@ -3088,6 +3089,7 @@ static void ext4_end_io_buffer_write(struct buffer_head *bh, int uptodate)*/ inode = io_end->inode;ext4_set_io_unwritten_flag (inode, io_end); +ext4_es_convert_unwritten_extents (inode, io_end->offset, io_end->size);ext4_add_complete_io (io_end); out: bh->b_private =NULL ;
@@ -3246,6 +3248,9 @@ static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb, }else if (ret >0 && !overwrite &&ext4_test_inode_state (inode,EXT4_STATE_DIO_UNWRITTEN )) {int err; + err =ext4_es_convert_unwritten_extents (inode, offset, ret); +if (err) + ret = err;/* * for non AIO case, since the IO is already * completed, we could do the conversion right here
fs/ext4/page-io.c +7 -1
@@ -276,6 +276,13 @@ static void ext4_end_bio(struct bio *bio, int error) error =0 ;bio_put (bio); +/* +* We need to convert unwrittne extents in extent status tree before +* end_page_writeback() is called. Otherwise, when dioread_nolock is +* enabled, we will be likely to read stale data. +*/ + inode = io_end->inode; +ext4_es_convert_unwritten_extents (inode, io_end->offset, io_end->size);for (i =0 ; i < io_end->num_io_pages; i++) {struct page *page = io_end->pages[i]->p_page;struct buffer_head *bh, *head;
@@ -305,7 +312,6 @@ static void ext4_end_bio(struct bio *bio, int error)put_io_page (io_end->pages[i]); } io_end->num_io_pages =0 ; - inode = io_end->inode;if (error) { io_end->flag |=EXT4_IO_END_ERROR ;
include/trace/events/ext4.h +25 -0
@@ -2233,6 +2233,31 @@ TRACE_EVENT(ext4_es_lookup_extent_exit, __entry->found ? __entry->status : 0) ); +TRACE_EVENT (ext4_es_convert_unwritten_extents, + TP_PROTO(struct inode *inode, loff_t offset, loff_t size), + +TP_ARGS (inode, offset, size), + +TP_STRUCT__entry ( + __field( dev_t, dev ) + __field( ino_t, ino ) + __field( loff_t, offset ) +__field ( loff_t, size ) + ), + +TP_fast_assign ( + __entry->dev = inode->i_sb->s_dev; + __entry->ino = inode->i_ino; + __entry->offset = offset; + __entry->size = size; + ), + +TP_printk ("dev %d,%d ino %lu convert unwritten extents [%llu/%llu" , +MAJOR (__entry->dev),MINOR (__entry->dev), + (unsigned long ) __entry->ino, + __entry->offset, __entry->size) +); + TRACE_EVENT(ext4_es_reclaim_extents_count, TP_PROTO(struct super_block *sb, int nr_cached),
Signature · 1 line
1.7.12.rc2.18.g61b472e
Re: [PATCH 09/10 v5] ext4: convert unwritten extents from extent status tree in end_io
Quoted 24 lines · Zheng Liu
From: Zheng Liu <[email protected]>
This commit tries to convert unwritten extents from extent status tree in
end_iocallback functions andext4_ext_direct_IO.Signed-off-by Zheng Liu <[email protected]>Cc "Theodore Ts'o" <[email protected]>Cc Jan kara <[email protected]>--- fs/ext4/extents.c | 6 +- fs/ext4/extents_status.c | 180 ++++++++++++++++++++++++++++++++++++++++---- fs/ext4/extents_status.h | 2 + fs/ext4/inode.c | 5 ++ fs/ext4/page-io.c | 8 +- include/trace/events/ext4.h | 25 ++++++ 6 files changed, 208 insertions(+), 18 deletions(-)fs/ext4/extents.c +0
-0@@ -4443,8 +4443,10 @@ int ext4_convert_unwritten_extents(struct inode *inode, loff_t offset, ret =PTR_ERR (handle);break ;
fs/ext4/extents.c int ext4_convert_unwritten_extents(struct inode *inode, loff_t offset, · line 4452
Quoted 10 lines
fs/ext4/extents.c +4
-2} - ret =ext4_map_blocks (handle, inode, &map, -EXT4_GET_BLOCKS_IO_CONVERT_EXT ); +down_write (&EXT4_I (inode)->i_data_sem); + ret =ext4_ext_map_blocks (handle, inode, &map, +EXT4_GET_BLOCKS_IO_CONVERT_EXT ); +up_write (&EXT4_I (inode)->i_data_sem);if (ret <=0 ) {WARN_ON (ret <=0 ); ext4_msg(inode->i_sb, KERN_ERR,
Hi Ted,
This chunk is missing in your 'dev' branch of ext4. If we call ext4_map_blocks here, unwritten extent in disk will never be converted because ext4_map_blocks first tries to lookup extent status tree and the unwriten extent in this tree has been converted in end_io callback function. It always looks up a written extent in cache, and return immdiately. Please check it again.
Thanks,
- Zheng
Quoted 400 lines
fs/ext4/extents_status.c +165
-15@@ -248,10 +248,11 @@ ext4_lblk_t ext4_es_find_delayed_extent(struct inode *inode,struct extent_status *es1 =NULL ;struct rb_node *node;ext4_lblk_t ret =EXT_MAX_BLOCKS ; +unsigned long flags;trace_ext4_es_find_delayed_extent_enter (inode, es->es_lblk); -read_lock (&EXT4_I (inode)->i_es_lock); +read_lock_irqsave (&EXT4_I (inode)->i_es_lock, flags); tree = &EXT4_I (inode)->i_es_tree;/* find extent in cache firstly */ @@ -291,7 +292,7 @@ out: } } -read_unlock (&EXT4_I (inode)->i_es_lock); +read_unlock_irqrestore (&EXT4_I (inode)->i_es_lock, flags);ext4_es_lru_add (inode);trace_ext4_es_find_delayed_extent_exit (inode, es, ret);@@ -458,6 +459,7 @@ int ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk, {struct extent_status newes;ext4_lblk_t end = lblk + len -1 ; +unsigned long flags;int err =0 ; es_debug("add [%u/%u) %llu %llx to extent status tree of inode %lu\n",@@ -471,14 +473,14 @@ int ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk,ext4_es_store_status (&newes, status);trace_ext4_es_insert_extent (inode, &newes); -write_lock (&EXT4_I (inode)->i_es_lock); +write_lock_irqsave (&EXT4_I (inode)->i_es_lock, flags); err =__es_remove_extent (inode, lblk, end);if (err !=0 ) goto error; err =__es_insert_extent (inode, &newes); error: -write_unlock (&EXT4_I (inode)->i_es_lock); +write_unlock_irqrestore (&EXT4_I (inode)->i_es_lock, flags);ext4_es_lru_add (inode);ext4_es_print_tree (inode);@@ -498,13 +500,14 @@ int ext4_es_lookup_extent(struct inode *inode, struct extent_status *es)struct ext4_es_tree *tree;struct extent_status *es1 =NULL ;struct rb_node *node; +unsigned long flags;int found =0 ;trace_ext4_es_lookup_extent_enter (inode, es->es_lblk);es_debug ("lookup extent in block %u\n" , es->es_lblk); tree = &EXT4_I (inode)->i_es_tree; -read_lock (&EXT4_I (inode)->i_es_lock); +read_lock_irqsave (&EXT4_I (inode)->i_es_lock, flags);/* find extent in cache firstly */ es->es_len = es->es_pblk =0 ;@@ -539,7 +542,7 @@ out: es->es_pblk = es1->es_pblk; } -read_unlock (&EXT4_I (inode)->i_es_lock); +read_unlock_irqrestore (&EXT4_I (inode)->i_es_lock, flags);ext4_es_lru_add (inode);trace_ext4_es_lookup_extent_exit (inode, es, found);@@ -649,6 +652,7 @@ int ext4_es_remove_extent(struct inode *inode, ext4_lblk_t lblk, ext4_lblk_t len) {ext4_lblk_t end; +unsigned long flags;int err =0 ;trace_ext4_es_remove_extent (inode, lblk, len);@@ -658,9 +662,9 @@ int ext4_es_remove_extent(struct inode *inode, ext4_lblk_t lblk, end = lblk + len -1 ;BUG_ON (end < lblk); -write_lock (&EXT4_I (inode)->i_es_lock); +write_lock_irqsave (&EXT4_I (inode)->i_es_lock, flags); err =__es_remove_extent (inode, lblk, end); -write_unlock (&EXT4_I (inode)->i_es_lock); +write_unlock_irqrestore (&EXT4_I (inode)->i_es_lock, flags);ext4_es_print_tree (inode);return err; }@@ -671,6 +675,7 @@ static int ext4_es_shrink(struct shrinker *shrink, struct shrink_control *sc) struct ext4_sb_info, s_es_shrinker);struct ext4_inode_info *ei;struct list_head *cur, *tmp, scanned; +unsigned long flags;int nr_to_scan = sc->nr_to_scan;int ret, nr_shrunk =0 ;@@ -687,16 +692,16 @@ static int ext4_es_shrink(struct shrinker *shrink, struct shrink_control *sc) ei = list_entry(cur, struct ext4_inode_info, i_es_lru); -read_lock (&ei->i_es_lock); +read_lock_irqsave (&ei->i_es_lock, flags);if (ei->i_es_lru_nr ==0 ) { -read_unlock (&ei->i_es_lock); +read_unlock_irqrestore (&ei->i_es_lock, flags);continue ; } -read_unlock (&ei->i_es_lock); +read_unlock_irqrestore (&ei->i_es_lock, flags); -write_lock (&ei->i_es_lock); +write_lock_irqsave (&ei->i_es_lock, flags); ret =__es_try_to_reclaim_extents (ei, nr_to_scan); -write_unlock (&ei->i_es_lock); +write_unlock_irqrestore (&ei->i_es_lock, flags); nr_shrunk += ret; nr_to_scan -= ret;@@ -756,14 +761,15 @@ static int ext4_es_reclaim_extents_count(struct super_block *sb)struct ext4_sb_info *sbi =EXT4_SB (sb);struct ext4_inode_info *ei;struct list_head *cur; +unsigned long flags;int nr_cached =0 ;spin_lock (&sbi->s_es_lru_lock);list_for_each (cur, &sbi->s_es_lru) { ei = list_entry(cur, struct ext4_inode_info, i_es_lru); -read_lock (&ei->i_es_lock); +read_lock_irqsave (&ei->i_es_lock, flags); nr_cached += ei->i_es_lru_nr; -read_unlock (&ei->i_es_lock); +read_unlock_irqrestore (&ei->i_es_lock, flags); }spin_unlock (&sbi->s_es_lru_lock);trace_ext4_es_reclaim_extents_count (sb, nr_cached);@@ -801,3 +807,147 @@ static int __es_try_to_reclaim_extents(struct ext4_inode_info *ei, tree->cache_es =NULL ;return nr_shrunk; } + +int ext4_es_convert_unwritten_extents (struct inode *inode,loff_t offset, +size_t size) +{ +struct ext4_es_tree *tree; +struct rb_node *node; +struct extent_status *es, orig_es, conv_es; +ext4_lblk_t end, len1, len2; +ext4_lblk_t lblk =0 , len =0 ; +ext4_fsblk_t block; +unsigned long flags; +unsigned int blkbits; +int err =0 ; + +trace_ext4_es_convert_unwritten_extents (inode, offset, size); + blkbits = inode->i_blkbits; + lblk = offset >> blkbits; + len = (EXT4_BLOCK_ALIGN (offset + size, blkbits) >> blkbits) - lblk; + + end = lblk + len -1 ; +BUG_ON (end < lblk); + + tree = &EXT4_I (inode)->i_es_tree; + +write_lock_irqsave (&EXT4_I (inode)->i_es_lock, flags); + es =__es_tree_search (&tree->root, lblk); +if (!es) + goto out; +if (es->es_lblk > end) + goto out; + + tree->cache_es =NULL ; + + orig_es.es_lblk = es->es_lblk; + orig_es.es_len = es->es_len; + orig_es.es_pblk = es->es_pblk; + + len1 = lblk > es->es_lblk ? lblk - es->es_lblk :0 ; + len2 =ext4_es_end (es) > end ? +ext4_es_end (es) - end :0 ; +if (len1 >0 ) + es->es_len = len1; +if (len2 >0 ) { +if (len1 >0 ) { +struct extent_status newes; + + newes.es_lblk = end +1 ; + newes.es_len = len2; + block =ext4_es_pblock (&orig_es) + + orig_es.es_len - len2; +ext4_es_store_pblock (&newes, block); +ext4_es_store_status (&newes,ext4_es_status (&orig_es)); + err =__es_insert_extent (inode, &newes); +if (err) { + es->es_lblk = orig_es.es_lblk; + es->es_len = orig_es.es_len; + es->es_pblk = orig_es.es_pblk; + goto out; + } + + conv_es.es_lblk = orig_es.es_lblk + len1; + conv_es.es_len = orig_es.es_len - len1 - len2; + block =ext4_es_pblock (&orig_es) + len1; +ext4_es_store_pblock (&conv_es, block); +ext4_es_store_status (&conv_es,EXTENT_STATUS_WRITTEN ); + err =__es_insert_extent (inode, &conv_es); +if (err) { +int err2 =__es_remove_extent (inode, + conv_es.es_lblk, +ext4_es_end (&newes)); +if (err2) + goto out; + es->es_lblk = orig_es.es_lblk; + es->es_len = orig_es.es_len; + es->es_pblk = orig_es.es_pblk; + goto out; + } + }else { + es->es_lblk = end +1 ; + es->es_len = len2; + block =ext4_es_pblock (&orig_es) + + orig_es.es_len - len2; +ext4_es_store_pblock (es, block); + + conv_es.es_lblk = orig_es.es_lblk; + conv_es.es_len = orig_es.es_len - len2; +ext4_es_store_pblock (&conv_es, +ext4_es_pblock (&orig_es)); +ext4_es_store_status (&conv_es,EXTENT_STATUS_WRITTEN ); + err =__es_insert_extent (inode, &conv_es); +if (err) { + es->es_lblk = orig_es.es_lblk; + es->es_len = orig_es.es_len; + es->es_pblk = orig_es.es_pblk; + } + } + goto out; + } + +if (len1 >0 ) { + node =rb_next (&es->rb_node); +if (node) + es = rb_entry(node, struct extent_status, rb_node); +else + es =NULL ; + } + +while (es &&ext4_es_end (es) <= end) { + node =rb_next (&es->rb_node); +ext4_es_store_status (es,EXTENT_STATUS_WRITTEN ); +if (!inode) { + es =NULL ; +break ; + } + es = rb_entry(node, struct extent_status, rb_node); + } + +if (es && es->es_lblk < end +1 ) { +ext4_lblk_t orig_len = es->es_len; + +/* +* Here we first set conv_es just because of avoiding copy the +* value of es to a temporary variable. +*/ + len1 =ext4_es_end (es) - end; + conv_es.es_lblk = es->es_lblk; + conv_es.es_len = es->es_len - len1; +ext4_es_store_pblock (&conv_es,ext4_es_pblock (es)); +ext4_es_store_status (&conv_es,EXTENT_STATUS_WRITTEN ); + + es->es_lblk = end +1 ; + es->es_len = len1; + block =ext4_es_pblock (es) + orig_len - len1; +ext4_es_store_pblock (es, block); + + err =__es_insert_extent (inode, &conv_es); +if (err) + goto out; + } + +out: +write_unlock_irqrestore (&EXT4_I (inode)->i_es_lock, flags); +return err; +}fs/ext4/extents_status.h +2
-0@@ -54,6 +54,8 @@ extern int ext4_es_remove_extent(struct inode *inode, ext4_lblk_t lblk,extern ext4_lblk_t ext4_es_find_delayed_extent (struct inode *inode,struct extent_status *es);extern int ext4_es_lookup_extent (struct inode *inode,struct extent_status *es); +extern int ext4_es_convert_unwritten_extents (struct inode *inode,loff_t offset, +size_t size);static inline int ext4_es_is_written (struct extent_status *es) {fs/ext4/inode.c +5
-0@@ -3063,6 +3063,7 @@ out: io_end->result = ret; } +ext4_es_convert_unwritten_extents (inode, offset, size);ext4_add_complete_io (io_end); }@@ -3088,6 +3089,7 @@ static void ext4_end_io_buffer_write(struct buffer_head *bh, int uptodate)*/ inode = io_end->inode;ext4_set_io_unwritten_flag (inode, io_end); +ext4_es_convert_unwritten_extents (inode, io_end->offset, io_end->size);ext4_add_complete_io (io_end); out: bh->b_private =NULL ;@@ -3246,6 +3248,9 @@ static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb, }else if (ret >0 && !overwrite &&ext4_test_inode_state (inode,EXT4_STATE_DIO_UNWRITTEN )) {int err; + err =ext4_es_convert_unwritten_extents (inode, offset, ret); +if (err) + ret = err;/* * for non AIO case, since the IO is already * completed, we could do the conversion right here fs/ext4/page-io.c +7
-1@@ -276,6 +276,13 @@ static void ext4_end_bio(struct bio *bio, int error) error =0 ;bio_put (bio); +/* +* We need to convert unwrittne extents in extent status tree before +* end_page_writeback() is called. Otherwise, when dioread_nolock is +* enabled, we will be likely to read stale data. +*/ + inode = io_end->inode; +ext4_es_convert_unwritten_extents (inode, io_end->offset, io_end->size);for (i =0 ; i < io_end->num_io_pages; i++) {struct page *page = io_end->pages[i]->p_page;struct buffer_head *bh, *head;@@ -305,7 +312,6 @@ static void ext4_end_bio(struct bio *bio, int error)put_io_page (io_end->pages[i]); } io_end->num_io_pages =0 ; - inode = io_end->inode;if (error) { io_end->flag |=EXT4_IO_END_ERROR ;include/trace/events/ext4.h +25
-0@@ -2233,6 +2233,31 @@ TRACE_EVENT(ext4_es_lookup_extent_exit, __entry->found ? __entry->status : 0) ); +TRACE_EVENT (ext4_es_convert_unwritten_extents, + TP_PROTO(struct inode *inode, loff_t offset, loff_t size), + +TP_ARGS (inode, offset, size), + +TP_STRUCT__entry ( + __field( dev_t, dev ) + __field( ino_t, ino ) + __field( loff_t, offset ) +__field ( loff_t, size ) + ), + +TP_fast_assign ( + __entry->dev = inode->i_sb->s_dev; + __entry->ino = inode->i_ino; + __entry->offset = offset; + __entry->size = size; + ), + +TP_printk ("dev %d,%d ino %lu convert unwritten extents [%llu/%llu" , +MAJOR (__entry->dev),MINOR (__entry->dev), + (unsigned long ) __entry->ino, + __entry->offset, __entry->size) +); + TRACE_EVENT(ext4_es_reclaim_extents_count, TP_PROTO(struct super_block *sb, int nr_cached),Signature · 1 line
1.7.12.rc2.18.g61b472e
Theodore Ts'o
maintainerRe: [PATCH 09/10 v5] ext4: convert unwritten extents from extent status tree in end_io
Quoted 7 lines · Zheng Liu
This chunk is missing in your 'dev' branch of ext4. If we call
ext4_map_blockshere, unwritten extent in disk will never be converted becauseext4_map_blocksfirst tries to lookup extent status tree and the unwriten extent in this tree has been converted inend_iocallback function. It always looks up a written extent in cache, and return immdiately. Please check it again.
Thanks for catching this! I missed the the patch hunk getting rejected because I had been distracted with the patch hunk rejection caused by the fact that we've since dropped the function ext4_end_io_buffer_write().
I've fixed this up and pushed an updated git "dev" branch.
- Ted
Jan Kara
reviewerRe: [PATCH 09/10 v5] ext4: convert unwritten extents from extent status tree in end_io
In reply to Zheng LiuQuoted 4 lines · Zheng Liu
From: Zheng Liu <[email protected]>
This commit tries to convert unwritten extents from extent status tree in
end_iocallback functions andext4_ext_direct_IO.
Why should we do this?
...
Quoted 138 lines
fs/ext4/extents_status.c +134
-0@@ -801,3 +807,147 @@ static int __es_try_to_reclaim_extents(struct ext4_inode_info *ei, tree->cache_es =NULL ;return nr_shrunk; } + +int ext4_es_convert_unwritten_extents (struct inode *inode,loff_t offset, +size_t size) +{ +struct ext4_es_tree *tree; +struct rb_node *node; +struct extent_status *es, orig_es, conv_es; +ext4_lblk_t end, len1, len2; +ext4_lblk_t lblk =0 , len =0 ; +ext4_fsblk_t block; +unsigned long flags; +unsigned int blkbits; +int err =0 ; + +trace_ext4_es_convert_unwritten_extents (inode, offset, size); + blkbits = inode->i_blkbits; + lblk = offset >> blkbits; + len = (EXT4_BLOCK_ALIGN (offset + size, blkbits) >> blkbits) - lblk; + + end = lblk + len -1 ; +BUG_ON (end < lblk); + + tree = &EXT4_I (inode)->i_es_tree; + +write_lock_irqsave (&EXT4_I (inode)->i_es_lock, flags); + es =__es_tree_search (&tree->root, lblk); +if (!es) + goto out; +if (es->es_lblk > end) + goto out; + + tree->cache_es =NULL ; + + orig_es.es_lblk = es->es_lblk; + orig_es.es_len = es->es_len; + orig_es.es_pblk = es->es_pblk; + + len1 = lblk > es->es_lblk ? lblk - es->es_lblk :0 ; + len2 =ext4_es_end (es) > end ? +ext4_es_end (es) - end :0 ; +if (len1 >0 ) + es->es_len = len1; +if (len2 >0 ) { +if (len1 >0 ) { +struct extent_status newes; + + newes.es_lblk = end +1 ; + newes.es_len = len2; + block =ext4_es_pblock (&orig_es) + + orig_es.es_len - len2; +ext4_es_store_pblock (&newes, block); +ext4_es_store_status (&newes,ext4_es_status (&orig_es)); + err =__es_insert_extent (inode, &newes); +if (err) { + es->es_lblk = orig_es.es_lblk; + es->es_len = orig_es.es_len; + es->es_pblk = orig_es.es_pblk; + goto out; + } + + conv_es.es_lblk = orig_es.es_lblk + len1; + conv_es.es_len = orig_es.es_len - len1 - len2; + block =ext4_es_pblock (&orig_es) + len1; +ext4_es_store_pblock (&conv_es, block); +ext4_es_store_status (&conv_es,EXTENT_STATUS_WRITTEN ); + err =__es_insert_extent (inode, &conv_es); +if (err) { +int err2 =__es_remove_extent (inode, + conv_es.es_lblk, +ext4_es_end (&newes)); +if (err2) + goto out; + es->es_lblk = orig_es.es_lblk; + es->es_len = orig_es.es_len; + es->es_pblk = orig_es.es_pblk; + goto out; + } + }else { + es->es_lblk = end +1 ; + es->es_len = len2; + block =ext4_es_pblock (&orig_es) + + orig_es.es_len - len2; +ext4_es_store_pblock (es, block); + + conv_es.es_lblk = orig_es.es_lblk; + conv_es.es_len = orig_es.es_len - len2; +ext4_es_store_pblock (&conv_es, +ext4_es_pblock (&orig_es)); +ext4_es_store_status (&conv_es,EXTENT_STATUS_WRITTEN ); + err =__es_insert_extent (inode, &conv_es); +if (err) { + es->es_lblk = orig_es.es_lblk; + es->es_len = orig_es.es_len; + es->es_pblk = orig_es.es_pblk; + } + } + goto out; + } + +if (len1 >0 ) { + node =rb_next (&es->rb_node); +if (node) + es = rb_entry(node, struct extent_status, rb_node); +else + es =NULL ; + } + +while (es &&ext4_es_end (es) <= end) { + node =rb_next (&es->rb_node); +ext4_es_store_status (es,EXTENT_STATUS_WRITTEN ); +if (!inode) { + es =NULL ; +break ; + } + es = rb_entry(node, struct extent_status, rb_node); + } + +if (es && es->es_lblk < end +1 ) { +ext4_lblk_t orig_len = es->es_len; + +/* +* Here we first set conv_es just because of avoiding copy the +* value of es to a temporary variable. +*/ + len1 =ext4_es_end (es) - end; + conv_es.es_lblk = es->es_lblk; + conv_es.es_len = es->es_len - len1; +ext4_es_store_pblock (&conv_es,ext4_es_pblock (es)); +ext4_es_store_status (&conv_es,EXTENT_STATUS_WRITTEN ); + + es->es_lblk = end +1 ; + es->es_len = len1; + block =ext4_es_pblock (es) + orig_len - len1; +ext4_es_store_pblock (es, block);
fs/ext4/extents_status.c static int __es_try_to_reclaim_extents(struct ext4_inode_info *ei, · line 953
Quoted 10 lines
fs/ext4/extents_status.c +10
-0+ + err =__es_insert_extent (inode, &conv_es); +if (err) + goto out; + } + +out: +write_unlock_irqrestore (&EXT4_I (inode)->i_es_lock, flags); +return err; +}
Is this really needed? Why don't you just use ext4_es_insert_extent() to
insert new extent of proper type? Also the way you wrote it, we can return (freshly written) data to the user, then reclaim the extent status from memory and later return 0s because we read the original status from disk (conversion hasn't still happened on disk). That would be certainly confusing.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH 09/10 v5] ext4: convert unwritten extents from extent status tree in end_io
Quoted 154 lines · Jan Kara
Quoted 4 lines · Zheng Liu
From: Zheng Liu <[email protected]>
This commit tries to convert unwritten extents from extent status tree in
end_iocallback functions andext4_ext_direct_IO.Why should we do this?
...
Quoted 146 lines
fs/ext4/extents_status.c +142
-0@@ -801,3 +807,147 @@ static int __es_try_to_reclaim_extents(struct ext4_inode_info *ei, tree->cache_es =NULL ;return nr_shrunk; } + +int ext4_es_convert_unwritten_extents (struct inode *inode,loff_t offset, +size_t size) +{ +struct ext4_es_tree *tree; +struct rb_node *node; +struct extent_status *es, orig_es, conv_es; +ext4_lblk_t end, len1, len2; +ext4_lblk_t lblk =0 , len =0 ; +ext4_fsblk_t block; +unsigned long flags; +unsigned int blkbits; +int err =0 ; + +trace_ext4_es_convert_unwritten_extents (inode, offset, size); + blkbits = inode->i_blkbits; + lblk = offset >> blkbits; + len = (EXT4_BLOCK_ALIGN (offset + size, blkbits) >> blkbits) - lblk; + + end = lblk + len -1 ; +BUG_ON (end < lblk); + + tree = &EXT4_I (inode)->i_es_tree; + +write_lock_irqsave (&EXT4_I (inode)->i_es_lock, flags); + es =__es_tree_search (&tree->root, lblk); +if (!es) + goto out; +if (es->es_lblk > end) + goto out; + + tree->cache_es =NULL ; + + orig_es.es_lblk = es->es_lblk; + orig_es.es_len = es->es_len; + orig_es.es_pblk = es->es_pblk; + + len1 = lblk > es->es_lblk ? lblk - es->es_lblk :0 ; + len2 =ext4_es_end (es) > end ? +ext4_es_end (es) - end :0 ; +if (len1 >0 ) + es->es_len = len1; +if (len2 >0 ) { +if (len1 >0 ) { +struct extent_status newes; + + newes.es_lblk = end +1 ; + newes.es_len = len2; + block =ext4_es_pblock (&orig_es) + + orig_es.es_len - len2; +ext4_es_store_pblock (&newes, block); +ext4_es_store_status (&newes,ext4_es_status (&orig_es)); + err =__es_insert_extent (inode, &newes); +if (err) { + es->es_lblk = orig_es.es_lblk; + es->es_len = orig_es.es_len; + es->es_pblk = orig_es.es_pblk; + goto out; + } + + conv_es.es_lblk = orig_es.es_lblk + len1; + conv_es.es_len = orig_es.es_len - len1 - len2; + block =ext4_es_pblock (&orig_es) + len1; +ext4_es_store_pblock (&conv_es, block); +ext4_es_store_status (&conv_es,EXTENT_STATUS_WRITTEN ); + err =__es_insert_extent (inode, &conv_es); +if (err) { +int err2 =__es_remove_extent (inode, + conv_es.es_lblk, +ext4_es_end (&newes)); +if (err2) + goto out; + es->es_lblk = orig_es.es_lblk; + es->es_len = orig_es.es_len; + es->es_pblk = orig_es.es_pblk; + goto out; + } + }else { + es->es_lblk = end +1 ; + es->es_len = len2; + block =ext4_es_pblock (&orig_es) + + orig_es.es_len - len2; +ext4_es_store_pblock (es, block); + + conv_es.es_lblk = orig_es.es_lblk; + conv_es.es_len = orig_es.es_len - len2; +ext4_es_store_pblock (&conv_es, +ext4_es_pblock (&orig_es)); +ext4_es_store_status (&conv_es,EXTENT_STATUS_WRITTEN ); + err =__es_insert_extent (inode, &conv_es); +if (err) { + es->es_lblk = orig_es.es_lblk; + es->es_len = orig_es.es_len; + es->es_pblk = orig_es.es_pblk; + } + } + goto out; + } + +if (len1 >0 ) { + node =rb_next (&es->rb_node); +if (node) + es = rb_entry(node, struct extent_status, rb_node); +else + es =NULL ; + } + +while (es &&ext4_es_end (es) <= end) { + node =rb_next (&es->rb_node); +ext4_es_store_status (es,EXTENT_STATUS_WRITTEN ); +if (!inode) { + es =NULL ; +break ; + } + es = rb_entry(node, struct extent_status, rb_node); + } + +if (es && es->es_lblk < end +1 ) { +ext4_lblk_t orig_len = es->es_len; + +/* +* Here we first set conv_es just because of avoiding copy the +* value of es to a temporary variable. +*/ + len1 =ext4_es_end (es) - end; + conv_es.es_lblk = es->es_lblk; + conv_es.es_len = es->es_len - len1; +ext4_es_store_pblock (&conv_es,ext4_es_pblock (es)); +ext4_es_store_status (&conv_es,EXTENT_STATUS_WRITTEN ); + + es->es_lblk = end +1 ; + es->es_len = len1; + block =ext4_es_pblock (es) + orig_len - len1; +ext4_es_store_pblock (es, block); + + err =__es_insert_extent (inode, &conv_es); +if (err) + goto out; + } + +out: +write_unlock_irqrestore (&EXT4_I (inode)->i_es_lock, flags);
Quoted 8 lines
fs/ext4/extents_status.c static int __es_try_to_reclaim_extents(struct ext4_inode_info *ei, · line 953
Quoted 2 lines
fs/ext4/extents_status.c +2
-0+return err; +}Is this really needed? Why don't you just use
ext4_es_insert_extent()to
insert new extent of proper type? Also the way you wrote it, we can return (freshly written) data to the user, then reclaim the extent status from memory and later return 0s because we read the original status from disk (conversion hasn't still happened on disk). That would be certainly confusing.
Yes, you are right. So it seems that a new flag called EXTENT_STATUS_DIRTY need to be defined to prevent memory reclaim from shrinker.
Thanks,
- Zheng
PATCH v5 10/10 ext4: remove bogus wait for unwritten extents in ext4_ind_direct_IO
In reply to Zheng LiuFrom: Zheng Liu <[email protected]>
After converting unwritten extents from extent status tree in end_io, we can safely remove this bogus wait and don't worry about read stale data because we always try to lookup a block mapping in extent status tree firstly and unwritten extents in the tree has been converted at this time.
Before that commit, we need to flush unwritten ios before a dio read when dioread_nolock is enabled because in ext4_end_io_buffer_write and ext4_end_bio end_page_writeback() is called before converting unwritten extents in disk. So here is a window that a dio reader will read stale data as below if we don't wait for unwritten extents:
dio read buffered write
->ext4_file_write
->ext4_da_write_begin
->ext4_da_write_end
[buffered write has finished, but
the data and metadata has not
been flushed]
->generic_file_aio_read
->filemap_write_and_wait_range
->do_writepages
->ext4_da_writepages
->filemap_fdatawait_range
->wait_on_page_writeback
->ext4_end_bio
->end_page_writeback
[unwritten extent has not been
converted]
->ext4_ind_direct_IO
[here we need to flush unwritten io]After that commit, we never need to wait for unwritten extents.
dio read buffered write
->ext4_file_write
->ext4_da_write_begin
->ext4_da_write_end
[buffered write has finished, but
the data and metadata has not
been flushed]
->generic_file_aio_read
->filemap_write_and_wait_range
->do_writepages
->ext4_da_writepages
->filemap_fdatawait_range
->wait_on_page_writeback
->ext4_end_bio
->ext4_es_convert_unwritten_extents
->end_page_writeback
[unwritten extent has not been
converted in disk, but they are
converted in extent status tree]
->ext4_ind_direct_IO
[here we will see the written
extents in extent status tree]--- fs/ext4/indirect.c | 5 ----- 1 file changed, 5 deletions(-)
fs/ext4/indirect.c +0 -5
@@ -807,11 +807,6 @@ ssize_t ext4_ind_direct_IO(int rw, struct kiocb *iocb, retry:if (rw ==READ &&ext4_should_dioread_nolock (inode)) { -if (unlikely (atomic_read (&EXT4_I (inode)->i_unwritten))) { -mutex_lock (&inode->i_mutex); -ext4_flush_unwritten_io (inode); -mutex_unlock (&inode->i_mutex); - }/* * Nolock dioread optimization may be dynamically disabled * via ext4_inode_block_unlocked_dio(). Check inode's state
Signature · 1 line
1.7.12.rc2.18.g61b472e
Jan Kara
reviewerRe: [PATCH 10/10 v5] ext4: remove bogus wait for unwritten extents in ext4_ind_direct_IO
Quoted 7 lines · Zheng Liu
From: Zheng Liu <[email protected]>
After converting unwritten extents from extent status tree in
end_io, we can safely remove this bogus wait and don't worry about read stale data because we always try to lookup a block mapping in extent status tree firstly and unwritten extents in the tree has been converted at this time.
But you have to make sure the extent for the range really is in the
status tree (you didn't in the previous patch I think) and cannot be reclaimed until the conversion is performed on disk.
Honza
Quoted 78 lines
Before that commit, we need to flush unwritten ios before a dio read when
dioread_nolockis enabled because inext4_end_io_buffer_writeandext4_end_bioend_page_writeback()is called before converting unwritten extents in disk. So here is a window that a dio reader will read stale data as below if we don't wait for unwritten extents:dio read buffered write ->ext4_file_write ->ext4_da_write_begin ->ext4_da_write_end [buffered write has finished, but the data and metadata has not been flushed] ->generic_file_aio_read ->filemap_write_and_wait_range ->do_writepages ->ext4_da_writepages ->filemap_fdatawait_range ->wait_on_page_writeback ->ext4_end_bio ->end_page_writeback [unwritten extent has not been converted] ->ext4_ind_direct_IO [here we need to flush unwritten io]After that commit, we never need to wait for unwritten extents.
dio read buffered write ->ext4_file_write ->ext4_da_write_begin ->ext4_da_write_end [buffered write has finished, but the data and metadata has not been flushed] ->generic_file_aio_read ->filemap_write_and_wait_range ->do_writepages ->ext4_da_writepages ->filemap_fdatawait_range ->wait_on_page_writeback ->ext4_end_bio ->ext4_es_convert_unwritten_extents ->end_page_writeback [unwritten extent has not been converted in disk, but they are converted in extent status tree] ->ext4_ind_direct_IO [here we will see the written extents in extent status tree]Signed-off-by Zheng Liu <[email protected]>Cc "Theodore Ts'o" <[email protected]>Cc Jan kara <[email protected]>--- fs/ext4/indirect.c | 5 ----- 1 file changed, 5 deletions(-)fs/ext4/indirect.c +0
-5@@ -807,11 +807,6 @@ ssize_t ext4_ind_direct_IO(int rw, struct kiocb *iocb, retry:if (rw ==READ &&ext4_should_dioread_nolock (inode)) { -if (unlikely (atomic_read (&EXT4_I (inode)->i_unwritten))) { -mutex_lock (&inode->i_mutex); -ext4_flush_unwritten_io (inode); -mutex_unlock (&inode->i_mutex); - }/* * Nolock dioread optimization may be dynamically disabled * via ext4_inode_block_unlocked_dio(). Check inode's state Signature · 1 line
1.7.12.rc2.18.g61b472e
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH 10/10 v5] ext4: remove bogus wait for unwritten extents in ext4_ind_direct_IO
Quoted 11 lines · Jan Kara
Quoted 7 lines · Zheng Liu
From: Zheng Liu <[email protected]>
After converting unwritten extents from extent status tree in
end_io, we can safely remove this bogus wait and don't worry about read stale data because we always try to lookup a block mapping in extent status tree firstly and unwritten extents in the tree has been converted at this time.But you have to make sure the extent for the range really is in the
status tree (you didn't in the previous patch I think) and cannot be reclaimed until the conversion is performed on disk.
Thanks for pointing out. I will fix this problem.
Regards,
- Zheng
Theodore Ts'o
maintainerHi Zheng,
Thanks for working on this! I've included your v5 extent status tree patches into the ext4 dev tree. I will start doing further testing.
I suspected it wouldn't make a different, but I tested and confirmed that your patches don't help fix the regression introduced by the
patch: disable-merging-of-uninitialized-extents
As a result, I've moved the following patches to the unstable portion of the ext4 patch queue, pending further investigation and discussion:
disable-merging-of-uninitialized-extents remove-unnecessary-wait-for-extent-coversion-in-ext4_fallocate ext4_split_extent_should_take_care_of_extent_zeroout
I will be running a full set of tests and looking more deeply at the patches, but for now I want to get them into linux-next for more testing and review.
Cheers,
- Ted
Quoted 165 lines · Zheng Liu
Hi all,
This is my fifth try to implement the second step of extent status tree. The patch set can be divided into the following parts.
Patch 1/10
This patch refines the extent status treePatch 2/10-6/10
These patches try to track all extent status in extent status tree and
make it as a extent cache. Inextent_statusstructure bit field is removed because we get some warnings from 'sparse'. Nowes_pblkandes_statusare manipulated by ext4_es_*_pblock and ext4_es_*_status directly. Currently when an unwritten extent is allocated, we never know it frommap->m_flagsbecauseext4_ext_map_blocksdoesn't returnEXT4_MAP_UNWRITTENflag. A patch fixes it and we can determine the extent status according tom_flags.
According to Jan's feedback, we put the hole into extent cache to avoid
to access extent tree in disk as far as possible. Here if the whole file is a hole, this hole will not be cached in extent status tree because it is always splitted immediately. Meanwhile the hole will not be cached whenext4_da_map_blockslooks up a block mapping because this hole will be as a delayed extent later.Patch 7/10-8/10
This two patches try to reclaim memory from extent status tree when we
are under a high memeory pressure.Patch 9/10-10/10
Thses patches are picked up again from 1st version because I aware that
they could remove a bogus wait inext4_ind_direct_IOwhendioread_nolockis enabled. After applied them, the latency of dio read can be reduced.I measure it using fio and the result shows as below.
config file
-----------
[global]
ioengine=psync
direct=1
bs=4k
threadgroup_reporting
directory=/mnt/sda1/
filename=testfile
filesize=10g
size=10g
runtime=120
iodepth=16[fio]
rw=randrw
numjobs=4result
------
w/ bogus wait
read : io=1508.1MB, bw=12876KB/s, iops=3218 , runt=120001msecclat (usec): min=128 , max=268738 , avg=718.62, stdev=3703.97 lat (usec): min=128 , max=268739 , avg=718.78, stdev=3703.97 write: io=1505.2MB, bw=12843KB/s, iops=3210 , runt=120001msec clat (usec): min=47 , max=991727 , avg=520.94, stdev=3451.63 lat (usec): min=47 , max=991727 , avg=521.31, stdev=3451.63w/o bogus wait
read : io=1576.4MB, bw=13451KB/s, iops=3362 , runt=120001msecclat (usec): min=128 , max=283906 , avg=685.88, stdev=2762.64 lat (usec): min=128 , max=283907 , avg=686.05, stdev=2762.64 write: io=1577.9MB, bw=13458KB/s, iops=3364 , runt=120001msec clat (usec): min=48 , max=977942 , avg=498.97, stdev=3093.08 lat (usec): min=48 , max=977943 , avg=499.33, stdev=3093.08From the result we can see that the avg. of latency could be reduced a little.
changelog:
v5 <- v4:
- drop a patch that removesEXT4_MAP_FROM_CLUSTERflag
(I will revise it in the patch set ofget_block_trefinement)
- fold original patch 3/9 into patch 4/9
- manipulatees_pblkandes_statusdirectly
(bit field is removed because it causes some warnings from 'sparse')
- letext4_ext_map_blocksreturnEXT4_MAP_UNWRITTENflag
- renameext4_es_find_extentwithext4_es_find_delayed_extent
- add hole status and put hole into extent status tree as a cache
- convert unwritten extents from extent status tree inext4_ext_direct_IOandend_iocallback
- remove a bogus wait inext4_ind_direct_IOwhendioread_nolockis enabledv4 <- v3:
- register a normal shrinker to reclaim extent from extent status treev3 <- v2:
- useprune_super()to reclaim extents from extent status tree
- stashedes_statusintoes_pblk
- remove single extent cache
- rebase against 3.8-rc4v2 <- v1:
- drop patches that try to improve unwritten extent conversion
- removeEXT4_MAP_FROM_CLUSTERflag
- add tracepoint forext4_es_lookup_extent()
- drop a patch, which tries to fix a warning when bigalloc and delalloc are enabled
- add a shrinker to reclaim memory from extent status tree
- rebase against 3.8-rc2v4: http://lwn.net/Articles/536037/
v3: http://lwn.net/Articles/533730/
v2: http://lwn.net/Articles/532446/
v1: http://lwn.net/Articles/531065/As always, any comments or feedbacks are welcome.
FWIW, when I try to implement patch 3/10, I realize that
get_block_tand*_map_blocksfunctions need to be refactored because in ext4 we already have sixget_block_tfunctions
-ext4_get_block
-ext4_get_block_write
-ext4_get_block_write_nolock
-noalloc_get_block_write
-ext4_da_get_block_prep
-_ext4_get_blockand four
*_map_blocks
-ext4_map_blocks
-ext4_da_map_blocks
-ext4_ext_map_blocks
-ext4_ind_map_blocksSo I am planning to refine them. First I will try to split
ext4_map_blocksinto two parts, e.g.ext4_map_blocks_readandext4_map_blocks_write, and then try other cleanups and improvmentes.Thanks,
- ZhengZheng Liu (10):
ext4: refine extent status tree
ext4: add physical block and status member into extent status tree
ext4: letext4_ext_map_blocksreturnEXT4_MAP_UNWRITTENflag
ext4: track all extent status in extent status tree
ext4: lookup block mapping in extent status tree
ext4: remove single extent cache
ext4: adjust some functions for reclaiming extents from extent status
tree
ext4: reclaim extents from extent status tree
ext4: convert unwritten extents from extent status tree inend_io
ext4: remove bogus wait for unwritten extents inext4_ind_direct_IOfs/ext4/ext4.h | 21 +- fs/ext4/ext4_extents.h | 6 - fs/ext4/extents.c | 211 ++++-------- fs/ext4/extents_status.c | 779 +++++++++++++++++++++++++++++++++++--------- fs/ext4/extents_status.h | 84 ++++- fs/ext4/file.c | 16 +- fs/ext4/indirect.c | 5 - fs/ext4/inode.c | 148 +++++++-- fs/ext4/move_extent.c | 3 - fs/ext4/page-io.c | 8 +- fs/ext4/super.c | 8 +- include/trace/events/ext4.h | 207 ++++++++++-- 12 files changed, 1075 insertions(+), 421 deletions(-)Signature · 1 line
1.7.12.rc2.18.g61b472e
Hi Ted,
Quoted 12 lines · Theodore Ts'o
Hi Zheng,
Thanks for working on this! I've included your v5 extent status tree patches into the ext4 dev tree. I will start doing further testing.
I suspected it wouldn't make a different, but I tested and confirmed that your patches don't help fix the regression introduced by the
patch: disable-merging-of-uninitialized-extentsAs a result, I've moved the following patches to the unstable portion of the ext4 patch queue, pending further investigation and discussion:
Quoted 7 lines
disable-merging-of-uninitialized-extents remove-unnecessary-wait-for-extent-coversion-in-ext4_fallocate
ext4_split_extent_should_take_care_of_extent_zerooutI will be running a full set of tests and looking more deeply at the patches, but for now I want to get them into linux-next for more testing and review.
I have seen that the patch series has been merged into 'dev' branch of ext4 repo. But I found a problem that a chunk in patch 9/10 is missing in your branch. In that patch ext4_map_blocks is replaced with ext4_ext_map_blocks because when we call ext4_map_blocks to convert unwritten extents it will fail. In ext4_map_blocks it first tries to lookup extent status tree and the unwritten extent in this tree has been converted in end_io callback function. So that means that ext4_map_blocks will return immediately and unwritten extent in disk will never be converted. I have replied a mail for that patch to describe it. Please check it.
Thanks,
- Zheng
Quoted 166 lines · Zheng Liu
Quoted 165 lines
Hi all,
This is my fifth try to implement the second step of extent status tree. The patch set can be divided into the following parts.
Patch 1/10
This patch refines the extent status treePatch 2/10-6/10
These patches try to track all extent status in extent status tree and
make it as a extent cache. Inextent_statusstructure bit field is removed because we get some warnings from 'sparse'. Nowes_pblkandes_statusare manipulated by ext4_es_*_pblock and ext4_es_*_status directly. Currently when an unwritten extent is allocated, we never know it frommap->m_flagsbecauseext4_ext_map_blocksdoesn't returnEXT4_MAP_UNWRITTENflag. A patch fixes it and we can determine the extent status according tom_flags.
According to Jan's feedback, we put the hole into extent cache to avoid
to access extent tree in disk as far as possible. Here if the whole file is a hole, this hole will not be cached in extent status tree because it is always splitted immediately. Meanwhile the hole will not be cached whenext4_da_map_blockslooks up a block mapping because this hole will be as a delayed extent later.Patch 7/10-8/10
This two patches try to reclaim memory from extent status tree when we
are under a high memeory pressure.Patch 9/10-10/10
Thses patches are picked up again from 1st version because I aware that
they could remove a bogus wait inext4_ind_direct_IOwhendioread_nolockis enabled. After applied them, the latency of dio read can be reduced.I measure it using fio and the result shows as below.
config file
-----------
[global]
ioengine=psync
direct=1
bs=4k
threadgroup_reporting
directory=/mnt/sda1/
filename=testfile
filesize=10g
size=10g
runtime=120
iodepth=16[fio]
rw=randrw
numjobs=4result
------
w/ bogus wait
read : io=1508.1MB, bw=12876KB/s, iops=3218 , runt=120001msecclat (usec): min=128 , max=268738 , avg=718.62, stdev=3703.97 lat (usec): min=128 , max=268739 , avg=718.78, stdev=3703.97 write: io=1505.2MB, bw=12843KB/s, iops=3210 , runt=120001msec clat (usec): min=47 , max=991727 , avg=520.94, stdev=3451.63 lat (usec): min=47 , max=991727 , avg=521.31, stdev=3451.63w/o bogus wait
read : io=1576.4MB, bw=13451KB/s, iops=3362 , runt=120001msecclat (usec): min=128 , max=283906 , avg=685.88, stdev=2762.64 lat (usec): min=128 , max=283907 , avg=686.05, stdev=2762.64 write: io=1577.9MB, bw=13458KB/s, iops=3364 , runt=120001msec clat (usec): min=48 , max=977942 , avg=498.97, stdev=3093.08 lat (usec): min=48 , max=977943 , avg=499.33, stdev=3093.08From the result we can see that the avg. of latency could be reduced a little.
changelog:
v5 <- v4:
- drop a patch that removesEXT4_MAP_FROM_CLUSTERflag
(I will revise it in the patch set ofget_block_trefinement)
- fold original patch 3/9 into patch 4/9
- manipulatees_pblkandes_statusdirectly
(bit field is removed because it causes some warnings from 'sparse')
- letext4_ext_map_blocksreturnEXT4_MAP_UNWRITTENflag
- renameext4_es_find_extentwithext4_es_find_delayed_extent
- add hole status and put hole into extent status tree as a cache
- convert unwritten extents from extent status tree inext4_ext_direct_IOandend_iocallback
- remove a bogus wait inext4_ind_direct_IOwhendioread_nolockis enabledv4 <- v3:
- register a normal shrinker to reclaim extent from extent status treev3 <- v2:
- useprune_super()to reclaim extents from extent status tree
- stashedes_statusintoes_pblk
- remove single extent cache
- rebase against 3.8-rc4v2 <- v1:
- drop patches that try to improve unwritten extent conversion
- removeEXT4_MAP_FROM_CLUSTERflag
- add tracepoint forext4_es_lookup_extent()
- drop a patch, which tries to fix a warning when bigalloc and delalloc are enabled
- add a shrinker to reclaim memory from extent status tree
- rebase against 3.8-rc2v4: http://lwn.net/Articles/536037/
v3: http://lwn.net/Articles/533730/
v2: http://lwn.net/Articles/532446/
v1: http://lwn.net/Articles/531065/As always, any comments or feedbacks are welcome.
FWIW, when I try to implement patch 3/10, I realize that
get_block_tand*_map_blocksfunctions need to be refactored because in ext4 we already have sixget_block_tfunctions
-ext4_get_block
-ext4_get_block_write
-ext4_get_block_write_nolock
-noalloc_get_block_write
-ext4_da_get_block_prep
-_ext4_get_blockand four
*_map_blocks
-ext4_map_blocks
-ext4_da_map_blocks
-ext4_ext_map_blocks
-ext4_ind_map_blocksSo I am planning to refine them. First I will try to split
ext4_map_blocksinto two parts, e.g.ext4_map_blocks_readandext4_map_blocks_write, and then try other cleanups and improvmentes.Thanks,
- ZhengZheng Liu (10):
ext4: refine extent status tree
ext4: add physical block and status member into extent status tree
ext4: letext4_ext_map_blocksreturnEXT4_MAP_UNWRITTENflag
ext4: track all extent status in extent status tree
ext4: lookup block mapping in extent status tree
ext4: remove single extent cache
ext4: adjust some functions for reclaiming extents from extent status
tree
ext4: reclaim extents from extent status tree
ext4: convert unwritten extents from extent status tree inend_io
ext4: remove bogus wait for unwritten extents inext4_ind_direct_IOfs/ext4/ext4.h | 21 +- fs/ext4/ext4_extents.h | 6 - fs/ext4/extents.c | 211 ++++-------- fs/ext4/extents_status.c | 779 +++++++++++++++++++++++++++++++++++--------- fs/ext4/extents_status.h | 84 ++++- fs/ext4/file.c | 16 +- fs/ext4/indirect.c | 5 - fs/ext4/inode.c | 148 +++++++-- fs/ext4/move_extent.c | 3 - fs/ext4/page-io.c | 8 +- fs/ext4/super.c | 8 +- include/trace/events/ext4.h | 207 ++++++++++-- 12 files changed, 1075 insertions(+), 421 deletions(-)Signature · 1 line
1.7.12.rc2.18.g61b472e