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: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Thu, 23 Apr 2020 13:57:34 +0800
From:   "Huang\, Ying" <ying.huang@...el.com>
To:     Wei Yang <richard.weiyang@...il.com>
Cc:     <akpm@...ux-foundation.org>, <linux-mm@...ck.org>,
        <linux-kernel@...r.kernel.org>, Hugh Dickins <hughd@...gle.com>
Subject: Re: [PATCH v2] mm/swapfile.c: simplify the scan loop in scan_swap_map_slots()

Wei Yang <richard.weiyang@...il.com> writes:

> After commit c60aa176c6de8 ("swapfile: swap allocation cycle if
> nonrot"), swap allocation is cyclic. Current approach is done with two
> separate loop on the upper and lower half. This looks a little
> redundant.

I can understand that the redundant code doesn't smell good.  But I
don't think the new code is easier to be understood than the original
one.

> From another point of view, the loop iterates [lowest_bit, highest_bit]
> range starting with (offset + 1) but except scan_base. So we can
> simplify the loop with condition (next_offset() != scan_base) by
> introducing next_offset() which makes sure offset fit in that range
> with correct order.
>
> Signed-off-by: Wei Yang <richard.weiyang@...il.com>
> CC: Hugh Dickins <hughd@...gle.com>
> CC: "Huang, Ying" <ying.huang@...el.com>
>
> ---
> v2:
>   * return scan_base if the lower part is eaten
>   * only start over when iterating on the upper part
> ---
>  mm/swapfile.c | 31 ++++++++++++++-----------------
>  1 file changed, 14 insertions(+), 17 deletions(-)
>
> diff --git a/mm/swapfile.c b/mm/swapfile.c
> index f903e5a165d5..0005a4a1c1b4 100644
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
> @@ -729,6 +729,19 @@ static void swap_range_free(struct swap_info_struct *si, unsigned long offset,
>  	}
>  }
>  
> +static unsigned long next_offset(struct swap_info_struct *si,
> +				unsigned long *offset, unsigned long scan_base)
> +{
> +	/* only start over when iterating on the upper part */
> +	if (++(*offset) > si->highest_bit && *offset > scan_base) {
> +		*offset = si->lowest_bit;
> +		/* someone has eaten the lower part */
> +		if (si->lowest_bit >= scan_base)
> +			return scan_base;
> +	}

if "offset > si->highest_bit" is true and "offset < scan_base" is true,
scan_base need to be returned.

Again, the new code doesn't make it easier to find this kind of issues.

Best Regards,
Huang, Ying

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ