Linux operating system memory management source code implementation

Source: Internet
Author: User
Article title: Linux operating system memory management source code implementation. 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.

Recently I have been reading the Linux source code and want to write out what I can see. I think the memory part is the simplest and I will write it first. Please correct me!

The address with a minimum memory of 4 K is a page Directory (page_dir) with 1024 items in total, 4 bytes in each item. The directory item structure is as follows:


____________________________________
| 32-12 characters: page box address | U | R | p |
| S | W |
| _________________ | ______ | _ |


The next 16 K is used to create four page tables. the page table item structure is the same as the page directory item structure. Each item in the page table points to a physical page, that is, a 4 K space in the memory. With these four page tables, we can address 16 MB of memory. The following code sets a page directory and four page tables in the head. s program during system initialization. In this case, only the first four items in the page directory are valid, pointing to the four page tables under which the four page tables address the minimum memory size of 16 MB.


198 setup_paging:
199 movl 24*5, % ecx/* 5 pages-pg_dir + 4 page tables */
200 xorl % eax, % eax
201 xorl % edi, % edi/* pg_dir is at 0x000 */
202 cld; rep; stosl
203 movl $ pg0 + 7, _ pg_dir/* set present bit/user r/w */
204 movl $ pg1 + 7, _ pg_dir + 4 /*---------""---------*/
205 movl $ pg2 + 7, _ pg_dir + 8 /*---------""---------*/
206 movl $ pg3 + 7, _ pg_dir + 12 /*---------""---------*/
207 movl $ pg3 + 4092, % edi
208 movl xfff007, % eax/* 16 Mb-4096 + 7 (r/w user, p )*/
209 std
210 1: stosl/* fill pages backwards-more efficient :-)*/
211 subl x1000, % eax
212 jge 1b


In the future, each time a new fork process exists, the memory will be allocated to the new process. But how is it done? I also want to know. let's take a look. When fork is executed, int0x80 is used to call the sys_fork function. the sys_fork code is located in system_call.s, which is very short as follows:


208 _ sys_fork:
209 call _ find_empty_process
210 testl % eax, % eax
211 js 1f
212 push % gs
213 pushl % esi
214 pushl % edi
215 pushl % ebp
216 pushl % eax
217 call _ copy_process
218 addl, % esp
219 1: ret

[1] [2] [3] [4] [5] [6] [7] Next page

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.