lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <11f5a5ab96e143689c07531c9e5e704a@AcuMS.aculab.com>
Date:   Tue, 17 Jan 2023 15:52:08 +0000
From:   David Laight <David.Laight@...LAB.COM>
To:     'Amy Parker' <apark0006@...dent.cerritos.edu>,
        "willy@...radead.org" <willy@...radead.org>
CC:     "linux-fsdevel@...r.kernel.org" <linux-fsdevel@...r.kernel.org>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: RE: [PATCH] dax: use switch statement over chained ifs

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@...dent.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)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ