Skip to content

Commit 5238dcf

Browse files
osandovaxboe
authored andcommitted
block: replace bio->bi_issue_stat with bio-specific type
struct blk_issue_stat is going away, and bio->bi_issue_stat doesn't even use the blk-stats interface, so we can provide a separate implementation specific for bios. The helpers work the same way as the blk-stats helpers. Signed-off-by: Omar Sandoval <osandov@fb.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent a8a4594 commit 5238dcf

2 files changed

Lines changed: 56 additions & 12 deletions

File tree

‎block/blk-throttle.c‎

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ static int throtl_quantum = 32;
3636
*/
3737
#define LATENCY_FILTERED_HD (1000L) /* 1ms */
3838

39-
#define SKIP_LATENCY (((u64)1) << BLK_STAT_RES_SHIFT)
40-
4139
static struct blkcg_policy blkcg_policy_throtl;
4240

4341
/* A workqueue to queue throttle related work */
@@ -2139,7 +2137,7 @@ static void blk_throtl_assoc_bio(struct throtl_grp *tg, struct bio *bio)
21392137
bio->bi_cg_private = tg;
21402138
blkg_get(tg_to_blkg(tg));
21412139
}
2142-
blk_stat_set_issue(&bio->bi_issue_stat, bio_sectors(bio));
2140+
bio_issue_init(&bio->bi_issue, bio_sectors(bio));
21432141
#endif
21442142
}
21452143

@@ -2251,7 +2249,7 @@ bool blk_throtl_bio(struct request_queue *q, struct blkcg_gq *blkg,
22512249

22522250
#ifdef CONFIG_BLK_DEV_THROTTLING_LOW
22532251
if (throttled || !td->track_bio_latency)
2254-
bio->bi_issue_stat.stat |= SKIP_LATENCY;
2252+
bio->bi_issue.value |= BIO_ISSUE_THROTL_SKIP_LATENCY;
22552253
#endif
22562254
return throttled;
22572255
}
@@ -2302,25 +2300,24 @@ void blk_throtl_bio_endio(struct bio *bio)
23022300
finish_time_ns = ktime_get_ns();
23032301
tg->last_finish_time = finish_time_ns >> 10;
23042302

2305-
start_time = blk_stat_time(&bio->bi_issue_stat) >> 10;
2306-
finish_time = __blk_stat_time(finish_time_ns) >> 10;
2303+
start_time = bio_issue_time(&bio->bi_issue) >> 10;
2304+
finish_time = __bio_issue_time(finish_time_ns) >> 10;
23072305
if (!start_time || finish_time <= start_time) {
23082306
blkg_put(tg_to_blkg(tg));
23092307
return;
23102308
}
23112309

23122310
lat = finish_time - start_time;
23132311
/* this is only for bio based driver */
2314-
if (!(bio->bi_issue_stat.stat & SKIP_LATENCY))
2315-
throtl_track_latency(tg->td, blk_stat_size(&bio->bi_issue_stat),
2316-
bio_op(bio), lat);
2312+
if (!(bio->bi_issue.value & BIO_ISSUE_THROTL_SKIP_LATENCY))
2313+
throtl_track_latency(tg->td, bio_issue_size(&bio->bi_issue),
2314+
bio_op(bio), lat);
23172315

23182316
if (tg->latency_target && lat >= tg->td->filtered_latency) {
23192317
int bucket;
23202318
unsigned int threshold;
23212319

2322-
bucket = request_bucket_index(
2323-
blk_stat_size(&bio->bi_issue_stat));
2320+
bucket = request_bucket_index(bio_issue_size(&bio->bi_issue));
23242321
threshold = tg->td->avg_buckets[rw][bucket].latency +
23252322
tg->latency_target;
23262323
if (lat > threshold)

‎include/linux/blk_types.h‎

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <linux/types.h>
1010
#include <linux/bvec.h>
11+
#include <linux/ktime.h>
1112

1213
struct bio_set;
1314
struct bio;
@@ -94,6 +95,52 @@ struct blk_issue_stat {
9495
u64 stat;
9596
};
9697

98+
/*
99+
* From most significant bit:
100+
* 1 bit: reserved for other usage, see below
101+
* 12 bits: original size of bio
102+
* 51 bits: issue time of bio
103+
*/
104+
#define BIO_ISSUE_RES_BITS 1
105+
#define BIO_ISSUE_SIZE_BITS 12
106+
#define BIO_ISSUE_RES_SHIFT (64 - BIO_ISSUE_RES_BITS)
107+
#define BIO_ISSUE_SIZE_SHIFT (BIO_ISSUE_RES_SHIFT - BIO_ISSUE_SIZE_BITS)
108+
#define BIO_ISSUE_TIME_MASK ((1ULL << BIO_ISSUE_SIZE_SHIFT) - 1)
109+
#define BIO_ISSUE_SIZE_MASK \
110+
(((1ULL << BIO_ISSUE_SIZE_BITS) - 1) << BIO_ISSUE_SIZE_SHIFT)
111+
#define BIO_ISSUE_RES_MASK (~((1ULL << BIO_ISSUE_RES_SHIFT) - 1))
112+
113+
/* Reserved bit for blk-throtl */
114+
#define BIO_ISSUE_THROTL_SKIP_LATENCY (1ULL << 63)
115+
116+
struct bio_issue {
117+
u64 value;
118+
};
119+
120+
static inline u64 __bio_issue_time(u64 time)
121+
{
122+
return time & BIO_ISSUE_TIME_MASK;
123+
}
124+
125+
static inline u64 bio_issue_time(struct bio_issue *issue)
126+
{
127+
return __bio_issue_time(issue->value);
128+
}
129+
130+
static inline sector_t bio_issue_size(struct bio_issue *issue)
131+
{
132+
return ((issue->value & BIO_ISSUE_SIZE_MASK) >> BIO_ISSUE_SIZE_SHIFT);
133+
}
134+
135+
static inline void bio_issue_init(struct bio_issue *issue,
136+
sector_t size)
137+
{
138+
size &= (1ULL << BIO_ISSUE_SIZE_BITS) - 1;
139+
issue->value = ((issue->value & BIO_ISSUE_RES_MASK) |
140+
(ktime_get_ns() & BIO_ISSUE_TIME_MASK) |
141+
((u64)size << BIO_ISSUE_SIZE_SHIFT));
142+
}
143+
97144
/*
98145
* main unit of I/O for the block layer and lower layers (ie drivers and
99146
* stacking drivers)
@@ -138,7 +185,7 @@ struct bio {
138185
struct cgroup_subsys_state *bi_css;
139186
#ifdef CONFIG_BLK_DEV_THROTTLING_LOW
140187
void *bi_cg_private;
141-
struct blk_issue_stat bi_issue_stat;
188+
struct bio_issue bi_issue;
142189
#endif
143190
#endif
144191
union {

0 commit comments

Comments
 (0)