2

I am studying Professional Linux Kernel Architecture and I am in Chapter 3 Memory Management. While I studied kernel address space itself is split into direct mapping area, vmalloc area, kmap area and fixed mapping area.

enter image description here

What I am wondering is just like below.

  1. Can direct mapping area(896MB) of kernel address space in 32-bit machine be accessed by function like __va, __pa without MMU?

  2. if 1. is true then master kernel page table(swapper_pg_dir) manages only 128MB ?

  3. While I am studying kernel code I found difference in paging_init function between 32-bit and 64-bit. In 32-bit, I found pagetable_init function which initialize and master kernel page table in paging_init function.

function paging_init in 32-bit

void __init pageit_init(void){
    pagetable_init();
    __flush_tlb_all();

    kmap_init();

    olpc_dt_build_devicetree();
    sparse_memory_present_with_active_regions(MAX_NUMNODES);
    sparse_init();
    zone_sizes_init(); 
}

But in 64-bit, I could't find kernel page table related function in paging_init function.

void __init paging_init(void)
{
    sparse_memory_present_with_active_regions(MAX_NUMNODES);
    sparse_init();

    node_clear_state(0, N_MEMORY);
    if (N_MEMORY != N_NORMAL_MEMORY)
        node_clear_state(0, N_NORMAL_MEMORY);

    zone_sizes_init();
}

Is 64-bit kernel doesn't have master kernel page table? If it's true is it just access kernel memory only by direct mapping?

3

Answers to questions 1 and 2: no, once paging has been enabled, the CPU instructions only use virtual addresses, which are translated to physical addresses using the MMU before reading or writing RAM. The __va and __pa macros don't access memory, they just convert addresses between the address spaces. On a 32-bit machine, __va just adds 0xc0000000 to the physical address given as argument, because the mapping has been set up so that physical address N is at virtual address N+0xc0000000.

Addresses you want to access with the CPU must have a mapping; you can't bypass the MMU. So a mapping that manages only 128 MB is not sufficient.

  • Thank you so much!! It really helped a lot!! I can understand how it works!! – JuHyung Son Dec 20 '17 at 20:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.