Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to initialize Linux memory

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to initialize Linux memory". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to initialize Linux memory.

Paging_initvoid _ init paging_init (void)

{

Phys_addr_t pgd_phys = early_pgtable_alloc (); / / allocate a page size of physical storage into pgd

Pgd_t * pgd = pgd_set_fixmap (pgd_phys)

Map_kernel (pgd); / / Map each segment of the kernel .text .init .data .bss

Map_mem (pgd); / / Map the physical memory added by the memblock subsystem (map the physical address to the linear area)

/ *

* We want to reuse the original swapper_pg_dir so we don't have to

* communicate the new address to non-coherent secondaries in

* secondary_entry, and so cpu_switch_mm can generate the address with

* adrp+add rather than a load from some global variable.

*

* To do this we need to go via a temporary pgd.

, /

Cpu_replace_ttbr1 (_ _ va (pgd_phys)); / / switch page table

Memcpy (swapper_pg_dir, pgd, PGD_SIZE); / / replace the newly created page table content with the swapper_pg_dir page table content

Cpu_replace_ttbr1 (lm_alias (swapper_pg_dir))

Pgd_clear_fixmap ()

Memblock_free (pgd_phys, PAGE_SIZE)

/ *

* We only reuse the PGD from the swapper_pg_dir, not the pud + pmd

* allocated with it.

, /

Memblock_free (_ _ pa_symbol (swapper_pg_dir) + PAGE_SIZE)

SWAPPER_DIR_SIZE-PAGE_SIZE)

}

Early_pgtable_alloc: allocate a page size of physical storage into pgdmap_kernel (pgd): map each segment of the kernel (.text .init .data .bss)

Map_mem (pgd): maps physical memory added by the memblock subsystem (maps physical addresses to linear areas)

The main task is to complete the physical memory mapping added to the system through memblock_add, and note that if memblock has the MEMBLOCK_NOMAP flag set, its address is not mapped.

Cpu_replace_ttbr1 (_ _ va (pgd_phys)): switch page table memcpy (swapper_pg_dir, pgd, PGD_SIZE): replace the newly created page table content with swapper_pg_dir page table content bootmem_initvoid _ _ init bootmem_init (void)

{

Unsigned long min, max

Min = PFN_UP (memblock_start_of_DRAM ())

Max = PFN_DOWN (memblock_end_of_DRAM ())

Early_memtest (min

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report