From: Tim Deegan Subject: Re: [PATCH 1/6] mmu: Introduce XENMEM_claim_pages (subop of memory ops). Date: Tue, 5 Mar 2013 12:01:56 +0000 Message-ID: <20130305120156.GA1139@ocelot.phlegethon.org> References: <1362419234-29446-1-git-send-email-konrad.wilk@oracle.com> <1362419234-29446-2-git-send-email-konrad.wilk@oracle.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Content-Disposition: inline In-Reply-To: <1362419234-29446-2-git-send-email-konrad.wilk@oracle.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Konrad Rzeszutek Wilk Cc: dan.magenheimer@oracle.com, xen-devel@lists.xensource.com, keir@xen.org, keir.xen@gmail.com List-Id: xen-devel@lists.xenproject.org Hi, At 12:47 -0500 on 04 Mar (1362401229), Konrad Rzeszutek Wilk wrote: > --- a/xen/common/page_alloc.c > +++ b/xen/common/page_alloc.c > @@ -252,11 +252,124 @@ static long midsize_alloc_zone_pages; > #define MIDSIZE_ALLOC_FRAC 128 > > static DEFINE_SPINLOCK(heap_lock); > +static long total_unclaimed_pages; /* total outstanding claims by all domains */ Could this field (& associated per-domain stuff) have a better name? AFAICT from the code, this is a count of _claimed_ pages (specifically, claimed but not allocated). It caused me to double-take almost every time I saw it used in this patch. How about outstanding_claimed_pages, or just outstanding_claims? > unsigned long domain_adjust_tot_pages(struct domain *d, long pages) > { > + long dom_before, dom_after, dom_claimed, sys_before, sys_after; > + > ASSERT(spin_is_locked(&d->page_alloc_lock)); > - return d->tot_pages += pages; > + d->tot_pages += pages; > + > + /* > + * can test d->claimed_pages race-free because it can only change > + * if d->page_alloc_lock and heap_lock are both held, see also > + * domain_set_unclaimed_pages below > + */ > + if ( !d->unclaimed_pages ) > + goto out; > + > + spin_lock(&heap_lock); > + /* adjust domain unclaimed_pages; may not go negative */ > + dom_before = d->unclaimed_pages; > + dom_after = dom_before - pages; > + if ( (dom_before > 0) && (dom_after < 0) ) > + dom_claimed = 0; Why the test for dom_before > 0 ? I think it might be better to BUG_ON() any of these counts ever being negative, rather than to carry on regardless. Or is this meant to be a cunning way of handling the case where sizeof (long) == 4 and unclaimed_pages > 2^31 ? I suspect that will fall foul of the undefinedness of signed overflow. > + else > + dom_claimed = dom_after; > + d->unclaimed_pages = dom_claimed; > + /* flag accounting bug if system unclaimed_pages would go negative */ > + sys_before = total_unclaimed_pages; > + sys_after = sys_before - (dom_before - dom_claimed); > + BUG_ON((sys_before > 0) && (sys_after < 0)); Same question here. > +/* > + * XENMEM_claim_pages flags: > + * normal: claim is successful only if sufficient free pages > + * are available. > + * tmem: claim is successful only if sufficient free pages > + * are available and (if tmem is enabled) hypervisor > + * may also consider tmem "freeable" pages to satisfy the claim. The 'normal' restriction isn't actually enforced except at claim time. Since the gate in alloc_heap_pages is effectively: (request > free + freeable - total_reserved) later allocations (from any source) can take up all the free memory as long as freeable >= total_reserved). Is there a use for it? Presumably by turning on tmem you're happy with the idea that allocations might have to come from freeable memory? Cheers, Tim.