From: Peter Zijlstra <peterz@infradead.org>
To: Davidlohr Bueso <dave@stgolabs.net>
Cc: Mel Gorman <mgorman@techsingularity.net>,
Thomas Gleixner <tglx@linutronix.de>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
Chris Mason <clm@fb.com>, Darren Hart <dvhart@linux.intel.com>,
linux-kernel@vger.kernel.org, Davidlohr Bueso <dbueso@suse.de>
Subject: Re: [PATCH] futex: Reduce the scope of lock_page, aka lockless futex_get_key()
Date: Tue, 5 Jan 2016 21:33:17 +0100 [thread overview]
Message-ID: <20160105203317.GQ6344@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <1452025435-15355-1-git-send-email-dave@stgolabs.net>
On Tue, Jan 05, 2016 at 12:23:55PM -0800, Davidlohr Bueso wrote:
> +++ b/kernel/futex.c
> @@ -520,7 +520,18 @@ again:
> else
> err = 0;
>
> - lock_page(page);
> + /*
> + * The treatment of mapping from this point on is critical. The page
> + * lock protects many things but in this context the page lock
> + * stabilises mapping, prevents inode freeing in the shared
> + * file-backed region case and guards against movement to swap cache.
A little extra whitespace separating this into paragraphs might help
readability.
> + * Strictly speaking the page lock is not needed in all cases being
> + * considered here and page lock forces unnecessarily serialisation.
> + * From this point on, mapping will be reverified if necessary and
> + * page lock will be acquired only if it is unavoiable.
> + */
> + mapping = READ_ONCE(compound_head(page)->mapping);
> +
> /*
> * If page->mapping is NULL, then it cannot be a PageAnon
> * page; but it might be the ZERO_PAGE or in the gate area or
> + if (unlikely(!mapping)) {
> + int shmem_swizzled;
> +
> + /*
> + * Page lock is required to identify which special case above
> + * applies. If this is really a shmem page then the page lock
> + * will prevent unexpected transitions.
> + */
> + lock_page(page);
> + shmem_swizzled = PageSwapCache(page);
> unlock_page(page);
> put_page(page);
> + WARN_ON_ONCE(mapping);
We've not re-loaded mapping, so how could this possibly be?
> + /*
> + * Take a reference unless it is about to be freed. Previously
> + * this reference was taken by ihold under the page lock
> + * pinning the inode in place so i_lock was unnecessary. The
> + * only way for this check to fail is if the inode was
> + * truncated in parallel so warn for now if this happens.
> + *
> + * TODO: VFS and/or filesystem people should review this check
> + * and see if there is a safer or more reliable way to do this.
> + */
> + if (WARN_ON(!atomic_inc_not_zero(&inode->i_count))) {
> + rcu_read_unlock();
> + put_page(page);
> + goto again;
> + }
> +
> + /*
> + * get_futex_key() must imply MB (B) and we are not going to
> + * call into get_futex_key_refs() at this point.
> + */
> + smp_mb__after_atomic();
I don't get this one, the above is a successful atomic op with return
value, that _must_ imply a full barrier.
next prev parent reply other threads:[~2016-01-05 20:33 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-05 20:23 [PATCH] futex: Reduce the scope of lock_page, aka lockless futex_get_key() Davidlohr Bueso
2016-01-05 20:33 ` Peter Zijlstra [this message]
2016-01-05 20:43 ` Davidlohr Bueso
2016-01-05 21:11 ` Davidlohr Bueso
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=20160105203317.GQ6344@twins.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=bigeasy@linutronix.de \
--cc=clm@fb.com \
--cc=dave@stgolabs.net \
--cc=dbueso@suse.de \
--cc=dvhart@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@techsingularity.net \
--cc=tglx@linutronix.de \
/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).