From: "Huang\, Ying" <ying.huang@intel.com>
To: Daniel Jordan <daniel.m.jordan@oracle.com>
Cc: Andrew Morton <akpm@linux-foundation.org>, <linux-mm@kvack.org>,
<linux-kernel@vger.kernel.org>, Michal Hocko <mhocko@suse.com>,
Minchan Kim <minchan@kernel.org>,
Tim Chen <tim.c.chen@linux.intel.com>,
Hugh Dickins <hughd@google.com>
Subject: Re: [PATCH -V3] swap: Reduce lock contention on swap cache from swap slots allocation
Date: Thu, 28 May 2020 13:32:40 +0800 [thread overview]
Message-ID: <87h7w0hbev.fsf@yhuang-dev.intel.com> (raw)
In-Reply-To: <20200528013724.flx6pwcmaazpek32@ca-dmjordan1.us.oracle.com> (Daniel Jordan's message of "Wed, 27 May 2020 21:37:24 -0400")
Daniel Jordan <daniel.m.jordan@oracle.com> writes:
> On Mon, May 25, 2020 at 08:26:48AM +0800, Huang Ying wrote:
>> diff --git a/mm/swapfile.c b/mm/swapfile.c
>> index 423c234aca15..0abd93d2a4fc 100644
>> --- a/mm/swapfile.c
>> +++ b/mm/swapfile.c
>> @@ -615,7 +615,8 @@ static bool scan_swap_map_try_ssd_cluster(struct swap_info_struct *si,
>> * discarding, do discard now and reclaim them
>> */
>> swap_do_scheduled_discard(si);
>> - *scan_base = *offset = si->cluster_next;
>> + *scan_base = this_cpu_read(*si->cluster_next_cpu);
>> + *offset = *scan_base;
>> goto new_cluster;
>
> Why is this done? As far as I can tell, the values always get overwritten at
> the end of the function with tmp and tmp isn't derived from them. Seems
> ebc2a1a69111 moved some logic that used to make sense but doesn't have any
> effect now.
If we fail to allocate from cluster, "scan_base" and "offset" will not
be overridden. And "cluster_next" or "cluster_next_cpu" may be changed
in swap_do_scheduled_discard(), because the lock is released and
re-acquired there.
The code may not have much value. And you may think that it's better to
remove it. But that should be in another patch.
>> } else
>> return false;
>> @@ -721,6 +722,34 @@ static void swap_range_free(struct swap_info_struct *si, unsigned long offset,
>> }
>> }
>>
>> +static void set_cluster_next(struct swap_info_struct *si, unsigned long next)
>> +{
>> + unsigned long prev;
>> +
>> + if (!(si->flags & SWP_SOLIDSTATE)) {
>> + si->cluster_next = next;
>> + return;
>> + }
>> +
>> + prev = this_cpu_read(*si->cluster_next_cpu);
>> + /*
>> + * Cross the swap address space size aligned trunk, choose
>> + * another trunk randomly to avoid lock contention on swap
>> + * address space if possible.
>> + */
>> + if ((prev >> SWAP_ADDRESS_SPACE_SHIFT) !=
>> + (next >> SWAP_ADDRESS_SPACE_SHIFT)) {
>> + /* No free swap slots available */
>> + if (si->highest_bit <= si->lowest_bit)
>> + return;
>> + next = si->lowest_bit +
>> + prandom_u32_max(si->highest_bit - si->lowest_bit + 1);
>> + next = ALIGN(next, SWAP_ADDRESS_SPACE_PAGES);
>> + next = max_t(unsigned int, next, si->lowest_bit);
>
> next is always greater than lowest_bit because it's aligned up. I think the
> intent of the max_t line is to handle when next is aligned outside the valid
> range, so it'd have to be ALIGN_DOWN instead?
Oops. I misunderstood "ALIGN()" here. Yes. we should use ALIGN_DOWN()
instead. Thanks for pointing this out!
>
> These aside, patch looks good to me.
Thanks for your review! It really help me to improve the quality of the
patch. Can I add your "Reviewed-by" in the next version?
Best Regards,
Huang, Ying
next prev parent reply other threads:[~2020-05-28 5:32 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-25 0:26 [PATCH -V3] swap: Reduce lock contention on swap cache from swap slots allocation Huang Ying
2020-05-28 1:37 ` Daniel Jordan
2020-05-28 5:32 ` Huang, Ying [this message]
2020-05-28 17:11 ` Daniel Jordan
2020-05-29 0:43 ` Huang, Ying
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=87h7w0hbev.fsf@yhuang-dev.intel.com \
--to=ying.huang@intel.com \
--cc=akpm@linux-foundation.org \
--cc=daniel.m.jordan@oracle.com \
--cc=hughd@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
--cc=minchan@kernel.org \
--cc=tim.c.chen@linux.intel.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).