From: Tim Chen <tim.c.chen@linux.intel.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Andi Kleen <andi@firstfloor.org>,
linux-kernel@vger.kernel.org, Andi Kleen <ak@linux.intel.com>,
Hugh Dickins <hughd@google.com>
Subject: Re: [PATCH v2 1/2] tmpfs: Quick token library to allow scalable retrieval of tokens from token jar
Date: Fri, 11 Jun 2010 15:06:43 -0700 [thread overview]
Message-ID: <1276294003.2385.48.camel@mudge.jf.intel.com> (raw)
In-Reply-To: <20100611145219.017a87c0.akpm@linux-foundation.org>
On Fri, 2010-06-11 at 14:52 -0700, Andrew Morton wrote:
> On Thu, 10 Jun 2010 10:06:14 -0700
> Tim Chen <tim.c.chen@linux.intel.com> wrote:
>
> > On Wed, 2010-06-09 at 15:36 -0700, Andrew Morton wrote:
> >
> > > >
> > > > You need some synchronization, otherwise the accounting
> > > > would not be exact and you could overflow. Yes you could
> > > > open code it, but having it in a library is nicer.
> > >
> > > The code doesn't have synchronisation! qtoken_return() can modify the
> > > per-cpu "cache" in parallel with qtoken_avail()'s walk across the
> > > per-cpu "caches", yielding an inaccurate result.
> > >
> > > This is all the same as percpu_add() executing in parallel with
> > > percpu_counter_sum() or percpu_counter_sum_positive().
> > >
> > > If we cannot tolerate that inaccuracy then these patches are no good
> > > and we need a rethink.
> > >
> > > If we _can_ tolerate that inaccuracy then percpu_counters can be used
> > > here. And doing that is preferable to reinventing percpu_counters
> > > badly.
> > >
> > > I'm just not seeing it.
> >
> >
> > The first version of the patch does a qtoken_reap_cache to reap the
> > tokens into pool before doing an accounting of the tokens and the token
> > count will be precise. It was not done in the second version of the
> > patch due to objection that it may be costly, and also the tokens count
> > will be fluctuating anyway. However, qtoken_avail is not called very
> > often (usually caller will use qtoken_get to access the tokens and it
> > will not need a total accounting of the tokens). We can do it the
> > previous way and there will be no inaccuracies.
> >
>
> afacit, your proposed implementation could have used percpu_counters.
> If so, that would be by far the best way of doing it, because that
> doesn't require the addition of new infrastructure.
Just having percpu counters is not enough.
There is additional logic required to manage the per cpu counters:
(1) set limit on the total number of tokens (2) distribute tokens into
per cpu counter (3) logic to coordinate where to get additional tokens
when we run out of tokens in the per cpu counter. (4) rebalance the
tokens when we have too many of the tokens returned to a per cpu
counter. I'm trying to encapsulate these logic into the library.
Otherwise, these logic will still need to be duplicated in the code
using the per cpu counters.
Tim
next prev parent reply other threads:[~2010-06-11 22:09 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-26 19:32 [PATCH v2 1/2] tmpfs: Quick token library to allow scalable retrieval of tokens from token jar Tim Chen
2010-06-01 21:51 ` Andrew Morton
2010-06-02 8:58 ` Andi Kleen
2010-06-09 22:36 ` Andrew Morton
2010-06-10 17:06 ` Tim Chen
2010-06-11 21:52 ` Andrew Morton
2010-06-11 22:06 ` Tim Chen [this message]
2010-06-11 22:26 ` Andrew Morton
2010-06-11 23:29 ` Tim Chen
2010-06-11 23:54 ` Andrew Morton
2010-06-12 7:36 ` Andi Kleen
2010-06-12 15:27 ` Andrew Morton
2010-06-15 1:24 ` Tim Chen
2010-06-02 17:32 ` Tim Chen
2010-06-09 22:41 ` Andrew Morton
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=1276294003.2385.48.camel@mudge.jf.intel.com \
--to=tim.c.chen@linux.intel.com \
--cc=ak@linux.intel.com \
--cc=akpm@linux-foundation.org \
--cc=andi@firstfloor.org \
--cc=hughd@google.com \
--cc=linux-kernel@vger.kernel.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 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).