From: "Huang\, Ying" <ying.huang@intel.com>
To: Wei Yang <richard.weiyang@gmail.com>
Cc: <akpm@linux-foundation.org>, <linux-mm@kvack.org>,
<linux-kernel@vger.kernel.org>, Hugh Dickins <hughd@google.com>
Subject: Re: [PATCH v2] mm/swapfile.c: simplify the scan loop in scan_swap_map_slots()
Date: Fri, 24 Apr 2020 10:02:58 +0800 [thread overview]
Message-ID: <87r1wdzlm5.fsf@yhuang-dev.intel.com> (raw)
In-Reply-To: <20200423131507.2rgrk3okh42oo6gh@master> (Wei Yang's message of "Thu, 23 Apr 2020 13:15:07 +0000")
Wei Yang <richard.weiyang@gmail.com> writes:
> On Thu, Apr 23, 2020 at 01:57:34PM +0800, Huang, Ying wrote:
>>Wei Yang <richard.weiyang@gmail.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@gmail.com>
>>> CC: Hugh Dickins <hughd@google.com>
>>> CC: "Huang, Ying" <ying.huang@intel.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.
>>
>
> When this case would happen in the original code?
In the original code, the loop can still stop.
Best Regards,
Huang, Ying
>>Again, the new code doesn't make it easier to find this kind of issues.
>>
>>Best Regards,
>>Huang, Ying
next prev parent reply other threads:[~2020-04-24 2:03 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-22 21:41 [PATCH v2] mm/swapfile.c: simplify the scan loop in scan_swap_map_slots() Wei Yang
2020-04-23 5:57 ` Huang, Ying
2020-04-23 13:15 ` Wei Yang
2020-04-24 2:02 ` Huang, Ying [this message]
2020-04-25 0:30 ` Wei Yang
2020-04-26 1:07 ` Huang, Ying
2020-04-26 21:19 ` Wei Yang
2020-04-27 0:55 ` Huang, Ying
2020-04-28 21:22 ` Wei Yang
2020-04-29 0:52 ` Huang, Ying
2020-04-29 22:06 ` Wei Yang
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=87r1wdzlm5.fsf@yhuang-dev.intel.com \
--to=ying.huang@intel.com \
--cc=akpm@linux-foundation.org \
--cc=hughd@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=richard.weiyang@gmail.com \
/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;
as well as URLs for NNTP newsgroup(s).