linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dave Hansen <dave.hansen@intel.com>
To: Liang Li <liang.z.li@intel.com>, mst@redhat.com
Cc: pbonzini@redhat.com, amit.shah@redhat.com, quintela@redhat.com,
	dgilbert@redhat.com, qemu-devel@nongnu.org, kvm@vger.kernel.org,
	virtio-dev@lists.oasis-open.org, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org,
	virtualization@lists.linux-foundation.org,
	mgorman@techsingularity.net, cornelia.huck@de.ibm.com
Subject: Re: [PATCH kernel v4 7/7] virtio-balloon: tell host vm's unused page info
Date: Fri, 4 Nov 2016 11:10:11 -0700	[thread overview]
Message-ID: <b25eac6e-3744-3874-93a8-02f814549adf@intel.com> (raw)
In-Reply-To: <1478067447-24654-8-git-send-email-liang.z.li@intel.com>

Please squish this and patch 5 together.  It makes no sense to separate
them.

> +static void send_unused_pages_info(struct virtio_balloon *vb,
> +				unsigned long req_id)
> +{
> +	struct scatterlist sg_in;
> +	unsigned long pfn = 0, bmap_len, pfn_limit, last_pfn, nr_pfn;
> +	struct virtqueue *vq = vb->req_vq;
> +	struct virtio_balloon_resp_hdr *hdr = vb->resp_hdr;
> +	int ret = 1, used_nr_bmap = 0, i;
> +
> +	if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_PAGE_BITMAP) &&
> +		vb->nr_page_bmap == 1)
> +		extend_page_bitmap(vb);
> +
> +	pfn_limit = PFNS_PER_BMAP * vb->nr_page_bmap;
> +	mutex_lock(&vb->balloon_lock);
> +	last_pfn = get_max_pfn();
> +
> +	while (ret) {
> +		clear_page_bitmap(vb);
> +		ret = get_unused_pages(pfn, pfn + pfn_limit, vb->page_bitmap,
> +			 PFNS_PER_BMAP, vb->nr_page_bmap);

This changed the underlying data structure without changing the way that
the structure is populated.

This algorithm picks a "PFNS_PER_BMAP * vb->nr_page_bmap"-sized set of
pfns, allocates a bitmap for them, the loops through all zones looking
for pages in any free list that are in that range.

Unpacking all the indirection, it looks like this:

for (pfn = 0; pfn < get_max_pfn(); pfn += BITMAP_SIZE_IN_PFNS)
	for_each_populated_zone(zone)
		for_each_migratetype_order(order, t)
			list_for_each(..., &zone->free_area[order])...

Let's say we do a 32k bitmap that can hold ~1M pages.  That's 4GB of
RAM.  On a 1TB system, that's 256 passes through the top-level loop.
The bottom-level lists have tens of thousands of pages in them, even on
my laptop.  Only 1/256 of these pages will get consumed in a given pass.

That's an awfully inefficient way of doing it.  This patch essentially
changed the data structure without changing the algorithm to populate it.

Please change the *algorithm* to use the new data structure efficiently.
 Such a change would only do a single pass through each freelist, and
would choose whether to use the extent-based (pfn -> range) or
bitmap-based approach based on the contents of the free lists.

You should not be using get_max_pfn().  Any patch set that continues to
use it is not likely to be using a proper algorithm.

  reply	other threads:[~2016-11-04 18:10 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-02  6:17 [PATCH kernel v4 0/7] Extend virtio-balloon for fast (de)inflating & fast live migration Liang Li
2016-11-02  6:17 ` [PATCH kernel v4 1/7] virtio-balloon: rework deflate to add page to a list Liang Li
2016-11-02  6:17 ` [PATCH kernel v4 2/7] virtio-balloon: define new feature bit and head struct Liang Li
2016-11-02  6:17 ` [PATCH kernel v4 3/7] mm: add a function to get the max pfn Liang Li
2016-11-02  6:17 ` [PATCH kernel v4 4/7] virtio-balloon: speed up inflate/deflate process Liang Li
2016-11-02  6:17 ` [PATCH kernel v4 5/7] mm: add the related functions to get unused page Liang Li
2016-11-02  6:17 ` [PATCH kernel v4 6/7] virtio-balloon: define flags and head for host request vq Liang Li
2016-11-02  6:17 ` [PATCH kernel v4 7/7] virtio-balloon: tell host vm's unused page info Liang Li
2016-11-04 18:10   ` Dave Hansen [this message]
2016-11-07  3:37     ` Li, Liang Z
2016-11-07 17:23       ` Dave Hansen
2016-11-08  5:50         ` Li, Liang Z
2016-11-08 18:30           ` Dave Hansen
2016-11-08 21:07         ` Michael S. Tsirkin

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=b25eac6e-3744-3874-93a8-02f814549adf@intel.com \
    --to=dave.hansen@intel.com \
    --cc=amit.shah@redhat.com \
    --cc=cornelia.huck@de.ibm.com \
    --cc=dgilbert@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=liang.z.li@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mgorman@techsingularity.net \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    --cc=virtio-dev@lists.oasis-open.org \
    --cc=virtualization@lists.linux-foundation.org \
    /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;
as well as URLs for NNTP newsgroup(s).