grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] bufio: round up block size to power of 2


From: Michael Chang
Subject: Re: [PATCH] bufio: round up block size to power of 2
Date: Tue, 24 Apr 2018 14:08:51 +0800
User-agent: NeoMutt/20170421 (1.8.2)

On Mon, Apr 23, 2018 at 03:57:22PM +0200, Daniel Kiper wrote:
> On Fri, Apr 20, 2018 at 03:21:30PM +0800, Michael Chang wrote:
> > Rounding up the bufio->block_size to meet power of 2 to facilitate next_buf
> > calcuation in grub_bufio_read.
> >
> > Signed-off-by: Michael Chang <address@hidden>
> > ---
> >  grub-core/io/bufio.c | 8 ++++++++
> >  1 file changed, 8 insertions(+)
> >
> > diff --git a/grub-core/io/bufio.c b/grub-core/io/bufio.c
> > index 22438277d..4d66b65a3 100644
> > --- a/grub-core/io/bufio.c
> > +++ b/grub-core/io/bufio.c
> > @@ -61,6 +61,14 @@ grub_bufio_open (grub_file_t io, int size)
> >      size = ((io->size > GRUB_BUFIO_MAX_SIZE) ? GRUB_BUFIO_MAX_SIZE :
> >              io->size);
> >
> > +  /* round up size to power of 2 */
> 
> May I ask you to say why here?

OK.

> 
> > +  if (size & (size - 1))
> > +    {
> > +      int round_up;
> > +      for (round_up = 1; round_up < size; round_up <<= 1);
> > +      size = round_up;
> > +    }
> 
> Please use this (stolen from linux/drivers/md/raid5.c):
>   while (size & (size - 1))
>     size = (size | (size - 1)) + 1;

Cool. They will be added in upcoming V2 patch.

Thanks,
Michael

> 
> Daniel



reply via email to

[Prev in Thread] Current Thread [Next in Thread]