History

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.

Tejun Heo committed 7 years ago

Commit d3f77df1 parent 653c45c6 files · +92 −4Browse files

Showing the changes to include/linux (4 of 6 files). Show all

Unified · Split

4 files
  1. include/linux/backing-dev.h +1 −0
  2. include/linux/blk-cgroup.h +15 −1
  3. include/linux/blk_types.h +10 −0
  4. include/linux/writeback.h +10 −3
include/linux/backing-dev.h+1−0
@@ -48,6 +48,7 @@ extern spinlock_t bdi_lock; · 47 unmodified lines
4848 extern struct list_head bdi_list;
4949
5050 extern struct workqueue_struct *bdi_wq;
51+extern struct workqueue_struct *bdi_async_bio_wq;
5152
5253 static inline bool wb_has_dirty_io(struct bdi_writeback *wb)
5354 {
include/linux/blk-cgroup.h+15−1
@@ -132,13 +132,17 @@ struct blkcg_gq { · 131 unmodified lines
132132
133133 struct blkg_policy_data *pd[BLKCG_MAX_POLS];
134134
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;
136138
137139 atomic_t use_delay;
138140 atomic64_t delay_nsec;
139141 atomic64_t delay_start;
140142 u64 last_delay;
141143 int last_use;
144+
145+ struct rcu_head rcu_head;
142146 };
143147
144148 typedef 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 · 556 unmodified lines
701705 struct bio *bio) { return false; }
702706 #endif
703707
708+bool __blkcg_punt_bio_submit(struct bio *bio);
709+
710+static 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+}
704717
705718 static inline void blkcg_bio_issue_init(struct bio *bio)
706719 {
@@ -848,6 +861,7 @@ static inline char *blkg_path(struct blkcg_gq *blkg) { return NULL; } · 141 unmodified lines
848861 static inline void blkg_get(struct blkcg_gq *blkg) { }
849862 static inline void blkg_put(struct blkcg_gq *blkg) { }
850863
864+static inline bool blkcg_punt_bio_submit(struct bio *bio) { return false; }
851865 static inline void blkcg_bio_issue_init(struct bio *bio) { }
852866 static inline bool blkcg_bio_issue_check(struct request_queue *q,
853867 struct bio *bio) { return true; }
include/linux/blk_types.h+10−0
@@ -311,6 +311,14 @@ enum req_flag_bits { · 310 unmodified lines
311311 __REQ_RAHEAD, /* read ahead, can fail anytime */
312312 __REQ_BACKGROUND, /* background IO */
313313 __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,
314322
315323 /* command specific flags for REQ_OP_WRITE_ZEROES: */
316324 __REQ_NOUNMAP, /* do not free blocks when zeroing */
@@ -337,6 +345,8 @@ enum req_flag_bits { · 20 unmodified lines
337345 #define REQ_RAHEAD (1ULL << __REQ_RAHEAD)
338346 #define REQ_BACKGROUND (1ULL << __REQ_BACKGROUND)
339347 #define REQ_NOWAIT (1ULL << __REQ_NOWAIT)
348+#define REQ_CGROUP_PUNT (1ULL << __REQ_CGROUP_PUNT)
349+
340350 #define REQ_NOUNMAP (1ULL << __REQ_NOUNMAP)
341351 #define REQ_HIPRI (1ULL << __REQ_HIPRI)
342352
include/linux/writeback.h+10−3
@@ -78,6 +78,8 @@ struct writeback_control { · 77 unmodified lines
7878 */
7979 unsigned no_cgroup_owner:1;
8080
81+ unsigned punt_to_cgroup:1; /* cgrp punting, see __REQ_CGROUP_PUNT */
82+
8183 #ifdef CONFIG_CGROUP_WRITEBACK
8284 struct bdi_writeback *wb; /* wb this writeback is issued under */
8385 struct inode *inode; /* inode being written out */
@@ -94,12 +96,17 @@ struct writeback_control { · 10 unmodified lines
9496
9597 static inline int wbc_to_write_flags(struct writeback_control *wbc)
9698 {
99+ int flags = 0;
100+
101+ if (wbc->punt_to_cgroup)
102+ flags = REQ_CGROUP_PUNT;
103+
97104 if (wbc->sync_mode == WB_SYNC_ALL)
98− return REQ_SYNC;
105+ flags |= REQ_SYNC;
99106 else if (wbc->for_kupdate || wbc->for_background)
100− return REQ_BACKGROUND;
107+ flags |= REQ_BACKGROUND;
101108
102− return 0;
109+ return flags;
103110 }
104111
105112 static inline struct cgroup_subsys_state *

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t