All of lore.kernel.org
 help / color / mirror / Atom feed
* A question about memblock.reserved
@ 2022-06-23  5:25 Chan Kim
  2022-06-24  6:40 ` Wonhyuk Yang
  0 siblings, 1 reply; 3+ messages in thread
From: Chan Kim @ 2022-06-23  5:25 UTC (permalink / raw)
  To: kernelnewbies


[-- Attachment #1.1: Type: text/plain, Size: 1460 bytes --]

Hello all,

I mm/memblock.c I see this struct memblock memblock which is initialized
with empty list.

	static struct memblock_region
memblock_memory_init_regions[INIT_MEMBLOCK_REGIONS] __initdata_memblock;
	static struct memblock_region
memblock_reserved_init_regions[INIT_MEMBLOCK_RESERVED_REGIONS]
__initdata_memblock;
	#ifdef CONFIG_HAVE_MEMBLOCK_PHYS_MAP
	static struct memblock_region
memblock_physmem_init_regions[INIT_PHYSMEM_REGIONS];
	#endif
	 
	struct memblock memblock __initdata_memblock = {
	    .memory.regions     = memblock_memory_init_regions,
	    .memory.cnt     = 1,    /* empty dummy entry */
	    .memory.max     = INIT_MEMBLOCK_REGIONS,
	    .memory.name        = "memory",

	    .reserved.regions   = memblock_reserved_init_regions,
	    .reserved.cnt       = 1,    /* empty dummy entry */
	    .reserved.max       = INIT_MEMBLOCK_RESERVED_REGIONS,
	    .reserved.name      = "reserved",

	    .bottom_up      = false,
	    .current_limit      = MEMBLOCK_ALLOC_ANYWHERE,
	};

And I guess this struct will be filled during early boot and used during
boot. (I saw somewhere the memory regions are later moved to buddy
allocation system for normal use).
My question is : we can speicify "reserved-memory" in the device tree. Some
drivers use the reserved memory for its own use.
Then, are the 'reserved-memory' regions are put into this memblock.reserved
regions during the boot process?(I mean during dtb parsing).

Thank you!

Chan Kim

[-- Attachment #1.2: Type: text/html, Size: 5970 bytes --]

[-- Attachment #2: Type: text/plain, Size: 170 bytes --]

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

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

* Re: A question about memblock.reserved
  2022-06-23  5:25 A question about memblock.reserved Chan Kim
@ 2022-06-24  6:40 ` Wonhyuk Yang
  2022-06-29  4:39   ` Chan Kim
  0 siblings, 1 reply; 3+ messages in thread
From: Wonhyuk Yang @ 2022-06-24  6:40 UTC (permalink / raw)
  To: Chan Kim; +Cc: kernelnewbies

On Thu, Jun 23, 2022 at 2:25 PM Chan Kim <ckim@etri.re.kr> wrote:
>
> I mm/memblock.c I see this struct memblock memblock which is initialized with empty list.
>
> static struct memblock_region memblock_memory_init_regions[INIT_MEMBLOCK_REGIONS] __initdata_memblock;
> static struct memblock_region memblock_reserved_init_regions[INIT_MEMBLOCK_RESERVED_REGIONS] __initdata_memblock;
>
> struct memblock memblock __initdata_memblock = {
>     .memory.regions     = memblock_memory_init_regions,
>     .memory.cnt     = 1,    /* empty dummy entry */
>     .memory.max     = INIT_MEMBLOCK_REGIONS,
>     .memory.name        = "memory",
>     .reserved.regions   = memblock_reserved_init_regions,
>     .reserved.cnt       = 1,    /* empty dummy entry */
>     .reserved.max       = INIT_MEMBLOCK_RESERVED_REGIONS,
>     .reserved.name      = "reserved",
>     .bottom_up      = false,
>     .current_limit      = MEMBLOCK_ALLOC_ANYWHERE,
> };
>
> My question is : we can speicify "reserved-memory" in the device tree. Some drivers use the reserved memory for its own use.
> Then, are the 'reserved-memory' regions are put into this memblock.reserved  regions during the boot process?(I mean during dtb parsing).
>

Yes, reserved memblock is initialized while scanning the fdt.
I'll attach some call graph below and I hope it helps you.

setup_arch ()
  arm64_memblock_init ()
    early_init_fdt_scan_reserved_mem ()
      fdt_init_reserved_mem ()
        fdt_scan_reserved_mem ()
          __reserved_mem_reserve_reg ()
            early_init_dt_reserve_memory_arch ()
              memblock_reserve ()

Plus, I written some *scribbled* notes about this in Korean.
I don't know if it will help, but I will attach it below.

https://kjhg4321.gitbook.io/doodle/

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

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

* RE: A question about memblock.reserved
  2022-06-24  6:40 ` Wonhyuk Yang
@ 2022-06-29  4:39   ` Chan Kim
  0 siblings, 0 replies; 3+ messages in thread
From: Chan Kim @ 2022-06-29  4:39 UTC (permalink / raw)
  To: 'Wonhyuk Yang'; +Cc: 'kernelnewbies'

Hi Wonhyuk, 
Thank you for the reply (I found it this morning :))
Yes, I saw your blog and it helped. And I later found in a book that this memblock puts the kernel image, initrd, page tables, dtb,.. and the "reserved-memory" regions from the dtb in its memblock.reserved regions. 
Have a nice day!
Chan Kim

>>-----Original Message-----
>>From: Wonhyuk Yang <vvghjk1234@gmail.com>
>>Sent: Friday, June 24, 2022 3:41 PM
>>To: Chan Kim <ckim@etri.re.kr>
>>Cc: kernelnewbies <kernelnewbies@kernelnewbies.org>
>>Subject: Re: A question about memblock.reserved
>>
>>On Thu, Jun 23, 2022 at 2:25 PM Chan Kim <ckim@etri.re.kr> wrote:
>>>
>>> I mm/memblock.c I see this struct memblock memblock which is initialized
>>with empty list.
>>>
>>> static struct memblock_region
>>> memblock_memory_init_regions[INIT_MEMBLOCK_REGIONS]
>>> __initdata_memblock; static struct memblock_region
>>> memblock_reserved_init_regions[INIT_MEMBLOCK_RESERVED_REGIONS]
>>> __initdata_memblock;
>>>
>>> struct memblock memblock __initdata_memblock = {
>>>     .memory.regions     = memblock_memory_init_regions,
>>>     .memory.cnt     = 1,    /* empty dummy entry */
>>>     .memory.max     = INIT_MEMBLOCK_REGIONS,
>>>     .memory.name        = "memory",
>>>     .reserved.regions   = memblock_reserved_init_regions,
>>>     .reserved.cnt       = 1,    /* empty dummy entry */
>>>     .reserved.max       = INIT_MEMBLOCK_RESERVED_REGIONS,
>>>     .reserved.name      = "reserved",
>>>     .bottom_up      = false,
>>>     .current_limit      = MEMBLOCK_ALLOC_ANYWHERE,
>>> };
>>>
>>> My question is : we can speicify "reserved-memory" in the device tree.
>>Some drivers use the reserved memory for its own use.
>>> Then, are the 'reserved-memory' regions are put into this
>>memblock.reserved  regions during the boot process?(I mean during dtb
>>parsing).
>>>
>>
>>Yes, reserved memblock is initialized while scanning the fdt.
>>I'll attach some call graph below and I hope it helps you.
>>
>>setup_arch ()
>>  arm64_memblock_init ()
>>    early_init_fdt_scan_reserved_mem ()
>>      fdt_init_reserved_mem ()
>>        fdt_scan_reserved_mem ()
>>          __reserved_mem_reserve_reg ()
>>            early_init_dt_reserve_memory_arch ()
>>              memblock_reserve ()
>>
>>Plus, I written some *scribbled* notes about this in Korean.
>>I don't know if it will help, but I will attach it below.
>>
>>https://kjhg4321.gitbook.io/doodle/





_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

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

end of thread, other threads:[~2022-06-29  4:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-23  5:25 A question about memblock.reserved Chan Kim
2022-06-24  6:40 ` Wonhyuk Yang
2022-06-29  4:39   ` Chan Kim

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.