Memory and operating system memory management

Memory and operating system memory management



1. Basic knowledge of memory

  Memory is the hardware used to store data, and the data needs to be placed in the memory before the program can be processed by the CPU . The memory solves the data distinction of each program under concurrent execution by addressing the internal storage unit. According to the word length of the computer, the size of the storage unit is different (for example, each word size of a 64-bit computer is 64 bits, 8 bytes). Relative addressing of
  memory storage : The addressing of instructions compiled by the compiled language is achieved through relative addresses . When actually stored in the memory, the absolute address is obtained according to the initial value of the process in the memory . The addresses in the compiled machine language are actually logical addresses . After linking (to form a complete logical address), they are loaded into the memory to run through the load module. At this time, the logical address is converted into a physical address (mainly using dynamic relocation equipment). Entry method: There is a relocation register in the CPU to save the starting position of the program storage memory, and dynamic relocation can be realized by combining with the logical address).

Two, memory management

  The operating system is the manager of system resources and also needs to manage memory. The operating system is responsible for the following things:

  1. Provide a technology to logically expand the memory space
  2. Allocation and recovery of memory space
  3. Provide address conversion function, responsible for the conversion of the program from logical address to physical address (dynamic relocation, dependent on relocation register)
  4. Provide memory protection function to ensure that each process runs in its own storage space without interfering with each other.

2.1 Memory space expansion

  The operating system's expansion of memory space mainly includes overlay technology, exchange technology and virtual storage technology (detailed later):

  • Covering technology: used in early operating systems.
  • Exchange technology: Actually, it is the memory scheduling in process scheduling . The process is dynamically scheduled between the memory and the disk (PCB information is always retained in the memory before the process ends). The process is swapped out from the memory and stored in the swap area of the disk (the I/O speed of this area is faster than the file area, and the details are explained in the file section).

2.2 Allocation and Reclamation of Memory Space**

  Memory space allocation is divided into continuous allocation management mode and non-continuous allocation management mode:
(1)Continuous distribution management methodIt is divided into single continuous allocation, fixed partition allocation and dynamic partition allocation .

  • Single continuous allocation is only applicable to single-task operating systems.
  • Fixed partition allocation , divide the user space in the memory except the system area into partitions of fixed size or different sizes, and establish a data structure (array or linked list) of the partition description table to record the size, starting address, status, etc. of each partition Information, the disadvantage is that the user program is too large to cover technical support, and will generate internal fragmentation.
  • Dynamic partition allocation , when the process is loaded into the memory, the partition is dynamically created. The operating system uses the free partition table or free partition chain to record memory usage (partition number, partition size, starting address, etc.).
    Commonly used data structure for recording memory usage
    When a new process needs to be loaded into the memory, a dynamic partition allocation algorithm is needed to select a suitable partition.
    (2)Discontinuous distribution management methodThe user process can be allocated some scattered memory space, the main management methods are paged storage management , segmented storage management, and segmented paged storage management :
  • Paging storage management : Divide the memory space into small partitions of equal size. Each partition is called a page frame , and the number starts from 0. Accordingly, the address space of the user process is also divided into equal sized page frame in one area, each part is called the page , the same number from zero. (Note: The last page of the process may not be as large as a page frame, so the page frame cannot be too large, otherwise excessive internal fragmentation may occur)
      Then the page storage is discrete storage, how to realize the conversion from logical address to physical address?
      The dynamic relocation is thought to use the paging store calculated first address corresponding to the logical page number, the page number to give the starting address stored in the memory, calculating a logical address within the page of the "offset", whereby the physical Address = page address + offset within the page. To know where each page of a process is stored in memory, the operating system needs to create a page table for each process .
    Basic address change process of paging
  • Segmented storage management : According to the logic relationship of the program itself, it is divided into several segments , each segment has a segment name, and each segment starts from 0 for addressing. Each segment occupies a continuous space in the memory, but the segments may not be adjacent to each other. Similar to paging storage, the operating system creates a segment table for each process during segmented storage to store the segment length and base address corresponding to each segment discretely loaded into the memory (similar to paging, the segment table entry length is the same, and you can pass the segment The table calculates the segment number, so the segment number is implicit and does not occupy storage space,) and other information. Segmented storage manages the conversion from logical address to physical address as shown in the figure below: It
    Segment basic address change process
    can be seen that in segmented storage, since the length of each segment is different, there are more in-segment address out-of-bounds checks compared to paging storage.
  • Comparison of segmentation and paging
  1. The page is the physical unit of information that is invisible to the user, and the segment is the logical unit of information that is visible to the user.
  2. The size of the page is fixed and determined by the system , and the length of the segment is not fixed and determined by the program written by the user .
  3. The user process address of the page is one-dimensional (only one mnemonic is needed), and the user process address of the segment is two-dimensional (the segment name and the address within the segment need to be given).
  4. Segmentation makes it easier to share and protect information (only code that is not a critical resource can be shared). When you need to share a segment in memory with multiple processes, you only need to point the segment table of each process to the same segment. can.
  • Speed ​​up the paging process
  1. How to improve the mapping speed of logical address and physical address? ( Quick List )
      Once the system has visited a certain page, it will work stably on this page for a period of time. Therefore, in order to increase the speed of accessing the page table, the computer is equipped with a set of hardware registers that can accommodate part of the page table . When the system needs to convert the address again, first access this group of hardware registers (ie, fast table).
  2. How to solve the page table is too large?
      Page table there is a problem, the page table must continuously store the device in consecutive pages box, when discrete memory page table is too big to lose its essential meaning, it is possible to build an index ( two page tables ) to make the original page Table continuous page table entries are grouped discretely.

Portal—> Summary of all knowledge points of the operating system


Reference: "Wang Dao Postgraduate Entrance Exam Operating System"
Address: https://www.bilibili.com/video/BV1YE411D7nH

Guess you like

Origin blog.csdn.net/weixin_38836273/article/details/114224486