Throttled background buffered writeback
Subsystems (12)
PATCH v6 1/1 Throttled background buffered writeback
Hi,
Since the dawn of time, our background buffered writeback has sucked. When we do background buffered writeback, it should have little impact on foreground activity. That's the definition of background activity... But for as long as I can remember, heavy buffered writers have not behaved like that. For instance, if I do something like this:
$ dd if=/dev/zero of=foo bs=1M count=10k
on my laptop, and then try and start chrome, it basically won't start before the buffered writeback is done. Or, for server oriented workloads, where installation of a big RPM (or similar) adversely impacts database reads or sync writes. When that happens, I get people yelling at me.
I have posted plenty of results previously, I'll keep it shorter this time. Here's a run on my laptop, using read-to-pipe-async for reading a 5g file, and rewriting it. You can find this test program in the fio git repo.
4.6-rc3:
$ t/read-to-pipe-async -f ~/5g > 5g-new
Latency percentiles (usec) (READERS)
50.0000th: 2 75.0000th: 3 90.0000th: 5 95.0000th: 7 99.0000th: 43 99.5000th: 77 99.9000th: 9008 99.9900th: 91008 99.9990th: 286208 99.9999th: 347648 Over=1251, min=0, max=358081 Latency percentiles (usec) (WRITERS) 50.0000th: 4 75.0000th: 8 90.0000th: 13 95.0000th: 15 99.0000th: 32 99.5000th: 43 99.9000th: 81 99.9900th: 2372 99.9990th: 104320 99.9999th: 349696 Over=63, min=1, max=358321
Read rate (KB/sec) : 91859
Write rate (KB/sec): 91859
4.6-rc3 + wb-buf-throttle
Latency percentiles (usec) (READERS)
50.0000th: 2 75.0000th: 3 90.0000th: 5 95.0000th: 8 99.0000th: 48 99.5000th: 79 99.9000th: 5304 99.9900th: 22496 99.9990th: 29408 99.9999th: 33728 Over=860, min=0, max=37599 Latency percentiles (usec) (WRITERS) 50.0000th: 4 75.0000th: 9 90.0000th: 14 95.0000th: 16 99.0000th: 34 99.5000th: 45 99.9000th: 87 99.9900th: 1342 99.9990th: 13648 99.9999th: 21280 Over=29, min=1, max=30457
Read rate (KB/sec) : 95832
Write rate (KB/sec): 95832
Better throughput and tighter latencies, for both reads and writes. That's hard not to like.
The above was the why. The how is basically throttling background writeback. We still want to issue big writes from the vm side of things, so we get nice and big extents on the file system end. But we don't need to flood the device with THOUSANDS of requests for background writeback. For most devices, we don't need a whole lot to get decent throughput.
This adds some simple blk-wb code that keeps limits how much buffered writeback we keep in flight on the device end. It's all about managing the queues on the hardware side. The big change in this version is that it should be pretty much auto-tuning - you no longer have to set a given percentage of writeback bandwidth. I've implemented something similar to CoDel to manage the writeback queue. See the last patch for a full description, but the tldr is that we monitor min latencies over a window of time, and scale up/down the queue based on that. This needs a minimum of tunables, and it stays out of the way, if your device is fast enough. There's a single tunable now, wb_last_usec, that simply sets this latency target. Most people won't have to touch this, it'll work pretty well just being in the ballpark.
I welcome testing. If you are sick of Linux bogging down when buffered writes are happening, then this is for you, laptop or server. The patchset is fully stable, I have not observed problems. It passes full xfstest runs, and a variety of benchmarks as well. It works equally well on blk-mq/scsi-mq, and "classic" setups.
You can also find this in a branch in the block git repo:
git://git.kernel.dk/linux-block.git wb-buf-throttle
Note that I rebase this branch when I collapse patches. The wb-buf-throttle-v6 will remain the same as this version. I know there are a bunch of folks running this patchset with success. If there's any interest in a version that applies cleanly to Linux v4.7, let me know, and I can provide one.
the patches here on top of my for-next. A full patch against Linus' current tree can also be downloaded here:
http://brick.kernel.dk/snaps/wb-buf-throttle-v6.patch
Changes since v5
- Rebased on top of 4.8-rc4, drop parts of the series that is now in mainline.
- Fixes for QD=1 devices, should make them perform better.
- Fix for hang with disabling WBT with IO in flight
- Change in the sync issue/completion logic. Previously we used whether this IO was tracked or not (eg was a buffered write), this has now been changed to just look at reads. This is a better metric, and should improve behavior.
- Add some more comments to the code, explaining how it works.
Changes since v4
- Add some documentation for the two queue sysfs files
- Kill off wb_stats sysfs file. Use the trace points to get this info now.
- Various work around making this block layer agnostic. The main code now resides in lib/wbt.c and can be plugged into NFS as well, for instance.
- Fix an issue with double completions on the block layer side.
- Fix an issue where a long sync issue was disregarded, if the stat sample weren't valid.
- Speed up the division in rwb_arm_timer().
- Add logic to scale back up for 'unknown' latency events.
- Don't track sync issue timestamp of wbt is disabled.
- Drop the dirty/writeback page inc/dec patch. We don't need it, and it was racy.
- Move block/blk-wb.c to lib/wbt.c
Changes since v3
- Re-do the mm/ writheback parts. Add REQ_BG for background writes, and don't overload the wbc 'reason' for writeback decisions.
- Add tracking for when apps are sleeping waiting for a page to complete.
- Change wbc_to_write() to wbc_to_write_cmd().
- Use atomic_t for the balance_dirty_pages() sleep count.
- Add a basic scalable block stats tracking framework.
- Rewrite blk-wb core as described above, to dynamically adapt. This is a big change, see the last patch for a full description of it.
- Add tracing to blk-wb, instead of using debug printk's.
- Rebased to 4.6-rc3 (ish)
Changes since v2
- Switch from wb_depth to wb_percent, as that's an easier tunable.
- Add the patch to track device depth on the block layer side.
- Cleanup the limiting code.
- Don't use a fixed limit in the wb wait, since it can change between wakeups.
- Minor tweaks, fixups, cleanups.
Changes since v1
- Drop sync() WB_SYNC_NONE -> WB_SYNC_ALL change
- wb_start_writeback() fills in background/reclaim/sync info in the writeback work, based on writeback reason.
- Use WRITE_SYNC for reclaim/sync IO
- Split balance_dirty_pages() sleep change into separate patch
- Drop get_request() u64 flag change, set the bit on the request directly after-the-fact.
- Fix wrong sysfs return value
- Various small cleanups
Documentation/block/queue-sysfs.txt | 13 block/Kconfig | 1 block/Makefile | 2 block/blk-core.c | 22 + block/blk-mq-sysfs.c | 47 ++ block/blk-mq.c | 42 ++ block/blk-mq.h | 3 block/blk-settings.c | 15 block/blk-stat.c | 205 ++++++++++++ block/blk-stat.h | 17 + block/blk-sysfs.c | 145 ++++++++ block/cfq-iosched.c | 12 drivers/scsi/scsi.c | 3 fs/buffer.c | 2 fs/f2fs/data.c | 2 fs/f2fs/node.c | 2 fs/gfs2/meta_io.c | 3 fs/mpage.c | 2 fs/xfs/xfs_aops.c | 7 include/linux/backing-dev-defs.h | 2 include/linux/blk_types.h | 16 include/linux/blkdev.h | 19 + include/linux/fs.h | 3 include/linux/wbt.h | 118 +++++++ include/linux/writeback.h | 10 include/trace/events/wbt.h | 122 +++++++ lib/Kconfig | 4 lib/Makefile | 1 lib/wbt.c | 587 ++++++++++++++++++++++++++++++++++++ mm/backing-dev.c | 1 mm/page-writeback.c | 2 31 files changed, 1414 insertions(+), 16 deletions(-)
Signature · 1 line
Jens Axboe
PATCH 1/8 block: add WRITE_BG
This adds a new request flag, REQ_BG, that callers can use to tell the block layer that this is background (non-urgent) IO.
--- include/linux/blk_types.h | 4 +++- include/linux/fs.h | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-)
include/linux/blk_types.h +3 -1
@@ -155,6 +155,7 @@ enum rq_flag_bits { __REQ_INTEGRITY,/* I/O includes block integrity payload */ __REQ_FUA,/* forced unit access */ __REQ_PREFLUSH,/* request for cache flush */ + __REQ_BG,/* background activity */ /* bio only flags */ __REQ_RAHEAD, /* read ahead, can fail anytime */
@@ -198,7 +199,7 @@ enum rq_flag_bits { (REQ_FAILFAST_DEV | REQ_FAILFAST_TRANSPORT | REQ_FAILFAST_DRIVER)#define REQ_COMMON_MASK \ (REQ_FAILFAST_MASK | REQ_SYNC | REQ_META | REQ_PRIO | REQ_NOIDLE | \ - REQ_PREFLUSH | REQ_FUA | REQ_INTEGRITY | REQ_NOMERGE) + REQ_PREFLUSH | REQ_FUA | REQ_INTEGRITY | REQ_NOMERGE | REQ_BG)#define REQ_CLONE_MASK REQ_COMMON_MASK/* This mask is used for both bio and request merge checking */
@@ -223,6 +224,7 @@ enum rq_flag_bits {#define REQ_COPY_USER (1ULL << __REQ_COPY_USER)#define REQ_PREFLUSH (1ULL << __REQ_PREFLUSH)#define REQ_FLUSH_SEQ (1ULL << __REQ_FLUSH_SEQ) +#define REQ_BG (1ULL << __REQ_BG)#define REQ_IO_STAT (1ULL << __REQ_IO_STAT)#define REQ_MIXED_MERGE (1ULL << __REQ_MIXED_MERGE)#define REQ_PM (1ULL << __REQ_PM)
include/linux/fs.h +3 -0
@@ -189,6 +189,8 @@ typedef int (dio_iodone_t)(struct kiocb *iocb, loff_t offset,* WRITE_FLUSH_FUA Combination of WRITE_FLUSH and FUA. The IO is preceded * by a cache flush and data is guaranteed to be on * non-volatile media on completion. +* WRITE_BG Background write. This is for background activity like +* the periodic flush and background threshold writeback * */ #define RW_MASK REQ_OP_WRITE
@@ -202,6 +204,7 @@ typedef int (dio_iodone_t)(struct kiocb *iocb, loff_t offset,#define WRITE_FLUSH (REQ_SYNC | REQ_NOIDLE | REQ_PREFLUSH)#define WRITE_FUA (REQ_SYNC | REQ_NOIDLE | REQ_FUA)#define WRITE_FLUSH_FUA (REQ_SYNC | REQ_NOIDLE | REQ_PREFLUSH | REQ_FUA) +#define WRITE_BG (REQ_NOIDLE | REQ_BG)/* * Attribute flags. These should be or-ed together to figure out what
Signature · 1 line
2.7.4
PATCH 2/8 writeback: add wbc_to_write_flags()
In reply to Jens AxboeAdd wbc_to_write_flags(), which returns the write modifier flags to use, based on a struct writeback_control. No functional changes in this patch, but it prepares us for factoring other wbc fields for write type.
--- fs/buffer.c | 2 +- fs/f2fs/data.c | 2 +- fs/f2fs/node.c | 2 +- fs/gfs2/meta_io.c | 3 +-- fs/mpage.c | 2 +- fs/xfs/xfs_aops.c | 7 +++---- include/linux/writeback.h | 8 ++++++++ 7 files changed, 16 insertions(+), 10 deletions(-)
fs/buffer.c +1 -1
@@ -1698,7 +1698,7 @@ int __block_write_full_page(struct inode *inode, struct page *page,struct buffer_head *bh, *head;unsigned int blocksize, bbits;int nr_underway =0 ; -int write_flags = (wbc->sync_mode ==WB_SYNC_ALL ?WRITE_SYNC :0 ); +int write_flags =wbc_to_write_flags (wbc); head =create_page_buffers (page, inode, (1 << BH_Dirty)|(1 << BH_Uptodate));
fs/f2fs/data.c +1 -1
@@ -1240,7 +1240,7 @@ static int f2fs_write_data_page(struct page *page, .sbi = sbi, .type = DATA, .op = REQ_OP_WRITE, - .op_flags = (wbc->sync_mode == WB_SYNC_ALL) ? WRITE_SYNC : 0, + .op_flags = wbc_to_write_flags(wbc), .page = page, .encrypted_page = NULL, };
fs/f2fs/node.c +1 -1
@@ -1561,7 +1561,7 @@ static int f2fs_write_node_page(struct page *page, .sbi = sbi, .type = NODE, .op = REQ_OP_WRITE, - .op_flags = (wbc->sync_mode == WB_SYNC_ALL) ? WRITE_SYNC : 0, + .op_flags = wbc_to_write_flags(wbc), .page = page, .encrypted_page = NULL, };
fs/gfs2/meta_io.c +1 -2
@@ -37,8 +37,7 @@ static int gfs2_aspace_writepage(struct page *page, struct writeback_control *wb {struct buffer_head *bh, *head;int nr_underway =0 ; -int write_flags =REQ_META |REQ_PRIO | - (wbc->sync_mode ==WB_SYNC_ALL ?WRITE_SYNC :0 ); +int write_flags =REQ_META |REQ_PRIO |wbc_to_write_flags (wbc);BUG_ON (!PageLocked (page));BUG_ON (!page_has_buffers (page));
fs/mpage.c +1 -1
@@ -489,7 +489,7 @@ static int __mpage_writepage(struct page *page, struct writeback_control *wbc,struct buffer_head map_bh;loff_t i_size =i_size_read (inode);int ret =0 ; -int op_flags = (wbc->sync_mode ==WB_SYNC_ALL ?WRITE_SYNC :0 ); +int op_flags =wbc_to_write_flags (wbc);if (page_has_buffers (page)) {struct buffer_head *head =page_buffers (page);
fs/xfs/xfs_aops.c +3 -4
@@ -447,8 +447,8 @@ xfs_submit_ioend( ioend->io_bio->bi_private = ioend; ioend->io_bio->bi_end_io = xfs_end_bio; -bio_set_op_attrs (ioend->io_bio,REQ_OP_WRITE , - (wbc->sync_mode ==WB_SYNC_ALL ) ?WRITE_SYNC :0 ); +bio_set_op_attrs (ioend->io_bio,REQ_OP_WRITE ,wbc_to_write_flags (wbc)); +/* * If we are failing the IO now, just mark the ioend with an * error and finish it. This will run IO completion immediately
@@ -519,8 +519,7 @@ xfs_chain_bio(bio_chain (ioend->io_bio, new);bio_get (ioend->io_bio);/* for xfs_destroy_ioend */ -bio_set_op_attrs (ioend->io_bio,REQ_OP_WRITE , - (wbc->sync_mode ==WB_SYNC_ALL ) ?WRITE_SYNC :0 ); +bio_set_op_attrs (ioend->io_bio,REQ_OP_WRITE ,wbc_to_write_flags (wbc));submit_bio (ioend->io_bio); ioend->io_bio = new; }
include/linux/writeback.h +8 -0
@@ -100,6 +100,14 @@ struct writeback_control {#endif }; +static inline int wbc_to_write_flags (struct writeback_control *wbc) +{ +if (wbc->sync_mode ==WB_SYNC_ALL ) +return WRITE_SYNC ; + +return WRITE ; +} +/* * A wb_domain represents a domain that wb's (bdi_writeback's) belong to * and are measured against each other in. There always is one global
Signature · 1 line
2.7.4
PATCH 3/8 writeback: use WRITE_BG for kupdate and background writeback
In reply to Jens AxboeIf we're doing background type writes, then use the appropriate write command for that.
--- include/linux/writeback.h | 2 ++ 1 file changed, 2 insertions(+)
include/linux/writeback.h +2 -0
@@ -104,6 +104,8 @@ static inline int wbc_to_write_flags(struct writeback_control *wbc) {if (wbc->sync_mode ==WB_SYNC_ALL )return WRITE_SYNC ; +else if (wbc->for_kupdate || wbc->for_background) +return WRITE_BG ;return WRITE ; }
Signature · 1 line
2.7.4
PATCH 4/8 writeback: track if we're sleeping on progress in balance_dirty_pages()
In reply to Jens AxboeNote in the bdi_writeback structure if a task is currently being limited in balance_dirty_pages(), waiting for writeback to proceed.
--- include/linux/backing-dev-defs.h | 2 ++ mm/backing-dev.c | 1 + mm/page-writeback.c | 2 ++ 3 files changed, 5 insertions(+)
include/linux/backing-dev-defs.h +2 -0
@@ -116,6 +116,8 @@ struct bdi_writeback {struct list_head work_list;struct delayed_work dwork;/* work item used for writeback */ +atomic_t dirty_sleeping;/* waiting on dirty limit exceeded */ +struct list_head bdi_node;/* anchored at bdi->wb_list */ #ifdef CONFIG_CGROUP_WRITEBACK
mm/backing-dev.c +1 -0
@@ -310,6 +310,7 @@ static int wb_init(struct bdi_writeback *wb, struct backing_dev_info *bdi,spin_lock_init (&wb->work_lock);INIT_LIST_HEAD (&wb->work_list);INIT_DELAYED_WORK (&wb->dwork, wb_workfn); +atomic_set (&wb->dirty_sleeping,0 ); wb->congested =wb_congested_get_create (bdi, blkcg_id, gfp);if (!wb->congested)
mm/page-writeback.c +2 -0
@@ -1778,7 +1778,9 @@ pause: pause, start_time);__set_current_state (TASK_KILLABLE ); +atomic_inc (&wb->dirty_sleeping);io_schedule_timeout (pause); +atomic_dec (&wb->dirty_sleeping); current->dirty_paused_when = now + pause; current->nr_dirtied =0 ;
Signature · 1 line
2.7.4
PATCH 5/8 block: add code to track actual device queue depth
In reply to Jens AxboeFor blk-mq, ->nr_requests does track queue depth, at least at init time. But for the older queue paths, it's simply a soft setting. On top of that, it's generally larger than the hardware setting on purpose, to allow backup of requests for merging.
Fill a hole in struct request with a 'queue_depth' member, that drivers can call to more closely inform the block layer of the real queue depth.
--- block/blk-settings.c | 12 ++++++++++++ drivers/scsi/scsi.c | 3 +++ include/linux/blkdev.h | 11 +++++++++++ 3 files changed, 26 insertions(+)
block/blk-settings.c +12 -0
@@ -832,6 +832,18 @@ void blk_queue_flush_queueable(struct request_queue *q, bool queueable)EXPORT_SYMBOL_GPL (blk_queue_flush_queueable);/** +* blk_set_queue_depth - tell the block layer about the device queue depth +* @q: the request queue for the device +* @depth: queue depth +* +*/ +void blk_set_queue_depth (struct request_queue *q,unsigned int depth) +{ + q->queue_depth = depth; +} +EXPORT_SYMBOL (blk_set_queue_depth); + +/** * blk_queue_write_cache - configure queue's write cache * @q: the request queue for the device * @wc: write back cache on or off
drivers/scsi/scsi.c +3 -0
@@ -621,6 +621,9 @@ int scsi_change_queue_depth(struct scsi_device *sdev, int depth)wmb (); } +if (sdev->request_queue) +blk_set_queue_depth (sdev->request_queue, depth); +return sdev->queue_depth; }EXPORT_SYMBOL (scsi_change_queue_depth);
include/linux/blkdev.h +11 -0
@@ -327,6 +327,8 @@ struct request_queue {struct blk_mq_ctx __percpu *queue_ctx;unsigned int nr_queues; +unsigned int queue_depth; +/* hw dispatch queues */ struct blk_mq_hw_ctx **queue_hw_ctx;unsigned int nr_hw_queues;
@@ -683,6 +685,14 @@ static inline bool blk_write_same_mergeable(struct bio *a, struct bio *b)return false; } +static inline unsigned int blk_queue_depth (struct request_queue *q) +{ +if (q->queue_depth) +return q->queue_depth; + +return q->nr_requests; +} +/* * q->prep_rq_fn return values */
@@ -999,6 +1009,7 @@ extern void blk_limits_io_min(struct queue_limits *limits, unsigned int min);extern void blk_queue_io_min (struct request_queue *q,unsigned int min);extern void blk_limits_io_opt (struct queue_limits *limits,unsigned int opt);extern void blk_queue_io_opt (struct request_queue *q,unsigned int opt); +extern void blk_set_queue_depth (struct request_queue *q,unsigned int depth);extern void blk_set_default_limits (struct queue_limits *lim);extern void blk_set_stacking_limits (struct queue_limits *lim); extern int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,
Signature · 1 line
2.7.4
PATCH 6/8 block: add scalable completion tracking of requests
In reply to Jens AxboeFor legacy block, we simply track them in the request queue. For blk-mq, we track them on a per-sw queue basis, which we can then sum up through the hardware queues and finally to a per device state.
The stats are tracked in, roughly, 0.1s interval windows.
Add sysfs files to display the stats.
--- block/Makefile | 2 +- block/blk-core.c | 4 + block/blk-mq-sysfs.c | 47 +++++++++++ block/blk-mq.c | 14 ++++ block/blk-mq.h | 3 + block/blk-stat.c | 204 ++++++++++++++++++++++++++++++++++++++++++++++ block/blk-stat.h | 17 ++++ block/blk-sysfs.c | 26 ++++++ include/linux/blk_types.h | 12 +++ include/linux/blkdev.h | 4 + 10 files changed, 332 insertions(+), 1 deletion(-) create mode 100644 block/blk-stat.c create mode 100644 block/blk-stat.h
block/Makefile +1 -1
@@ -5,7 +5,7 @@ obj-$(CONFIG_BLOCK) := bio.o elevator.o blk-core.o blk-tag.o blk-sysfs.o \ blk-flush.o blk-settings.o blk-ioc.o blk-map.o \ blk-exec.o blk-merge.o blk-softirq.o blk-timeout.o \ - blk-lib.o blk-mq.o blk-mq-tag.o \ + blk-lib.o blk-mq.o blk-mq-tag.o blk-stat.o \ blk-mq-sysfs.o blk-mq-cpu.o blk-mq-cpumap.o ioctl.o \ genhd.o scsi_ioctl.o partition-generic.o ioprio.o \ badblocks.o partitions/
block/blk-core.c +4 -0
@@ -2475,6 +2475,8 @@ void blk_start_request(struct request *req) {blk_dequeue_request (req); + req->issue_time =ktime_to_ns (ktime_get ()); +/* * We are now handing the request to the hardware, initialize * resid_len to full count and add the timeout handler.
@@ -2542,6 +2544,8 @@ bool blk_update_request(struct request *req, int error, unsigned int nr_bytes)trace_block_rq_complete (req->q, req, nr_bytes); +blk_stat_add (&req->q->rq_stats[rq_data_dir (req)], req); +if (!req->bio)return false;
block/blk-mq-sysfs.c +47 -0
65 lines not on this page · raw message
block/blk-mq.c +14 -0
@@ -29,6 +29,7 @@#include "blk.h" #include "blk-mq.h" #include "blk-mq-tag.h" +#include "blk-stat.h" static DEFINE_MUTEX (all_q_mutex);static LIST_HEAD (all_q_list);
@@ -400,10 +401,19 @@ static void blk_mq_ipi_complete_request(struct request *rq)put_cpu (); } +static void blk_mq_stat_add (struct request *rq) +{ +struct blk_rq_stat *stat = &rq->mq_ctx->stat[rq_data_dir (rq)]; + +blk_stat_add (stat, rq); +} +static void __blk_mq_complete_request (struct request *rq) {struct request_queue *q = rq->q; +blk_mq_stat_add (rq); +if (!q->softirq_done_fn)blk_mq_end_request (rq, rq->errors);else
@@ -447,6 +457,8 @@ void blk_mq_start_request(struct request *rq)if (unlikely (blk_bidi_rq (rq))) rq->next_rq->resid_len =blk_rq_bytes (rq->next_rq); + rq->issue_time =ktime_to_ns (ktime_get ()); +blk_add_timer (rq);/*
@@ -1795,6 +1807,8 @@ static void blk_mq_init_cpu_queues(struct request_queue *q,spin_lock_init (&__ctx->lock);INIT_LIST_HEAD (&__ctx->rq_list); __ctx->queue = q; +blk_stat_init (&__ctx->stat[0 ]); +blk_stat_init (&__ctx->stat[1 ]);/* If the cpu isn't online, the cpu is mapped to first hctx */ if (!cpu_online (i))
block/blk-mq.h +3 -0
@@ -1,6 +1,8 @@#ifndef INT_BLK_MQ_H #define INT_BLK_MQ_H +#include "blk-stat.h" +struct blk_mq_tag_set ; struct blk_mq_ctx {
@@ -20,6 +22,7 @@ struct blk_mq_ctx {/* incremented at completion time */ unsigned long ____cacheline_aligned_in_smp rq_completed[2 ]; +struct blk_rq_stat stat[2 ];struct request_queue *queue;struct kobject kobj;
block/blk-stat.c new file +204 -0
204 lines not on this page · raw message
block/blk-stat.h new file +17 -0
@@ -0,0 +1,17 @@ +#ifndef BLK_STAT_H +#define BLK_STAT_H + +/* +* ~0.13s window as a power-of-2 (2^27 nsecs) +*/ +#define BLK_STAT_NSEC 134217728ULL +#define BLK_STAT_MASK ~(BLK_STAT_NSEC - 1) + +void blk_stat_add (struct blk_rq_stat *,struct request *); +void blk_hctx_stat_get (struct blk_mq_hw_ctx *,struct blk_rq_stat *); +void blk_queue_stat_get (struct request_queue *,struct blk_rq_stat *); +void blk_stat_clear (struct request_queue *q); +void blk_stat_init (struct blk_rq_stat *); +void blk_stat_sum (struct blk_rq_stat *,struct blk_rq_stat *); + +#endif
block/blk-sysfs.c +26 -0
@@ -384,6 +384,26 @@ static ssize_t queue_dax_show(struct request_queue *q, char *page)return queue_var_show (blk_queue_dax (q), page); } +static ssize_t print_stat (char *page,struct blk_rq_stat *stat,const char *pre) +{ +return sprintf (page,"%s samples=%llu, mean=%lld, min=%lld, max=%lld\n" , + pre, (long long ) stat->nr_samples, + (long long ) stat->mean, (long long ) stat->min, + (long long ) stat->max); +} + +static ssize_t queue_stats_show (struct request_queue *q,char *page) +{ +struct blk_rq_stat stat[2 ]; +ssize_t ret; + +blk_queue_stat_get (q, stat); + + ret =print_stat (page, &stat[0 ],"read :" ); + ret +=print_stat (page + ret, &stat[1 ],"write:" ); +return ret; +} +static struct queue_sysfs_entry queue_requests_entry = { .attr = {.name ="nr_requests" , .mode =S_IRUGO |S_IWUSR }, .show = queue_requests_show,
@@ -526,6 +546,11 @@ static struct queue_sysfs_entry queue_dax_entry = { .show = queue_dax_show, }; +static struct queue_sysfs_entry queue_stats_entry = { + .attr = {.name ="stats" , .mode =S_IRUGO }, + .show = queue_stats_show, +}; +static struct attribute *default_attrs[] = { &queue_requests_entry.attr, &queue_ra_entry.attr,
@@ -553,6 +578,7 @@ static struct attribute *default_attrs[] = { &queue_poll_entry.attr, &queue_wc_entry.attr, &queue_dax_entry.attr, + &queue_stats_entry.attr, NULL, };
include/linux/blk_types.h +12 -0
@@ -266,4 +266,16 @@ static inline unsigned int blk_qc_t_to_tag(blk_qc_t cookie) return cookie & ((1u << BLK_QC_T_SHIFT) - 1); } +#define BLK_RQ_STAT_BATCH 64 + +struct blk_rq_stat { +s64 mean; +u64 min; +u64 max; +s32 nr_samples; +s32 nr_batch; +u64 batch; +s64 time; +}; +#endif /* __LINUX_BLK_TYPES_H */
include/linux/blkdev.h +4 -0
@@ -151,6 +151,7 @@ struct request {struct gendisk *rq_disk;struct hd_struct *part;unsigned long start_time; +s64 issue_time;#ifdef CONFIG_BLK_CGROUP struct request_list *rl;/* rl this rq is alloced from */ unsigned long long start_time_ns;
@@ -414,6 +415,9 @@ struct request_queue {unsigned int nr_sorted;unsigned int in_flight[2 ]; + +struct blk_rq_stat rq_stats[2 ]; +/* * Number of active block driver functions for which blk_drain_queue() * must wait. Must be incremented around functions that unlock the
Signature · 1 line
2.7.4
PATCH 7/8 wbt: add general throttling mechanism
In reply to Jens AxboeWe can hook this up to the block layer, to help throttle buffered writes. Or NFS can tap into it, to accomplish the same.
wbt registers a few trace points that can be used to track what is happening in the system:
wbt_lat: 259:0: latency 2446318wbt_stat: 259:0: rmean=2446318, rmin=2446318, rmax=2446318, rsamples=1,
wmean=518866, wmin=15522, wmax=5330353, wsamples=57
wbt_step: 259:0: step down: step=1, window=72727272, background=8, normal=16, max=32
This shows a sync issue event (wbt_lat) that exceeded it's time. wbt_stat dumps the current read/write stats for that window, and wbt_step shows a step down event where we now scale back writes. Each trace includes the device, 259:0 in this case.
--- include/linux/wbt.h | 118 +++++++++ include/trace/events/wbt.h | 122 ++++++++++ lib/Kconfig | 4 + lib/Makefile | 1 + lib/wbt.c | 587 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 832 insertions(+) create mode 100644 include/linux/wbt.h create mode 100644 include/trace/events/wbt.h create mode 100644 lib/wbt.c
include/linux/wbt.h new file +118 -0
@@ -0,0 +1,118 @@ +#ifndef WB_THROTTLE_H +#define WB_THROTTLE_H + +#include <linux/atomic.h> +#include <linux/wait.h> +#include <linux/timer.h> +#include <linux/ktime.h> + +enum { +ISSUE_STAT_TRACKED =1ULL <<63 , +ISSUE_STAT_READ =1ULL <<62 , +ISSUE_STAT_MASK =ISSUE_STAT_TRACKED |ISSUE_STAT_READ , +ISSUE_STAT_TIME_MASK = ~ISSUE_STAT_MASK , + +WBT_TRACKED =1 , +WBT_READ =2 , +}; + +struct wb_issue_stat { +u64 time; +}; + +static inline void wbt_issue_stat_set_time (struct wb_issue_stat *stat) +{ + stat->time = (stat->time &ISSUE_STAT_MASK ) | + (ktime_to_ns (ktime_get ()) &ISSUE_STAT_TIME_MASK ); +} + +static inline u64 wbt_issue_stat_get_time (struct wb_issue_stat *stat) +{ +return stat->time &ISSUE_STAT_TIME_MASK ; +} + +static inline void wbt_mark_tracked (struct wb_issue_stat *stat) +{ + stat->time |=ISSUE_STAT_TRACKED ; +} + +static inline void wbt_clear_state (struct wb_issue_stat *stat) +{ + stat->time &= ~(ISSUE_STAT_TRACKED |ISSUE_STAT_READ ); +} + +static inline bool wbt_tracked (struct wb_issue_stat *stat) +{ +return (stat->time &ISSUE_STAT_TRACKED ) !=0 ; +} + +static inline void wbt_mark_read (struct wb_issue_stat *stat) +{ + stat->time |=ISSUE_STAT_READ ; +} + +static inline bool wbt_is_read (struct wb_issue_stat *stat) +{ +return (stat->time &ISSUE_STAT_READ ) !=0 ; +} + +struct wb_stat_ops { +void (*get)(void *,struct blk_rq_stat *); +void (*clear)(void *); +}; + +struct rq_wb { +/* +* Settings that govern how we throttle +*/ +unsigned int wb_background;/* background writeback */ +unsigned int wb_normal;/* normal writeback */ +unsigned int wb_max;/* max throughput writeback */ +unsigned int scale_step; + +u64 win_nsec;/* default window size */ +u64 cur_win_nsec;/* current window size */ + +/* +* Number of consecutive periods where we don't have enough +* information to make a firm scale up/down decision. +*/ +unsigned int unknown_cnt; + +struct timer_list window_timer; + +s64 sync_issue; +void *sync_cookie; + +unsigned int wc; +unsigned int queue_depth; + +unsigned long last_issue;/* last non-throttled issue */ +unsigned long last_comp;/* last non-throttled comp */ +unsigned long min_lat_nsec; +struct backing_dev_info *bdi; +struct request_queue *q; +wait_queue_head_t wait; +atomic_t inflight; + +struct wb_stat_ops *stat_ops; +void *ops_data; +}; + +struct backing_dev_info ; + +void __wbt_done (struct rq_wb *); +void wbt_done (struct rq_wb *,struct wb_issue_stat *); +unsigned int wbt_wait (struct rq_wb *,unsigned int ,spinlock_t *); +struct rq_wb *wbt_init (struct backing_dev_info *,struct wb_stat_ops *,void *); +void wbt_exit (struct rq_wb *); +void wbt_update_limits (struct rq_wb *); +void wbt_requeue (struct rq_wb *,struct wb_issue_stat *); +void wbt_issue (struct rq_wb *,struct wb_issue_stat *); +void wbt_disable (struct rq_wb *); +void wbt_track (struct wb_issue_stat *,unsigned int ); + +void wbt_set_queue_depth (struct rq_wb *,unsigned int ); +void wbt_set_write_cache (struct rq_wb *,bool ); + +#endif
include/trace/events/wbt.h new file +122 -0
122 lines not on this page · raw message
lib/Kconfig +4 -0
@@ -550,4 +550,8 @@ config STACKDEPOT bool select STACKTRACE +config WBT + bool + select SCALE_BITMAP + endmenu
lib/Makefile +1 -0
@@ -178,6 +178,7 @@ obj-$(CONFIG_SG_SPLIT) += sg_split.o obj-$(CONFIG_SG_POOL) += sg_pool.o obj-$(CONFIG_STMP_DEVICE) += stmp_device.o obj-$(CONFIG_IRQ_POLL) += irq_poll.o +obj-$(CONFIG_WBT) += wbt.o obj-$(CONFIG_STACKDEPOT) += stackdepot.o KASAN_SANITIZE_stackdepot.o := n
lib/wbt.c new file +587 -0
587 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH 8/8 writeback: throttle buffered writeback
In reply to Jens AxboeTest patch that throttles buffered writeback to make it a lot more smooth, and has way less impact on other system activity. Background writeback should be, by definition, background activity. The fact that we flush huge bundles of it at the time means that it potentially has heavy impacts on foreground workloads, which isn't ideal. We can't easily limit the sizes of writes that we do, since that would impact file system layout in the presence of delayed allocation. So just throttle back buffered writeback, unless someone is waiting for it.
The algorithm for when to throttle takes its inspiration in the CoDel networking scheduling algorithm. Like CoDel, blk-wb monitors the minimum latencies of requests over a window of time. In that window of time, if the minimum latency of any request exceeds a given target, then a scale count is incremented and the queue depth is shrunk. The next monitoring window is shrunk accordingly. Unlike CoDel, if we hit a window that exhibits good behavior, then we simply increment the scale count and re-calculate the limits for that scale value. This prevents us from oscillating between a close-to-ideal value and max all the time, instead remaining in the windows where we get good behavior.
The patch registers two sysfs entries. The first one, 'wb_window_usec', defines the window of monitoring. The second one, 'wb_lat_usec', sets the latency target for the window. It defaults to 2 msec for non-rotational storage, and 75 msec for rotational storage. Setting this value to '0' disables blk-wb. Generally, a user would not have to touch these settings.
We don't enable WBT on devices that are managed with CFQ, and have a non-root block cgroup attached. If we have a proportional share setup on this particular disk, then the wbt throttling will interfere with that. We don't have a strong need for wbt for that case, since we will rely on CFQ doing that for us.
--- Documentation/block/queue-sysfs.txt | 13 ++++ block/Kconfig | 1 + block/blk-core.c | 20 +++++- block/blk-mq.c | 30 ++++++++- block/blk-settings.c | 3 + block/blk-stat.c | 5 +- block/blk-sysfs.c | 119 ++++++++++++++++++++++++++++++++++++ block/cfq-iosched.c | 12 ++++ include/linux/blkdev.h | 6 +- 9 files changed, 200 insertions(+), 9 deletions(-)
Documentation/block/queue-sysfs.txt +13 -0
@@ -169,5 +169,18 @@ This is the number of bytes the device can write in a single write-same command. A value of '0' means write-same is not supported by this device. +wb_lat_usec (RW) +---------------- +If the device is registered for writeback throttling, then this file shows +the target minimum read latency. If this latency is exceeded in a given +window of time (see wb_window_usec), then the writeback throttling will start +scaling back writes. + +wb_window_usec (RW) +------------------- +If the device is registered for writeback throttling, then this file shows +the value of the monitoring window in which we'll look at the target +latency. See wb_lat_usec. + Jens Axboe <[email protected]>, February 2009
block/Kconfig +1 -0
@@ -4,6 +4,7 @@ menuconfig BLOCK bool "Enable the block layer" if EXPERT default y + select WBT help Provide block layer support for the kernel.
block/blk-core.c +17 -3
@@ -33,6 +33,7 @@#include <linux/ratelimit.h> #include <linux/pm_runtime.h> #include <linux/blk-cgroup.h> +#include <linux/wbt.h> #define CREATE_TRACE_POINTS #include <trace/events/block.h>
@@ -882,6 +883,8 @@ blk_init_allocated_queue(struct request_queue *q, request_fn_proc *rfn, fail:blk_free_flush_queue (q->fq); +wbt_exit (q->rq_wb); + q->rq_wb =NULL ;return NULL ; }EXPORT_SYMBOL (blk_init_allocated_queue);
@@ -1346,6 +1349,7 @@ void blk_requeue_request(struct request_queue *q, struct request *rq)blk_delete_timer (rq);blk_clear_rq_complete (rq);trace_block_rq_requeue (q, rq); +wbt_requeue (q->rq_wb, &rq->wb_stat);if (rq->cmd_flags &REQ_QUEUED )blk_queue_end_tag (q, rq);
@@ -1436,6 +1440,8 @@ void __blk_put_request(struct request_queue *q, struct request *req)/* this is a bio leak */ WARN_ON (req->bio !=NULL ); +wbt_done (q->rq_wb, &req->wb_stat); +/* * Request may not have originated from ll_rw_blk. if not, * it didn't come out of our reserved rq pools
@@ -1667,6 +1673,7 @@ static blk_qc_t blk_queue_bio(struct request_queue *q, struct bio *bio)int el_ret, rw_flags =0 , where =ELEVATOR_INSERT_SORT ;struct request *req;unsigned int request_count =0 ; +unsigned int wb_acct;/* * low level driver can indicate that it wants pages above a
@@ -1719,6 +1726,8 @@ static blk_qc_t blk_queue_bio(struct request_queue *q, struct bio *bio) } get_rq: + wb_acct =wbt_wait (q->rq_wb, bio->bi_opf, q->queue_lock); +/* * This sync check and mask will be re-done in init_request_from_bio(), * but we need to set it earlier to expose the sync flag to the
@@ -1738,11 +1747,15 @@ get_rq:*/ req =get_request (q,bio_data_dir (bio), rw_flags, bio,GFP_NOIO );if (IS_ERR (req)) { +if (wb_acct &WBT_TRACKED ) +__wbt_done (q->rq_wb); bio->bi_error =PTR_ERR (req);bio_endio (bio); goto out_unlock; } +wbt_track (&req->wb_stat, wb_acct); +/* * After dropping the lock and possibly sleeping here, our request * may now be mergeable after it had proven unmergeable (above).
@@ -2475,7 +2488,7 @@ void blk_start_request(struct request *req) {blk_dequeue_request (req); - req->issue_time =ktime_to_ns (ktime_get ()); +wbt_issue (req->q->rq_wb, &req->wb_stat);/* * We are now handing the request to the hardware, initialize
@@ -2713,9 +2726,10 @@ void blk_finish_request(struct request *req, int error)blk_account_io_done (req); -if (req->end_io) +if (req->end_io) { +wbt_done (req->q->rq_wb, &req->wb_stat); req->end_io (req, error); -else { + }else {if (blk_bidi_rq (req))__blk_put_request (req->next_rq->q, req->next_rq);
block/blk-mq.c +27 -3
@@ -22,6 +22,7 @@#include <linux/sched/sysctl.h> #include <linux/delay.h> #include <linux/crash_dump.h> +#include <linux/wbt.h> #include <trace/events/block.h>
@@ -319,6 +320,8 @@ static void __blk_mq_free_request(struct blk_mq_hw_ctx *hctx,if (rq->cmd_flags &REQ_MQ_INFLIGHT )atomic_dec (&hctx->nr_active); + +wbt_done (q->rq_wb, &rq->wb_stat); rq->cmd_flags =0 ;clear_bit (REQ_ATOM_STARTED , &rq->atomic_flags);
@@ -351,6 +354,7 @@ inline void __blk_mq_end_request(struct request *rq, int error)blk_account_io_done (rq);if (rq->end_io) { +wbt_done (rq->q->rq_wb, &rq->wb_stat); rq->end_io (rq, error); }else {if (unlikely (blk_bidi_rq (rq)))
@@ -457,7 +461,7 @@ void blk_mq_start_request(struct request *rq)if (unlikely (blk_bidi_rq (rq))) rq->next_rq->resid_len =blk_rq_bytes (rq->next_rq); - rq->issue_time =ktime_to_ns (ktime_get ()); +wbt_issue (q->rq_wb, &rq->wb_stat);blk_add_timer (rq);
@@ -494,6 +498,7 @@ static void __blk_mq_requeue_request(struct request *rq)struct request_queue *q = rq->q;trace_block_rq_requeue (q, rq); +wbt_requeue (q->rq_wb, &rq->wb_stat);if (test_and_clear_bit (REQ_ATOM_STARTED , &rq->atomic_flags)) {if (q->dma_drain_size &&blk_rq_bytes (rq))
@@ -1312,6 +1317,7 @@ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio)struct blk_plug *plug;struct request *same_queue_rq =NULL ;blk_qc_t cookie; +unsigned int wb_acct;blk_queue_bounce (q, &bio);
@@ -1326,9 +1332,16 @@ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio) blk_attempt_plug_merge(q, bio, &request_count, &same_queue_rq))return BLK_QC_T_NONE ; + wb_acct =wbt_wait (q->rq_wb, bio->bi_opf,NULL ); + rq =blk_mq_map_request (q, bio, &data); -if (unlikely (!rq)) +if (unlikely (!rq)) { +if (wb_acct &WBT_TRACKED ) +__wbt_done (q->rq_wb);return BLK_QC_T_NONE ; + } + +wbt_track (&rq->wb_stat, wb_acct); cookie =blk_tag_to_qc_t (rq->tag, data.hctx->queue_num);
@@ -1405,6 +1418,7 @@ static blk_qc_t blk_sq_make_request(struct request_queue *q, struct bio *bio)struct blk_map_ctx data;struct request *rq;blk_qc_t cookie; +unsigned int wb_acct;blk_queue_bounce (q, &bio);
@@ -1421,9 +1435,16 @@ static blk_qc_t blk_sq_make_request(struct request_queue *q, struct bio *bio) }else request_count =blk_plug_queued_count (q); + wb_acct =wbt_wait (q->rq_wb, bio->bi_opf,NULL ); + rq =blk_mq_map_request (q, bio, &data); -if (unlikely (!rq)) +if (unlikely (!rq)) { +if (wb_acct &WBT_TRACKED ) +__wbt_done (q->rq_wb);return BLK_QC_T_NONE ; + } + +wbt_track (&rq->wb_stat, wb_acct); cookie =blk_tag_to_qc_t (rq->tag, data.hctx->queue_num);
@@ -2147,6 +2168,9 @@ void blk_mq_free_queue(struct request_queue *q)list_del_init (&q->all_q_node);mutex_unlock (&all_q_mutex); +wbt_exit (q->rq_wb); + q->rq_wb =NULL ; +blk_mq_del_queue_tag_set (q);blk_mq_exit_hw_queues (q, set, set->nr_hw_queues);
block/blk-settings.c +3 -0
@@ -840,6 +840,7 @@ EXPORT_SYMBOL_GPL(blk_queue_flush_queueable);void blk_set_queue_depth (struct request_queue *q,unsigned int depth) { q->queue_depth = depth; +wbt_set_queue_depth (q->rq_wb, depth); }EXPORT_SYMBOL (blk_set_queue_depth);
@@ -863,6 +864,8 @@ void blk_queue_write_cache(struct request_queue *q, bool wc, bool fua)else queue_flag_clear (QUEUE_FLAG_FUA , q);spin_unlock_irq (q->queue_lock); + +wbt_set_write_cache (q->rq_wb,test_bit (QUEUE_FLAG_WC , &q->queue_flags)); }EXPORT_SYMBOL_GPL (blk_queue_write_cache);
block/blk-stat.c +3 -2
@@ -162,15 +162,16 @@ void blk_stat_init(struct blk_rq_stat *stat)void blk_stat_add (struct blk_rq_stat *stat,struct request *rq) {s64 now, value; +u64 rq_time =wbt_issue_stat_get_time (&rq->wb_stat); now =ktime_to_ns (ktime_get ()); -if (now < rq->issue_time) +if (now < rq_time)return ;if ((now &BLK_STAT_MASK ) != (stat->time &BLK_STAT_MASK ))__blk_stat_init (stat, now); - value = now - rq->issue_time; + value = now - rq_time;if (value > stat->max) stat->max = value;if (value < stat->min)
block/blk-sysfs.c +119 -0
161 lines not on this page · raw message
block/cfq-iosched.c +12 -0
@@ -3777,6 +3777,18 @@ static void check_blkcg_changed(struct cfq_io_cq *cic, struct bio *bio)return ;/* +* If we have a non-root cgroup, we can depend on that to +* do proper throttling of writes. Turn off wbt for that +* case. +*/ +if (bio_blkcg (bio) != &blkcg_root) { +struct request_queue *q = cfqd->queue; + +if (q->rq_wb) +wbt_disable (q->rq_wb); + } + +/* * Drop reference to queues. New queues will be assigned in new * group upon arrival of fresh requests. */
include/linux/blkdev.h +5 -1
@@ -24,6 +24,7 @@#include <linux/rcupdate.h> #include <linux/percpu-refcount.h> #include <linux/scatterlist.h> +#include <linux/wbt.h> struct module ;struct scsi_ioctl_command ;
@@ -37,6 +38,7 @@ struct bsg_job;struct blkcg_gq ;struct blk_flush_queue ;struct pr_ops ; +struct rq_wb ;#define BLKDEV_MIN_RQ 4#define BLKDEV_MAX_RQ 128/* Default maximum */
@@ -151,7 +153,7 @@ struct request {struct gendisk *rq_disk;struct hd_struct *part;unsigned long start_time; -s64 issue_time; +struct wb_issue_stat wb_stat;#ifdef CONFIG_BLK_CGROUP struct request_list *rl;/* rl this rq is alloced from */ unsigned long long start_time_ns;
@@ -303,6 +305,8 @@ struct request_queue {int nr_rqs[2 ];/* # allocated [a]sync rqs */ int nr_rqs_elvpriv;/* # allocated rqs w/ elvpriv */ +struct rq_wb *rq_wb; +/* * If blkcg is not used, @q->root_rl serves all requests. If blkcg * is used, root blkg allocates from @q->root_rl and all other
Signature · 1 line
2.7.4
Re: [PATCH 2/8] writeback: add wbc_to_write_flags()
In reply to Jens AxboeQuoted 6 lines · Jens Axboe
Add
wbc_to_write_flags(), which returns the write modifier flags to use, based on a structwriteback_control. No functional changes in this patch, but it prepares us for factoring other wbc fields for write type.Signed-off-by Jens Axboe <[email protected]>Reviewed-by Jan Kara <[email protected]>
[snip]
Quoted 5 lines
include/linux/writeback.h +0
-0
include/linux/writeback.h struct writeback_control { · line 108
Quoted 9 lines
include/linux/writeback.h +6
-0@@ -100,6 +100,14 @@ struct writeback_control {#endif }; +static inline int wbc_to_write_flags (struct writeback_control *wbc) +{ +if (wbc->sync_mode ==WB_SYNC_ALL ) +return WRITE_SYNC ; + +return WRITE ;
I think this should be return 0; after the op/flags split. WRITE == 1, so this would get interpreted as REQ_FAILFAST_DEV in bi_opf.
Quoted 1 line
From
2a222ca992c3("fs: havesubmit_bhusers pass in op and flags
separately"):
@@ -1697,7 +1697,7 @@ static int __block_write_full_page(struct inode *inode, struct page *page,
struct buffer_head *bh, *head;
unsigned int blocksize, bbits;
int nr_underway = 0;- int write_op = (wbc->sync_mode == WB_SYNC_ALL ? WRITE_SYNC : WRITE);
+ int write_flags = (wbc->sync_mode == WB_SYNC_ALL ? WRITE_SYNC : 0);
Signature · 1 line
Omar
Re: [PATCH 2/8] writeback: add wbc_to_write_flags()
Quoted 18 lines · Omar Sandoval
Quoted 6 lines · Jens Axboe
Add
wbc_to_write_flags(), which returns the write modifier flags to use, based on a structwriteback_control. No functional changes in this patch, but it prepares us for factoring other wbc fields for write type.Signed-off-by Jens Axboe <[email protected]>Reviewed-by Jan Kara <[email protected]>[snip]
Quoted 8 lines
include/linux/writeback.h +0
-0@@ -100,6 +100,14 @@ struct writeback_control {#endif };
Quoted 9 lines
include/linux/writeback.h struct writeback_control { · line 108
Quoted 6 lines
include/linux/writeback.h +6
-0+static inline int wbc_to_write_flags (struct writeback_control *wbc) +{ +if (wbc->sync_mode ==WB_SYNC_ALL ) +return WRITE_SYNC ; + +return WRITE ;I think this should be
return 0;after the op/flags split. WRITE == 1, so this would get interpreted asREQ_FAILFAST_DEVinbi_opf.
Good catch, thanks! Fixed up.
Signature · 1 line
Jens Axboe
Re: [PATCH 1/8] block: add WRITE_BG
In reply to Jens AxboeQuoted 5 lines · Jens Axboe
This adds a new request flag,
REQ_BG, that callers can use to tell the block layer that this is background (non-urgent) IO.Signed-off-by Jens Axboe <[email protected]>---
s/WRITE_BG/REQ_BG/ in Subject?
Signature · 6 lines
Johannes Thumshirn Storage [email protected] +49 911 74053 689 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N�rnberg GF: Felix Imend�rffer, Jane Smithard, Graham Norton HRB 21284 (AG N�rnberg) Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
Re: [PATCH 1/8] block: add WRITE_BG
Quoted 8 lines · Johannes Thumshirn
Quoted 5 lines · Jens Axboe
This adds a new request flag,
REQ_BG, that callers can use to tell the block layer that this is background (non-urgent) IO.Signed-off-by Jens Axboe <[email protected]>---
s/WRITE_BG/REQ_BG/ in Subject?
Gah rm $LAST_MAIL
Signature · 6 lines
Johannes Thumshirn Storage [email protected] +49 911 74053 689 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N�rnberg GF: Felix Imend�rffer, Jane Smithard, Graham Norton HRB 21284 (AG N�rnberg) Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
Re: [PATCH 7/8] wbt: add general throttling mechanism
In reply to Jens AxboeQuoted 28 lines · Jens Axboe
We can hook this up to the block layer, to help throttle buffered writes. Or NFS can tap into it, to accomplish the same.
wbt registers a few trace points that can be used to track what is happening in the system:
wbt_lat: 259:0: latency 2446318wbt_stat: 259:0: rmean=2446318, rmin=2446318, rmax=2446318, rsamples=1,wmean=518866, wmin=15522, wmax=5330353, wsamples=57
wbt_step: 259:0: step down: step=1, window=72727272, background=8, normal=16, max=32This shows a sync issue event (
wbt_lat) that exceeded it's time.wbt_statdumps the current read/write stats for that window, andwbt_stepshows a step down event where we now scale back writes. Each trace includes the device, 259:0 in this case.Signed-off-by Jens Axboe <[email protected]>--- include/linux/wbt.h | 118 +++++++++ include/trace/events/wbt.h | 122 ++++++++++ lib/Kconfig | 4 + lib/Makefile | 1 + lib/wbt.c | 587 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 832 insertions(+) create mode 100644 include/linux/wbt.h create mode 100644 include/trace/events/wbt.h create mode 100644 lib/wbt.c
[snip]
lib/Kconfig config STACKDEPOT · line 555
Quoted 11 lines
lib/Kconfig +3
-0@@ -550,4 +550,8 @@ config STACKDEPOT bool select STACKTRACE +config WBT + bool + select SCALE_BITMAP
Looks like this snuck in from your experiments to get this to work on top of scale_bitmap?
[snip]
Quoted 25 lines
lib/Kconfig +25
-0+void __wbt_done(struct rq_wb *rwb) +{ + int inflight, limit; + + inflight = atomic_dec_return(&rwb->inflight); + + /* + * wbt got disabled with IO in flight. Wake up any potential + * waiters, we don't have to do more than that. + */ + if (unlikely(!rwb_enabled(rwb))) { + wake_up_all(&rwb->wait); + return; + } + + /* + * If the device does write back caching, drop further down + * before we wake people up. + */ + if (rwb->wc && !atomic_read(&rwb->bdi->wb.dirty_sleeping)) + limit = 0; + else + limit = rwb->wb_normal; + + /*
lib/Kconfig config STACKDEPOT
Quoted 10 lines
lib/Kconfig +10
-0+ * Don't wake anyone up if we are above the normal limit. + */ + if (inflight && inflight >= limit) + return; + + if (waitqueue_active(&rwb->wait)) { + int diff = limit - inflight; + + if (!inflight || diff >= rwb->wb_background / 2) + wake_up_nr(&rwb->wait, 1);
wake_up(&rwb->wait)?
Signature · 1 line
Omar
Re: [PATCH 7/8] wbt: add general throttling mechanism
Quoted 8 lines · Omar Sandoval
Quoted 8 lines
lib/Kconfig +0
-0@@ -550,4 +550,8 @@ config STACKDEPOT bool select STACKTRACE
Quoted 6 lines
lib/Kconfig config STACKDEPOT · line 555
Quoted 3 lines
lib/Kconfig +3
-0+config WBT + bool + select SCALE_BITMAPLooks like this snuck in from your experiments to get this to work on top of
scale_bitmap?
Oops yes, it is indeed. Killed, thanks.
Quoted 7 lines
lib/Kconfig config STACKDEPOT
Quoted 5 lines
lib/Kconfig +5
-0+ if (waitqueue_active(&rwb->wait)) { + int diff = limit - inflight; + + if (!inflight || diff >= rwb->wb_background / 2) + wake_up_nr(&rwb->wait, 1);
wake_up(&rwb->wait)?
Yeah, that'd be cleaner. I think this is a leftover from when I experimented with batched wakeups, with nr != 1. I'll change it to just wake_up().
Signature · 1 line
Jens Axboe