From: Michal Hocko <mhocko@suse.cz>
To: Johannes Weiner <hannes@cmpxchg.org>
Cc: Vladimir Davydov <vdavydov@parallels.com>,
linux-mm@kvack.org, Greg Thelen <gthelen@google.com>,
Dave Hansen <dave@sr71.net>,
cgroups@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [patch] mm: memcontrol: lockless page counters
Date: Thu, 25 Sep 2014 15:07:16 +0200 [thread overview]
Message-ID: <20140925130716.GE12090@dhcp22.suse.cz> (raw)
In-Reply-To: <20140924170017.GB9968@cmpxchg.org>
On Wed 24-09-14 13:00:17, Johannes Weiner wrote:
> On Wed, Sep 24, 2014 at 04:16:33PM +0200, Michal Hocko wrote:
> > On Tue 23-09-14 13:05:25, Johannes Weiner wrote:
> > [...]
> > > #include <trace/events/vmscan.h>
> > >
> > > -int page_counter_sub(struct page_counter *counter, unsigned long nr_pages)
> > > +/**
> > > + * page_counter_cancel - take pages out of the local counter
> > > + * @counter: counter
> > > + * @nr_pages: number of pages to cancel
> > > + *
> > > + * Returns whether there are remaining pages in the counter.
> > > + */
> > > +int page_counter_cancel(struct page_counter *counter, unsigned long nr_pages)
> > > {
> > > long new;
> > >
> > > new = atomic_long_sub_return(nr_pages, &counter->count);
> > >
> > > - if (WARN_ON(unlikely(new < 0)))
> > > - atomic_long_set(&counter->count, 0);
> > > + if (WARN_ON_ONCE(unlikely(new < 0)))
> > > + atomic_long_add(nr_pages, &counter->count);
> > >
> > > return new > 0;
> > > }
> >
> > I am not sure I understand this correctly.
> >
> > The original res_counter code has protection against < 0 because it used
> > unsigned longs and wanted to protect from really disturbing effects of
> > underflow I guess (this wasn't documented anywhere). But you are using
> > long so even underflow shouldn't be a big problem so why do we need a
> > fixup?
>
> Immediate issues might be bogus numbers showing up in userspace or
> endless looping during reparenting. Negative values are just not
> defined for that counter, so I want to mitigate exposing them.
>
> It's not completely leak-free, as you can see, but I don't think it'd
> be worth weighing down the hot path any more than this just to
> mitigate the unlikely consequences of kernel bug.
>
> > The only way how we can end up < 0 would be a cancel without pairing
> > charge AFAICS. A charge should always appear before uncharge
> > because both of them are using atomics which imply memory barriers
> > (atomic_*_return). So do I understand correctly that your motivation
> > is to fix up those cancel-without-charge automatically? This would
> > definitely ask for a fat comment. Or am I missing something?
>
> This function is also used by the uncharge path, so any imbalance in
> accounting, not just from spurious cancels, is caught that way.
>
> As you said, these are all atomics, so it has nothing to do with
> memory ordering. It's simply catching logical underflows.
OK, I think we should document this in the changelog and/or in the
comment. These things are easy to forget...
Thanks!
--
Michal Hocko
SUSE Labs
--
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:[~2014-09-25 13:07 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-19 13:22 Johannes Weiner
2014-09-19 13:29 ` Johannes Weiner
2014-09-22 14:41 ` Vladimir Davydov
2014-09-22 18:57 ` Johannes Weiner
2014-09-23 11:06 ` Vladimir Davydov
2014-09-23 13:28 ` Johannes Weiner
2014-09-23 15:21 ` Vladimir Davydov
2014-09-23 17:05 ` Johannes Weiner
2014-09-24 8:02 ` Vladimir Davydov
2014-09-24 13:33 ` Michal Hocko
2014-09-24 16:51 ` Johannes Weiner
2014-09-24 14:16 ` Michal Hocko
2014-09-24 17:00 ` Johannes Weiner
2014-09-25 13:07 ` Michal Hocko [this message]
2014-09-22 14:44 ` Michal Hocko
2014-09-22 15:50 ` Johannes Weiner
2014-09-22 17:28 ` Michal Hocko
2014-09-22 19:58 ` Johannes Weiner
2014-09-23 13:25 ` Michal Hocko
2014-09-23 14:05 ` Johannes Weiner
2014-09-23 14:28 ` Michal Hocko
2014-09-23 22:33 ` David Rientjes
2014-09-23 7:46 ` Kamezawa Hiroyuki
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=20140925130716.GE12090@dhcp22.suse.cz \
--to=mhocko@suse.cz \
--cc=cgroups@vger.kernel.org \
--cc=dave@sr71.net \
--cc=gthelen@google.com \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=vdavydov@parallels.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