aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2019-06-27 16:39:52 -0400
committerJens Axboe <axboe@kernel.dk>2019-07-10 11:00:57 -0400
commitd3f77dfdc71835f8db71ca57d272b1fbec9dfc18 (patch)
treeced59cee416b39c3c2f80c647c736a2d378772e3 /include/linux
parent653c45c6b90c9659facbef10546d1f3a8e37d0cf (diff)
blkcg: implement REQ_CGROUP_PUNT
When a shared kthread needs to issue a bio for a cgroup, doing so synchronously can lead to priority inversions as the kthread can be trapped waiting for that cgroup. This patch implements REQ_CGROUP_PUNT flag which makes submit_bio() punt the actual issuing to a dedicated per-blkcg work item to avoid such priority inversions. This will be used to fix priority inversions in btrfs compression and should be generally useful as we grow filesystem support for comprehensive IO control. Cc: Chris Mason <clm@fb.com> Reviewed-by: Josef Bacik <josef@toxicpanda.com> Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Tejun Heo <tj@kernel.org> Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/backing-dev.h1
-rw-r--r--include/linux/blk-cgroup.h16
-rw-r--r--include/linux/blk_types.h10
-rw-r--r--include/linux/writeback.h13
4 files changed, 36 insertions, 4 deletions
diff --git a/include/linux/backing-dev.h b/include/linux/backing-dev.h
index f9b029180241..35b31d176f74 100644
--- a/include/linux/backing-dev.h
+++ b/include/linux/backing-dev.h
@@ -48,6 +48,7 @@ extern spinlock_t bdi_lock;
48extern struct list_head bdi_list; 48extern struct list_head bdi_list;
49 49
50extern struct workqueue_struct *bdi_wq; 50extern struct workqueue_struct *bdi_wq;
51extern struct workqueue_struct *bdi_async_bio_wq;
51 52
52static inline bool wb_has_dirty_io(struct bdi_writeback *wb) 53static inline bool wb_has_dirty_io(struct bdi_writeback *wb)
53{ 54{
diff --git a/include/linux/blk-cgroup.h b/include/linux/blk-cgroup.h
index 33f23a858438..689a58231288 100644
--- a/include/linux/blk-cgroup.h
+++ b/include/linux/blk-cgroup.h
@@ -132,13 +132,17 @@ struct blkcg_gq {
132 132
133 struct blkg_policy_data *pd[BLKCG_MAX_POLS]; 133 struct blkg_policy_data *pd[BLKCG_MAX_POLS];
134 134
135 struct rcu_head rcu_head; 135 spinlock_t async_bio_lock;
136 struct bio_list async_bios;
137 struct work_struct async_bio_work;
136 138
137 atomic_t use_delay; 139 atomic_t use_delay;
138 atomic64_t delay_nsec; 140 atomic64_t delay_nsec;
139 atomic64_t delay_start; 141 atomic64_t delay_start;
140 u64 last_delay; 142 u64 last_delay;
141 int last_use; 143 int last_use;
144
145 struct rcu_head rcu_head;
142}; 146};
143 147
144typedef struct blkcg_policy_data *(blkcg_pol_alloc_cpd_fn)(gfp_t gfp); 148typedef struct blkcg_policy_data *(blkcg_pol_alloc_cpd_fn)(gfp_t gfp);
@@ -701,6 +705,15 @@ static inline bool blk_throtl_bio(struct request_queue *q, struct blkcg_gq *blkg
701 struct bio *bio) { return false; } 705 struct bio *bio) { return false; }
702#endif 706#endif
703 707
708bool __blkcg_punt_bio_submit(struct bio *bio);
709
710static inline bool blkcg_punt_bio_submit(struct bio *bio)
711{
712 if (bio->bi_opf & REQ_CGROUP_PUNT)
713 return __blkcg_punt_bio_submit(bio);
714 else
715 return false;
716}
704 717
705static inline void blkcg_bio_issue_init(struct bio *bio) 718static inline void blkcg_bio_issue_init(struct bio *bio)
706{ 719{
@@ -848,6 +861,7 @@ static inline char *blkg_path(struct blkcg_gq *blkg) { return NULL; }
848static inline void blkg_get(struct blkcg_gq *blkg) { } 861static inline void blkg_get(struct blkcg_gq *blkg) { }
849static inline void blkg_put(struct blkcg_gq *blkg) { } 862static inline void blkg_put(struct blkcg_gq *blkg) { }
850 863
864static inline bool blkcg_punt_bio_submit(struct bio *bio) { return false; }
851static inline void blkcg_bio_issue_init(struct bio *bio) { } 865static inline void blkcg_bio_issue_init(struct bio *bio) { }
852static inline bool blkcg_bio_issue_check(struct request_queue *q, 866static inline bool blkcg_bio_issue_check(struct request_queue *q,
853 struct bio *bio) { return true; } 867 struct bio *bio) { return true; }
diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h
index 6a53799c3fe2..feff3fe4467e 100644
--- a/include/linux/blk_types.h
+++ b/include/linux/blk_types.h
@@ -311,6 +311,14 @@ enum req_flag_bits {
311 __REQ_RAHEAD, /* read ahead, can fail anytime */ 311 __REQ_RAHEAD, /* read ahead, can fail anytime */
312 __REQ_BACKGROUND, /* background IO */ 312 __REQ_BACKGROUND, /* background IO */
313 __REQ_NOWAIT, /* Don't wait if request will block */ 313 __REQ_NOWAIT, /* Don't wait if request will block */
314 /*
315 * When a shared kthread needs to issue a bio for a cgroup, doing
316 * so synchronously can lead to priority inversions as the kthread
317 * can be trapped waiting for that cgroup. CGROUP_PUNT flag makes
318 * submit_bio() punt the actual issuing to a dedicated per-blkcg
319 * work item to avoid such priority inversions.
320 */
321 __REQ_CGROUP_PUNT,
314 322
315 /* command specific flags for REQ_OP_WRITE_ZEROES: */ 323 /* command specific flags for REQ_OP_WRITE_ZEROES: */
316 __REQ_NOUNMAP, /* do not free blocks when zeroing */ 324 __REQ_NOUNMAP, /* do not free blocks when zeroing */
@@ -337,6 +345,8 @@ enum req_flag_bits {
337#define REQ_RAHEAD (1ULL << __REQ_RAHEAD) 345#define REQ_RAHEAD (1ULL << __REQ_RAHEAD)
338#define REQ_BACKGROUND (1ULL << __REQ_BACKGROUND) 346#define REQ_BACKGROUND (1ULL << __REQ_BACKGROUND)
339#define REQ_NOWAIT (1ULL << __REQ_NOWAIT) 347#define REQ_NOWAIT (1ULL << __REQ_NOWAIT)
348#define REQ_CGROUP_PUNT (1ULL << __REQ_CGROUP_PUNT)
349
340#define REQ_NOUNMAP (1ULL << __REQ_NOUNMAP) 350#define REQ_NOUNMAP (1ULL << __REQ_NOUNMAP)
341#define REQ_HIPRI (1ULL << __REQ_HIPRI) 351#define REQ_HIPRI (1ULL << __REQ_HIPRI)
342 352
diff --git a/include/linux/writeback.h b/include/linux/writeback.h
index e056a22075cf..8945aac31392 100644
--- a/include/linux/writeback.h
+++ b/include/linux/writeback.h
@@ -78,6 +78,8 @@ struct writeback_control {
78 */ 78 */
79 unsigned no_cgroup_owner:1; 79 unsigned no_cgroup_owner:1;
80 80
81 unsigned punt_to_cgroup:1; /* cgrp punting, see __REQ_CGROUP_PUNT */
82
81#ifdef CONFIG_CGROUP_WRITEBACK 83#ifdef CONFIG_CGROUP_WRITEBACK
82 struct bdi_writeback *wb; /* wb this writeback is issued under */ 84 struct bdi_writeback *wb; /* wb this writeback is issued under */
83 struct inode *inode; /* inode being written out */ 85 struct inode *inode; /* inode being written out */
@@ -94,12 +96,17 @@ struct writeback_control {
94 96
95static inline int wbc_to_write_flags(struct writeback_control *wbc) 97static inline int wbc_to_write_flags(struct writeback_control *wbc)
96{ 98{
99 int flags = 0;
100
101 if (wbc->punt_to_cgroup)
102 flags = REQ_CGROUP_PUNT;
103
97 if (wbc->sync_mode == WB_SYNC_ALL) 104 if (wbc->sync_mode == WB_SYNC_ALL)
98 return REQ_SYNC; 105 flags |= REQ_SYNC;
99 else if (wbc->for_kupdate || wbc->for_background) 106 else if (wbc->for_kupdate || wbc->for_background)
100 return REQ_BACKGROUND; 107 flags |= REQ_BACKGROUND;
101 108
102 return 0; 109 return flags;
103} 110}
104 111
105static inline struct cgroup_subsys_state * 112static inline struct cgroup_subsys_state *