Find the answer to your Linux question:
Results 1 to 7 of 7
Like Tree1Likes
  • 1 Post By hazel
I am trying to understand basic kernel memory management from this page: www tldp.org/LDP/tlk/mm/memory.html. It says: Once an executable image has been memory mapped into a processes virtual memory it ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jul 2009
    Posts
    9

    memory management basic theory


    I am trying to understand basic kernel memory management from this page: www tldp.org/LDP/tlk/mm/memory.html. It says:
    Once an executable image has been memory mapped into a processes virtual memory it can start to execute. As only the very start of the image is physically pulled into memory it will soon access an area of virtual memory that is not yet in physical memory. When a process accesses a virtual address that does not have a valid page table entry, the processor will report a page fault to Linux.

    The page fault describes the virtual address where the page fault occurred and the type of memory access that caused.

    Linux must find the vm_area_struct that represents the area of memory that the page fault occurred in.
    I don't understand why does Linux need to find the vm_area_struct that represents the area of memory that the page fault occured in. Linux is supposed to know already where is vm_area_struct which is trying to access in the first place, before the page fault occured.

    Thank you for suggestions.

  2. #2
    Linux Engineer hazel's Avatar
    Join Date
    May 2004
    Location
    Harrow, UK
    Posts
    1,190
    At this stage Linux knows the vm_area_struct it has loaded the first page from (it's the one for the main executable). It does not know anything about the page that has not been found in memory. This could be a later page in the executable but it could also be a page from a library, or a data page. Once the processor has reported the page number, the kernel can quickly find out which vm_area_struct contains it and therefore how the page should be loaded..
    "I'm just a little old lady; don't try to dazzle me with jargon!"

  3. #3
    Just Joined!
    Join Date
    Jul 2009
    Posts
    9
    Quote Originally Posted by hazel View Post
    At this stage Linux knows the vm_area_struct it has loaded the first page from (it's the one for the main executable). It does not know anything about the page that has not been found in memory. This could be a later page in the executable but it could also be a page from a library, or a data page. Once the processor has reported the page number, the kernel can quickly find out which vm_area_struct contains it and therefore how the page should be loaded..
    it will soon access an area of virtual memory that is not yet in physical memory.
    The process tries to access an area of virtual memory which is not yet in physical memory. It searches the virtual memory area which directs it to Page Tables and Page Tables sends back a page fault. (or maybe it does not go to Page Tables at all, it knows already that it has no Page Table entry.) However, the process knows very well the virtual memory area he tried to access. Of course the process searches for the virtual area it needs, but the page fault is raised after the virtual area is found and accessed, so the process has no reason to search the virtual area again.
    Last edited by doru; 09-15-2012 at 04:04 PM. Reason: reformulation

  4. #4
    Just Joined!
    Join Date
    Jul 2009
    Posts
    9
    Quote Originally Posted by hazel View Post
    At this stage Linux knows the vm_area_struct it has loaded the first page from (it's the one for the main executable). It does not know anything about the page that has not been found in memory. This could be a later page in the executable but it could also be a page from a library, or a data page. Once the processor has reported the page number, the kernel can quickly find out which vm_area_struct contains it and therefore how the page should be loaded..
    I apologize, I did not read your answer carefully. Of course, you say that I am right and that linux has no business searching "through the vm_area_struct data structures" again. Thank you.
    Last edited by doru; 09-18-2012 at 12:28 PM.

  5. #5
    Just Joined!
    Join Date
    Jul 2009
    Posts
    9
    Quote Originally Posted by hazel View Post
    At this stage Linux knows the vm_area_struct it has loaded the first page from (it's the one for the main executable). It does not know anything about the page that has not been found in memory. This could be a later page in the executable but it could also be a page from a library, or a data page. Once the processor has reported the page number, the kernel can quickly find out which vm_area_struct contains it and therefore how the page should be loaded..
    I believe that I finally read carefully what you say. However, I don't understand how can the processor know the page number requested by a process which does not know the vm_area_struct that it needs to access. The process tries to access a vm_area_struct which targets a page which is not loaded in RAM.

  6. #6
    Linux Engineer hazel's Avatar
    Join Date
    May 2004
    Location
    Harrow, UK
    Posts
    1,190
    Each instruction in a program consists of a binary instruction code and an address. Dividing this address by the page size gives a virtual memory page number and an offset. The next step is to look in the page translation tables to see if this virtual page has a corresponding physical page in core. If so, the processor goes to that page and finds the correct address using the offset. If not, a page fault is raised.

    That tells the kernel that a specific virtual page number has not been found in physical memory. The kernel has already mapped out virtual memory in a series of vm_area_structs of different sizes. The first two fields in each structure are the first and last page number. So it is easy to find out which vm_area_struct is involved.
    doru likes this.
    "I'm just a little old lady; don't try to dazzle me with jargon!"

  7. #7
    Just Joined!
    Join Date
    Jul 2009
    Posts
    9
    Quote Originally Posted by hazel View Post
    Each instruction in a program consists of a binary instruction code and an address. Dividing this address by the page size gives a virtual memory page number and an offset. The next step is to look in the page translation tables to see if this virtual page has a corresponding physical page in core. If so, the processor goes to that page and finds the correct address using the offset. If not, a page fault is raised.

    That tells the kernel that a specific virtual page number has not been found in physical memory. The kernel has already mapped out virtual memory in a series of vm_area_structs of different sizes. The first two fields in each structure are the first and last page number. So it is easy to find out which vm_area_struct is involved.
    Thank you for your answer. Now it finally makes sense to me. The process runs on the cpu and it addresses its pages directly in RAM, using its Page Translation Table. When such a page is not in RAM, then vm_area_structs is used as a database where information about the location of that page on any device is found.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •