Skip to content

Commit 271508d

Browse files
rientjesaxboe
authored andcommitted
block: allocate request memory local to request queue
blk_init_rl() allocates a mempool using mempool_create_node() with node local memory. This only allocates the mempool and element list locally to the requeue queue node. What we really want to do is allocate the request itself local to the queue. To do this, we need our own alloc and free functions that will allocate from request_cachep and pass the request queue node in to prefer node local memory. Acked-by: Tejun Heo <tj@kernel.org> Signed-off-by: David Rientjes <rientjes@google.com> Signed-off-by: Jens Axboe <axboe@fb.com>
1 parent bfd343a commit 271508d

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

block/blk-core.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,18 @@ void blk_cleanup_queue(struct request_queue *q)
557557
}
558558
EXPORT_SYMBOL(blk_cleanup_queue);
559559

560+
/* Allocate memory local to the request queue */
561+
static void *alloc_request_struct(gfp_t gfp_mask, void *data)
562+
{
563+
int nid = (int)(long)data;
564+
return kmem_cache_alloc_node(request_cachep, gfp_mask, nid);
565+
}
566+
567+
static void free_request_struct(void *element, void *unused)
568+
{
569+
kmem_cache_free(request_cachep, element);
570+
}
571+
560572
int blk_init_rl(struct request_list *rl, struct request_queue *q,
561573
gfp_t gfp_mask)
562574
{
@@ -569,9 +581,10 @@ int blk_init_rl(struct request_list *rl, struct request_queue *q,
569581
init_waitqueue_head(&rl->wait[BLK_RW_SYNC]);
570582
init_waitqueue_head(&rl->wait[BLK_RW_ASYNC]);
571583

572-
rl->rq_pool = mempool_create_node(BLKDEV_MIN_RQ, mempool_alloc_slab,
573-
mempool_free_slab, request_cachep,
574-
gfp_mask, q->node);
584+
rl->rq_pool = mempool_create_node(BLKDEV_MIN_RQ, alloc_request_struct,
585+
free_request_struct,
586+
(void *)(long)q->node, gfp_mask,
587+
q->node);
575588
if (!rl->rq_pool)
576589
return -ENOMEM;
577590

0 commit comments

Comments
 (0)