All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mikulas Patocka <mpatocka@redhat.com>
To: Matthew Wilcox <willy@infradead.org>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>,
	Jens Axboe <axboe@kernel.dk>,
	linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org
Subject: Re: [PATCH] buffer: a small optimization in grow_buffers
Date: Mon, 22 Mar 2021 12:36:30 -0400 (EDT)	[thread overview]
Message-ID: <alpine.LRH.2.02.2103221225330.1530@file01.intranet.prod.int.rdu2.redhat.com> (raw)
In-Reply-To: <20210322151124.GP1719932@casper.infradead.org>



On Mon, 22 Mar 2021, Matthew Wilcox wrote:

> On Mon, Mar 22, 2021 at 10:05:05AM -0400, Mikulas Patocka wrote:
> > This patch replaces a loop with a "tzcnt" instruction.
> 
> Are you sure that's an optimisation?  The loop would execute very few
> times under normal circumstances (a maximum of three times on x86).
> Some numbers would be nice.

According to Agner's instruction tables, tzcnt has latency 3 on Skylake 
and 2 on Zen. (386, 486, Pentium and K6 didn't have hardware for the bsf 
instruction, they executed it in microcode bit-by-bit, but newer 
processors execute it quickly).

The patch reduces code size by 16 bytes.

Mikulas

> > Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
> > 
> > Index: linux-2.6/fs/buffer.c
> > ===================================================================
> > --- linux-2.6.orig/fs/buffer.c
> > +++ linux-2.6/fs/buffer.c
> 
> Are ... are you still using CVS?!
> 
> > @@ -1020,11 +1020,7 @@ grow_buffers(struct block_device *bdev,
> >  	pgoff_t index;
> >  	int sizebits;
> >  
> > -	sizebits = -1;
> > -	do {
> > -		sizebits++;
> > -	} while ((size << sizebits) < PAGE_SIZE);
> > -
> > +	sizebits = PAGE_SHIFT - __ffs(size);
> >  	index = block >> sizebits;
> >  
> >  	/*
> > 
> 


  reply	other threads:[~2021-03-22 16:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-22 14:05 [PATCH] buffer: a small optimization in grow_buffers Mikulas Patocka
2021-03-22 15:11 ` Matthew Wilcox
2021-03-22 16:36   ` Mikulas Patocka [this message]
2021-03-22 15:34 ` Al Viro

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LRH.2.02.2103221225330.1530@file01.intranet.prod.int.rdu2.redhat.com \
    --to=mpatocka@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.