linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] sparc64: simplify reduce_memory() function
@ 2019-02-12  9:32 Mike Rapoport
  2019-02-17  8:28 ` Mike Rapoport
  0 siblings, 1 reply; 5+ messages in thread
From: Mike Rapoport @ 2019-02-12  9:32 UTC (permalink / raw)
  To: 'David S . Miller'
  Cc: linux-mm, sparclinux, linux-kernel, Mike Rapoport

The reduce_memory() function clampls the available memory to a limit
defined by the "mem=" command line parameter. It takes into account the
amount of already reserved memory and excludes it from the limit
calculations.

Rather than traverse memblocks and remove them by hand, use
memblock_reserved_size() to account the reserved memory and
memblock_enforce_memory_limit() to clamp the available memory.

Signed-off-by: Mike Rapoport <rppt@linux.ibm.com>
---
 arch/sparc/mm/init_64.c | 42 ++----------------------------------------
 1 file changed, 2 insertions(+), 40 deletions(-)

diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
index b4221d3..478b818 100644
--- a/arch/sparc/mm/init_64.c
+++ b/arch/sparc/mm/init_64.c
@@ -2261,19 +2261,6 @@ static unsigned long last_valid_pfn;
 static void sun4u_pgprot_init(void);
 static void sun4v_pgprot_init(void);
 
-static phys_addr_t __init available_memory(void)
-{
-	phys_addr_t available = 0ULL;
-	phys_addr_t pa_start, pa_end;
-	u64 i;
-
-	for_each_free_mem_range(i, NUMA_NO_NODE, MEMBLOCK_NONE, &pa_start,
-				&pa_end, NULL)
-		available = available + (pa_end  - pa_start);
-
-	return available;
-}
-
 #define _PAGE_CACHE_4U	(_PAGE_CP_4U | _PAGE_CV_4U)
 #define _PAGE_CACHE_4V	(_PAGE_CP_4V | _PAGE_CV_4V)
 #define __DIRTY_BITS_4U	 (_PAGE_MODIFIED_4U | _PAGE_WRITE_4U | _PAGE_W_4U)
@@ -2287,33 +2274,8 @@ static phys_addr_t __init available_memory(void)
  */
 static void __init reduce_memory(phys_addr_t limit_ram)
 {
-	phys_addr_t avail_ram = available_memory();
-	phys_addr_t pa_start, pa_end;
-	u64 i;
-
-	if (limit_ram >= avail_ram)
-		return;
-
-	for_each_free_mem_range(i, NUMA_NO_NODE, MEMBLOCK_NONE, &pa_start,
-				&pa_end, NULL) {
-		phys_addr_t region_size = pa_end - pa_start;
-		phys_addr_t clip_start = pa_start;
-
-		avail_ram = avail_ram - region_size;
-		/* Are we consuming too much? */
-		if (avail_ram < limit_ram) {
-			phys_addr_t give_back = limit_ram - avail_ram;
-
-			region_size = region_size - give_back;
-			clip_start = clip_start + give_back;
-		}
-
-		memblock_remove(clip_start, region_size);
-
-		if (avail_ram <= limit_ram)
-			break;
-		i = 0UL;
-	}
+	limit_ram += memblock_reserved_size();
+	memblock_enforce_memory_limit(limit_ram);
 }
 
 void __init paging_init(void)
-- 
2.7.4


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

* Re: [PATCH] sparc64: simplify reduce_memory() function
  2019-02-12  9:32 [PATCH] sparc64: simplify reduce_memory() function Mike Rapoport
@ 2019-02-17  8:28 ` Mike Rapoport
  2019-02-17 18:15   ` David Miller
  0 siblings, 1 reply; 5+ messages in thread
From: Mike Rapoport @ 2019-02-17  8:28 UTC (permalink / raw)
  To: David S. Miller; +Cc: linux-mm, sparclinux, linux-kernel

Any comments on this?

On Tue, Feb 12, 2019 at 11:32:36AM +0200, Mike Rapoport wrote:
> The reduce_memory() function clampls the available memory to a limit
> defined by the "mem=" command line parameter. It takes into account the
> amount of already reserved memory and excludes it from the limit
> calculations.
> 
> Rather than traverse memblocks and remove them by hand, use
> memblock_reserved_size() to account the reserved memory and
> memblock_enforce_memory_limit() to clamp the available memory.
> 
> Signed-off-by: Mike Rapoport <rppt@linux.ibm.com>
> ---
>  arch/sparc/mm/init_64.c | 42 ++----------------------------------------
>  1 file changed, 2 insertions(+), 40 deletions(-)
> 
> diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
> index b4221d3..478b818 100644
> --- a/arch/sparc/mm/init_64.c
> +++ b/arch/sparc/mm/init_64.c
> @@ -2261,19 +2261,6 @@ static unsigned long last_valid_pfn;
>  static void sun4u_pgprot_init(void);
>  static void sun4v_pgprot_init(void);
>  
> -static phys_addr_t __init available_memory(void)
> -{
> -	phys_addr_t available = 0ULL;
> -	phys_addr_t pa_start, pa_end;
> -	u64 i;
> -
> -	for_each_free_mem_range(i, NUMA_NO_NODE, MEMBLOCK_NONE, &pa_start,
> -				&pa_end, NULL)
> -		available = available + (pa_end  - pa_start);
> -
> -	return available;
> -}
> -
>  #define _PAGE_CACHE_4U	(_PAGE_CP_4U | _PAGE_CV_4U)
>  #define _PAGE_CACHE_4V	(_PAGE_CP_4V | _PAGE_CV_4V)
>  #define __DIRTY_BITS_4U	 (_PAGE_MODIFIED_4U | _PAGE_WRITE_4U | _PAGE_W_4U)
> @@ -2287,33 +2274,8 @@ static phys_addr_t __init available_memory(void)
>   */
>  static void __init reduce_memory(phys_addr_t limit_ram)
>  {
> -	phys_addr_t avail_ram = available_memory();
> -	phys_addr_t pa_start, pa_end;
> -	u64 i;
> -
> -	if (limit_ram >= avail_ram)
> -		return;
> -
> -	for_each_free_mem_range(i, NUMA_NO_NODE, MEMBLOCK_NONE, &pa_start,
> -				&pa_end, NULL) {
> -		phys_addr_t region_size = pa_end - pa_start;
> -		phys_addr_t clip_start = pa_start;
> -
> -		avail_ram = avail_ram - region_size;
> -		/* Are we consuming too much? */
> -		if (avail_ram < limit_ram) {
> -			phys_addr_t give_back = limit_ram - avail_ram;
> -
> -			region_size = region_size - give_back;
> -			clip_start = clip_start + give_back;
> -		}
> -
> -		memblock_remove(clip_start, region_size);
> -
> -		if (avail_ram <= limit_ram)
> -			break;
> -		i = 0UL;
> -	}
> +	limit_ram += memblock_reserved_size();
> +	memblock_enforce_memory_limit(limit_ram);
>  }
>  
>  void __init paging_init(void)
> -- 
> 2.7.4
> 

-- 
Sincerely yours,
Mike.


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

* Re: [PATCH] sparc64: simplify reduce_memory() function
  2019-02-17  8:28 ` Mike Rapoport
@ 2019-02-17 18:15   ` David Miller
  2019-02-25 21:21     ` Mike Rapoport
  0 siblings, 1 reply; 5+ messages in thread
From: David Miller @ 2019-02-17 18:15 UTC (permalink / raw)
  To: rppt; +Cc: linux-mm, sparclinux, linux-kernel

From: Mike Rapoport <rppt@linux.ibm.com>
Date: Sun, 17 Feb 2019 10:28:17 +0200

> Any comments on this?

Acked-by: David S. Miller <davem@davemloft.net>


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

* Re: [PATCH] sparc64: simplify reduce_memory() function
  2019-02-17 18:15   ` David Miller
@ 2019-02-25 21:21     ` Mike Rapoport
  2019-02-26  0:37       ` David Miller
  0 siblings, 1 reply; 5+ messages in thread
From: Mike Rapoport @ 2019-02-25 21:21 UTC (permalink / raw)
  To: David Miller; +Cc: linux-mm, sparclinux, linux-kernel

On Sun, Feb 17, 2019 at 10:15:32AM -0800, David Miller wrote:
> From: Mike Rapoport <rppt@linux.ibm.com>
> Date: Sun, 17 Feb 2019 10:28:17 +0200
> 
> > Any comments on this?
> 
> Acked-by: David S. Miller <davem@davemloft.net>

Can you please take it via sparc tree? 

-- 
Sincerely yours,
Mike.


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

* Re: [PATCH] sparc64: simplify reduce_memory() function
  2019-02-25 21:21     ` Mike Rapoport
@ 2019-02-26  0:37       ` David Miller
  0 siblings, 0 replies; 5+ messages in thread
From: David Miller @ 2019-02-26  0:37 UTC (permalink / raw)
  To: rppt; +Cc: linux-mm, sparclinux, linux-kernel

From: Mike Rapoport <rppt@linux.ibm.com>
Date: Mon, 25 Feb 2019 23:21:45 +0200

> On Sun, Feb 17, 2019 at 10:15:32AM -0800, David Miller wrote:
>> From: Mike Rapoport <rppt@linux.ibm.com>
>> Date: Sun, 17 Feb 2019 10:28:17 +0200
>> 
>> > Any comments on this?
>> 
>> Acked-by: David S. Miller <davem@davemloft.net>
> 
> Can you please take it via sparc tree? 

Sure, applied.


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

end of thread, other threads:[~2019-02-26  0:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-12  9:32 [PATCH] sparc64: simplify reduce_memory() function Mike Rapoport
2019-02-17  8:28 ` Mike Rapoport
2019-02-17 18:15   ` David Miller
2019-02-25 21:21     ` Mike Rapoport
2019-02-26  0:37       ` David Miller

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).