Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to initialize Linux memory

Shulou Source: shulou.com Published: 2022-06-01 12:16:16 09月28日 Update

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

Tags: Memory physics kernel address content area size model meaning time system structure learning sparse consistency consistency function processor subsystem that is Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi vpn Shulou Tech Info NVidia MySQL