Skip to content

Commit 7c24d9f

Browse files
committed
Merge branch 'for-4.5/core' of git://git.kernel.dk/linux-block
Pull core block updates from Jens Axboe: "We don't have a lot of core changes this time around, it's mostly in drivers, which will come in a subsequent pull. The cores changes include: - blk-mq - Prep patch from Christoph, changing blk_mq_alloc_request() to take flags instead of just using gfp_t for sleep/nosleep. - Doc patch from me, clarifying the difference between legacy and blk-mq for timer usage. - Fixes from Raghavendra for memory-less numa nodes, and a reuse of CPU masks. - Cleanup from Geliang Tang, using offset_in_page() instead of open coding it. - From Ilya, rename request_queue slab to it reflects what it holds, and a fix for proper use of bdgrab/put. - A real fix for the split across stripe boundaries from Keith. We yanked a broken version of this from 4.4-rc final, this one works. - From Mike Krinkin, emit a trace message when we split. - From Wei Tang, two small cleanups, not explicitly clearing memory that is already cleared" * 'for-4.5/core' of git://git.kernel.dk/linux-block: block: use bd{grab,put}() instead of open-coding block: split bios to max possible length block: add call to split trace point blk-mq: Avoid memoryless numa node encoded in hctx numa_node blk-mq: Reuse hardware context cpumask for tags blk-mq: add a flags parameter to blk_mq_alloc_request Revert "blk-flush: Queue through IO scheduler when flush not required" block: clarify blk_add_timer() use case for blk-mq bio: use offset_in_page macro block: do not initialise statics to 0 or NULL block: do not initialise globals to 0 or NULL block: rename request_queue slab cache
2 parents 99e38df + ed8a9d2 commit 7c24d9f

17 files changed

+79
-64
lines changed

block/bio.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
11251125
int i, ret;
11261126
int nr_pages = 0;
11271127
unsigned int len = iter->count;
1128-
unsigned int offset = map_data ? map_data->offset & ~PAGE_MASK : 0;
1128+
unsigned int offset = map_data ? offset_in_page(map_data->offset) : 0;
11291129

11301130
for (i = 0; i < iter->nr_segs; i++) {
11311131
unsigned long uaddr;
@@ -1304,7 +1304,7 @@ struct bio *bio_map_user_iov(struct request_queue *q,
13041304
goto out_unmap;
13051305
}
13061306

1307-
offset = uaddr & ~PAGE_MASK;
1307+
offset = offset_in_page(uaddr);
13081308
for (j = cur_page; j < page_limit; j++) {
13091309
unsigned int bytes = PAGE_SIZE - offset;
13101310

block/blk-core.c

+8-7
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ DEFINE_IDA(blk_queue_ida);
5151
/*
5252
* For the allocated request tables
5353
*/
54-
struct kmem_cache *request_cachep = NULL;
54+
struct kmem_cache *request_cachep;
5555

5656
/*
5757
* For queue allocation
@@ -646,15 +646,15 @@ struct request_queue *blk_alloc_queue(gfp_t gfp_mask)
646646
}
647647
EXPORT_SYMBOL(blk_alloc_queue);
648648

649-
int blk_queue_enter(struct request_queue *q, gfp_t gfp)
649+
int blk_queue_enter(struct request_queue *q, bool nowait)
650650
{
651651
while (true) {
652652
int ret;
653653

654654
if (percpu_ref_tryget_live(&q->q_usage_counter))
655655
return 0;
656656

657-
if (!gfpflags_allow_blocking(gfp))
657+
if (nowait)
658658
return -EBUSY;
659659

660660
ret = wait_event_interruptible(q->mq_freeze_wq,
@@ -1292,7 +1292,9 @@ static struct request *blk_old_get_request(struct request_queue *q, int rw,
12921292
struct request *blk_get_request(struct request_queue *q, int rw, gfp_t gfp_mask)
12931293
{
12941294
if (q->mq_ops)
1295-
return blk_mq_alloc_request(q, rw, gfp_mask, false);
1295+
return blk_mq_alloc_request(q, rw,
1296+
(gfp_mask & __GFP_DIRECT_RECLAIM) ?
1297+
0 : BLK_MQ_REQ_NOWAIT);
12961298
else
12971299
return blk_old_get_request(q, rw, gfp_mask);
12981300
}
@@ -2060,8 +2062,7 @@ blk_qc_t generic_make_request(struct bio *bio)
20602062
do {
20612063
struct request_queue *q = bdev_get_queue(bio->bi_bdev);
20622064

2063-
if (likely(blk_queue_enter(q, __GFP_DIRECT_RECLAIM) == 0)) {
2064-
2065+
if (likely(blk_queue_enter(q, false) == 0)) {
20652066
ret = q->make_request_fn(q, bio);
20662067

20672068
blk_queue_exit(q);
@@ -3534,7 +3535,7 @@ int __init blk_dev_init(void)
35343535
request_cachep = kmem_cache_create("blkdev_requests",
35353536
sizeof(struct request), 0, SLAB_PANIC, NULL);
35363537

3537-
blk_requestq_cachep = kmem_cache_create("blkdev_queue",
3538+
blk_requestq_cachep = kmem_cache_create("request_queue",
35383539
sizeof(struct request_queue), 0, SLAB_PANIC, NULL);
35393540

35403541
return 0;

block/blk-merge.c

+19-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include <linux/blkdev.h>
88
#include <linux/scatterlist.h>
99

10+
#include <trace/events/block.h>
11+
1012
#include "blk.h"
1113

1214
static struct bio *blk_bio_discard_split(struct request_queue *q,
@@ -81,16 +83,29 @@ static struct bio *blk_bio_segment_split(struct request_queue *q,
8183
struct bio *new = NULL;
8284

8385
bio_for_each_segment(bv, bio, iter) {
84-
if (sectors + (bv.bv_len >> 9) > queue_max_sectors(q))
85-
goto split;
86-
8786
/*
8887
* If the queue doesn't support SG gaps and adding this
8988
* offset would create a gap, disallow it.
9089
*/
9190
if (bvprvp && bvec_gap_to_prev(q, bvprvp, bv.bv_offset))
9291
goto split;
9392

93+
if (sectors + (bv.bv_len >> 9) >
94+
blk_max_size_offset(q, bio->bi_iter.bi_sector)) {
95+
/*
96+
* Consider this a new segment if we're splitting in
97+
* the middle of this vector.
98+
*/
99+
if (nsegs < queue_max_segments(q) &&
100+
sectors < blk_max_size_offset(q,
101+
bio->bi_iter.bi_sector)) {
102+
nsegs++;
103+
sectors = blk_max_size_offset(q,
104+
bio->bi_iter.bi_sector);
105+
}
106+
goto split;
107+
}
108+
94109
if (bvprvp && blk_queue_cluster(q)) {
95110
if (seg_size + bv.bv_len > queue_max_segment_size(q))
96111
goto new_segment;
@@ -162,6 +177,7 @@ void blk_queue_split(struct request_queue *q, struct bio **bio,
162177
split->bi_rw |= REQ_NOMERGE;
163178

164179
bio_chain(split, *bio);
180+
trace_block_split(q, split, (*bio)->bi_iter.bi_sector);
165181
generic_make_request(*bio);
166182
*bio = split;
167183
}

block/blk-mq-cpumap.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ int blk_mq_hw_queue_to_node(unsigned int *mq_map, unsigned int index)
113113

114114
for_each_possible_cpu(i) {
115115
if (index == mq_map[i])
116-
return cpu_to_node(i);
116+
return local_memory_node(cpu_to_node(i));
117117
}
118118

119119
return NUMA_NO_NODE;

block/blk-mq-tag.c

+5-6
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ static int bt_get(struct blk_mq_alloc_data *data,
268268
if (tag != -1)
269269
return tag;
270270

271-
if (!gfpflags_allow_blocking(data->gfp))
271+
if (data->flags & BLK_MQ_REQ_NOWAIT)
272272
return -1;
273273

274274
bs = bt_wait_ptr(bt, hctx);
@@ -303,7 +303,7 @@ static int bt_get(struct blk_mq_alloc_data *data,
303303
data->ctx = blk_mq_get_ctx(data->q);
304304
data->hctx = data->q->mq_ops->map_queue(data->q,
305305
data->ctx->cpu);
306-
if (data->reserved) {
306+
if (data->flags & BLK_MQ_REQ_RESERVED) {
307307
bt = &data->hctx->tags->breserved_tags;
308308
} else {
309309
last_tag = &data->ctx->last_tag;
@@ -349,10 +349,9 @@ static unsigned int __blk_mq_get_reserved_tag(struct blk_mq_alloc_data *data)
349349

350350
unsigned int blk_mq_get_tag(struct blk_mq_alloc_data *data)
351351
{
352-
if (!data->reserved)
353-
return __blk_mq_get_tag(data);
354-
355-
return __blk_mq_get_reserved_tag(data);
352+
if (data->flags & BLK_MQ_REQ_RESERVED)
353+
return __blk_mq_get_reserved_tag(data);
354+
return __blk_mq_get_tag(data);
356355
}
357356

358357
static struct bt_wait_state *bt_wake_ptr(struct blk_mq_bitmap_tags *bt)

block/blk-mq.c

+10-21
Original file line numberDiff line numberDiff line change
@@ -229,33 +229,31 @@ __blk_mq_alloc_request(struct blk_mq_alloc_data *data, int rw)
229229
return NULL;
230230
}
231231

232-
struct request *blk_mq_alloc_request(struct request_queue *q, int rw, gfp_t gfp,
233-
bool reserved)
232+
struct request *blk_mq_alloc_request(struct request_queue *q, int rw,
233+
unsigned int flags)
234234
{
235235
struct blk_mq_ctx *ctx;
236236
struct blk_mq_hw_ctx *hctx;
237237
struct request *rq;
238238
struct blk_mq_alloc_data alloc_data;
239239
int ret;
240240

241-
ret = blk_queue_enter(q, gfp);
241+
ret = blk_queue_enter(q, flags & BLK_MQ_REQ_NOWAIT);
242242
if (ret)
243243
return ERR_PTR(ret);
244244

245245
ctx = blk_mq_get_ctx(q);
246246
hctx = q->mq_ops->map_queue(q, ctx->cpu);
247-
blk_mq_set_alloc_data(&alloc_data, q, gfp & ~__GFP_DIRECT_RECLAIM,
248-
reserved, ctx, hctx);
247+
blk_mq_set_alloc_data(&alloc_data, q, flags, ctx, hctx);
249248

250249
rq = __blk_mq_alloc_request(&alloc_data, rw);
251-
if (!rq && (gfp & __GFP_DIRECT_RECLAIM)) {
250+
if (!rq && !(flags & BLK_MQ_REQ_NOWAIT)) {
252251
__blk_mq_run_hw_queue(hctx);
253252
blk_mq_put_ctx(ctx);
254253

255254
ctx = blk_mq_get_ctx(q);
256255
hctx = q->mq_ops->map_queue(q, ctx->cpu);
257-
blk_mq_set_alloc_data(&alloc_data, q, gfp, reserved, ctx,
258-
hctx);
256+
blk_mq_set_alloc_data(&alloc_data, q, flags, ctx, hctx);
259257
rq = __blk_mq_alloc_request(&alloc_data, rw);
260258
ctx = alloc_data.ctx;
261259
}
@@ -1175,8 +1173,7 @@ static struct request *blk_mq_map_request(struct request_queue *q,
11751173
rw |= REQ_SYNC;
11761174

11771175
trace_block_getrq(q, bio, rw);
1178-
blk_mq_set_alloc_data(&alloc_data, q, GFP_ATOMIC, false, ctx,
1179-
hctx);
1176+
blk_mq_set_alloc_data(&alloc_data, q, BLK_MQ_REQ_NOWAIT, ctx, hctx);
11801177
rq = __blk_mq_alloc_request(&alloc_data, rw);
11811178
if (unlikely(!rq)) {
11821179
__blk_mq_run_hw_queue(hctx);
@@ -1185,8 +1182,7 @@ static struct request *blk_mq_map_request(struct request_queue *q,
11851182

11861183
ctx = blk_mq_get_ctx(q);
11871184
hctx = q->mq_ops->map_queue(q, ctx->cpu);
1188-
blk_mq_set_alloc_data(&alloc_data, q,
1189-
__GFP_RECLAIM|__GFP_HIGH, false, ctx, hctx);
1185+
blk_mq_set_alloc_data(&alloc_data, q, 0, ctx, hctx);
11901186
rq = __blk_mq_alloc_request(&alloc_data, rw);
11911187
ctx = alloc_data.ctx;
11921188
hctx = alloc_data.hctx;
@@ -1794,7 +1790,7 @@ static void blk_mq_init_cpu_queues(struct request_queue *q,
17941790
* not, we remain on the home node of the device
17951791
*/
17961792
if (nr_hw_queues > 1 && hctx->numa_node == NUMA_NO_NODE)
1797-
hctx->numa_node = cpu_to_node(i);
1793+
hctx->numa_node = local_memory_node(cpu_to_node(i));
17981794
}
17991795
}
18001796

@@ -1854,6 +1850,7 @@ static void blk_mq_map_swqueue(struct request_queue *q,
18541850
hctx->tags = set->tags[i];
18551851
WARN_ON(!hctx->tags);
18561852

1853+
cpumask_copy(hctx->tags->cpumask, hctx->cpumask);
18571854
/*
18581855
* Set the map size to the number of mapped software queues.
18591856
* This is more accurate and more efficient than looping
@@ -1867,14 +1864,6 @@ static void blk_mq_map_swqueue(struct request_queue *q,
18671864
hctx->next_cpu = cpumask_first(hctx->cpumask);
18681865
hctx->next_cpu_batch = BLK_MQ_CPU_WORK_BATCH;
18691866
}
1870-
1871-
queue_for_each_ctx(q, ctx, i) {
1872-
if (!cpumask_test_cpu(i, online_mask))
1873-
continue;
1874-
1875-
hctx = q->mq_ops->map_queue(q, i);
1876-
cpumask_set_cpu(i, hctx->tags->cpumask);
1877-
}
18781867
}
18791868

18801869
static void queue_set_hctx_shared(struct request_queue *q, bool shared)

block/blk-mq.h

+4-7
Original file line numberDiff line numberDiff line change
@@ -96,22 +96,19 @@ static inline void blk_mq_put_ctx(struct blk_mq_ctx *ctx)
9696
struct blk_mq_alloc_data {
9797
/* input parameter */
9898
struct request_queue *q;
99-
gfp_t gfp;
100-
bool reserved;
99+
unsigned int flags;
101100

102101
/* input & output parameter */
103102
struct blk_mq_ctx *ctx;
104103
struct blk_mq_hw_ctx *hctx;
105104
};
106105

107106
static inline void blk_mq_set_alloc_data(struct blk_mq_alloc_data *data,
108-
struct request_queue *q, gfp_t gfp, bool reserved,
109-
struct blk_mq_ctx *ctx,
110-
struct blk_mq_hw_ctx *hctx)
107+
struct request_queue *q, unsigned int flags,
108+
struct blk_mq_ctx *ctx, struct blk_mq_hw_ctx *hctx)
111109
{
112110
data->q = q;
113-
data->gfp = gfp;
114-
data->reserved = reserved;
111+
data->flags = flags;
115112
data->ctx = ctx;
116113
data->hctx = hctx;
117114
}

block/blk-timeout.c

+6
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ unsigned long blk_rq_timeout(unsigned long timeout)
186186
* Notes:
187187
* Each request has its own timer, and as it is added to the queue, we
188188
* set up the timer. When the request completes, we cancel the timer.
189+
* Queue lock must be held for the non-mq case, mq case doesn't care.
189190
*/
190191
void blk_add_timer(struct request *req)
191192
{
@@ -209,6 +210,11 @@ void blk_add_timer(struct request *req)
209210
req->timeout = q->rq_timeout;
210211

211212
req->deadline = jiffies + req->timeout;
213+
214+
/*
215+
* Only the non-mq case needs to add the request to a protected list.
216+
* For the mq case we simply scan the tag map.
217+
*/
212218
if (!q->mq_ops)
213219
list_add_tail(&req->timeout_list, &req->q->timeout_list);
214220

block/genhd.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1449,7 +1449,7 @@ static DEFINE_MUTEX(disk_events_mutex);
14491449
static LIST_HEAD(disk_events);
14501450

14511451
/* disable in-kernel polling by default */
1452-
static unsigned long disk_events_dfl_poll_msecs = 0;
1452+
static unsigned long disk_events_dfl_poll_msecs;
14531453

14541454
static unsigned long disk_events_poll_jiffies(struct gendisk *disk)
14551455
{

drivers/block/mtip32xx/mtip32xx.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ static struct mtip_cmd *mtip_get_int_command(struct driver_data *dd)
173173
{
174174
struct request *rq;
175175

176-
rq = blk_mq_alloc_request(dd->queue, 0, __GFP_RECLAIM, true);
176+
rq = blk_mq_alloc_request(dd->queue, 0, BLK_MQ_REQ_RESERVED);
177177
return blk_mq_rq_to_pdu(rq);
178178
}
179179

drivers/block/null_blk.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ static int null_lnvm_submit_io(struct nvm_dev *dev, struct nvm_rq *rqd)
449449
struct request *rq;
450450
struct bio *bio = rqd->bio;
451451

452-
rq = blk_mq_alloc_request(q, bio_rw(bio), GFP_KERNEL, 0);
452+
rq = blk_mq_alloc_request(q, bio_rw(bio), 0);
453453
if (IS_ERR(rq))
454454
return -ENOMEM;
455455

drivers/char/raw.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ static int raw_open(struct inode *inode, struct file *filp)
7171
err = -ENODEV;
7272
if (!bdev)
7373
goto out;
74-
igrab(bdev->bd_inode);
74+
bdgrab(bdev);
7575
err = blkdev_get(bdev, filp->f_mode | FMODE_EXCL, raw_open);
7676
if (err)
7777
goto out;

drivers/nvme/host/lightnvm.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ static int nvme_nvm_submit_io(struct nvm_dev *dev, struct nvm_rq *rqd)
471471
struct bio *bio = rqd->bio;
472472
struct nvme_nvm_command *cmd;
473473

474-
rq = blk_mq_alloc_request(q, bio_rw(bio), GFP_KERNEL, 0);
474+
rq = blk_mq_alloc_request(q, bio_rw(bio), 0);
475475
if (IS_ERR(rq))
476476
return -ENOMEM;
477477

drivers/nvme/host/pci.c

+6-5
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,7 @@ int __nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd,
10411041
struct request *req;
10421042
int ret;
10431043

1044-
req = blk_mq_alloc_request(q, write, GFP_KERNEL, false);
1044+
req = blk_mq_alloc_request(q, write, 0);
10451045
if (IS_ERR(req))
10461046
return PTR_ERR(req);
10471047

@@ -1094,7 +1094,8 @@ static int nvme_submit_async_admin_req(struct nvme_dev *dev)
10941094
struct nvme_cmd_info *cmd_info;
10951095
struct request *req;
10961096

1097-
req = blk_mq_alloc_request(dev->admin_q, WRITE, GFP_ATOMIC, true);
1097+
req = blk_mq_alloc_request(dev->admin_q, WRITE,
1098+
BLK_MQ_REQ_NOWAIT | BLK_MQ_REQ_RESERVED);
10981099
if (IS_ERR(req))
10991100
return PTR_ERR(req);
11001101

@@ -1119,7 +1120,7 @@ static int nvme_submit_admin_async_cmd(struct nvme_dev *dev,
11191120
struct request *req;
11201121
struct nvme_cmd_info *cmd_rq;
11211122

1122-
req = blk_mq_alloc_request(dev->admin_q, WRITE, GFP_KERNEL, false);
1123+
req = blk_mq_alloc_request(dev->admin_q, WRITE, 0);
11231124
if (IS_ERR(req))
11241125
return PTR_ERR(req);
11251126

@@ -1320,8 +1321,8 @@ static void nvme_abort_req(struct request *req)
13201321
if (!dev->abort_limit)
13211322
return;
13221323

1323-
abort_req = blk_mq_alloc_request(dev->admin_q, WRITE, GFP_ATOMIC,
1324-
false);
1324+
abort_req = blk_mq_alloc_request(dev->admin_q, WRITE,
1325+
BLK_MQ_REQ_NOWAIT);
13251326
if (IS_ERR(abort_req))
13261327
return;
13271328

0 commit comments

Comments
 (0)