All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mike Rapoport <rppt@kernel.org>
To: Atish Patra <atish.patra@wdc.com>
Cc: Albert Ou <aou@eecs.berkeley.edu>,
	Anup Patel <anup.patel@wdc.com>,
	linux-kernel@vger.kernel.org, Palmer Dabbelt <palmer@dabbelt.com>,
	Zong Li <zong.li@sifive.com>,
	Paul Walmsley <paul.walmsley@sifive.com>,
	linux-riscv@lists.infradead.org
Subject: Re: [PATCH] RISC-V: Consider sparse memory while removing unusable memory
Date: Sat, 12 Sep 2020 13:45:02 +0300	[thread overview]
Message-ID: <20200912104502.GF2142832@kernel.org> (raw)
In-Reply-To: <20200912002341.4869-1-atish.patra@wdc.com>

Hello Atish,

On Fri, Sep 11, 2020 at 05:23:41PM -0700, Atish Patra wrote:
> Currently, any usable memory area beyond page_offset is removed by adding the
> memory sizes from each memblock. That may not work for sparse memory
> as memory regions can be very far apart resulting incorrect removal of some
> usable memory.

If I understand correctly, the memory with physical addresses larger
than (-PAGE_OFFSET) cannot be used. Since it was aready
memblock_add()'ed during device tree parsing, you need to remove it from
memblock.

For that you can use memblock_enforce_memory_limit(-PAGE_OFFSET).

> Just use the start of the first memory block and the end of the last memory
> block to compute the size of the total memory that can be used.
> 
> Signed-off-by: Atish Patra <atish.patra@wdc.com>
> ---
>  arch/riscv/mm/init.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
> index 787c75f751a5..188281fc2816 100644
> --- a/arch/riscv/mm/init.c
> +++ b/arch/riscv/mm/init.c
> @@ -147,7 +147,6 @@ void __init setup_bootmem(void)
>  {
>  	struct memblock_region *reg;
>  	phys_addr_t mem_size = 0;
> -	phys_addr_t total_mem = 0;
>  	phys_addr_t mem_start, end = 0;
>  	phys_addr_t vmlinux_end = __pa_symbol(&_end);
>  	phys_addr_t vmlinux_start = __pa_symbol(&_start);
> @@ -155,18 +154,17 @@ void __init setup_bootmem(void)
>  	/* Find the memory region containing the kernel */
>  	for_each_memblock(memory, reg) {
>  		end = reg->base + reg->size;
> -		if (!total_mem)
> +		if (!mem_start)
>  			mem_start = reg->base;
>  		if (reg->base <= vmlinux_start && vmlinux_end <= end)
>  			BUG_ON(reg->size == 0);
> -		total_mem = total_mem + reg->size;
>  	}
>  
>  	/*
>  	 * Remove memblock from the end of usable area to the
>  	 * end of region
>  	 */
> -	mem_size = min(total_mem, (phys_addr_t)-PAGE_OFFSET);
> +	mem_size = min(end - mem_start, (phys_addr_t)-PAGE_OFFSET);
>  	if (mem_start + mem_size < end)
>  		memblock_remove(mem_start + mem_size,
>  				end - mem_start - mem_size);
> -- 
> 2.24.0
> 

-- 
Sincerely yours,
Mike.

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

WARNING: multiple messages have this Message-ID (diff)
From: Mike Rapoport <rppt@kernel.org>
To: Atish Patra <atish.patra@wdc.com>
Cc: linux-kernel@vger.kernel.org, Albert Ou <aou@eecs.berkeley.edu>,
	Anup Patel <anup.patel@wdc.com>,
	linux-riscv@lists.infradead.org,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Paul Walmsley <paul.walmsley@sifive.com>,
	Zong Li <zong.li@sifive.com>
Subject: Re: [PATCH] RISC-V: Consider sparse memory while removing unusable memory
Date: Sat, 12 Sep 2020 13:45:02 +0300	[thread overview]
Message-ID: <20200912104502.GF2142832@kernel.org> (raw)
In-Reply-To: <20200912002341.4869-1-atish.patra@wdc.com>

Hello Atish,

On Fri, Sep 11, 2020 at 05:23:41PM -0700, Atish Patra wrote:
> Currently, any usable memory area beyond page_offset is removed by adding the
> memory sizes from each memblock. That may not work for sparse memory
> as memory regions can be very far apart resulting incorrect removal of some
> usable memory.

If I understand correctly, the memory with physical addresses larger
than (-PAGE_OFFSET) cannot be used. Since it was aready
memblock_add()'ed during device tree parsing, you need to remove it from
memblock.

For that you can use memblock_enforce_memory_limit(-PAGE_OFFSET).

> Just use the start of the first memory block and the end of the last memory
> block to compute the size of the total memory that can be used.
> 
> Signed-off-by: Atish Patra <atish.patra@wdc.com>
> ---
>  arch/riscv/mm/init.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
> index 787c75f751a5..188281fc2816 100644
> --- a/arch/riscv/mm/init.c
> +++ b/arch/riscv/mm/init.c
> @@ -147,7 +147,6 @@ void __init setup_bootmem(void)
>  {
>  	struct memblock_region *reg;
>  	phys_addr_t mem_size = 0;
> -	phys_addr_t total_mem = 0;
>  	phys_addr_t mem_start, end = 0;
>  	phys_addr_t vmlinux_end = __pa_symbol(&_end);
>  	phys_addr_t vmlinux_start = __pa_symbol(&_start);
> @@ -155,18 +154,17 @@ void __init setup_bootmem(void)
>  	/* Find the memory region containing the kernel */
>  	for_each_memblock(memory, reg) {
>  		end = reg->base + reg->size;
> -		if (!total_mem)
> +		if (!mem_start)
>  			mem_start = reg->base;
>  		if (reg->base <= vmlinux_start && vmlinux_end <= end)
>  			BUG_ON(reg->size == 0);
> -		total_mem = total_mem + reg->size;
>  	}
>  
>  	/*
>  	 * Remove memblock from the end of usable area to the
>  	 * end of region
>  	 */
> -	mem_size = min(total_mem, (phys_addr_t)-PAGE_OFFSET);
> +	mem_size = min(end - mem_start, (phys_addr_t)-PAGE_OFFSET);
>  	if (mem_start + mem_size < end)
>  		memblock_remove(mem_start + mem_size,
>  				end - mem_start - mem_size);
> -- 
> 2.24.0
> 

-- 
Sincerely yours,
Mike.

  reply	other threads:[~2020-09-12 10:45 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-12  0:23 [PATCH] RISC-V: Consider sparse memory while removing unusable memory Atish Patra
2020-09-12  0:23 ` Atish Patra
2020-09-12 10:45 ` Mike Rapoport [this message]
2020-09-12 10:45   ` Mike Rapoport
2020-09-13 23:47   ` Atish Patra
2020-09-13 23:47     ` Atish Patra
2020-09-14 11:52     ` Anup Patel
2020-09-14 11:52       ` Anup Patel
2020-09-14 17:53       ` Atish Patra
2020-09-14 17:53         ` Atish Patra
2020-09-14 11:49   ` Anup Patel
2020-09-14 11:49     ` Anup Patel

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=20200912104502.GF2142832@kernel.org \
    --to=rppt@kernel.org \
    --cc=anup.patel@wdc.com \
    --cc=aou@eecs.berkeley.edu \
    --cc=atish.patra@wdc.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=palmer@dabbelt.com \
    --cc=paul.walmsley@sifive.com \
    --cc=zong.li@sifive.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.