Operating System Notes-Chapter 3 Principles of Operating System Implementation and Management of Physical Memory

1. The target that the operating system needs to accomplish in memory

  • Abstraction: logical address space
  • Protection: independent address space
  • Sharing: access to the same memory
  • Virtualization: More address space

2. Different methods of managing memory in the operating system

  • Program relocation
  • Segmented
  • Pagination
  • Virtual Memory
  • Paging virtual memory on demand

3. The operating system is implemented when the memory is managed, which is highly dependent on the hardware

  • Must know the memory architecture
  • MMU (Memory Management Unit): The hardware component is responsible for processing the memory access request of the CPU, located in the CPU

4. Address space + address generation

Address space definition:

  • Physical address space: the address space supported by the hardware.
    When a process executes instructions and accesses data during runtime, it must be accessed from the main memory through a physical address. When the loader (Loader) loads the executable code into the memory, the logical address must be converted into a physical address through address conversion. This process is called address relocation.
  • Logical address space: The memory range owned by a running program is a one-dimensional linear address space.
    After the program is compiled, each target module is addressed from unit 0, which is called the relative address (or logical address) of the target module.
    Different processes can have the same logical address, because these same logical addresses can be mapped to different locations in the main memory.

Address generation:

  • Logical address generation: format compilation and conversion process of running program: initial file -> assembly -> link -> load (program relocation) [.c file ->.s file ->.o file ->.exe file- ->Program in memory】
  • Physical address generation
    • CPU: When a certain instruction needs to be executed, the memory content of the logical address is required, so a request with logical address parameters is initiated
    • CPU: MMU (Memory Management Unit) searches for the mapping between the logical address and the physical address, if not, a process is generated and the memory is searched
    • CPU: If found, the controller sends a request for the memory content at the physical address from the bus
    • Main memory: send the contents of the physical address memory to the CPU through the bus
  • The role of the operating system in this process is to establish a mapping between logical addresses and physical addresses before the entire process. The operating system also needs to complete address security detection

5. Continuous memory allocation

Memory fragmentation problem: free memory cannot be used

  • External fragmentation: unused memory between allocation units
  • Internal fragmentation: unused memory in allocation units

Dynamic allocation of partitions

  • Simple memory management method: when a program is allowed to run in memory, allocate a continuous interval
  • Allocation strategy
    • First adaptation: In order to allocate n bytes, use the first available free block so that the size of the block is larger than n.
    • Optimal adaptation: Find the space block with the smallest difference. Very effective when most of the allocation is small size
    • Worst adaptation: Find the space block with the largest difference. It works best if the distribution is medium size

Compressed defragmentation:

  • Action: Reset the program to merge holes
  • Prerequisite: All programs are required to be dynamically resettable
  • Disadvantages: difficult to control the reset time and expensive

Exchange defragmentation:

  • Situation: More memory is needed to run the program
  • Operation: preempt the waiting programs + reclaim their memory

Guess you like

Origin blog.csdn.net/MaoziYa/article/details/105285443