From: Dan Magenheimer Subject: Re: [RFC/PATCH] XENMEM_claim_pages (subop of an existing) hypercall Date: Wed, 14 Nov 2012 11:32:34 -0800 (PST) Message-ID: <4875f016-739f-4a62-9308-90ddd8791026@default> References: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Keir Fraser , Jan Beulich , TimDeegan Cc: Zhigang Wang , xen-devel@lists.xen.org, Konrad Wilk List-Id: xen-devel@lists.xenproject.org > From: Keir Fraser [mailto:keir.xen@gmail.com] > Subject: Re: [Xen-devel] [RFC/PATCH] XENMEM_claim_pages (subop of an existing) hypercall > > On 14/11/2012 17:42, "Dan Magenheimer" wrote: > > >> It would be nice if d->tot_pages adjustments didn't take the global > >> heap_lock in this case. There's probably some way to bail out of those new > >> update functions before doing the locked work, in that case. > > > > I agree. I played with atomics for a bit but couldn't > > see a way it would work without races. The generic > > pseudo-code is > > > > if (A) { > > atomically { > > modify A > > modify d->B > > } > > } else { > > modify d->B > > } > > > > Any ideas? > > E.g., > /* Fast path (new). */ > if ( !d->unclaimed_pages ) > return d->tot_pages += pages; > /* Slower path (as in your patch). */ > spin_lock(&heap_lock); > d->tot_pages += pages; > if ( d->unclaimed_pages ) > .... > > The only danger is around any necessary interlocking with d->unclaimed_pages > becoming non-zero. But the fast-path test is still under d->page_alloc_lock, > and you set up d->unclaimed_pages under that lock, so it looks okay to me. Hmmm, nice, I think you are right. I had just removed the d->page_alloc_lock in the "set" code at Jan's suggestion, but this is a good reason to keep it there. I'll also add a comment to document this subtle lock interdependency.