public inbox for linuxppc-dev@ozlabs.org 
 help / color / mirror / Atom feed
From: "Aneesh Kumar K.V" <aneesh.kumar@linux•vnet.ibm.com>
To: Anshuman Khandual <khandual@linux•vnet.ibm.com>,
	linuxppc-dev@lists•ozlabs.org
Subject: Re: [RFC] KVM: PPC: Book3S HV: Fall back to same size HPT in allocation ioctl
Date: Mon, 12 Sep 2016 17:35:28 +0530	[thread overview]
Message-ID: <8760q1pblj.fsf@linux.vnet.ibm.com> (raw)
In-Reply-To: <1473678797-22069-1-git-send-email-khandual@linux.vnet.ibm.com>

Anshuman Khandual <khandual@linux•vnet.ibm.com> writes:

> When the HPT size is explicitly passed on from the userspace, currently
> the KVM_PPC_ALLOCATE_HTAB will try to allocate the requested size of HPT
> from reserved CMA area and if that is not possible, the allocation just
> fails. With the commit 572abd563befd56 ("KVM: PPC: Book3S HV: Don't fall
> back to smaller HPT size in allocation ioctl"), it does not even try to
> allocate the same order pages from the page allocator before failing for
> good. Same order allocation should be attempted from the page allocator
> as a fallback option when the CMA allocation attempt fails.

IMO we should fix the reason for these CMA allocation failure. We are just
doing work around here.

>
> Signed-off-by: Anshuman Khandual <khandual@linux•vnet.ibm.com>
> ---
> - This change saves guests from failing to start after migration
>
>  arch/powerpc/kvm/book3s_64_mmu_hv.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
>
> diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c b/arch/powerpc/kvm/book3s_64_mmu_hv.c
> index 05f09ae..0a30eb4 100644
> --- a/arch/powerpc/kvm/book3s_64_mmu_hv.c
> +++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c
> @@ -78,6 +78,14 @@ long kvmppc_alloc_hpt(struct kvm *kvm, u32 *htab_orderp)
>  			--order;
>  	}
>
> +	/*
> +	 * Fallback in case the userspace has provided a size via ioctl.
> +	 * Try allocating the same order pages from the page allocator.
> +	 */
> +	if (!hpt && order > PPC_MIN_HPT_ORDER && htab_orderp)
> +		hpt = __get_free_pages(GFP_KERNEL|__GFP_ZERO|__GFP_REPEAT|
> +			__GFP_NOWARN, order - PAGE_SHIFT);
> +
>  	if (!hpt)
>  		return -ENOMEM;

A better way to do that would be (not even compile tested) ?

diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c b/arch/powerpc/kvm/book3s_64_mmu_hv.c
index 65b2b00d93d7..3f8995f27339 100644
--- a/arch/powerpc/kvm/book3s_64_mmu_hv.c
+++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c
@@ -68,16 +68,18 @@ long kvmppc_alloc_hpt(struct kvm *kvm, u32 *htab_orderp)
 		memset((void *)hpt, 0, (1ul << order));
 		kvm->arch.hpt_cma_alloc = 1;
 	}
-
-	/* Lastly try successively smaller sizes from the page allocator */
-	/* Only do this if userspace didn't specify a size via ioctl */
-	while (!hpt && order > PPC_MIN_HPT_ORDER && !htab_orderp) {
+	/*
+	 * Try successively smaller sizes from the page allocator.
+	 * If a size was specified via an ioctl, we just try that
+	 * specific size
+	 */
+-	while (!hpt && order > PPC_MIN_HPT_ORDER) {
 		hpt = __get_free_pages(GFP_KERNEL|__GFP_ZERO|__GFP_REPEAT|
 				       __GFP_NOWARN, order - PAGE_SHIFT);
-		if (!hpt)
-			--order;
+		if (htab_orderp)
+			break;
+		--order;
 	}
-
 	if (!hpt)
 		return -ENOMEM;
 

  parent reply	other threads:[~2016-09-12 12:05 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-12 11:13 [RFC] KVM: PPC: Book3S HV: Fall back to same size HPT in allocation ioctl Anshuman Khandual
2016-09-12 11:33 ` Balbir Singh
2016-09-13  4:07   ` Anshuman Khandual
2016-09-13  4:34     ` Balbir Singh
2016-09-13  5:49       ` Anshuman Khandual
2016-09-13  9:26         ` Balbir Singh
2016-09-12 12:05 ` Aneesh Kumar K.V [this message]
2016-09-13  6:26   ` Anshuman Khandual
2016-09-13 23:57 ` Michael Ellerman
2016-09-14  0:12   ` Paul Mackerras
2016-09-14  3:55     ` Anshuman Khandual
2016-09-14  3:52   ` Anshuman Khandual
2016-09-14  5:28   ` Anshuman Khandual

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=8760q1pblj.fsf@linux.vnet.ibm.com \
    --to=aneesh.kumar@linux$(echo .)vnet.ibm.com \
    --cc=khandual@linux$(echo .)vnet.ibm.com \
    --cc=linuxppc-dev@lists$(echo .)ozlabs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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