How to learn and work on Linux kernel-Virtual Storage

Source: Internet
Author: User
Article Title: learn and learn about Linux kernel-virtual storage. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

Virtual addresses are maintained by the operating system and can be converted by MMU. The page management of memory space is expanded, and the memory is divided into pages and pages. The size is the same. one is on disk and the other is in memory. A page table is like a function. the input is the page number and the output is the page number.

A page table can be a multi-level page table and can be cached using TLB (Translation Lookaside Buffer. The speed and cost are between memory and registers.

Page table items:Disable Cache, access bit, protection bit, modify bit, and exist bit -- page marker number

Page replacement:Optimal algorithm, first-in-first-out and least-Recently Used (Leaset Recently Used)

Linux virtual memory management

1. the default page size is 8 kB. each process maintains its own page table. Therefore, the virtual addresses of different processes may be the same.

2. Virtual Address: 0x2194 --> because the page size is 0x2000, this address is located at page 1. The offset address in the page is 0x194. if page 1 is mapped to page 4, its physical address is 0x8000 + 0x194 = 0x8194

3. paging ondemand

4. switch thrashing LRU

5. in Linux, it is assumed that the processor supports a three-level page table structure. PGD, PMD, and PTE are on Intel X86 computers. in linux, the table structure has only two levels of PGD and PTE (only one table entry for PMD)

6. every time a new thread is started, linux will allocate a task_struct struct containing memory management information such as ldt (local descriptor table), tss (task state segment), and mm. The mm_struct struct contains the storage-related information in the user process.

7. when the vma program is executed, the execution image is transferred to the virtual address space of the process. The shared library is also used. However, it is not actually in the physical memory.

In mm_struct, some data structures pointing to vm_area_struct describe the starting and ending locations of the virtual memory, the permissions of the process for this memory area, and a set of memory operations. Therefore, the management of virtual memory by the operating system is the management of this data structure. In addition, vma is not a group, so you need to manage, allocate, and cancel it through the red-black tree algorithm.

8. page allocation is carried out using the Buddy algorithm. The Memory Allocation Code searches the list maintained by the free_area array to find a free block that meets the requirements and is as small as possible. at the same time, the remaining parts are allocated.

9. asmlinkage do_page_fault (struct pt_regs * regs, unsigned long error_code); the compiler uses the stack instead of registers to pass parameters. When an MMS error is found, this function is called. When a page is missing, the CPU copies the address with a page missing exception to the cr2 control register and then processes the page missing exception.

If the system status EFLAGS is interrupted when an exception occurs, the terminal can be allowed to occur after cr2 is saved. the underlying process calls the sti command to enable the interruption.

Handle_fault_mm ()-> handle_pte_fault ()-> do_no_page ()-> do_swap_page ()

Trackback: http://tb.blog.csdn.net/TrackBack.aspx? PostId = 1475737

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.