page-writeback: move indoes from one superblock together
RFC 1/1 page-writeback: move indoes from one superblock together
__mark_inode_dirty adds inode to wb dirty list in random order. If a disk has several partitions, writeback might keep spindle moving between partitions. To reduce the move, better write big chunk of one partition and then move to another. Inodes from one fs usually are in one partion, so idealy move indoes from one fs together should reduce spindle move. This patch tries to address this. Before per-bdi writeback is added, the behavior is write indoes from one fs first and then another, so the patch restores previous behavior. The loop in the patch is a bit ugly, should we add a dirty list for each superblock in bdi_writeback?
Test in a two partition disk with attached fio script shows about 3% ~ 6% improvement.
fs/fs-writeback.c +19 -3
@@ -324,13 +324,29 @@ static void move_expired_inodes(struct list_head *delaying_queue,struct list_head *dispatch_queue, unsigned long *older_than_this) { +LIST_HEAD (tmp ); +struct list_head *pos, *node; +struct super_block *sb; +struct inode *inode; +while (!list_empty (delaying_queue)) { -struct inode *inode =list_entry (delaying_queue->prev, - struct inode, i_list); + inode = list_entry(delaying_queue->prev, struct inode, i_list);if (older_than_this &&inode_dirtied_after (inode, *older_than_this))break ; -list_move (&inode->i_list, dispatch_queue); +list_move (&inode->i_list, &tmp); + } + +/* Move indoes from one superblock together */ +while (!list_empty (&tmp)) { + inode = list_entry(tmp.prev, struct inode, i_list); + sb = inode->i_sb; +list_for_each_prev_safe (pos, node, &tmp) { +struct inode *inode =list_entry (pos, + struct inode, i_list); +if (inode->i_sb == sb) +list_move (&inode->i_list, dispatch_queue); + } } }
[global]
runtime=120
ioscheduler=cfq
size=2G
ioengine=sync
rw=write
file_service_type=random:256
overwrite=1
[sdb1]
directory=/mnt/b1
nrfiles=10
numjobs=4
[sdb2]
directory=/mnt/b2
nrfiles=10
numjobs=4
Quoted 10 lines · Shaohua
__mark_inode_dirtyadds inode to wb dirty list in random order. If a disk has several partitions, writeback might keep spindle moving between partitions. To reduce the move, better write big chunk of one partition and then move to another. Inodes from one fs usually are in one partion, so idealy move indoes from one fs together should reduce spindle move. This patch tries to address this. Before per-bdi writeback is added, the behavior is write indoes from one fs first and then another, so the patch restores previous behavior. The loop in the patch is a bit ugly, should we add a dirty list for each superblock inbdi_writeback?
Quoted 2 lines
Test in a two partition disk with attached fio script shows about 3% ~ 6% improvement.
Good idea! The optimization looks good to me, it addresses one weakness of per-bdi writeback.
But one problem is, Jan Kara and me are planning to remove b_io and hence this move_expired_inodes() function. Not sure how to do this optimization without b_io.
Quoted 21 lines
Signed-off-by Shaohua Li <[email protected]>fs/fs-writeback.c +6
-2@@ -324,13 +324,29 @@ static void move_expired_inodes(struct list_head *delaying_queue,struct list_head *dispatch_queue, unsigned long *older_than_this) { +LIST_HEAD (tmp ); +struct list_head *pos, *node; +struct super_block *sb; +struct inode *inode; +while (!list_empty (delaying_queue)) { -struct inode *inode =list_entry (delaying_queue->prev, - struct inode, i_list); + inode = list_entry(delaying_queue->prev, struct inode, i_list);if (older_than_this &&inode_dirtied_after (inode, *older_than_this))
fs/fs-writeback.c static void move_expired_inodes(struct list_head *delaying_queue, · line 344
Quoted 10 lines
fs/fs-writeback.c +8
-1break ; -list_move (&inode->i_list, dispatch_queue); +list_move (&inode->i_list, &tmp); + } + +/* Move indoes from one superblock together */ +while (!list_empty (&tmp)) { + inode = list_entry(tmp.prev, struct inode, i_list); + sb = inode->i_sb; +list_for_each_prev_safe (pos, node, &tmp) {
We are in spin lock, so not necessary to use the safe version?
fs/fs-writeback.c static void move_expired_inodes(struct list_head *delaying_queue, · line 345
Quoted 1 line
fs/fs-writeback.c +1
-0+ struct inode *inode = list_entry(pos,
Could just reuse inode.
Thanks,
Fengguang
fs/fs-writeback.c static void move_expired_inodes(struct list_head *delaying_queue, · line 352
Quoted 8 lines
fs/fs-writeback.c +4
-0+ struct inode, i_list); +if (inode->i_sb == sb) +list_move (&inode->i_list, dispatch_queue); + } } }
Content-Description: newfio
Quoted 18 lines
[global]
runtime=120
ioscheduler=cfq
size=2G
ioengine=sync
rw=write
file_service_type=random:256
overwrite=1[sdb1]
directory=/mnt/b1
nrfiles=10
numjobs=4[sdb2]
directory=/mnt/b2
nrfiles=10
numjobs=4
Quoted 51 lines · On Thu, 24 Sep 2009 15:14:15 +0800 Wu Fengguang <[email protected]> wrote:
Quoted 11 lines · Shaohua
__mark_inode_dirtyadds inode to wb dirty list in random order. If a disk has several partitions, writeback might keep spindle moving between partitions. To reduce the move, better write big chunk of one partition and then move to another. Inodes from one fs usually are in one partion, so idealy move indoes from one fs together should reduce spindle move. This patch tries to address this. Before per-bdi writeback is added, the behavior is write indoes from one fs first and then another, so the patch restores previous behavior. The loop in the patch is a bit ugly, should we add a dirty list for each superblock inbdi_writeback?Quoted 2 lines
Test in a two partition disk with attached fio script shows about 3% ~ 6% improvement.
Reviewed-by Wu Fengguang <[email protected]>Good idea! The optimization looks good to me, it addresses one weakness of per-bdi writeback.
But one problem is, Jan Kara and me are planning to remove
b_ioand hence thismove_expired_inodes()function. Not sure how to do this optimization withoutb_io.Quoted 27 lines
Signed-off-by Shaohua Li <[email protected]>fs/fs-writeback.c +6
-2@@ -324,13 +324,29 @@ static void move_expired_inodes(struct list_head *delaying_queue, struct list_head *dispatch_queue, unsigned long *older_than_this) { +LIST_HEAD (tmp ); +struct list_head *pos, *node; +struct super_block *sb; +struct inode *inode; +while (!list_empty (delaying_queue)) { - struct inode *inode =list_entry (delaying_queue->prev, - struct inode, i_list); + inode = list_entry(delaying_queue->prev, structinode,
i_list); if (older_than_this&&fs/fs-writeback.c +2
-1inode_dirtied_after(inode, *older_than_this)) break; -list_move (&inode->i_list, dispatch_queue); +list_move (&inode->i_list, &tmp); + }
Quoted 9 lines
fs/fs-writeback.c static void move_expired_inodes(struct list_head *delaying_queue, · line 344
Quoted 6 lines
fs/fs-writeback.c +6
-0+ +/* Move indoes from one superblock together */ +while (!list_empty (&tmp)) { + inode = list_entry(tmp.prev, struct inode, i_list); + sb = inode->i_sb; +list_for_each_prev_safe (pos, node, &tmp) {We are in spin lock, so not necessary to use the safe version?
safe is needed for list walks that remove entries from the list has nothing to do with locking ;-)
Signature · 3 lines
Arjan van de Ven Intel Open Source Technology Centre For development, discussion and tips for power savings, visit http://www.lesswatts.org
Quoted 64 lines · Arjan van de Ven
Quoted 51 lines · On Thu, 24 Sep 2009 15:14:15 +0800 Wu Fengguang <[email protected]> wrote:
Quoted 11 lines · Shaohua
__mark_inode_dirtyadds inode to wb dirty list in random order. If a disk has several partitions, writeback might keep spindle moving between partitions. To reduce the move, better write big chunk of one partition and then move to another. Inodes from one fs usually are in one partion, so idealy move indoes from one fs together should reduce spindle move. This patch tries to address this. Before per-bdi writeback is added, the behavior is write indoes from one fs first and then another, so the patch restores previous behavior. The loop in the patch is a bit ugly, should we add a dirty list for each superblock inbdi_writeback?Quoted 2 lines
Test in a two partition disk with attached fio script shows about 3% ~ 6% improvement.
Reviewed-by Wu Fengguang <[email protected]>Good idea! The optimization looks good to me, it addresses one weakness of per-bdi writeback.
But one problem is, Jan Kara and me are planning to remove
b_ioand hence thismove_expired_inodes()function. Not sure how to do this optimization withoutb_io.Quoted 27 lines
Signed-off-by Shaohua Li <[email protected]>fs/fs-writeback.c +6
-2@@ -324,13 +324,29 @@ static void move_expired_inodes(struct list_head *delaying_queue, struct list_head *dispatch_queue, unsigned long *older_than_this) { +LIST_HEAD (tmp ); +struct list_head *pos, *node; +struct super_block *sb; +struct inode *inode; +while (!list_empty (delaying_queue)) { - struct inode *inode =list_entry (delaying_queue->prev, - struct inode, i_list); + inode = list_entry(delaying_queue->prev, structinode,
i_list); if (older_than_this&&fs/fs-writeback.c +2
-1inode_dirtied_after(inode, *older_than_this)) break; -list_move (&inode->i_list, dispatch_queue); +list_move (&inode->i_list, &tmp); + }Quoted 9 lines
fs/fs-writeback.c static void move_expired_inodes(struct list_head *delaying_queue, · line 344
Quoted 6 lines
fs/fs-writeback.c +6
-0+ +/* Move indoes from one superblock together */ +while (!list_empty (&tmp)) { + inode = list_entry(tmp.prev, struct inode, i_list); + sb = inode->i_sb; +list_for_each_prev_safe (pos, node, &tmp) {We are in spin lock, so not necessary to use the safe version?
Quoted 2 lines
safe is needed for list walks that remove entries from the list has nothing to do with locking ;-)
Ah yes, thanks!
Shaohua Li
Reviewed-by Wu FengguangQuoted 48 lines · Fengguang
Quoted 10 lines · Shaohua
__mark_inode_dirtyadds inode to wb dirty list in random order. If a disk has several partitions, writeback might keep spindle moving between partitions. To reduce the move, better write big chunk of one partition and then move to another. Inodes from one fs usually are in one partion, so idealy move indoes from one fs together should reduce spindle move. This patch tries to address this. Before per-bdi writeback is added, the behavior is write indoes from one fs first and then another, so the patch restores previous behavior. The loop in the patch is a bit ugly, should we add a dirty list for each superblock inbdi_writeback?Quoted 2 lines
Test in a two partition disk with attached fio script shows about 3% ~ 6% improvement.
Reviewed-by Wu Fengguang <[email protected]>Good idea! The optimization looks good to me, it addresses one weakness of per-bdi writeback.
But one problem is, Jan Kara and me are planning to remove
b_ioand hence thismove_expired_inodes()function. Not sure how to do this optimization withoutb_io.Quoted 25 lines
Signed-off-by Shaohua Li <[email protected]>fs/fs-writeback.c +8
-3@@ -324,13 +324,29 @@ static void move_expired_inodes(struct list_head *delaying_queue,struct list_head *dispatch_queue, unsigned long *older_than_this) { +LIST_HEAD (tmp ); +struct list_head *pos, *node; +struct super_block *sb; +struct inode *inode; +while (!list_empty (delaying_queue)) { -struct inode *inode =list_entry (delaying_queue->prev, - struct inode, i_list); + inode = list_entry(delaying_queue->prev, struct inode, i_list);if (older_than_this &&inode_dirtied_after (inode, *older_than_this))break ; -list_move (&inode->i_list, dispatch_queue); +list_move (&inode->i_list, &tmp); + }
Quoted 8 lines
fs/fs-writeback.c static void move_expired_inodes(struct list_head *delaying_queue, · line 344
Quoted 6 lines
fs/fs-writeback.c +6
-0+ +/* Move indoes from one superblock together */ +while (!list_empty (&tmp)) { + inode = list_entry(tmp.prev, struct inode, i_list); + sb = inode->i_sb; +list_for_each_prev_safe (pos, node, &tmp) {We are in spin lock, so not necessary to use the safe version?
it's to protect list delete.
Quoted 3 lines
fs/fs-writeback.c static void move_expired_inodes(struct list_head *delaying_queue, · line 345
Quoted 1 line
fs/fs-writeback.c +1
-0+ struct inode *inode = list_entry(pos,Could just reuse inode.
oops, forgot to remove it when moveing inode to global.
__mark_inode_dirty adds inode to wb dirty list in random order. If a disk has several partitions, writeback might keep spindle moving between partitions. To reduce the move, better write big chunk of one partition and then move to another. Inodes from one fs usually are in one partion, so idealy move indoes from one fs together should reduce spindle move. This patch tries to address this. Before per-bdi writeback is added, the behavior is write indoes from one fs first and then another, so the patch restores previous behavior. The loop in the patch is a bit ugly, should we add a dirty list for each superblock in bdi_writeback?
Test in a two partition disk with attached fio script shows about 3% ~ 6% improvement.
fs/fs-writeback.c +18 -3
@@ -324,13 +324,28 @@ static void move_expired_inodes(struct list_head *delaying_queue,struct list_head *dispatch_queue, unsigned long *older_than_this) { +LIST_HEAD (tmp ); +struct list_head *pos, *node; +struct super_block *sb; +struct inode *inode; +while (!list_empty (delaying_queue)) { -struct inode *inode =list_entry (delaying_queue->prev, - struct inode, i_list); + inode = list_entry(delaying_queue->prev, struct inode, i_list);if (older_than_this &&inode_dirtied_after (inode, *older_than_this))break ; -list_move (&inode->i_list, dispatch_queue); +list_move (&inode->i_list, &tmp); + } + +/* Move indoes from one superblock together */ +while (!list_empty (&tmp)) { + inode = list_entry(tmp.prev, struct inode, i_list); + sb = inode->i_sb; +list_for_each_prev_safe (pos, node, &tmp) { + inode = list_entry(pos, struct inode, i_list); +if (inode->i_sb == sb) +list_move (&inode->i_list, dispatch_queue); + } } }
Quoted 2 lines
Quoted 1 line
Could just reuse inode.
oops, forgot to remove it when moveing inode to global.
This is the one I merged. I added the below as wel, we don't need to reiterate the list if we only moved inodes from a single super block.
fs/fs-writeback.c +11 -1
@@ -336,17 +336,27 @@ static void move_expired_inodes(struct list_head *delaying_queue, {LIST_HEAD (tmp);struct list_head *pos, *node; -struct super_block *sb; +struct super_block *sb =NULL ;struct inode *inode; +int do_sb_sort =0 ;while (!list_empty (delaying_queue)) { inode = list_entry(delaying_queue->prev, struct inode, i_list);if (older_than_this &&inode_dirtied_after (inode, *older_than_this))break ; +if (sb && sb != inode->i_sb) + do_sb_sort =1 ; + sb = inode->i_sb;list_move (&inode->i_list, &tmp); } +/* just one sb in list, splice to dispatch_queue and we're done */ +if (!do_sb_sort) { +list_splice (&tmp, dispatch_queue); +return ; + } +/* Move inodes from one superblock together */ while (!list_empty (&tmp)) { inode = list_entry(tmp.prev, struct inode, i_list);
Signature · 1 line
Jens Axboe
Quoted 5 lines · Jens Axboe
Quoted 2 lines
Quoted 1 line
Could just reuse inode.
oops, forgot to remove it when moveing inode to global.
This is the one I merged. I added the below as wel, we don't need to reiterate the list if we only moved inodes from a single super block.
Looks good to me.
Quoted 36 lines
fs/fs-writeback.c +11
-1@@ -336,17 +336,27 @@ static void move_expired_inodes(struct list_head *delaying_queue, {LIST_HEAD (tmp);struct list_head *pos, *node; -struct super_block *sb; +struct super_block *sb =NULL ;struct inode *inode; +int do_sb_sort =0 ;while (!list_empty (delaying_queue)) { inode = list_entry(delaying_queue->prev, struct inode, i_list);if (older_than_this &&inode_dirtied_after (inode, *older_than_this))break ; +if (sb && sb != inode->i_sb) + do_sb_sort =1 ; + sb = inode->i_sb;list_move (&inode->i_list, &tmp); } +/* just one sb in list, splice to dispatch_queue and we're done */ +if (!do_sb_sort) { +list_splice (&tmp, dispatch_queue); +return ; + } +/* Move inodes from one superblock together */ while (!list_empty (&tmp)) { inode = list_entry(tmp.prev, struct inode, i_list);Signature · 2 lines
-- Jens Axboe
Quoted 10 lines · Shaohua
__mark_inode_dirtyadds inode to wb dirty list in random order. If a disk has several partitions, writeback might keep spindle moving between partitions. To reduce the move, better write big chunk of one partition and then move to another. Inodes from one fs usually are in one partion, so idealy move indoes from one fs together should reduce spindle move. This patch tries to address this. Before per-bdi writeback is added, the behavior is write indoes from one fs first and then another, so the patch restores previous behavior. The loop in the patch is a bit ugly, should we add a dirty list for each superblock inbdi_writeback?
Quoted 2 lines
Test in a two partition disk with attached fio script shows about 3% ~ 6% improvement.
A side note: given the noticeable performance gain, I wonder if it deserves to generalize the idea to do whole disk location ordered writeback. That should benefit many small file workloads more than 10%. Because this patch only sorted 2 partitions and inodes in 5s time window, while the below patch will roughly divide the disk into 5 areas and sort inodes in a larger 25s time window.
http://lkml.org/lkml/2007/8/27/45
Judging from this old patch, the complexity cost would be about 250 lines of code (need a rbtree).
Thanks,
Fengguang
Quoted 30 lines
Signed-off-by Shaohua Li <[email protected]>fs/fs-writeback.c +12
-3@@ -324,13 +324,29 @@ static void move_expired_inodes(struct list_head *delaying_queue,struct list_head *dispatch_queue, unsigned long *older_than_this) { +LIST_HEAD (tmp ); +struct list_head *pos, *node; +struct super_block *sb; +struct inode *inode; +while (!list_empty (delaying_queue)) { -struct inode *inode =list_entry (delaying_queue->prev, - struct inode, i_list); + inode = list_entry(delaying_queue->prev, struct inode, i_list);if (older_than_this &&inode_dirtied_after (inode, *older_than_this))break ; -list_move (&inode->i_list, dispatch_queue); +list_move (&inode->i_list, &tmp); + } + +/* Move indoes from one superblock together */ +while (!list_empty (&tmp)) { + inode = list_entry(tmp.prev, struct inode, i_list);
fs/fs-writeback.c static void move_expired_inodes(struct list_head *delaying_queue, · line 352
Quoted 10 lines
fs/fs-writeback.c +7
-0+ sb = inode->i_sb; +list_for_each_prev_safe (pos, node, &tmp) { +struct inode *inode =list_entry (pos, + struct inode, i_list); +if (inode->i_sb == sb) +list_move (&inode->i_list, dispatch_queue); + } } }
Content-Description: newfio
Quoted 18 lines
[global]
runtime=120
ioscheduler=cfq
size=2G
ioengine=sync
rw=write
file_service_type=random:256
overwrite=1[sdb1]
directory=/mnt/b1
nrfiles=10
numjobs=4[sdb2]
directory=/mnt/b2
nrfiles=10
numjobs=4
Quoted 21 lines · Wu Fengguang
Quoted 10 lines · Shaohua
__mark_inode_dirtyadds inode to wb dirty list in random order. If a disk has several partitions, writeback might keep spindle moving between partitions. To reduce the move, better write big chunk of one partition and then move to another. Inodes from one fs usually are in one partion, so idealy move indoes from one fs together should reduce spindle move. This patch tries to address this. Before per-bdi writeback is added, the behavior is write indoes from one fs first and then another, so the patch restores previous behavior. The loop in the patch is a bit ugly, should we add a dirty list for each superblock inbdi_writeback?Quoted 2 lines
Test in a two partition disk with attached fio script shows about 3% ~ 6% improvement.
A side note: given the noticeable performance gain, I wonder if it deserves to generalize the idea to do whole disk location ordered writeback. That should benefit many small file workloads more than 10%. Because this patch only sorted 2 partitions and inodes in 5s time window, while the below patch will roughly divide the disk into 5 areas and sort inodes in a larger 25s time window.
Quoted 4 lines
http://lkml.org/lkml/2007/8/27/45Judging from this old patch, the complexity cost would be about 250 lines of code (need a rbtree).
First of all, nice patch, I'll add it to the current tree. I too was pondering using an rbtree for sb+dirty_time insertion and extraction. But for 100 inodes or less, I bet that just doing the re-sort in writeback time ends up being cheaper on the CPU cycle side.
Signature · 1 line
Jens Axboe
Quoted 22 lines · Jens Axboe
Quoted 21 lines · Wu Fengguang
Quoted 10 lines · Shaohua
__mark_inode_dirtyadds inode to wb dirty list in random order. If a disk has several partitions, writeback might keep spindle moving between partitions. To reduce the move, better write big chunk of one partition and then move to another. Inodes from one fs usually are in one partion, so idealy move indoes from one fs together should reduce spindle move. This patch tries to address this. Before per-bdi writeback is added, the behavior is write indoes from one fs first and then another, so the patch restores previous behavior. The loop in the patch is a bit ugly, should we add a dirty list for each superblock inbdi_writeback?Quoted 2 lines
Test in a two partition disk with attached fio script shows about 3% ~ 6% improvement.
A side note: given the noticeable performance gain, I wonder if it deserves to generalize the idea to do whole disk location ordered writeback. That should benefit many small file workloads more than 10%. Because this patch only sorted 2 partitions and inodes in 5s time window, while the below patch will roughly divide the disk into 5 areas and sort inodes in a larger 25s time window.
Quoted 6 lines
Quoted 4 lines
http://lkml.org/lkml/2007/8/27/45Judging from this old patch, the complexity cost would be about 250 lines of code (need a rbtree).
First of all, nice patch, I'll add it to the current tree. I too was
You mean Shaohua's patch? It should be a good addition for 2.6.32.
In long term move_expired_inodes() needs some rework. Because it could be time consuming to move around all the inodes in a large system, and thus hold inode_lock() for too long time (and this patch scales up the locked time).
So would need to split the list moves into smaller pieces in future, or to change data structure.
Quoted 1 line
pondering using an rbtree for sb+dirty_time insertion and extraction.
FYI Michael Rubin did some work on a rbtree implementation, just in case you are interested:
http://lkml.org/lkml/2008/1/15/25
Quoted 2 lines
But for 100 inodes or less, I bet that just doing the re-sort in writeback time ends up being cheaper on the CPU cycle side.
Yeah.
Thanks,
Fengguang
Quoted 23 lines · Wu Fengguang
Quoted 22 lines · Jens Axboe
Quoted 21 lines · Wu Fengguang
Quoted 10 lines · Shaohua
__mark_inode_dirtyadds inode to wb dirty list in random order. If a disk has several partitions, writeback might keep spindle moving between partitions. To reduce the move, better write big chunk of one partition and then move to another. Inodes from one fs usually are in one partion, so idealy move indoes from one fs together should reduce spindle move. This patch tries to address this. Before per-bdi writeback is added, the behavior is write indoes from one fs first and then another, so the patch restores previous behavior. The loop in the patch is a bit ugly, should we add a dirty list for each superblock inbdi_writeback?Quoted 2 lines
Test in a two partition disk with attached fio script shows about 3% ~ 6% improvement.
A side note: given the noticeable performance gain, I wonder if it deserves to generalize the idea to do whole disk location ordered writeback. That should benefit many small file workloads more than 10%. Because this patch only sorted 2 partitions and inodes in 5s time window, while the below patch will roughly divide the disk into 5 areas and sort inodes in a larger 25s time window.
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
http://lkml.org/lkml/2007/8/27/45Judging from this old patch, the complexity cost would be about 250 lines of code (need a rbtree).
First of all, nice patch, I'll add it to the current tree. I too was
You mean Shaohua's patch? It should be a good addition for 2.6.32.
Yes indeed, the parent patch.
Quoted 4 lines
In long term
move_expired_inodes()needs some rework. Because it could be time consuming to move around all the inodes in a large system, and thus holdinode_lock()for too long time (and this patch scales up the locked time).
It does. As mentioned in my reply, for 100 inodes or less, it will still be faster than eg using an rbtree. But the more "reliable" runtime of an rbtree based solution is appealing, though. It's not hugely critical, though.
Quoted 2 lines
So would need to split the list moves into smaller pieces in future, or to change data structure.
Yes, those are the two options.
Quoted 6 lines
Quoted 1 line
pondering using an rbtree for sb+dirty_time insertion and extraction.
FYI Michael Rubin did some work on a rbtree implementation, just in case you are interested:
http://lkml.org/lkml/2008/1/15/25
Thanks, I'll take a look.
Signature · 1 line
Jens Axboe
Quoted 40 lines · Jens Axboe
Quoted 23 lines · Wu Fengguang
Quoted 22 lines · Jens Axboe
Quoted 21 lines · Wu Fengguang
Quoted 10 lines · Shaohua
__mark_inode_dirtyadds inode to wb dirty list in random order. If a disk has several partitions, writeback might keep spindle moving between partitions. To reduce the move, better write big chunk of one partition and then move to another. Inodes from one fs usually are in one partion, so idealy move indoes from one fs together should reduce spindle move. This patch tries to address this. Before per-bdi writeback is added, the behavior is write indoes from one fs first and then another, so the patch restores previous behavior. The loop in the patch is a bit ugly, should we add a dirty list for each superblock inbdi_writeback?Quoted 2 lines
Test in a two partition disk with attached fio script shows about 3% ~ 6% improvement.
A side note: given the noticeable performance gain, I wonder if it deserves to generalize the idea to do whole disk location ordered writeback. That should benefit many small file workloads more than 10%. Because this patch only sorted 2 partitions and inodes in 5s time window, while the below patch will roughly divide the disk into 5 areas and sort inodes in a larger 25s time window.
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
http://lkml.org/lkml/2007/8/27/45Judging from this old patch, the complexity cost would be about 250 lines of code (need a rbtree).
First of all, nice patch, I'll add it to the current tree. I too was
You mean Shaohua's patch? It should be a good addition for 2.6.32.
Yes indeed, the parent patch.
Quoted 4 lines
In long term
move_expired_inodes()needs some rework. Because it could be time consuming to move around all the inodes in a large system, and thus holdinode_lock()for too long time (and this patch scales up the locked time).
Quoted 4 lines
It does. As mentioned in my reply, for 100 inodes or less, it will still be faster than eg using an rbtree. But the more "reliable" runtime of an rbtree based solution is appealing, though. It's not hugely critical, though.
Agreed. Desktops are not big worries; servers rarely do many partitions per disk.
Quoted 6 lines
Quoted 2 lines
So would need to split the list moves into smaller pieces in future, or to change data structure.
Yes, those are the two options.
Quoted 1 line
Quoted 1 line
pondering using an rbtree for sb+dirty_time insertion and extraction.
Note that dirty_time may not be unique, so need some workaround. And the resulted rbtree implementation may not be more efficient than several list traversals even for a very large list (as long as superblocks numbers are low).
The good side is, once sb+dirty_time rbtree is implemented, it should be trivial to switch the key to sb+inode_number (also may not be unique), and to do location ordered writeback ;)
Thanks,
Fengguang
Quoted 9 lines
Quoted 4 lines
FYI Michael Rubin did some work on a rbtree implementation, just in case you are interested:
http://lkml.org/lkml/2008/1/15/25Thanks, I'll take a look.
Signature · 1 line
Jens Axboe
Quoted 9 lines · On Thu, 24 Sep 2009 21:46:25 +0800 Wu Fengguang <[email protected]> wrote:
Note that
dirty_timemay not be unique, so need some workaround. And the resulted rbtree implementation may not be more efficient than several list traversals even for a very large list (as long as superblocks numbers are low).The good side is, once sb+dirty_time rbtree is implemented, it should be trivial to switch the key to sb+inode_number (also may not be unique), and to do location ordered writeback ;)
would you want to sort by dirty time, or by inode number? (assuming inode number is loosely related to location on disk)
Signature · 3 lines
Arjan van de Ven Intel Open Source Technology Centre For development, discussion and tips for power savings, visit http://www.lesswatts.org
Quoted 8 lines · Arjan van de Ven
Quoted 6 lines · On Thu, 24 Sep 2009 21:46:25 +0800 Wu Fengguang <[email protected]> wrote:
Note that
dirty_timemay not be unique, so need some workaround. And the resulted rbtree implementation may not be more efficient than several list traversals even for a very large list (as long as superblocks numbers are low).
Quoted 6 lines
Quoted 3 lines
The good side is, once sb+dirty_time rbtree is implemented, it should be trivial to switch the key to sb+inode_number (also may not be unique), and to do location ordered writeback ;)
would you want to sort by dirty time, or by inode number? (assuming inode number is loosely related to location on disk)
Sort by inode number; dirty time will also be considered when judging whether the traversed inode is old enough(*) to be eligible for writeback.
(*) this "old enough" criterion has to be much more relaxed, from the original >30s to >5s. The promise to user would change from
"dirtied inodes will be started writeback _around_ 30s"
to
"dirtied inodes will be started writeback _within_ 30s"
The more detailed algorithm would be:
- put inodes to rbtree with key sb+inode_number
- in each per-5s writeback, traverse a range of 1/5 rbtree
- in each traverse, sync inodes that is dirtied more than 5s ago
So the user visible result would be
- on every 5s, roughly a 1/5 disk area will be visited
- for each dirtied inode, it will be synced after 5-30s
Thanks,
Fengguang
Quoted 13 lines · Wu Fengguang
Quoted 12 lines · Arjan van de Ven
Quoted 9 lines · On Thu, 24 Sep 2009 21:46:25 +0800 Wu Fengguang <[email protected]> wrote:
Note that
dirty_timemay not be unique, so need some workaround. And the resulted rbtree implementation may not be more efficient than several list traversals even for a very large list (as long as superblocks numbers are low).The good side is, once sb+dirty_time rbtree is implemented, it should be trivial to switch the key to sb+inode_number (also may not be unique), and to do location ordered writeback ;)
Quoted 5 lines
Quoted 2 lines
would you want to sort by dirty time, or by inode number? (assuming inode number is loosely related to location on disk)
Sort by inode number; dirty time will also be considered when judging whether the traversed inode is old
enough(*)to be eligible for writeback.
Even if the inode number is directly related to location on disk (like for XFS), there is no guarantee that the data or related metadata (indirect blocks) writeback location is in any way related to the inode number. e.g when using the 32 bit allocator on XFS (default for > 1TB filesystems), there is _zero correlation_ between the inode number and the data location. Hence writeback by inode number will not improve writeback patterns at all.
Only the filesystem knows what the best writeback pattern really is; any change is going to affect filesystems differently.
Quoted 9 lines
The more detailed algorithm would be:
- put inodes to rbtree with key sb+inode_number
- in each per-5s writeback, traverse a range of 1/5 rbtree
- in each traverse, sync inodes that is dirtied more than 5s agoSo the user visible result would be
- on every 5s, roughly a 1/5 disk area will be visited
- for each dirtied inode, it will be synced after 5-30s
Personally, I'd prefer that writeback calls a vector that says "writeback inodes older than N" and implement something like the above as the generic mechanism. That way filesystems can override the generic algorithm if there is a better way to track and write back dirty inodes for that filesystem.
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Quoted 20 lines · Dave Chinner
Quoted 13 lines · Wu Fengguang
Quoted 12 lines · Arjan van de Ven
Quoted 9 lines · On Thu, 24 Sep 2009 21:46:25 +0800 Wu Fengguang <[email protected]> wrote:
Note that
dirty_timemay not be unique, so need some workaround. And the resulted rbtree implementation may not be more efficient than several list traversals even for a very large list (as long as superblocks numbers are low).The good side is, once sb+dirty_time rbtree is implemented, it should be trivial to switch the key to sb+inode_number (also may not be unique), and to do location ordered writeback ;)
Quoted 5 lines
Quoted 2 lines
would you want to sort by dirty time, or by inode number? (assuming inode number is loosely related to location on disk)
Sort by inode number; dirty time will also be considered when judging whether the traversed inode is old
enough(*)to be eligible for writeback.
Quoted 7 lines
Even if the inode number is directly related to location on disk (like for XFS), there is no guarantee that the data or related metadata (indirect blocks) writeback location is in any way related to the inode number. e.g when using the 32 bit allocator on XFS (default for > 1TB filesystems), there is
_zerocorrelation_between the inode number and the data location. Hence writeback by inode number will not improve writeback patterns at all.
The location ordering is mainly an optimization for _small files_. So no indirect blocks. A good filesystem will put metadata+data as close as possible for small files. Is that true for XFS?
Quoted 13 lines
Only the filesystem knows what the best writeback pattern really is; any change is going to affect filesystems differently.
Quoted 9 lines
The more detailed algorithm would be:
- put inodes to rbtree with key sb+inode_number
- in each per-5s writeback, traverse a range of 1/5 rbtree
- in each traverse, sync inodes that is dirtied more than 5s agoSo the user visible result would be
- on every 5s, roughly a 1/5 disk area will be visited
- for each dirtied inode, it will be synced after 5-30s
Quoted 5 lines
Personally, I'd prefer that writeback calls a vector that says "writeback inodes older than N" and implement something like the above as the generic mechanism. That way filesystems can override the generic algorithm if there is a better way to track and write back dirty inodes for that filesystem.
We have wbc->older_than_this. Is it good enough for XFS?
Thanks,
Fengguang