From: Nick Piggin <npiggin@suse.de>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Hugh Dickins <hugh@veritas.com>,
Linux Memory Management List <linux-mm@kvack.org>,
Benjamin Herrenschmidt <benh@kernel.crashing.org>
Subject: Re: [patch] mm: fix PageUptodate memory ordering bug
Date: Sun, 23 Dec 2007 06:57:30 +0100 [thread overview]
Message-ID: <20071223055730.GA29288@wotan.suse.de> (raw)
In-Reply-To: <20071222005737.2675c33b.akpm@linux-foundation.org>
On Sat, Dec 22, 2007 at 12:57:37AM -0800, Andrew Morton wrote:
> On Tue, 18 Dec 2007 02:26:32 +0100 Nick Piggin <npiggin@suse.de> wrote:
>
> > After running SetPageUptodate, preceeding stores to the page contents to
> > actually bring it uptodate may not be ordered with the store to set the page
> > uptodate.
> >
> > Therefore, another CPU which checks PageUptodate is true, then reads the
> > page contents can get stale data.
> >
> > Fix this by having an smp_wmb before SetPageUptodate, and smp_rmb after
> > PageUptodate.
> >
> > Many places that test PageUptodate, do so with the page locked, and this
> > would be enough to ensure memory ordering in those places if SetPageUptodate
> > were only called while the page is locked. Unfortunately that is not always
> > the case for some filesystems, but it could be an idea for the future.
> >
> > One thing I like about it is that it brings the handling of anonymous page
> > uptodateness in line with that of file backed page management, by marking anon
> > pages as uptodate when they _are_ uptodate, rather than when our implementation
> > requires that they be marked as such. Doing allows us to get rid of the
> > smp_wmb's in the page copying functions, which were especially added for
> > anonymous pages for an analogous memory ordering problem, and are now handled
> > with the same code as the PageUptodate memory ordering problem.
> >
> > Introduce a SetNewPageUptodate for these anonymous pages: it contains non
> > atomic bitops so as not to introduce too much overhead into these paths.
> >
>
> hrm.
>
> > +static inline void SetNewPageUptodate(struct page *page)
> > +{
> > + smp_wmb();
> > + __set_bit(PG_uptodate, &(page)->flags);
>
> argh. Put the pin back in that thing before you hurt someone.
>
> Sigh. I guess it's fairly clear but it could do with a big fat warning
> over it before you go and kill someone.
Hmm, perhaps it should use the more conventional __SetPageUptodate. I had
named it SetNewPageUptodate in an earlier version of the ptach which was
slightly different.
> Because if this little hand grenade gets used in the wrong place, it will
> cause a horrid, horrid data-corrupting bug which might take us literally
> years to hunt down and fix.
Yeah, like the other non-atomic bitops. I guess we just have to make sure
they're used correctly... they really make a big difference to performance.
I guess the memory ordering bug would take years to hunt down and fix too,
OTOH I guess it would probably be the powerpc guys, rather than you or I,
that have to debug it ;)
> > #ifdef CONFIG_S390
>
> > + page_clear_dirty(page);
> > +#endif
> > +}
>
>
> For an overall 0.5% increase in the i386 size of several core mm files. If
> you don't blow us up on the spot, you'll slowly bleed us to death.
>
> Can it be improved?
At first glance you'd think that, loads being in order on i386, it should be
a noop, but we actually still require a barrier to be technically correct
(even on i386). Which increases the size of some otherwise unchanged files.
Adding a few SetNewPageUptodates adds the rest, I guess. The alternative would
be to have more open coded smp_wmb()s around. I like this way much better.
Given the amount of crap that's "pending", I'd be surprised if I was the one
who bleeds us to death with bugfixes ;) But if you'd rather see some speedups,
I could certainly rustle something up.
Anyway, thanks for picking it up. That's already tripled the amount of feedback
it hsa got ;)
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2007-12-23 5:57 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-12-18 1:26 [patch] mm: fix PageUptodate memory ordering bug Nick Piggin
2007-12-22 8:57 ` Andrew Morton
2007-12-22 12:14 ` Hugh Dickins
2007-12-23 6:54 ` Nick Piggin
2007-12-23 6:54 ` Nick Piggin
2007-12-23 5:57 ` Nick Piggin [this message]
2007-12-23 6:32 ` Andrew Morton
2007-12-23 7:15 ` Nick Piggin
2007-12-23 7:29 ` Andrew Morton
2007-12-23 9:14 ` Nick Piggin
2007-12-23 9:28 ` Andrew Morton
2007-12-23 16:02 ` Andi Kleen
2007-12-30 16:33 ` Ingo Molnar
2008-01-01 23:26 ` Nick Piggin
2008-01-02 21:01 ` Andi Kleen
2008-01-03 3:32 ` Nick Piggin
2008-01-03 13:08 ` Andi Kleen
2007-12-23 17:22 ` Linus Torvalds
2007-12-23 21:35 ` Nick Piggin
2007-12-23 22:41 ` Nick Piggin
2008-01-01 23:41 ` Alan Cox
2008-01-02 11:02 ` [patch] i386: avoid expensive ppro ordering workaround for default 686 kernels Nick Piggin
2008-01-02 13:44 ` Alan Cox
2008-01-03 4:17 ` Nick Piggin
2008-01-03 14:23 ` Alan Cox
2008-01-03 20:20 ` Benjamin Herrenschmidt
2008-01-03 22:23 ` Alan Cox
2008-01-03 23:10 ` Nick Piggin
2008-01-04 16:27 ` Alan Cox
2008-01-07 0:12 ` Nick Piggin
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=20071223055730.GA29288@wotan.suse.de \
--to=npiggin@suse.de \
--cc=akpm@linux-foundation.org \
--cc=benh@kernel.crashing.org \
--cc=hugh@veritas.com \
--cc=linux-mm@kvack.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.