All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hanweidong <hanweidong@huawei.com>
To: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: George Dunlap <George.Dunlap@eu.citrix.com>,
	Andrew Cooper <Andrew.Cooper3@citrix.com>,
	Yanqiangjun <yanqiangjun@huawei.com>,
	"Tim (Xen.org)" <tim@xen.org>,
	"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>,
	"xen-devel@lists.xen.org" <xen-devel@lists.xen.org>,
	"Gonglei (Arei)" <arei.gonglei@huawei.com>,
	Anthony Perard <anthony.perard@citrix.com>,
	Wangzhenguo <wangzhenguo@huawei.com>
Subject: Re: [Qemu-devel] frequently ballooning results in qemu exit
Date: Sat, 30 Mar 2013 15:04:17 +0000	[thread overview]
Message-ID: <FAB5C136CA8BEA4DBEA2F641E3F536384A8C6734__31291.6183881045$1364656071$gmane$org@szxeml538-mbx.china.huawei.com> (raw)
In-Reply-To: <alpine.DEB.2.02.1303291209020.4430@kaball.uk.xensource.com>


> -----Original Message-----
> From: Stefano Stabellini [mailto:stefano.stabellini@eu.citrix.com]
> Sent: 2013年3月29日 20:37
> To: Hanweidong
> Cc: Tim (Xen.org); George Dunlap; Andrew Cooper; Yanqiangjun; qemu-
> devel@nongnu.org; xen-devel@lists.xen.org; Gonglei (Arei); Anthony
> Perard; Wangzhenguo
> Subject: Re: [Qemu-devel] [Xen-devel] frequently ballooning results in
> qemu exit
> 
> On Mon, 25 Mar 2013, Hanweidong wrote:
> > We fixed this issue by below patch which computed the correct size
> for test_bits(). qemu_get_ram_ptr() and qemu_safe_ram_ptr() will call
> xen_map_cache() with size is 0 if the requested address is in the RAM.
> Then xen_map_cache() will pass the size 0 to test_bits() for checking
> if the corresponding pfn was mapped in cache. But test_bits() will
> always return 1 when size is 0 without any bit testing. Actually, for
> this case, test_bits should check one bit. So this patch introduced a
> __test_bit_size which is greater than 0 and a multiple of XC_PAGE_SIZE,
> then test_bits can work correctly with __test_bit_size >> XC_PAGE_SHIFT
> as its size.
> >
> > Signed-off-by: Zhenguo Wang <wangzhenguo@huawei.com>
> > Signed-off-by: Weidong Han <hanweidong@huawei.com>
> 
> Thanks for the patch and for debugging this difficult problem.
> The reality is that size is never actually 0: when qemu_get_ram_ptr
> calls xen_map_cache with size 0, it actually means "map until the end
> of
> the page". As a consequence test_bits should always test at least 1 bit,
> like you wrote.

Yes, for the case of size is 0, we can just simply set __test_bit_size 1. But for size > 0, I think set __test_bit_size to size >> XC_PAGE_SHIFT is incorrect. If size is not multiple of XC_PAGE_SIZE, then the part of (size % XC_PAGE_SIZE) also needs to test 1 bit. For example size is XC_PAGE_SIZE + 1, then it needs to test 2 bits, but size >> XC_PAGE_SHIFT is only 1. 

-weidong

> 
> I tried to simplify your patch a bit, does this one work for you?
> 
> 
> diff --git a/xen-mapcache.c b/xen-mapcache.c
> index dc6d1fa..b03b373 100644
> --- a/xen-mapcache.c
> +++ b/xen-mapcache.c
> @@ -202,6 +202,7 @@ uint8_t *xen_map_cache(hwaddr phys_addr, hwaddr
> size,
>      hwaddr address_index;
>      hwaddr address_offset;
>      hwaddr __size = size;
> +    hwaddr __test_bit_size = size >> XC_PAGE_SHIFT;
>      bool translated = false;
> 
>  tryagain:
> @@ -224,12 +225,16 @@ tryagain:
>      } else {
>          __size = MCACHE_BUCKET_SIZE;
>      }
> +    /* always test at least one page */
> +    if (!__test_bit_size) {
> +        __test_bit_size = 1UL;
> +    }
> 
>      entry = &mapcache->entry[address_index % mapcache->nr_buckets];
> 
>      while (entry && entry->lock && entry->vaddr_base &&
>              (entry->paddr_index != address_index || entry->size !=
> __size ||
> -             !test_bits(address_offset >> XC_PAGE_SHIFT, size >>
> XC_PAGE_SHIFT,
> +             !test_bits(address_offset >> XC_PAGE_SHIFT,
> __test_bit_size,
>                   entry->valid_mapping))) {
>          pentry = entry;
>          entry = entry->next;
> @@ -241,13 +246,13 @@ tryagain:
>      } else if (!entry->lock) {
>          if (!entry->vaddr_base || entry->paddr_index != address_index
> ||
>                  entry->size != __size ||
> -                !test_bits(address_offset >> XC_PAGE_SHIFT, size >>
> XC_PAGE_SHIFT,
> +                !test_bits(address_offset >> XC_PAGE_SHIFT,
> __test_bit_size,
>                      entry->valid_mapping)) {
>              xen_remap_bucket(entry, __size, address_index);
>          }
>      }
> 
> -    if(!test_bits(address_offset >> XC_PAGE_SHIFT, size >>
> XC_PAGE_SHIFT,
> +    if(!test_bits(address_offset >> XC_PAGE_SHIFT, __test_bit_size,
>                  entry->valid_mapping)) {
>          mapcache->last_address_index = -1;
>          if (!translated && mapcache->phys_offset_to_gaddr) {
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

  reply	other threads:[~2013-03-30 15:04 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-13 13:50 frequently ballooning results in qemu exit Hanweidong
2013-03-14 10:17 ` George Dunlap
2013-03-14 10:38   ` Anthony PERARD
2013-03-14 14:10     ` Hanweidong
2013-03-14 14:34       ` Tim Deegan
2013-03-15  5:54         ` Hanweidong
2013-03-21 12:15           ` Tim Deegan
2013-03-21 13:33             ` Hanweidong
2013-03-25 12:40               ` [Qemu-devel] [Xen-devel] " Hanweidong
2013-03-29 12:37                 ` [Qemu-devel] " Stefano Stabellini
2013-03-29 12:37                 ` [Qemu-devel] [Xen-devel] " Stefano Stabellini
2013-03-30 15:04                   ` Hanweidong [this message]
2013-03-30 15:04                   ` Hanweidong
2013-04-01 14:39                     ` Stefano Stabellini
2013-04-02  1:06                       ` Hanweidong
2013-04-02 13:27                         ` [Qemu-devel] " Stefano Stabellini
2013-04-02 13:27                         ` [Qemu-devel] [Xen-devel] " Stefano Stabellini
2013-04-03  8:15                           ` Hanweidong
2013-04-03 10:36                             ` Stefano Stabellini
2013-04-03 10:36                               ` [Qemu-devel] " Stefano Stabellini
2013-04-03  8:15                           ` Hanweidong
2013-04-02  1:06                       ` Hanweidong
2013-04-01 14:39                     ` Stefano Stabellini
2013-03-25 12:40               ` Hanweidong
2013-03-14 10:48   ` Hanweidong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='FAB5C136CA8BEA4DBEA2F641E3F536384A8C6734__31291.6183881045$1364656071$gmane$org@szxeml538-mbx.china.huawei.com' \
    --to=hanweidong@huawei.com \
    --cc=Andrew.Cooper3@citrix.com \
    --cc=George.Dunlap@eu.citrix.com \
    --cc=anthony.perard@citrix.com \
    --cc=arei.gonglei@huawei.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefano.stabellini@eu.citrix.com \
    --cc=tim@xen.org \
    --cc=wangzhenguo@huawei.com \
    --cc=xen-devel@lists.xen.org \
    --cc=yanqiangjun@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.