jbd[2]: enhance fsync performance when using CFQ
Subsystems (4)
v6 cover jbd[2]: enhance fsync performance when using CFQ
Hi,
Running iozone or fs_mark with fsync enabled, the performance of CFQ is far worse than that of deadline for enterprise class storage when dealing with file sizes of 8MB or less. I used the following command line as a representative test case:
fs_mark -S 1 -D 10000 -N 100000 -d /mnt/test/fs_mark -s 65536 -t 1 -w 4096 -F
When run using the deadline I/O scheduler, an average of the first 5 numbers will give you 529.44 files / second. CFQ will yield only 106.7.
Because the iozone process is issuing synchronous writes, it is put onto CFQ's SYNC service tree. The significance of this is that CFQ will idle for up to 8ms waiting for requests on such queues. So, what happens is that the iozone process will issue, say, 64KB worth of write I/O. That I/O will just land in the page cache. Then, the iozone process does an fsync which forces those I/Os to disk as synchronous writes. Then, the file system's fsync method is invoked, and for ext3/4, it calls log_start_commit followed by log_wait_commit. Because those synchronous writes were forced out in the context of the iozone process, CFQ will now idle on iozone's cfqq waiting for more I/O. However, iozone's progress is gated by the journal thread, now.
With this patch series applied (in addition to the two other patches I sent [1]), CFQ now achieves 530.82 files / second.
I also wanted to improve the performance of the fsync-ing process in the presence of a competing sequential reader. The workload I used for that was a fio job that did sequential buffered 4k reads while running the fs_mark process. The run-time was 30 seconds, except where otherwise noted.
Deadline got 450 files/second while achieving a throughput of 78.2 MB/s for the sequential reader. CFQ, unpatched, did not finish an fs_mark run in 30 seconds. I had to bump the time of the test up to 5 minutes, and then CFQ saw an fs_mark performance of 6.6 files/second and sequential reader throughput of 137.2MB/s.
The fs_mark process was being starved as the WRITE_SYNC I/O is marked with RQ_NOIDLE, and regular WRITES are part of the async workload by default. So, a single request would be served from either the fs_mark process or the journal thread, and then they would give up the I/O scheduler.
After applying this patch set, CFQ can now perform 113.2 files/second while achieving a throughput of 78.6 MB/s for the sequential reader. In table form, the results (all averages of 5 runs) look like this:
just just
fs_mark fio mixed
-------------------------------+--------------
deadline 529.44 151.4 | 450.0 78.2 vanilla cfq 107.88 164.4 | 6.6 137.2 patched cfq 530.82 158.7 | 113.2 78.6
While this is a huge jump for CFQ, it is still nowhere near competing with deadline. I'm not sure what else I can do in this approach to address that problem. I/O from the two streams really needs to be interleaved in order to keep the storage busy.
Comments, as always, are appreciated. I think I may have explored this alternative as far as is desirable, so if this is not a preferred method of dealing with the problem, I'm all ears for new approaches.
Thanks!
Jeff
---
Changes from the last posting:
- Yielding no longer expires the current queue. Instead, it sets up new requests from the target process so that they are issued in the yielding process' cfqq. This means that we don't need to worry about losing group or workload share.
- Journal commits are now synchronous I/Os, which was required to get any sort of performance out of the fs_mark process in the presence of a competing reader.
- WRITE_SYNC I/O no longer sets RQ_NOIDLE, for a similar reason.
- I did test OCFS2, and it does experience performance improvements, though I forgot to record those.
Previous postings can be found here:
http://lkml.org/lkml/2010/4/1/344
http://lkml.org/lkml/2010/4/7/325
http://lkml.org/lkml/2010/4/14/394
http://lkml.org/lkml/2010/5/18/365
http://lkml.org/lkml/2010/6/22/338
[1] http://lkml.org/lkml/2010/6/21/307
[PATCH 1/6] block: Implement a blk_yield function to voluntarily give up the I/O scheduler. [PATCH 2/6] jbd: yield the device queue when waiting for commits
[PATCH 3/6] jbd2: yield the device queue when waiting for journal commits [PATCH 4/6] jbd: use WRITE_SYNC for journal I/O
[PATCH 5/6] jbd2: use WRITE_SYNC for journal I/O
[PATCH 6/6] block: remove RQ_NOIDLE from WRITE_SYNC
PATCH v6 1/6 block: Implement a blk_yield function to voluntarily give up the I/O scheduler.
This patch implements a blk_yield function to allow a process to voluntarily give up its I/O scheduler time slice. This is desirable for those processes which know that they will be blocked on I/O from another process, such as the file system journal thread. The yield call works by causing the target process to issue I/O in the context of the cfqq of the calling process. Following patches will put calls to blk_yield into jbd and jbd2.
--- block/blk-core.c | 24 +++++++ block/blk-ioc.c | 1 + block/blk-settings.c | 6 ++ block/cfq-iosched.c | 147 +++++++++++++++++++++++++++++++++++++++++++- block/elevator.c | 15 +++++ include/linux/blkdev.h | 4 + include/linux/elevator.h | 3 + include/linux/iocontext.h | 3 + 8 files changed, 199 insertions(+), 4 deletions(-)
block/blk-core.c +24 -0
@@ -324,6 +324,29 @@ void blk_unplug(struct request_queue *q) }EXPORT_SYMBOL (blk_unplug); +static void generic_yield_iosched (struct request_queue *q, +struct task_struct *tsk) +{ +elv_yield (q, tsk); +} + +/** +* blk_yield() +* @q: request_queue to which we're doing I/O +* @tsk: task to which we're yielding the I/O scheduler +* +* This function should be called by code which knows that it is waiting +* on another thread to perform I/O in order for it to make progress. By +* yielding the I/O scheduler, a potentially significant idling window can +* be bypassed, resulting in better latency and throughput. +*/ +void blk_yield (struct request_queue *q,struct task_struct *tsk) +{ +if (q->yield_fn) + q->yield_fn (q, tsk); +} +EXPORT_SYMBOL (blk_yield); +/** * blk_start_queue - restart a previously stopped queue * @q: The &struct request_queue in question
@@ -609,6 +632,7 @@ blk_init_allocated_queue_node(struct request_queue *q, request_fn_proc *rfn, q->request_fn = rfn; q->prep_rq_fn =NULL ; q->unplug_fn = generic_unplug_device; + q->yield_fn = generic_yield_iosched; q->queue_flags =QUEUE_FLAG_DEFAULT ; q->queue_lock = lock;
block/blk-ioc.c +1 -0
@@ -97,6 +97,7 @@ struct io_context *alloc_io_context(gfp_t gfp_flags, int node)INIT_RADIX_TREE (&ret->radix_root,GFP_ATOMIC | __GFP_HIGH);INIT_HLIST_HEAD (&ret->cic_list); ret->ioc_data =NULL ; + ret->on_behalf_of =NULL ; }return ret;
block/blk-settings.c +6 -0
@@ -171,6 +171,12 @@ void blk_queue_make_request(struct request_queue *q, make_request_fn *mfn) }EXPORT_SYMBOL (blk_queue_make_request); +void blk_queue_yield_set (struct request_queue *q,yield_fn *yield) +{ + q->yield_fn = yield; +} +EXPORT_SYMBOL_GPL (blk_queue_yield_set); +/** * blk_queue_bounce_limit - set bounce buffer limit for queue * @q: the request queue for the device
block/cfq-iosched.c +143 -4
233 lines not on this page · raw message
block/elevator.c +15 -0
@@ -866,6 +866,21 @@ void elv_completed_request(struct request_queue *q, struct request *rq) } } +/** +* elv_yield() - explicitly give up the I/O scheduler +* @q: request_queue for the device to which we're doing I/O +* @tsk: task_struct of the process to which we're yielding +* +* This function abstracts out the I/O scheduler's yield function. +*/ +void elv_yield (struct request_queue *q,struct task_struct *tsk) +{ +struct elevator_queue *e = q->elevator; + +if (e && e->ops->elevator_yield_fn) + e->ops->elevator_yield_fn (q, tsk); +} +#define to_elv (atr) container_of((atr), struct elv_fs_entry, attr) static ssize_t
include/linux/blkdev.h +4 -0
@@ -263,6 +263,7 @@ struct request_pm_statetypedef void (request_fn_proc ) (struct request_queue *q);typedef int (make_request_fn ) (struct request_queue *q,struct bio *bio); +typedef void (yield_fn ) (struct request_queue *q,struct task_struct *tsk);typedef int (prep_rq_fn ) (struct request_queue *,struct request *);typedef void (unplug_fn ) (struct request_queue *);
@@ -345,6 +346,7 @@ struct request_queuerequest_fn_proc *request_fn;make_request_fn *make_request_fn; +yield_fn *yield_fn;prep_rq_fn *prep_rq_fn;unplug_fn *unplug_fn;merge_bvec_fn *merge_bvec_fn;
@@ -837,6 +839,7 @@ extern int blk_execute_rq(struct request_queue *, struct gendisk *,extern void blk_execute_rq_nowait (struct request_queue *,struct gendisk *,struct request *,int ,rq_end_io_fn *);extern void blk_unplug (struct request_queue *q); +extern void blk_yield (struct request_queue *q,struct task_struct *tsk);static inline struct request_queue *bdev_get_queue (struct block_device *bdev) {
@@ -929,6 +932,7 @@ extern struct request_queue *blk_init_allocated_queue(struct request_queue *, request_fn_proc *, spinlock_t *);extern void blk_cleanup_queue (struct request_queue *);extern void blk_queue_make_request (struct request_queue *,make_request_fn *); +extern void blk_queue_yield_set (struct request_queue *,yield_fn *);extern void blk_queue_bounce_limit (struct request_queue *,u64 );extern void blk_queue_max_hw_sectors (struct request_queue *,unsigned int );extern void blk_queue_max_segments (struct request_queue *,unsigned short );
include/linux/elevator.h +3 -0
@@ -23,6 +23,7 @@ typedef void (elevator_add_req_fn) (struct request_queue *, struct request *);typedef int (elevator_queue_empty_fn ) (struct request_queue *);typedef struct request *(elevator_request_list_fn ) (struct request_queue *,struct request *);typedef void (elevator_completed_req_fn ) (struct request_queue *,struct request *); +typedef void (elevator_yield_fn ) (struct request_queue *,struct task_struct *tsk);typedef int (elevator_may_queue_fn ) (struct request_queue *,int );typedef int (elevator_set_req_fn ) (struct request_queue *,struct request *,gfp_t );
@@ -48,6 +49,7 @@ struct elevator_opselevator_queue_empty_fn *elevator_queue_empty_fn;elevator_completed_req_fn *elevator_completed_req_fn; +elevator_yield_fn *elevator_yield_fn;elevator_request_list_fn *elevator_former_req_fn;elevator_request_list_fn *elevator_latter_req_fn;
@@ -111,6 +113,7 @@ extern void elv_bio_merged(struct request_queue *q, struct request *, struct bio *);extern void elv_requeue_request (struct request_queue *,struct request *);extern int elv_queue_empty (struct request_queue *); +extern void elv_yield (struct request_queue *,struct task_struct *);extern struct request *elv_former_request (struct request_queue *,struct request *);extern struct request *elv_latter_request (struct request_queue *,struct request *);extern int elv_register_queue (struct request_queue *q);
include/linux/iocontext.h +3 -0
@@ -54,6 +54,9 @@ struct io_context {struct radix_tree_root radix_root;struct hlist_head cic_list;void *ioc_data; +/* set when another process has yielded its I/O scheduler slice to +* this process */ +struct io_context *on_behalf_of; };static inline struct io_context *ioc_task_link (struct io_context *ioc)
Signature · 1 line
1.6.5.2
PATCH v6 4/6 jbd: use WRITE_SYNC for journal I/O
In reply to Jeff MoyerIn my fsync testing, journal I/O most definitely was sync I/O, since another process was blocked waiting for the results. By marking all journal I/O as WRITE_SYNC, I can get better performance with CFQ.
If there is a way to mark this only for cases where it is blocking progress in a dependent process, then that would be preferrable. Is there such a means for determining and flagging this?
Cheers,
Jeff
--- fs/jbd/commit.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
fs/jbd/commit.c +1 -1
@@ -317,7 +317,7 @@ void journal_commit_transaction(journal_t *journal)int first_tag =0 ;int tag_flag;int i; -int write_op =WRITE ; +int write_op =WRITE_SYNC ;/* * First job: lock down the current transaction and wait for
Signature · 1 line
1.6.5.2
PATCH v6 5/6 jbd2: use WRITE_SYNC for journal I/O
In reply to Jeff MoyerIn my fsync testing, journal I/O most definitely was sync I/O, since another process was blocked waiting for the results. By marking all journal I/O as WRITE_SYNC, I can get better performance with CFQ.
If there is a way to mark this only for cases where it is blocking progress in a dependent process, then that would be preferrable. Is there such a means for determining and flagging this?
Cheers,
Jeff
--- fs/jbd2/commit.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
fs/jbd2/commit.c +1 -1
@@ -369,7 +369,7 @@ void jbd2_journal_commit_transaction(journal_t *journal)int tag_bytes =journal_tag_bytes (journal);struct buffer_head *cbh =NULL ;/* For transactional checksums */ __u32 crc32_sum = ~0 ; -int write_op =WRITE ; +int write_op =WRITE_SYNC ;/* * First job: lock down the current transaction and wait for
Signature · 1 line
1.6.5.2
PATCH v6 2/6 jbd: yield the device queue when waiting for commits
In reply to Jeff MoyerThis patch gets CFQ back in line with deadline for iozone runs, especially those testing small files + fsync timings.
--- fs/jbd/journal.c | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-)
fs/jbd/journal.c +7 -0
@@ -36,6 +36,7 @@#include <linux/poison.h> #include <linux/proc_fs.h> #include <linux/debugfs.h> +#include <linux/blkdev.h> #include <asm/uaccess.h> #include <asm/page.h>
@@ -183,6 +184,7 @@ loop: should_sleep =0 ;if (should_sleep) {spin_unlock (&journal->j_state_lock); +blk_yield (journal->j_dev->bd_disk->queue,NULL );schedule ();spin_lock (&journal->j_state_lock); }
@@ -549,6 +551,11 @@ int log_wait_commit(journal_t *journal, tid_t tid)while (tid_gt (tid, journal->j_commit_sequence)) {jbd_debug (1 ,"JBD: want %d, j_commit_sequence=%d\n" , tid, journal->j_commit_sequence); +/* +* Give up our I/O scheduler time slice to allow the journal +* thread to issue I/O. +*/ +blk_yield (journal->j_dev->bd_disk->queue, journal->j_task);wake_up (&journal->j_wait_commit);spin_unlock (&journal->j_state_lock); wait_event(journal->j_wait_done_commit,
Signature · 1 line
1.6.5.2
PATCH v6 3/6 jbd2: yield the device queue when waiting for journal commits
In reply to Jeff MoyerThis patch gets CFQ back in line with deadline for iozone runs, especially those testing small files + fsync timings.
--- fs/jbd2/journal.c | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-)
fs/jbd2/journal.c +7 -0
@@ -41,6 +41,7 @@#include <linux/hash.h> #include <linux/log2.h> #include <linux/vmalloc.h> +#include <linux/blkdev.h> #define CREATE_TRACE_POINTS #include <trace/events/jbd2.h>
@@ -192,6 +193,7 @@ loop: should_sleep =0 ;if (should_sleep) {spin_unlock (&journal->j_state_lock); +blk_yield (journal->j_dev->bd_disk->queue,NULL );schedule ();spin_lock (&journal->j_state_lock); }
@@ -580,6 +582,11 @@ int jbd2_log_wait_commit(journal_t *journal, tid_t tid)while (tid_gt (tid, journal->j_commit_sequence)) {jbd_debug (1 ,"JBD: want %d, j_commit_sequence=%d\n" , tid, journal->j_commit_sequence); +/* +* Give up our I/O scheduler time slice to allow the journal +* thread to issue I/O. +*/ +blk_yield (journal->j_dev->bd_disk->queue, journal->j_task);wake_up (&journal->j_wait_commit);spin_unlock (&journal->j_state_lock); wait_event(journal->j_wait_done_commit,
Signature · 1 line
1.6.5.2
PATCH v6 6/6 block: remove RQ_NOIDLE from WRITE_SYNC
In reply to Jeff MoyerIn trying to get fsync-ing processes to perform as well under CFQ as they do in deadline, I found (with the current blk_yield approach) that it was necessary to get rid of the RQ_NOIDLE flag for WRITE_SYNC I/O. Instead, we do explicit yielding of the I/O scheduler.
Comments, as always, are greatly appreciated.
Cheers,
Jeff
--- include/linux/fs.h | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
include/linux/fs.h +2 -2
@@ -152,12 +152,12 @@ struct inodes_stat_t {#define SWRITE 3/* for ll_rw_block() - wait for buffer lock */ #define READ_SYNC (READ | (1 << BIO_RW_SYNCIO) | (1 << BIO_RW_UNPLUG))#define READ_META (READ | (1 << BIO_RW_META)) -#define WRITE_SYNC_PLUG (WRITE | (1 << BIO_RW_SYNCIO) | (1 << BIO_RW_NOIDLE)) +#define WRITE_SYNC_PLUG (WRITE | (1 << BIO_RW_SYNCIO))#define WRITE_SYNC (WRITE_SYNC_PLUG | (1 << BIO_RW_UNPLUG))#define WRITE_ODIRECT_PLUG (WRITE | (1 << BIO_RW_SYNCIO))#define WRITE_META (WRITE | (1 << BIO_RW_META))#define SWRITE_SYNC_PLUG \ - (SWRITE | (1 << BIO_RW_SYNCIO) | (1 << BIO_RW_NOIDLE)) + (SWRITE | (1 << BIO_RW_SYNCIO))#define SWRITE_SYNC (SWRITE_SYNC_PLUG | (1 << BIO_RW_UNPLUG))#define WRITE_BARRIER (WRITE | (1 << BIO_RW_BARRIER))
Signature · 1 line
1.6.5.2
On Fri, Jul 02, 2010 at 03:58:13PM -0400, Jeff Moyer wrote:
[..]
Quoted 9 lines
Changes from the last posting:
- Yielding no longer expires the current queue. Instead, it sets up new requests from the target process so that they are issued in the yielding process' cfqq. This means that we don't need to worry about losing group or workload share.
- Journal commits are now synchronous I/Os, which was required to get any sort of performance out of thefs_markprocess in the presence of a competing reader.
-WRITE_SYNCI/O no longer setsRQ_NOIDLE, for a similar reason.
Hi Jeff,
So this patchset relies on idling on WRITE_SYNC queues. Though in general we don't have examples that why one should idle on processes doing WRITE_SYNC IO because previous IO does not tell anything about the upcoming IO. I am bringing up this point again to make sure that fundamentally we agree that continue to idle on WRITE_SYNC is the right thing to do otherwise this patch will fall apart.
I have yet to go through the patch in detail but allowing other queue to dispatch requests in the same queue sounds like queue merging. So can we use that semantics to say elv_merge_context() or elv_merge_queue() instead of elv_yield(). In the code we can just merge the two queues when the next request comes in and separate them out at the slice expiry I guess.
Thanks
Vivek
Quoted 18 lines
- I did test OCFS2, and it does experience performance improvements, though I forgot to record those.
Previous postings can be found here:
http://lkml.org/lkml/2010/4/1/344
http://lkml.org/lkml/2010/4/7/325
http://lkml.org/lkml/2010/4/14/394
http://lkml.org/lkml/2010/5/18/365
http://lkml.org/lkml/2010/6/22/338[1] http://lkml.org/lkml/2010/6/21/307
[PATCH 1/6] block: Implement a
blk_yieldfunction to voluntarily give up the I/O scheduler. [PATCH 2/6] jbd: yield the device queue when waiting for commits
[PATCH 3/6] jbd2: yield the device queue when waiting for journal commits [PATCH 4/6] jbd: useWRITE_SYNCfor journal I/O
[PATCH 5/6] jbd2: useWRITE_SYNCfor journal I/O
[PATCH 6/6] block: removeRQ_NOIDLEfromWRITE_SYNC
Quoted 13 lines · Vivek Goyal
On Fri, Jul 02, 2010 at 03:58:13PM -0400, Jeff Moyer wrote:
[..]
Quoted 9 lines
Changes from the last posting:
- Yielding no longer expires the current queue. Instead, it sets up new requests from the target process so that they are issued in the yielding process' cfqq. This means that we don't need to worry about losing group or workload share.
- Journal commits are now synchronous I/Os, which was required to get any sort of performance out of thefs_markprocess in the presence of a competing reader.
-WRITE_SYNCI/O no longer setsRQ_NOIDLE, for a similar reason.
Quoted 8 lines
Hi Jeff,
So this patchset relies on idling on
WRITE_SYNCqueues. Though in general we don't have examples that why one should idle on processes doingWRITE_SYNCIO because previous IO does not tell anything about the upcoming IO. I am bringing up this point again to make sure that fundamentally we agree that continue to idle onWRITE_SYNCis the right thing to do otherwise this patch will fall apart.
I think a mail server would be an example of an application that might do this. I'll see if I can get a real world test case (or perhaps some real world data) and verify that.
I agree that if we choose not to idle on write's, then this approach can be thrown out the window.
Quoted 6 lines
I have yet to go through the patch in detail but allowing other queue to dispatch requests in the same queue sounds like queue merging. So can we use that semantics to say
elv_merge_context()orelv_merge_queue()instead ofelv_yield(). In the code we can just merge the two queues when the next request comes in and separate them out at the slice expiry I guess.
I considered that approach, but then you run into all of the questions about losing fairness across workloads and across groups. I believe the approach I've taken here is *significantly* simpler than merging and unmerging would be.
Cheers,
Jeff
Hi Jeff,
Quoted 9 lines · Jeff Moyer
Hi,
Running iozone or
fs_markwith fsync enabled, the performance of CFQ is far worse than that of deadline for enterprise class storage when dealing with file sizes of 8MB or less. I used the following command line as a representative test case:fs_mark -S 1 -D 10000 -N 100000 -d /mnt/test/fs_mark -s 65536 -t 1 -w 4096 -F
I ran the script with "35-rc4 + this patch version" for an ocfs2 volume, and get no hang now. Thanks for the work. I also have some number for you. See below.
Quoted 37 lines
Because the iozone process is issuing synchronous writes, it is put onto CFQ's SYNC service tree. The significance of this is that CFQ will idle for up to 8ms waiting for requests on such queues. So, what happens is that the iozone process will issue, say, 64KB worth of write I/O. That I/O will just land in the page cache. Then, the iozone process does an fsync which forces those I/Os to disk as synchronous writes. Then, the file system's fsync method is invoked, and for ext3/4, it calls
log_start_commitfollowed bylog_wait_commit. Because those synchronous writes were forced out in the context of the iozone process, CFQ will now idle on iozone's cfqq waiting for more I/O. However, iozone's progress is gated by the journal thread, now.With this patch series applied (in addition to the two other patches I sent [1]), CFQ now achieves 530.82 files / second.
I also wanted to improve the performance of the fsync-ing process in the presence of a competing sequential reader. The workload I used for that was a fio job that did sequential buffered 4k reads while running the
fs_markprocess. The run-time was 30 seconds, except where otherwise noted.Deadline got 450 files/second while achieving a throughput of 78.2 MB/s for the sequential reader. CFQ, unpatched, did not finish an
fs_markrun in 30 seconds. I had to bump the time of the test up to 5 minutes, and then CFQ saw anfs_markperformance of 6.6 files/second and sequential reader throughput of 137.2MB/s.The
fs_markprocess was being starved as theWRITE_SYNCI/O is marked withRQ_NOIDLE, and regular WRITES are part of the async workload by default. So, a single request would be served from either thefs_markprocess or the journal thread, and then they would give up the I/O scheduler.After applying this patch set, CFQ can now perform 113.2 files/second while achieving a throughput of 78.6 MB/s for the sequential reader. In table form, the results (all averages of 5 runs) look like this:
Quoted 6 lines
just just
fs_markfio mixed
-------------------------------+--------------deadline 529.44 151.4 | 450.0 78.2 vanilla cfq 107.88 164.4 | 6.6 137.2 patched cfq 530.82 158.7 | 113.2 78.6
Just some updates from the test of ocfs2.
fs_mark
------------------------
deadline 386.3 vanilla cfq 59.7 patched cfq 366.2
So there is really a fantastic improvement at least from what fs_mark gives us. Great thanks.
Regards,
Tao