Re: [PATCH] Block: Check major number before allocate the bufferin register_blkdev()

From: Jens Axboe
Date: Mon May 10 2010 - 08:35:38 EST



Please don't top post when replying to emails, I fixed this one up for
you.

On Mon, May 10 2010, wzt wzt wrote:
> On Mon, May 10, 2010 at 7:56 PM, Jens Axboe <jens.axboe@xxxxxxxxxx> wrote:
> > On Mon, May 10 2010, wzt.wzt@xxxxxxxxx wrote:
> >> Check major number before allocate the buffer, if the major number is not exist,
> >> and the register_blkdev() called many times, kmalloc()/kfree() will be no need
> >> to invoked many times. So check the major number before use kmalloc() to allocate
> >> the buffer will be better.
> >
> > This would generally be sound advice for performance oriented code, but
> > I can't see it making any difference here.
>
> the original code use kmalloc() to allocate struct blk_major_name
> buffer first, then find the major number in major_names array. if
> found it, it will kfree() the unused struct blk_major_name buffer,
> if register_blkdev() called many times like:
> register_blkdev(22, "aa");
> ....
> register_blkdev(22, "aa");
> kmalloc()/kfree() will be no need to invoked many times, my point is
> that find the major number first, then allocate the buffer will be
> better. this patch can handle the special case.

Yes I realize how it works and what your patch does, my point is that it
seems pointless to change code like that. Your 'test case' above isn't a
valid one. If register_blkdev() was called tons of times per second and
hence would be a hot code path, and it additionally most of the time
ended up freeing the buffer, then there would be a case for changing it.

--
Jens Axboe

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/