[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20121129192925.GH15094@google.com>
Date: Thu, 29 Nov 2012 11:29:25 -0800
From: Kent Overstreet <koverstreet@...gle.com>
To: Andi Kleen <andi@...stfloor.org>
Cc: linux-kernel@...r.kernel.org, linux-aio@...ck.org,
linux-fsdevel@...r.kernel.org, zab@...hat.com, bcrl@...ck.org,
jmoyer@...hat.com, axboe@...nel.dk, viro@...iv.linux.org.uk
Subject: Re: [PATCH 22/25] Generic dynamic per cpu refcounting
On Thu, Nov 29, 2012 at 08:20:03PM +0100, Andi Kleen wrote:
> > The trick is that we don't watch for the refcount hitting 0 until we're
> > shutting down - so this only works if you keep track of your initial
> > refcount. As long as we're not shutting down, we know the refcount can't
> > hit 0 because we haven't released the initial refcount.
>
> This seems dangerous to me: assume you have one CPU which always
> does get and another does put. So there may be 2^32 such operations
> without a kill and you wrap for real in a way that does not get
> corrected.
I don't know how to write a proof that it works (and I should... I
haven't done any real math in ages, argh) but try working out some
examples to see what happens:
cpu 0 does 2^32 gets, cpu 1 does 2^32 - 1 puts, actual ref should be 1:
cpu 0 ref: 0
cpu 1 ref: 1 (it started at 0, and subtracted 1 2^32 - 1 times)
cpu 0 does 2^32 + 1 gets, cpu 1 does 2^32 puts, again ref should be 1:
cpu 0 ref: 1
cpu 1 ref: 0
There's some kind of symmetry going on here, and if I'd been awake more
in college I could probably say exactly why it works, but it does.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists