Csapp Reading Notes (2)-Storage Management

Source: Internet
Author: User

Process execution requires process space. If the memory space is used directly, it is difficult for a multi-task operating system to maintain the memory space allocated by the process, it is not convenient for application writers. Introducing the concept of virtual memory is equivalent to adding a layer between the two to mask the complexity of the application at the upper layer. Virtual Memory, as its name implies, its corresponding address is virtual. It has a ing relationship with the physical memory address. The address space of the physical memory corresponds to the actual memory size. The address space of the virtual memory is generally 2 ^ 32 = 4 GB in a 32-bit system. With the virtual memory mechanism, the system can easily support memory management, cache, and memory protection mechanisms. First, let's take a look at how the virtual memory address is converted to the final physical address. The virtual memory is organized by page. The page size is generally 4 kb. Therefore, for 32-bit virtual memory addresses, the lower 12 bits are used for intra-page addressing, and the higher 20 bits are used for page table addressing. Low 12-bit (we call it VPO, or virtual page offset) Addressing in pages is no problem, and there is no need to switch, directly corresponding to the page addressing in the physical memory. However, the 20-bit high (VPN, full name: Virtual page number) is used as the page table addressing. 20-bit can indicate that the page table space is 2 ^ 20, and each page table address item needs 4 bytes. Therefore, if you load all the page tables to the memory, 4*2 ^ 20 = 4 MB. Considering that many address spaces are not always used, it is a waste to put all the page tables in the memory. Therefore, using a multi-level page table can solve this problem. A multi-level page table divides 20-bit page table addressing into 10-bit page Directory addressing and 10-bit page table addressing. The so-called page Directory is actually the page table of the page table, with an additional level of index. Shows the latest structure., The page Directory table (corresponding to the level 1 page table in the figure) can be stored in only 4 kb space. Most of the page Directory items are empty. Each page Directory corresponds to a 2-level page table, which contains 2 ^ 10 page table addresses. A page table address corresponds to a page, that is, a 4 kb virtual storage space. The rightmost part of the figure is the total virtual memory space ., The page table corresponding to the stack space of the process and the space where the Process Code and global data are located is generally resident memory. The rest can only be transferred as needed. The above is to solve the problem that the capacity of single-level page tables is too large. Using Multi-level page tables, the on-demand calling method greatly reduces the capacity of the page tables. In practical applications, this is not enough. Because the query efficiency is not high enough. In the computer system structure, Cache Usage is everywhere. The cache technology is also used to improve query efficiency. The cache here has a special term called TLB, which is the full name of translation lookaside buffer. TLB stores some VPN-to-PPN mappings, that is, the ing between virtual pages and physical pages. TLB divides the 20-bit VPN into two parts: tag and index, which are the same as the technology used by common cache in the CPU. In this way, if you find it in TLB, you can directly construct the physical address to complete the conversion. After the conversion is complete, obtain the actual physical address and access the actual content through multi-level cache. As mentioned above, the virtual memory can provide memory protection measures. How can we provide it? Note that the actual content of the two-level page table in the figure only needs 20 bits. The remaining 12 bits can be used as the flag settings. Including read/write permissions and user privileges. It is worth noting that the page-level protection does not execute permission settings, so that the program can run code on any address space, so that the buffer overflow attack can be successful. Let's take a look at the dynamic memory allocation. Dynamic memory allocation is used to allocate memory in the heap space, providing good support for program dynamics. The memory space in the heap is organized by block, and the block size must be 8 bytes aligned or 4 bytes aligned. This part mainly describes a variety of block allocation algorithms and block recovery algorithms, involving block splitting and merging and memory fragmentation. I will not go into details here. Check the details if necessary.

 

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.