Linux filesystem development
 help / color / mirror / Atom feed
From: David Laight <David.Laight@ACULAB.COM>
To: 'Amy Parker' <apark0006@student.cerritos.edu>,
	"willy@infradead.org" <willy@infradead.org>
Cc: "linux-fsdevel@vger.kernel.org" <linux-fsdevel@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH] dax: use switch statement over chained ifs
Date: Tue, 17 Jan 2023 15:52:08 +0000	[thread overview]
Message-ID: <11f5a5ab96e143689c07531c9e5e704a@AcuMS.aculab.com> (raw)
In-Reply-To: <CAPOgqxF_xEgKspetRJ=wq1_qSG3h8mkyXC58TXkUvx0agzEm_A@mail.gmail.com>

From: Amy Parker
> Sent: 17 January 2023 02:11
> 
> This patch uses a switch statement for pe_order, which improves
> readability and on some platforms may minorly improve performance. It
> also, to improve readability, recognizes that `PAGE_SHIFT - PAGE_SHIFT' is
> a constant, and uses 0 in its place instead.

The compiler is pretty much guaranteed to do that anyway.
The 'chained ifs' can generate better code because the
common case can be put first.
The compiler will base its 'chained ifs' (jump tables
can't be used due to cpu 'features' - and would be slower
anyway with only a few labels) on minimising the number
of conditionals.

(Never mind any of the other problems.)

	David

> 
> Signed-off-by: Amy Parker <apark0006@student.cerritos.edu>
> ---
>  fs/dax.c | 13 ++++++++-----
>  1 file changed, 8 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/dax.c b/fs/dax.c
> index c48a3a93ab29..e8beed601384 100644
> --- a/fs/dax.c
> +++ b/fs/dax.c
> @@ -32,13 +32,16 @@
> 
>  static inline unsigned int pe_order(enum page_entry_size pe_size)
>  {
> -    if (pe_size == PE_SIZE_PTE)
> -        return PAGE_SHIFT - PAGE_SHIFT;
> -    if (pe_size == PE_SIZE_PMD)
> +    switch (pe_size) {
> +    case PE_SIZE_PTE:
> +        return 0;
> +    case PE_SIZE_PMD:
>          return PMD_SHIFT - PAGE_SHIFT;
> -    if (pe_size == PE_SIZE_PUD)
> +    case PE_SIZE_PUD:
>          return PUD_SHIFT - PAGE_SHIFT;
> -    return ~0;
> +    default:
> +        return ~0;
> +    }
>  }
> 
>  /* We choose 4096 entries - same as per-zone page wait tables */
> --
> 2.39.0

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

      parent reply	other threads:[~2023-01-17 15:53 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-17  2:11 [PATCH] dax: use switch statement over chained ifs Amy Parker
2023-01-17  2:41 ` Matthew Wilcox
2023-01-17  5:07   ` Amy Parker
2023-01-17 14:23     ` Matthew Wilcox
2023-01-17 15:52 ` David Laight [this message]

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=11f5a5ab96e143689c07531c9e5e704a@AcuMS.aculab.com \
    --to=david.laight@aculab.com \
    --cc=apark0006@student.cerritos.edu \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox