From: Mel Gorman <mgorman@techsingularity.net>
To: Dave Hansen <dave.hansen@intel.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
mhocko@kernel.org, vbabka@suse.cz, Aaron Lu <aaron.lu@intel.com>,
linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [PATCH] mremap: Avoid TLB flushing anonymous pages that are not in swap cache
Date: Tue, 5 Jun 2018 20:12:46 +0100 [thread overview]
Message-ID: <20180605191245.3owve7gfut22tyob@techsingularity.net> (raw)
In-Reply-To: <bfc2e579-915f-24db-0ff0-29bd9148b8c0@intel.com>
On Tue, Jun 05, 2018 at 11:18:18AM -0700, Dave Hansen wrote:
> On 06/05/2018 10:13 AM, Mel Gorman wrote:
> > The anonymous page race fix is overkill for two reasons. Pages that are not
> > in the swap cache are not going to be issued for IO and if a stale TLB entry
> > is used, the write still occurs on the same physical page. Any race with
> > mmap replacing the address space is handled by mmap_sem. As anonymous pages
> > are often dirty, it can mean that mremap always has to flush even when it is
> > not necessary.
>
> This looks fine to me. One nit on the description: I found myself
> wondering if we skip the flush under the ptl where the flush is
> eventually done. That code is a bit out of the context, so we don't see
> it in the patch.
>
That's fair enough. I updated part of the changelog to read
This patch special cases anonymous pages to only flush ranges under the
page table lock if the page is in swap cache and can be potentially queued
for IO. Note that the full flush of the range being mremapped is still
flushed so TLB flushes are not eliminated entirely.
Does that work for you?
> We have two modes of flushing during move_ptes():
> 1. The flush_tlb_range() while holding the ptl in move_ptes().
> 2. A flush_tlb_range() at the end of move_table_tables(), driven by
> 'need_flush' which will be set any time move_ptes() does *not* flush.
>
> This patch broadens the scope where move_ptes() does not flush and
> shifts the burden to the flush inside move_table_tables().
>
> Right?
>
Yes. While this does not eliminate TLB flushes, it reduces the number
considerably as we potentially are replacing one-flush-per-LATENCY_LIMIT
with one flush.
> Other minor nits:
>
> > +/* Returns true if a TLB must be flushed before PTL is dropped */
> > +static bool should_force_flush(pte_t *pte)
> > +{
>
> I usually try to make the non-pte-modifying functions take a pte_t
> instead of 'pte_t *' to make it obvious that there no modification going
> on. Any reason not to do that here?
>
No, it was just a minor saving on stack usage.
> > + if (!trylock_page(page))
> > + return true;
> > + is_swapcache = PageSwapCache(page);
> > + unlock_page(page);
> > +
> > + return is_swapcache;
> > +}
>
> I was hoping we didn't have to go as far as taking the page lock, but I
> guess the proof is in the pudding that this tradeoff is worth it.
>
In the interest of full disclosure, the feedback I have from the customer is
based on a patch that modifies the LATENCY_LIMIT. This helped but did not
eliminate the problem. This was potentially a better solution but I wanted
review first. I'm waiting on confirmation this definitely behaves better.
> BTW, do you want to add a tiny comment about why we do the
> trylock_page()? I assume it's because we don't want to wait on finding
> an exact answer: we just assume it is in the swap cache if the page is
> locked and flush regardless.
It's really because calling lock_page while holding a spinlock is
eventually going to ruin your day.
Thanks.
--
Mel Gorman
SUSE Labs
next prev parent reply other threads:[~2018-06-05 19:12 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-05 17:13 Mel Gorman
2018-06-05 18:18 ` Dave Hansen
2018-06-05 19:12 ` Mel Gorman [this message]
2018-06-05 19:49 ` Dave Hansen
2018-06-05 19:51 ` Mel Gorman
2018-06-05 19:54 ` Dave Hansen
2018-06-05 20:00 ` Mel Gorman
2018-06-06 8:22 ` Michal Hocko
2018-06-05 19:53 ` Nadav Amit
2018-06-05 20:08 ` Mel Gorman
2018-06-05 22:53 ` Nadav Amit
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=20180605191245.3owve7gfut22tyob@techsingularity.net \
--to=mgorman@techsingularity.net \
--cc=aaron.lu@intel.com \
--cc=akpm@linux-foundation.org \
--cc=dave.hansen@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=vbabka@suse.cz \
/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