[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [PATCH v2 4/9] xen/arm: introduce put_page_nr and get_page_nr


  • To: Stefano Stabellini <sstabellini@xxxxxxxxxx>
  • From: Penny Zheng <Penny.Zheng@xxxxxxx>
  • Date: Sat, 7 May 2022 08:04:57 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com])
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none
  • Arc-message-signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=GtoGPaGTeUDaR/NHaU+hBPzcM8I0IL7vUBR/US4uTO0=; b=XEHgwHKojvNia1m1O3aIAr6+nk5UUPLvMtApOKUYvucVvezXCBrQuKGO3UBZAHu+Ay+T/DDNcwws8xA6adg2W5Lb73Py9CU30/mVn+e5U7Dp42NNfPbDIoLqqGJc67QidQmUhuVZE+OoRRVY7N7jZKMrdhUarYctPGbfpOaIYdykVIyg+iXauYXpDnBoO/UFe8yz8G73VMYtpMff+bGnAHAYXJHC2Aqj07D+kuM3JVdSSqmaQygdEXusnV+eSP1dOynuK3ijafNs89KKYdJYXSx9w57JW2bo+Z+Dzgc5xDy0wv+lJOxEP6xcX5vVv/nZLUmwoJ5udlybz85Q0qjvuQ==
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=GtoGPaGTeUDaR/NHaU+hBPzcM8I0IL7vUBR/US4uTO0=; b=nBjnb/ookbKqFHny3fMpjuJIAJcjCSgbUJ0ASp/NN0YgngaKhRtMpYlyh/YHRi5rgzMS7zJ4Jepg0Y9Gqk0amHMua3xxS3lWZ7K5dSH48Hnak7TSxXuXzO7PLoLws6jEmSf63KN5NaB6vXGKytWI0k0eprC/51pMD+IMLx2Sgoe2xampclSqPxhVN3tO4ysCKhN1LxtsRI6bRACo2TXyihq/2lIPyRr4VWGnbsfHa4EBEp1uHKrYZz+JdDYnUBAH3JyXu3jznXQfG2eX8B238zZ8NfQGtxbWU92vMCdlmgzbjQMCO2Q5n+OjOYxKe9aUrURoW2wC9sS3jChiYoc9rw==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=GAO0ZtIuxRpuO+8bhf9sAe+tev9Bi9o8n4kXJKh7O5xq51EAglIkqywNtxm1ZpAPEGpsH+/xiv4qqPIK04Jawo52mLBeAXANa67saHlJ8NkrFCiWhJmk5Cp007H+UkyXTx9ortVR4ABQpDfOIUSHEs0oDw32AFcH9AwJgY4kG3yAYjF4O2/GMSKmuM8AOcbRraWyZAHWY5g1/gX19KVhkbMstsy2YWcf0vlgRrkuzuLgg06vh1fjJzFKUUlSlrH6G3hIg21XZoN28vFfSxjHCHUogJ+GL2IXwhercYK9kOOA0L/tBeT2JaoS5+yB2K4y2xjVRuTGf89/kLbKGtlMvg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=An/P7SyRCiQ7XgWRDgqPLLJ1wSCWoviTsZ9gGzEeSQaJgPxSP/mFg+m8ZMaj4OVhlO6Ed7s7sY8QpKEpAknHQQcAy1GvM+XZ+r2XbLZLgd4Tyol5XT4Xh1qaLeCANBl9N2dkhY5yCl1xOUfiysco+LfaxKj53VcalGiLoeExIgNSI4yln30xXlOT5dbeFvSbw3gWihn37h9PJyI/WYlXUEpMKqXVK6pwzjwHI2RFAPy2F87QsBAi7Gsp+LlFnYWIrpJh6qfiZJpN5ARmr+qzWCtIIQyuscWZBugtGMsMSq9DvnUYrARgWn/vmHHaOKkF55GGb8kMGKdsCpIydi3hGQ==
  • Authentication-results-original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Wei Chen <Wei.Chen@xxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <Bertrand.Marquis@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Sat, 07 May 2022 08:05:44 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Original-authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Thread-index: AQHYYRqQd1unnA/4u0udLI/iXEbzaa0Sm9cAgABx6kA=
  • Thread-topic: [PATCH v2 4/9] xen/arm: introduce put_page_nr and get_page_nr

Hi Stefano

> -----Original Message-----
> From: Stefano Stabellini <sstabellini@xxxxxxxxxx>
> Sent: Saturday, May 7, 2022 9:09 AM
> To: Penny Zheng <Penny.Zheng@xxxxxxx>
> Cc: xen-devel@xxxxxxxxxxxxxxxxxxxx; Wei Chen <Wei.Chen@xxxxxxx>; Stefano
> Stabellini <sstabellini@xxxxxxxxxx>; Julien Grall <julien@xxxxxxx>; Bertrand
> Marquis <Bertrand.Marquis@xxxxxxx>; Volodymyr Babchuk
> <Volodymyr_Babchuk@xxxxxxxx>
> Subject: Re: [PATCH v2 4/9] xen/arm: introduce put_page_nr and get_page_nr
> 
> On Fri, 6 May 2022, Penny Zheng wrote:
> > Later, we need to add the right amount of references, which should be
> > the number of borrower domains, to the owner domain. Since we only
> > have
> > get_page() to increment the page reference by 1, a loop is needed per
> > page, which is inefficient and time-consuming.
> >
> > To save the loop time, this commit introduces a set of new helpers
> > put_page_nr() and get_page_nr() to increment/drop the page reference by
> nr.
> >
> > Signed-off-by: Penny Zheng <penny.zheng@xxxxxxx>
> > ---
> > v2 change:
> > - new commit
> > ---
> >  xen/arch/arm/include/asm/mm.h |  4 ++++
> >  xen/arch/arm/mm.c             | 36 +++++++++++++++++++++++++----------
> >  2 files changed, 30 insertions(+), 10 deletions(-)
> >
> > diff --git a/xen/arch/arm/include/asm/mm.h
> > b/xen/arch/arm/include/asm/mm.h index 424aaf2823..c737d51e4d 100644
> > --- a/xen/arch/arm/include/asm/mm.h
> > +++ b/xen/arch/arm/include/asm/mm.h
> > @@ -347,6 +347,10 @@ void free_init_memory(void);  int
> > guest_physmap_mark_populate_on_demand(struct domain *d, unsigned
> long gfn,
> >                                            unsigned int order);
> >
> > +extern bool get_page_nr(struct page_info *page, const struct domain
> *domain,
> > +                        unsigned long nr); extern void
> > +put_page_nr(struct page_info *page, unsigned long nr);
> > +
> >  extern void put_page_type(struct page_info *page);  static inline
> > void put_page_and_type(struct page_info *page)  { diff --git
> > a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 7b1f2f4906..e565979f3c
> > 100644
> > --- a/xen/arch/arm/mm.c
> > +++ b/xen/arch/arm/mm.c
> > @@ -1537,7 +1537,8 @@ long arch_memory_op(int op,
> XEN_GUEST_HANDLE_PARAM(void) arg)
> >      return 0;
> >  }
> >
> > -struct domain *page_get_owner_and_reference(struct page_info *page)
> > +static struct domain *page_get_owner_and_nr_reference(struct page_info
> *page,
> > +                                                      unsigned long
> > +nr)
> >  {
> >      unsigned long x, y = page->count_info;
> >      struct domain *owner;
> > @@ -1545,13 +1546,14 @@ struct domain
> *page_get_owner_and_reference(struct page_info *page)
> >      do {
> >          x = y;
> >          /*
> > +         * Consider the minimum case(nr = 1):
> >           * Count ==  0: Page is not allocated, so we cannot take a 
> > reference.
> >           * Count == -1: Reference count would wrap, which is invalid.
> >           */
> >          if ( unlikely(((x + 1) & PGC_count_mask) <= 1) )
> >              return NULL;
> >      }
> > -    while ( (y = cmpxchg(&page->count_info, x, x + 1)) != x );
> > +    while ( (y = cmpxchg(&page->count_info, x, x + nr)) != x );
> >
> >      owner = page_get_owner(page);
> >      ASSERT(owner);
> > @@ -1559,36 +1561,50 @@ struct domain
> *page_get_owner_and_reference(struct page_info *page)
> >      return owner;
> >  }
> >
> > -void put_page(struct page_info *page)
> > +struct domain *page_get_owner_and_reference(struct page_info *page) {
> > +    return page_get_owner_and_nr_reference(page, 1); }
> > +
> > +void put_page_nr(struct page_info *page, unsigned long nr)
> >  {
> >      unsigned long nx, x, y = page->count_info;
> >
> >      do {
> > -        ASSERT((y & PGC_count_mask) != 0);
> > +        ASSERT(((y - nr) & PGC_count_mask) >= 0);
> 
> Why this change? The original ASSERT is to check that we enter the loop only
> when count_info is greater than 0. It should still apply even for put_page_nr
> without modifications?
> 
> 

Oh, I understand wrongly about the ASSERT. I thought it was to
check the result count_info after the loop will be not smaller than 0.

Do you think we still need to ensure that? Maybe ASSERT( ((y & PGC_count_mask) 
!= 0) && (((y - nr) & PGC_count_mask) >= 0)); ?

> 
> >          x  = y;
> > -        nx = x - 1;
> > +        nx = x - nr;
> >      }
> >      while ( unlikely((y = cmpxchg(&page->count_info, x, nx)) != x) );
> >
> >      if ( unlikely((nx & PGC_count_mask) == 0) )
> > -    {
> >          free_domheap_page(page);
> > -    }
> >  }
> >
> > -bool get_page(struct page_info *page, const struct domain *domain)
> > +void put_page(struct page_info *page)
> >  {
> > -    const struct domain *owner = page_get_owner_and_reference(page);
> > +    put_page_nr(page, 1);
> > +}
> > +
> > +bool get_page_nr(struct page_info *page, const struct domain *domain,
> > +                 unsigned long nr)
> > +{
> > +    const struct domain *owner =
> > +page_get_owner_and_nr_reference(page, nr);
> >
> >      if ( likely(owner == domain) )
> >          return true;
> >
> >      if ( owner != NULL )
> > -        put_page(page);
> > +        put_page_nr(page, nr);
> >
> >      return false;
> >  }
> >
> > +bool get_page(struct page_info *page, const struct domain *domain) {
> > +    return get_page_nr(page, domain, 1); }
> > +
> >  /* Common code requires get_page_type and put_page_type.
> >   * We don't care about typecounts so we just do the minimum to make it
> >   * happy. */
> > --
> > 2.25.1
> >



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.