Skip to content

Commit 3d745ea

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: simplify queue allocation
Current make_request based drivers use either blk_alloc_queue_node or blk_alloc_queue to allocate a queue, and then set up the make_request_fn function pointer and a few parameters using the blk_queue_make_request helper. Simplify this by passing the make_request pointer to blk_alloc_queue, and while at it merge the _node variant into the main helper by always passing a node_id, and remove the superfluous gfp_mask parameter. A lower-level __blk_alloc_queue is kept for the blk-mq case. Signed-off-by: Christoph Hellwig <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent ff27668 commit 3d745ea

File tree

26 files changed

+54
-108
lines changed

26 files changed

+54
-108
lines changed

arch/m68k/emu/nfblock.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,11 @@ static int __init nfhd_init_one(int id, u32 blocks, u32 bsize)
118118
dev->bsize = bsize;
119119
dev->bshift = ffs(bsize) - 10;
120120

121-
dev->queue = blk_alloc_queue(GFP_KERNEL);
121+
dev->queue = blk_alloc_queue(nfhd_make_request, NUMA_NO_NODE);
122122
if (dev->queue == NULL)
123123
goto free_dev;
124124

125125
dev->queue->queuedata = dev;
126-
blk_queue_make_request(dev->queue, nfhd_make_request);
127126
blk_queue_logical_block_size(dev->queue, bsize);
128127

129128
dev->disk = alloc_disk(16);

arch/xtensa/platforms/iss/simdisk.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,13 +267,12 @@ static int __init simdisk_setup(struct simdisk *dev, int which,
267267
spin_lock_init(&dev->lock);
268268
dev->users = 0;
269269

270-
dev->queue = blk_alloc_queue(GFP_KERNEL);
270+
dev->queue = blk_alloc_queue(simdisk_make_request, NUMA_NO_NODE);
271271
if (dev->queue == NULL) {
272272
pr_err("blk_alloc_queue failed\n");
273273
goto out_alloc_queue;
274274
}
275275

276-
blk_queue_make_request(dev->queue, simdisk_make_request);
277276
dev->queue->queuedata = dev;
278277

279278
dev->gd = alloc_disk(SIMDISK_MINORS);

block/blk-cgroup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
10101010
* blkcg_init_queue - initialize blkcg part of request queue
10111011
* @q: request_queue to initialize
10121012
*
1013-
* Called from blk_alloc_queue_node(). Responsible for initializing blkcg
1013+
* Called from __blk_alloc_queue(). Responsible for initializing blkcg
10141014
* part of new request_queue @q.
10151015
*
10161016
* RETURNS:

block/blk-core.c

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -388,12 +388,6 @@ void blk_cleanup_queue(struct request_queue *q)
388388
}
389389
EXPORT_SYMBOL(blk_cleanup_queue);
390390

391-
struct request_queue *blk_alloc_queue(gfp_t gfp_mask)
392-
{
393-
return blk_alloc_queue_node(gfp_mask, NUMA_NO_NODE);
394-
}
395-
EXPORT_SYMBOL(blk_alloc_queue);
396-
397391
/**
398392
* blk_queue_enter() - try to increase q->q_usage_counter
399393
* @q: request queue pointer
@@ -470,32 +464,27 @@ static void blk_timeout_work(struct work_struct *work)
470464
{
471465
}
472466

473-
/**
474-
* blk_alloc_queue_node - allocate a request queue
475-
* @gfp_mask: memory allocation flags
476-
* @node_id: NUMA node to allocate memory from
477-
*/
478-
struct request_queue *blk_alloc_queue_node(gfp_t gfp_mask, int node_id)
467+
struct request_queue *__blk_alloc_queue(int node_id)
479468
{
480469
struct request_queue *q;
481470
int ret;
482471

483472
q = kmem_cache_alloc_node(blk_requestq_cachep,
484-
gfp_mask | __GFP_ZERO, node_id);
473+
GFP_KERNEL | __GFP_ZERO, node_id);
485474
if (!q)
486475
return NULL;
487476

488477
q->last_merge = NULL;
489478

490-
q->id = ida_simple_get(&blk_queue_ida, 0, 0, gfp_mask);
479+
q->id = ida_simple_get(&blk_queue_ida, 0, 0, GFP_KERNEL);
491480
if (q->id < 0)
492481
goto fail_q;
493482

494483
ret = bioset_init(&q->bio_split, BIO_POOL_SIZE, 0, BIOSET_NEED_BVECS);
495484
if (ret)
496485
goto fail_id;
497486

498-
q->backing_dev_info = bdi_alloc_node(gfp_mask, node_id);
487+
q->backing_dev_info = bdi_alloc_node(GFP_KERNEL, node_id);
499488
if (!q->backing_dev_info)
500489
goto fail_split;
501490

@@ -541,6 +530,9 @@ struct request_queue *blk_alloc_queue_node(gfp_t gfp_mask, int node_id)
541530
if (blkcg_init_queue(q))
542531
goto fail_ref;
543532

533+
blk_queue_dma_alignment(q, 511);
534+
blk_set_default_limits(&q->limits);
535+
544536
return q;
545537

546538
fail_ref:
@@ -557,7 +549,22 @@ struct request_queue *blk_alloc_queue_node(gfp_t gfp_mask, int node_id)
557549
kmem_cache_free(blk_requestq_cachep, q);
558550
return NULL;
559551
}
560-
EXPORT_SYMBOL(blk_alloc_queue_node);
552+
553+
struct request_queue *blk_alloc_queue(make_request_fn make_request, int node_id)
554+
{
555+
struct request_queue *q;
556+
557+
if (WARN_ON_ONCE(!make_request))
558+
return -EINVAL;
559+
560+
q = __blk_alloc_queue(node_id);
561+
if (!q)
562+
return NULL;
563+
q->make_request_fn = make_request;
564+
q->nr_requests = BLKDEV_MAX_RQ;
565+
return q;
566+
}
567+
EXPORT_SYMBOL(blk_alloc_queue);
561568

562569
bool blk_get_queue(struct request_queue *q)
563570
{

block/blk-mq.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2729,7 +2729,7 @@ struct request_queue *blk_mq_init_queue_data(struct blk_mq_tag_set *set,
27292729
{
27302730
struct request_queue *uninit_q, *q;
27312731

2732-
uninit_q = blk_alloc_queue_node(GFP_KERNEL, set->numa_node);
2732+
uninit_q = __blk_alloc_queue(set->numa_node);
27332733
if (!uninit_q)
27342734
return ERR_PTR(-ENOMEM);
27352735
uninit_q->queuedata = queuedata;
@@ -2939,11 +2939,7 @@ struct request_queue *blk_mq_init_allocated_queue(struct blk_mq_tag_set *set,
29392939
INIT_LIST_HEAD(&q->requeue_list);
29402940
spin_lock_init(&q->requeue_lock);
29412941

2942-
blk_queue_make_request(q, blk_mq_make_request);
2943-
2944-
/*
2945-
* Do this after blk_queue_make_request() overrides it...
2946-
*/
2942+
q->make_request_fn = blk_mq_make_request;
29472943
q->nr_requests = set->queue_depth;
29482944

29492945
/*

block/blk-settings.c

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -86,42 +86,6 @@ void blk_set_stacking_limits(struct queue_limits *lim)
8686
}
8787
EXPORT_SYMBOL(blk_set_stacking_limits);
8888

89-
/**
90-
* blk_queue_make_request - define an alternate make_request function for a device
91-
* @q: the request queue for the device to be affected
92-
* @mfn: the alternate make_request function
93-
*
94-
* Description:
95-
* The normal way for &struct bios to be passed to a device
96-
* driver is for them to be collected into requests on a request
97-
* queue, and then to allow the device driver to select requests
98-
* off that queue when it is ready. This works well for many block
99-
* devices. However some block devices (typically virtual devices
100-
* such as md or lvm) do not benefit from the processing on the
101-
* request queue, and are served best by having the requests passed
102-
* directly to them. This can be achieved by providing a function
103-
* to blk_queue_make_request().
104-
*
105-
* Caveat:
106-
* The driver that does this *must* be able to deal appropriately
107-
* with buffers in "highmemory". This can be accomplished by either calling
108-
* kmap_atomic() to get a temporary kernel mapping, or by calling
109-
* blk_queue_bounce() to create a buffer in normal memory.
110-
**/
111-
void blk_queue_make_request(struct request_queue *q, make_request_fn *mfn)
112-
{
113-
/*
114-
* set defaults
115-
*/
116-
q->nr_requests = BLKDEV_MAX_RQ;
117-
118-
q->make_request_fn = mfn;
119-
blk_queue_dma_alignment(q, 511);
120-
121-
blk_set_default_limits(&q->limits);
122-
}
123-
EXPORT_SYMBOL(blk_queue_make_request);
124-
12589
/**
12690
* blk_queue_bounce_limit - set bounce buffer limit for queue
12791
* @q: the request queue for the device

block/blk.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,4 +482,6 @@ static inline void part_nr_sects_write(struct hd_struct *part, sector_t size)
482482
#endif
483483
}
484484

485+
struct request_queue *__blk_alloc_queue(int node_id);
486+
485487
#endif /* BLK_INTERNAL_H */

drivers/block/brd.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,12 +381,10 @@ static struct brd_device *brd_alloc(int i)
381381
spin_lock_init(&brd->brd_lock);
382382
INIT_RADIX_TREE(&brd->brd_pages, GFP_ATOMIC);
383383

384-
brd->brd_queue = blk_alloc_queue(GFP_KERNEL);
384+
brd->brd_queue = blk_alloc_queue(brd_make_request, NUMA_NO_NODE);
385385
if (!brd->brd_queue)
386386
goto out_free_dev;
387387

388-
blk_queue_make_request(brd->brd_queue, brd_make_request);
389-
390388
/* This is so fdisk will align partitions on 4k, because of
391389
* direct_access API needing 4k alignment, returning a PFN
392390
* (This is only a problem on very small devices <= 4M,

drivers/block/drbd/drbd_main.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2801,7 +2801,7 @@ enum drbd_ret_code drbd_create_device(struct drbd_config_context *adm_ctx, unsig
28012801

28022802
drbd_init_set_defaults(device);
28032803

2804-
q = blk_alloc_queue_node(GFP_KERNEL, NUMA_NO_NODE);
2804+
q = blk_alloc_queue(drbd_make_request, NUMA_NO_NODE);
28052805
if (!q)
28062806
goto out_no_q;
28072807
device->rq_queue = q;
@@ -2828,7 +2828,6 @@ enum drbd_ret_code drbd_create_device(struct drbd_config_context *adm_ctx, unsig
28282828
q->backing_dev_info->congested_fn = drbd_congested;
28292829
q->backing_dev_info->congested_data = device;
28302830

2831-
blk_queue_make_request(q, drbd_make_request);
28322831
blk_queue_write_cache(q, true, true);
28332832
/* Setting the max_hw_sectors to an odd value of 8kibyte here
28342833
This triggers a max_bio_size message upon first attach or connect */

drivers/block/null_blk_main.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1743,12 +1743,11 @@ static int null_add_dev(struct nullb_device *dev)
17431743
goto out_cleanup_tags;
17441744
}
17451745
} else if (dev->queue_mode == NULL_Q_BIO) {
1746-
nullb->q = blk_alloc_queue_node(GFP_KERNEL, dev->home_node);
1746+
nullb->q = blk_alloc_queue(null_queue_bio, dev->home_node);
17471747
if (!nullb->q) {
17481748
rv = -ENOMEM;
17491749
goto out_cleanup_queues;
17501750
}
1751-
blk_queue_make_request(nullb->q, null_queue_bio);
17521751
rv = init_driver_queues(nullb);
17531752
if (rv)
17541753
goto out_cleanup_blk_queue;

drivers/block/pktcdvd.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2493,7 +2493,6 @@ static void pkt_init_queue(struct pktcdvd_device *pd)
24932493
{
24942494
struct request_queue *q = pd->disk->queue;
24952495

2496-
blk_queue_make_request(q, pkt_make_request);
24972496
blk_queue_logical_block_size(q, CD_FRAMESIZE);
24982497
blk_queue_max_hw_sectors(q, PACKET_MAX_SECTORS);
24992498
q->queuedata = pd;
@@ -2750,7 +2749,7 @@ static int pkt_setup_dev(dev_t dev, dev_t* pkt_dev)
27502749
disk->flags = GENHD_FL_REMOVABLE;
27512750
strcpy(disk->disk_name, pd->name);
27522751
disk->private_data = pd;
2753-
disk->queue = blk_alloc_queue(GFP_KERNEL);
2752+
disk->queue = blk_alloc_queue(pkt_make_request, NUMA_NO_NODE);
27542753
if (!disk->queue)
27552754
goto out_mem2;
27562755

drivers/block/ps3vram.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ static int ps3vram_probe(struct ps3_system_bus_device *dev)
737737

738738
ps3vram_proc_init(dev);
739739

740-
queue = blk_alloc_queue(GFP_KERNEL);
740+
queue = blk_alloc_queue(ps3vram_make_request, NUMA_NO_NODE);
741741
if (!queue) {
742742
dev_err(&dev->core, "blk_alloc_queue failed\n");
743743
error = -ENOMEM;
@@ -746,7 +746,6 @@ static int ps3vram_probe(struct ps3_system_bus_device *dev)
746746

747747
priv->queue = queue;
748748
queue->queuedata = dev;
749-
blk_queue_make_request(queue, ps3vram_make_request);
750749
blk_queue_max_segments(queue, BLK_MAX_SEGMENTS);
751750
blk_queue_max_segment_size(queue, BLK_MAX_SEGMENT_SIZE);
752751
blk_queue_max_hw_sectors(queue, BLK_SAFE_MAX_SECTORS);

drivers/block/rsxx/dev.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ int rsxx_setup_dev(struct rsxx_cardinfo *card)
248248
return -ENOMEM;
249249
}
250250

251-
card->queue = blk_alloc_queue(GFP_KERNEL);
251+
card->queue = blk_alloc_queue(rsxx_make_request, NUMA_NO_NODE);
252252
if (!card->queue) {
253253
dev_err(CARD_TO_DEV(card), "Failed queue alloc\n");
254254
unregister_blkdev(card->major, DRIVER_NAME);
@@ -269,7 +269,6 @@ int rsxx_setup_dev(struct rsxx_cardinfo *card)
269269
blk_queue_logical_block_size(card->queue, blk_size);
270270
}
271271

272-
blk_queue_make_request(card->queue, rsxx_make_request);
273272
blk_queue_max_hw_sectors(card->queue, blkdev_max_hw_sectors);
274273
blk_queue_physical_block_size(card->queue, RSXX_HW_BLK_SIZE);
275274

drivers/block/umem.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -885,11 +885,9 @@ static int mm_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
885885
card->biotail = &card->bio;
886886
spin_lock_init(&card->lock);
887887

888-
card->queue = blk_alloc_queue_node(GFP_KERNEL, NUMA_NO_NODE);
888+
card->queue = blk_alloc_queue(mm_make_request, NUMA_NO_NODE);
889889
if (!card->queue)
890890
goto failed_alloc;
891-
892-
blk_queue_make_request(card->queue, mm_make_request);
893891
card->queue->queuedata = card;
894892

895893
tasklet_init(&card->tasklet, process_page, (unsigned long)card);

drivers/block/zram/zram_drv.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1895,16 +1895,14 @@ static int zram_add(void)
18951895
#ifdef CONFIG_ZRAM_WRITEBACK
18961896
spin_lock_init(&zram->wb_limit_lock);
18971897
#endif
1898-
queue = blk_alloc_queue(GFP_KERNEL);
1898+
queue = blk_alloc_queue(zram_make_request, NUMA_NO_NODE);
18991899
if (!queue) {
19001900
pr_err("Error allocating disk queue for device %d\n",
19011901
device_id);
19021902
ret = -ENOMEM;
19031903
goto out_free_idr;
19041904
}
19051905

1906-
blk_queue_make_request(queue, zram_make_request);
1907-
19081906
/* gendisk structure */
19091907
zram->disk = alloc_disk(1);
19101908
if (!zram->disk) {

drivers/lightnvm/core.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,12 +380,11 @@ static int nvm_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create)
380380
goto err_dev;
381381
}
382382

383-
tqueue = blk_alloc_queue_node(GFP_KERNEL, dev->q->node);
383+
tqueue = blk_alloc_queue(tt->make_rq, dev->q->node);
384384
if (!tqueue) {
385385
ret = -ENOMEM;
386386
goto err_disk;
387387
}
388-
blk_queue_make_request(tqueue, tt->make_rq);
389388

390389
strlcpy(tdisk->disk_name, create->tgtname, sizeof(tdisk->disk_name));
391390
tdisk->flags = GENHD_FL_EXT_DEVT;

drivers/md/bcache/super.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -866,11 +866,10 @@ static int bcache_device_init(struct bcache_device *d, unsigned int block_size,
866866
d->disk->fops = &bcache_ops;
867867
d->disk->private_data = d;
868868

869-
q = blk_alloc_queue(GFP_KERNEL);
869+
q = blk_alloc_queue(make_request_fn, NUMA_NO_NODE);
870870
if (!q)
871871
return -ENOMEM;
872872

873-
blk_queue_make_request(q, make_request_fn);
874873
d->disk->queue = q;
875874
q->queuedata = d;
876875
q->backing_dev_info->congested_data = d;

drivers/md/dm.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1939,16 +1939,15 @@ static struct mapped_device *alloc_dev(int minor)
19391939
INIT_LIST_HEAD(&md->table_devices);
19401940
spin_lock_init(&md->uevent_lock);
19411941

1942-
md->queue = blk_alloc_queue_node(GFP_KERNEL, numa_node_id);
1943-
if (!md->queue)
1944-
goto bad;
1945-
md->queue->queuedata = md;
19461942
/*
19471943
* default to bio-based required ->make_request_fn until DM
19481944
* table is loaded and md->type established. If request-based
19491945
* table is loaded: blk-mq will override accordingly.
19501946
*/
1951-
blk_queue_make_request(md->queue, dm_make_request);
1947+
md->queue = blk_alloc_queue(dm_make_request, numa_node_id);
1948+
if (!md->queue)
1949+
goto bad;
1950+
md->queue->queuedata = md;
19521951

19531952
md->disk = alloc_disk_node(1, md->numa_node_id);
19541953
if (!md->disk)

drivers/md/md.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5623,12 +5623,11 @@ static int md_alloc(dev_t dev, char *name)
56235623
mddev->hold_active = UNTIL_STOP;
56245624

56255625
error = -ENOMEM;
5626-
mddev->queue = blk_alloc_queue(GFP_KERNEL);
5626+
mddev->queue = blk_alloc_queue(md_make_request, NUMA_NO_NODE);
56275627
if (!mddev->queue)
56285628
goto abort;
56295629
mddev->queue->queuedata = mddev;
56305630

5631-
blk_queue_make_request(mddev->queue, md_make_request);
56325631
blk_set_stacking_limits(&mddev->queue->limits);
56335632

56345633
disk = alloc_disk(1 << shift);

drivers/nvdimm/blk.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,13 +249,12 @@ static int nsblk_attach_disk(struct nd_namespace_blk *nsblk)
249249
internal_nlba = div_u64(nsblk->size, nsblk_internal_lbasize(nsblk));
250250
available_disk_size = internal_nlba * nsblk_sector_size(nsblk);
251251

252-
q = blk_alloc_queue(GFP_KERNEL);
252+
q = blk_alloc_queue(nd_blk_make_request, NUMA_NO_NODE);
253253
if (!q)
254254
return -ENOMEM;
255255
if (devm_add_action_or_reset(dev, nd_blk_release_queue, q))
256256
return -ENOMEM;
257257

258-
blk_queue_make_request(q, nd_blk_make_request);
259258
blk_queue_max_hw_sectors(q, UINT_MAX);
260259
blk_queue_logical_block_size(q, nsblk_sector_size(nsblk));
261260
blk_queue_flag_set(QUEUE_FLAG_NONROT, q);

0 commit comments

Comments
 (0)