From: Keir Fraser Subject: Re: [RFC/PATCH] XENMEM_claim_pages (subop of an existing) hypercall Date: Wed, 14 Nov 2012 18:58:34 +0000 Message-ID: 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: Dan Magenheimer , Jan Beulich , TimDeegan Cc: Zhigang Wang , Konrad Rzeszutek Wilk , xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org 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. -- Keir