public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/mm: stop allocating pmd page if failed
@ 2012-07-24 13:15 Yuanhan Liu
  2012-07-26  5:39 ` Jeremy Fitzhardinge
  0 siblings, 1 reply; 2+ messages in thread
From: Yuanhan Liu @ 2012-07-24 13:15 UTC (permalink / raw)
  To: x86
  Cc: linux-kernel, Yuanhan Liu, Jeremy Fitzhardinge, Thomas Gleixner,
	Ingo Molnar, H. Peter Anvin

The old code would call __get_free_page() even though previous
allocation fail met. This is not needed.

Signed-off-by: Yuanhan Liu <yliu.null@gmail.com>
Cc: Jeremy Fitzhardinge <jeremy@goop.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: "H. Peter Anvin" <hpa@zytor.com>
---
 arch/x86/mm/pgtable.c |   18 +++++++++---------
 1 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
index 8573b83..6760348 100644
--- a/arch/x86/mm/pgtable.c
+++ b/arch/x86/mm/pgtable.c
@@ -181,24 +181,24 @@ static void free_pmds(pmd_t *pmds[])
 {
 	int i;
 
-	for(i = 0; i < PREALLOCATED_PMDS; i++)
-		if (pmds[i])
-			free_page((unsigned long)pmds[i]);
+	for(i = 0; i < PREALLOCATED_PMDS; i++) {
+		if (pmds[i] == NULL)
+			break;
+		free_page((unsigned long)pmds[i]);
+	}
 }
 
 static int preallocate_pmds(pmd_t *pmds[])
 {
 	int i;
-	bool failed = false;
 
 	for(i = 0; i < PREALLOCATED_PMDS; i++) {
-		pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
-		if (pmd == NULL)
-			failed = true;
-		pmds[i] = pmd;
+		pmds[i] = (pmd_t *)__get_free_page(PGALLOC_GFP);
+		if (pmds[i] == NULL)
+			break;
 	}
 
-	if (failed) {
+	if (i < PREALLOCATED_PMDS) {
 		free_pmds(pmds);
 		return -ENOMEM;
 	}
-- 
1.7.4.4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] x86/mm: stop allocating pmd page if failed
  2012-07-24 13:15 [PATCH] x86/mm: stop allocating pmd page if failed Yuanhan Liu
@ 2012-07-26  5:39 ` Jeremy Fitzhardinge
  0 siblings, 0 replies; 2+ messages in thread
From: Jeremy Fitzhardinge @ 2012-07-26  5:39 UTC (permalink / raw)
  To: Yuanhan Liu
  Cc: x86, linux-kernel, Thomas Gleixner, Ingo Molnar, H. Peter Anvin

On 07/24/2012 06:15 AM, Yuanhan Liu wrote:
> The old code would call __get_free_page() even though previous
> allocation fail met. This is not needed.

Yeah, I guess, but its hardly worth changing.

    J


>
> Signed-off-by: Yuanhan Liu <yliu.null@gmail.com>
> Cc: Jeremy Fitzhardinge <jeremy@goop.org>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Ingo Molnar <mingo@elte.hu>
> Cc: "H. Peter Anvin" <hpa@zytor.com>
> ---
>  arch/x86/mm/pgtable.c |   18 +++++++++---------
>  1 files changed, 9 insertions(+), 9 deletions(-)
>
> diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
> index 8573b83..6760348 100644
> --- a/arch/x86/mm/pgtable.c
> +++ b/arch/x86/mm/pgtable.c
> @@ -181,24 +181,24 @@ static void free_pmds(pmd_t *pmds[])
>  {
>  	int i;
>  
> -	for(i = 0; i < PREALLOCATED_PMDS; i++)
> -		if (pmds[i])
> -			free_page((unsigned long)pmds[i]);
> +	for(i = 0; i < PREALLOCATED_PMDS; i++) {
> +		if (pmds[i] == NULL)
> +			break;
> +		free_page((unsigned long)pmds[i]);
> +	}
>  }
>  
>  static int preallocate_pmds(pmd_t *pmds[])
>  {
>  	int i;
> -	bool failed = false;
>  
>  	for(i = 0; i < PREALLOCATED_PMDS; i++) {
> -		pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
> -		if (pmd == NULL)
> -			failed = true;
> -		pmds[i] = pmd;
> +		pmds[i] = (pmd_t *)__get_free_page(PGALLOC_GFP);
> +		if (pmds[i] == NULL)
> +			break;
>  	}
>  
> -	if (failed) {
> +	if (i < PREALLOCATED_PMDS) {
>  		free_pmds(pmds);
>  		return -ENOMEM;
>  	}


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-07-26  5:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-24 13:15 [PATCH] x86/mm: stop allocating pmd page if failed Yuanhan Liu
2012-07-26  5:39 ` Jeremy Fitzhardinge

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox