linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Eric Ren <renzhengeek@gmail.com>
To: David Hildenbrand <david@redhat.com>, linux-kernel@vger.kernel.org
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
	Jason Wang <jasowang@redhat.com>, Zi Yan <ziy@nvidia.com>,
	Gavin Shan <gshan@redhat.com>, Hui Zhu <teawater@gmail.com>,
	Sebastien Boeuf <sebastien.boeuf@intel.com>,
	Pankaj Gupta <pankaj.gupta.linux@gmail.com>,
	Wei Yang <richard.weiyang@linux.alibaba.com>,
	virtualization@lists.linux-foundation.org, linux-mm@kvack.org
Subject: Re: [PATCH v1 2/2] virtio-mem: prepare fake page onlining code for granularity smaller than MAX_ORDER - 1
Date: Thu, 9 Dec 2021 19:51:24 +0800	[thread overview]
Message-ID: <a4e2099d-b543-e2e3-f189-0cdfcc38420e@gmail.com> (raw)
In-Reply-To: <20211126134209.17332-3-david@redhat.com>

Hi,

On 2021/11/26 21:42, David Hildenbrand wrote:
> Let's prepare our fake page onlining code for subblock size smaller than
> MAX_ORDER - 1: we might get called for ranges not covering properly
> aligned MAX_ORDER - 1 pages. We have to detect the order to use
> dynamically.
>
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
>   drivers/virtio/virtio_mem.c | 26 +++++++++++++-------------
>   1 file changed, 13 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c
> index 03e1c5743699..50de7582c9f8 100644
> --- a/drivers/virtio/virtio_mem.c
> +++ b/drivers/virtio/virtio_mem.c
> @@ -1121,15 +1121,18 @@ static void virtio_mem_clear_fake_offline(unsigned long pfn,
>    */
>   static void virtio_mem_fake_online(unsigned long pfn, unsigned long nr_pages)
>   {
> -	const unsigned long max_nr_pages = MAX_ORDER_NR_PAGES;
> +	unsigned long order = MAX_ORDER - 1;
>   	unsigned long i;
>   
>   	/*
> -	 * We are always called at least with MAX_ORDER_NR_PAGES
> -	 * granularity/alignment (e.g., the way subblocks work). All pages
> -	 * inside such a block are alike.
> +	 * We might get called for ranges that don't cover properly aligned
> +	 * MAX_ORDER - 1 pages; however, we can only online properly aligned
> +	 * pages with an order of MAX_ORDER - 1 at maximum.
>   	 */
> -	for (i = 0; i < nr_pages; i += max_nr_pages) {
> +	while (!IS_ALIGNED(pfn | nr_pages, 1 << order))
> +		order--;
> +
> +	for (i = 0; i < nr_pages; i += 1 << order) {
>   		struct page *page = pfn_to_page(pfn + i);
>   
>   		/*
> @@ -1139,14 +1142,12 @@ static void virtio_mem_fake_online(unsigned long pfn, unsigned long nr_pages)
>   		 * alike.
>   		 */
>   		if (PageDirty(page)) {
> -			virtio_mem_clear_fake_offline(pfn + i, max_nr_pages,
> -						      false);
> -			generic_online_page(page, MAX_ORDER - 1);
> +			virtio_mem_clear_fake_offline(pfn + i, 1 << order, false);
> +			generic_online_page(page, order);
>   		} else {
> -			virtio_mem_clear_fake_offline(pfn + i, max_nr_pages,
> -						      true);
> -			free_contig_range(pfn + i, max_nr_pages);
> -			adjust_managed_page_count(page, max_nr_pages);
> +			virtio_mem_clear_fake_offline(pfn + i, 1 << order, true);
> +			free_contig_range(pfn + i, 1 << order);
> +			adjust_managed_page_count(page, 1 << order);
In the loop, pfn + i, 1 << order are repeatedly calculated. 1 << order 
is a step size, pfn + i  is each step position.
Better to figure the numer once each iter?

LGTL.
LGTM.
Reviewed-by: Eric Ren <renzhengeek@gmail.com>
>   		}
>   	}
>   }
> @@ -2477,7 +2478,6 @@ static int virtio_mem_init_hotplug(struct virtio_mem *vm)
>   	/*
>   	 * We want subblocks to span at least MAX_ORDER_NR_PAGES and
>   	 * pageblock_nr_pages pages. This:
> -	 * - Simplifies our fake page onlining code (virtio_mem_fake_online).
>   	 * - Is required for now for alloc_contig_range() to work reliably -
>   	 *   it doesn't properly handle smaller granularity on ZONE_NORMAL.
>   	 */



  reply	other threads:[~2021-12-09 11:51 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-26 13:42 [PATCH v1 0/2] virtio-mem: prepare " David Hildenbrand
2021-11-26 13:42 ` [PATCH v1 1/2] virtio-mem: prepare page onlining code " David Hildenbrand
2021-12-09 11:26   ` Eric Ren
2021-11-26 13:42 ` [PATCH v1 2/2] virtio-mem: prepare fake " David Hildenbrand
2021-12-09 11:51   ` Eric Ren [this message]
2021-12-09 11:52     ` David Hildenbrand
2021-11-29 16:47 ` [PATCH v1 0/2] virtio-mem: prepare " Zi Yan
2021-11-30 14:51   ` David Hildenbrand
2021-11-30 23:56 ` Michael S. Tsirkin
2021-12-01  8:24   ` David Hildenbrand

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=a4e2099d-b543-e2e3-f189-0cdfcc38420e@gmail.com \
    --to=renzhengeek@gmail.com \
    --cc=david@redhat.com \
    --cc=gshan@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mst@redhat.com \
    --cc=pankaj.gupta.linux@gmail.com \
    --cc=richard.weiyang@linux.alibaba.com \
    --cc=sebastien.boeuf@intel.com \
    --cc=teawater@gmail.com \
    --cc=virtualization@lists.linux-foundation.org \
    --cc=ziy@nvidia.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