From: "Wang, Wei W" <wei.w.wang@intel.com>
To: Matthew Wilcox <willy@infradead.org>
Cc: "virtio-dev@lists.oasis-open.org"
<virtio-dev@lists.oasis-open.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>,
"virtualization@lists.linux-foundation.org"
<virtualization@lists.linux-foundation.org>,
"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
"linux-mm@kvack.org" <linux-mm@kvack.org>,
"mst@redhat.com" <mst@redhat.com>,
"mhocko@kernel.org" <mhocko@kernel.org>,
"akpm@linux-foundation.org" <akpm@linux-foundation.org>,
"mawilcox@microsoft.com" <mawilcox@microsoft.com>,
"david@redhat.com" <david@redhat.com>,
"cornelia.huck@de.ibm.com" <cornelia.huck@de.ibm.com>,
"mgorman@techsingularity.net" <mgorman@techsingularity.net>,
"aarcange@redhat.com" <aarcange@redhat.com>,
"amit.shah@redhat.com" <amit.shah@redhat.com>,
"pbonzini@redhat.com" <pbonzini@redhat.com>,
"liliang.opensource@gmail.com" <liliang.opensource@gmail.com>,
"yang.zhang.wz@gmail.com" <yang.zhang.wz@gmail.com>,
"quan.xu@aliyun.com" <quan.xu@aliyun.com>
Subject: RE: [PATCH v15 2/5] lib/xbitmap: add xb_find_next_bit() and xb_zero()
Date: Sat, 30 Sep 2017 04:24:26 +0000 [thread overview]
Message-ID: <286AC319A985734F985F78AFA26841F73931DE83@shsmsx102.ccr.corp.intel.com> (raw)
In-Reply-To: <20170911132710.GB32538@bombadil.infradead.org>
On Monday, September 11, 2017 9:27 PM, Matthew Wilcox wrote
> On Mon, Aug 28, 2017 at 06:08:30PM +0800, Wei Wang wrote:
> > +/**
> > + * xb_zero - zero a range of bits in the xbitmap
> > + * @xb: the xbitmap that the bits reside in
> > + * @start: the start of the range, inclusive
> > + * @end: the end of the range, inclusive */ void xb_zero(struct xb
> > +*xb, unsigned long start, unsigned long end) {
> > + unsigned long i;
> > +
> > + for (i = start; i <= end; i++)
> > + xb_clear_bit(xb, i);
> > +}
> > +EXPORT_SYMBOL(xb_zero);
>
> Um. This is not exactly going to be quick if you're clearing a range of bits.
> I think it needs to be more along the lines of this:
>
> void xb_clear(struct xb *xb, unsigned long start, unsigned long end) {
> struct radix_tree_root *root = &xb->xbrt;
> struct radix_tree_node *node;
> void **slot;
> struct ida_bitmap *bitmap;
>
> for (; end < start; start = (start | (IDA_BITMAP_BITS - 1)) + 1) {
> unsigned long index = start / IDA_BITMAP_BITS;
> unsigned long bit = start % IDA_BITMAP_BITS;
>
> bitmap = __radix_tree_lookup(root, index, &node, &slot);
> if (radix_tree_exception(bitmap)) {
> unsigned long ebit = bit + 2;
> unsigned long tmp = (unsigned long)bitmap;
> if (ebit >= BITS_PER_LONG)
> continue;
> tmp &= ... something ...;
> if (tmp == RADIX_TREE_EXCEPTIONAL_ENTRY)
> __radix_tree_delete(root, node, slot);
> else
> rcu_assign_pointer(*slot, (void *)tmp);
> } else if (bitmap) {
> unsigned int nbits = end - start + 1;
> if (nbits + bit > IDA_BITMAP_BITS)
> nbits = IDA_BITMAP_BITS - bit;
> bitmap_clear(bitmap->bitmap, bit, nbits);
> if (bitmap_empty(bitmap->bitmap, IDA_BITMAP_BITS)) {
> kfree(bitmap);
> __radix_tree_delete(root, node, slot);
> }
> }
> }
> }
>
> Also note that this should be called xb_clear(), not xb_zero() to fit in with
> bitmap_clear(). And this needs a thorough test suite testing all values for 'start'
> and 'end' between 0 and at least 1024; probably much higher. And a variable
> number of bits need to be set before calling
> xb_clear() in the test suite.
>
> Also, this implementation above is missing a few tricks. For example, if 'bit' is 0
> and 'nbits' == IDA_BITMAP_BITS, we can simply call kfree without first zeroing
> out the bits and then checking if the whole thing is zero.
Thanks for the optimization suggestions. We've seen significant improvement of
the ballooning time. Some other optimizations (stated in the changelog) haven't
been included in the new version. If possible, we can leave that to a second step
optimization outside this patch series.
Best,
Wei
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2017-09-30 4:24 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-28 10:08 [PATCH v15 0/5] Virtio-balloon Enhancement Wei Wang
2017-08-28 10:08 ` [PATCH v15 1/5] lib/xbitmap: Introduce xbitmap Wei Wang
2017-09-11 12:54 ` Matthew Wilcox
2017-09-12 13:23 ` Wei Wang
2017-08-28 10:08 ` [PATCH v15 2/5] lib/xbitmap: add xb_find_next_bit() and xb_zero() Wei Wang
2017-09-11 13:27 ` Matthew Wilcox
2017-09-30 4:24 ` Wang, Wei W [this message]
2017-08-28 10:08 ` [PATCH v15 3/5] virtio-balloon: VIRTIO_BALLOON_F_SG Wei Wang
2017-08-28 18:03 ` Michael S. Tsirkin
2017-08-29 3:09 ` Wei Wang
2017-09-08 3:36 ` Michael S. Tsirkin
2017-09-08 11:09 ` [virtio-dev] " Wei Wang
2017-09-29 4:01 ` Michael S. Tsirkin
2017-09-29 6:55 ` Wei Wang
2017-08-28 10:08 ` [PATCH v15 4/5] mm: support reporting free page blocks Wei Wang
2017-08-28 13:33 ` Michal Hocko
2017-08-28 14:09 ` Michal Hocko
2017-08-29 3:23 ` Wei Wang
2017-08-28 10:08 ` [PATCH v15 5/5] virtio-balloon: VIRTIO_BALLOON_F_CTRL_VQ Wei Wang
2017-09-05 11:57 ` Wang, Wei W
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=286AC319A985734F985F78AFA26841F73931DE83@shsmsx102.ccr.corp.intel.com \
--to=wei.w.wang@intel.com \
--cc=aarcange@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=amit.shah@redhat.com \
--cc=cornelia.huck@de.ibm.com \
--cc=david@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=liliang.opensource@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mawilcox@microsoft.com \
--cc=mgorman@techsingularity.net \
--cc=mhocko@kernel.org \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=quan.xu@aliyun.com \
--cc=virtio-dev@lists.oasis-open.org \
--cc=virtualization@lists.linux-foundation.org \
--cc=willy@infradead.org \
--cc=yang.zhang.wz@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox