Kernel address space and Kernel page table












1














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?










share|improve this question





























    1














    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?










    share|improve this question



























      1












      1








      1







      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?










      share|improve this question















      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?







      linux kernel linux-kernel memory memory-management






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 16 at 22:01









      Rui F Ribeiro

      38.9k1479129




      38.9k1479129










      asked Dec 20 '17 at 19:01









      JuHyung Son

      778




      778






















          1 Answer
          1






          active

          oldest

          votes


















          2














          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.






          share|improve this answer





















          • 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








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "106"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f412100%2fkernel-address-space-and-kernel-page-table%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          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.






          share|improve this answer





















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
















          2














          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.






          share|improve this answer





















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














          2












          2








          2






          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.






          share|improve this answer












          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.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 20 '17 at 20:22









          Johan Myréen

          7,40011423




          7,40011423












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


















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
















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




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


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Unix & Linux Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f412100%2fkernel-address-space-and-kernel-page-table%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Morgemoulin

          Scott Moir

          Souastre