* [PATCH] null_blk: Use bitmap_zalloc() when applicable
@ 2021-12-23 21:55 Christophe JAILLET
2021-12-30 2:28 ` Damien Le Moal
0 siblings, 1 reply; 4+ messages in thread
From: Christophe JAILLET @ 2021-12-23 21:55 UTC (permalink / raw)
To: axboe, chaitanya.kulkarni, damien.lemoal, ming.lei,
Johannes.Thumshirn, shinichiro.kawasaki, jiangguoqing
Cc: linux-block, linux-kernel, kernel-janitors, Christophe JAILLET
'nq->tag_map' is a bitmap. So use bitmap_zalloc() to simplify code and
improve the semantic.
Also change the corresponding kfree() into bitmap_free() to keep
consistency.
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
drivers/block/null_blk/main.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c
index 6be6ccd4a28f..9e058e0aa668 100644
--- a/drivers/block/null_blk/main.c
+++ b/drivers/block/null_blk/main.c
@@ -1661,7 +1661,7 @@ static blk_status_t null_queue_rq(struct blk_mq_hw_ctx *hctx,
static void cleanup_queue(struct nullb_queue *nq)
{
- kfree(nq->tag_map);
+ bitmap_free(nq->tag_map);
kfree(nq->cmds);
}
@@ -1790,14 +1790,13 @@ static const struct block_device_operations null_rq_ops = {
static int setup_commands(struct nullb_queue *nq)
{
struct nullb_cmd *cmd;
- int i, tag_size;
+ int i;
nq->cmds = kcalloc(nq->queue_depth, sizeof(*cmd), GFP_KERNEL);
if (!nq->cmds)
return -ENOMEM;
- tag_size = ALIGN(nq->queue_depth, BITS_PER_LONG) / BITS_PER_LONG;
- nq->tag_map = kcalloc(tag_size, sizeof(unsigned long), GFP_KERNEL);
+ nq->tag_map = bitmap_zalloc(nq->queue_depth, GFP_KERNEL);
if (!nq->tag_map) {
kfree(nq->cmds);
return -ENOMEM;
--
2.32.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] null_blk: Use bitmap_zalloc() when applicable
2021-12-23 21:55 [PATCH] null_blk: Use bitmap_zalloc() when applicable Christophe JAILLET
@ 2021-12-30 2:28 ` Damien Le Moal
2022-01-06 7:44 ` Dan Carpenter
0 siblings, 1 reply; 4+ messages in thread
From: Damien Le Moal @ 2021-12-30 2:28 UTC (permalink / raw)
To: Christophe JAILLET, axboe, chaitanya.kulkarni, damien.lemoal,
ming.lei, Johannes.Thumshirn, shinichiro.kawasaki, jiangguoqing
Cc: linux-block, linux-kernel, kernel-janitors
On 12/24/21 06:55, Christophe JAILLET wrote:
> 'nq->tag_map' is a bitmap. So use bitmap_zalloc() to simplify code and
> improve the semantic.
>
> Also change the corresponding kfree() into bitmap_free() to keep
> consistency.
>
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> drivers/block/null_blk/main.c | 7 +++----
> 1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c
> index 6be6ccd4a28f..9e058e0aa668 100644
> --- a/drivers/block/null_blk/main.c
> +++ b/drivers/block/null_blk/main.c
> @@ -1661,7 +1661,7 @@ static blk_status_t null_queue_rq(struct blk_mq_hw_ctx *hctx,
>
> static void cleanup_queue(struct nullb_queue *nq)
> {
> - kfree(nq->tag_map);
> + bitmap_free(nq->tag_map);
> kfree(nq->cmds);
> }
>
> @@ -1790,14 +1790,13 @@ static const struct block_device_operations null_rq_ops = {
> static int setup_commands(struct nullb_queue *nq)
> {
> struct nullb_cmd *cmd;
> - int i, tag_size;
> + int i;
>
> nq->cmds = kcalloc(nq->queue_depth, sizeof(*cmd), GFP_KERNEL);
> if (!nq->cmds)
> return -ENOMEM;
>
> - tag_size = ALIGN(nq->queue_depth, BITS_PER_LONG) / BITS_PER_LONG;
> - nq->tag_map = kcalloc(tag_size, sizeof(unsigned long), GFP_KERNEL);
> + nq->tag_map = bitmap_zalloc(nq->queue_depth, GFP_KERNEL);
> if (!nq->tag_map) {
> kfree(nq->cmds);
> return -ENOMEM;
Before this patch, tag_size would always be a multiple of BITS_PER_LONG.
Using bitmap_zalloc(), that alignment goes away, but I think this is OK.
Reviewed-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
--
Damien Le Moal
Western Digital Research
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] null_blk: Use bitmap_zalloc() when applicable
2021-12-30 2:28 ` Damien Le Moal
@ 2022-01-06 7:44 ` Dan Carpenter
2022-01-06 7:49 ` Damien Le Moal
0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2022-01-06 7:44 UTC (permalink / raw)
To: Damien Le Moal
Cc: Christophe JAILLET, axboe, chaitanya.kulkarni, damien.lemoal,
ming.lei, Johannes.Thumshirn, shinichiro.kawasaki, jiangguoqing,
linux-block, linux-kernel, kernel-janitors
On Thu, Dec 30, 2021 at 11:28:28AM +0900, Damien Le Moal wrote:
> >
> > - tag_size = ALIGN(nq->queue_depth, BITS_PER_LONG) / BITS_PER_LONG;
> > - nq->tag_map = kcalloc(tag_size, sizeof(unsigned long), GFP_KERNEL);
> > + nq->tag_map = bitmap_zalloc(nq->queue_depth, GFP_KERNEL);
> > if (!nq->tag_map) {
> > kfree(nq->cmds);
> > return -ENOMEM;
>
> Before this patch, tag_size would always be a multiple of BITS_PER_LONG.
> Using bitmap_zalloc(), that alignment goes away, but I think this is OK.
>
It's still going to be a multiple of long. Bitmaps are always stored
in longs.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] null_blk: Use bitmap_zalloc() when applicable
2022-01-06 7:44 ` Dan Carpenter
@ 2022-01-06 7:49 ` Damien Le Moal
0 siblings, 0 replies; 4+ messages in thread
From: Damien Le Moal @ 2022-01-06 7:49 UTC (permalink / raw)
To: Dan Carpenter
Cc: Christophe JAILLET, axboe, chaitanya.kulkarni, damien.lemoal,
ming.lei, Johannes.Thumshirn, shinichiro.kawasaki, jiangguoqing,
linux-block, linux-kernel, kernel-janitors
On 1/6/22 16:44, Dan Carpenter wrote:
> On Thu, Dec 30, 2021 at 11:28:28AM +0900, Damien Le Moal wrote:
>>>
>>> - tag_size = ALIGN(nq->queue_depth, BITS_PER_LONG) / BITS_PER_LONG;
>>> - nq->tag_map = kcalloc(tag_size, sizeof(unsigned long), GFP_KERNEL);
>>> + nq->tag_map = bitmap_zalloc(nq->queue_depth, GFP_KERNEL);
>>> if (!nq->tag_map) {
>>> kfree(nq->cmds);
>>> return -ENOMEM;
>>
>> Before this patch, tag_size would always be a multiple of BITS_PER_LONG.
>> Using bitmap_zalloc(), that alignment goes away, but I think this is OK.
>>
>
> It's still going to be a multiple of long. Bitmaps are always stored
> in longs.
Yes, I understand that. I was referring to tag_size, which was rounded
before. But tag_size is only a local variable and not the actual queue
depth, which is not rounded. I got confused :)
>
> regards,
> dan carpenter
>
--
Damien Le Moal
Western Digital Research
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-01-06 7:49 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-12-23 21:55 [PATCH] null_blk: Use bitmap_zalloc() when applicable Christophe JAILLET
2021-12-30 2:28 ` Damien Le Moal
2022-01-06 7:44 ` Dan Carpenter
2022-01-06 7:49 ` Damien Le Moal
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).