Operating System Lesson 4: Memory Management

memory management

The history of memory management

DOS era - only one process can be running at the same time (there are also some special algorithms to support multiple processes)

windows9x - Multiple processes loaded into memory 1: not enough memory 2: disturbing each other

In order to solve these two problems, the current memory management system was born: virtual address paging loading software and hardware combined addressing

Paging ( to solve the problem of insufficient memory )

The memory is divided into fixed-size page frames (4K), the program (on the hard disk) is divided into 4K-sized blocks, which block is used, and which block is loaded. During the loading process, if the memory is full, the least commonly used One piece is placed in the swap partition, and the latest piece is loaded in. This is the famous LRU algorithm.

  1. LRU algorithm LeetCode146 question, the headline requires hand tearing, and Ali also required hand tearing last year
  2. Least Recently Used
  3. Hash table (guaranteed lookup operation O(1)) + linked list (guaranteed sorting operation and new operation O(1)))
  4. Doubly linked list (guarantee that the left pointer points to the right block)

insert image description here

Virtual memory ( to solve the problem of mutual interference )

  1. DOS Win31 … kill each other
  2. In order to ensure no mutual influence - let the process work in the virtual space, the space address used in the program is no longer a direct physical address, but a virtual address, so that process A can never access the space of process B
  3. How big is the virtual space? Addressing space - 2^64 on 64-bit systems, much larger than physical space, in bytes
  4. From a virtual point of view, the process is exclusive to the entire system + CPU
  5. Memory map: offset + base address of segment = linear address (virtual space)
  6. Linear address via OS + MMU (Hardware Memory Management Unit)

insert image description here

Why use virtual memory?

  1. Isolated application
    • Every program thinks it has contiguously available memory
    • Break the physical memory limit
    • The application does not need to consider whether the physical memory is enough, whether it is enough to allocate and other underlying issues
  2. Safety
    • Protect physical memory from malicious access

Page fault breaks (not very important):

If there is no page memory needed, a page fault exception (interrupt) is generated, which is processed and loaded by the kernel

ZGC

The algorithm is called: Colored Pointer

GC information is recorded on the pointer, not in the header, immediate memory use

42-bit pointer addressing space 4T JDK13 expanded to 16T so far the largest 16T=2^44
insert image description here

How does the CPU differentiate between an immediate value and an instruction

The bus is divided into: data bus address bus control bus

Address bus present: 48 bits

Color pointers essentially contain the concept of address mapping

Guess you like

Origin blog.csdn.net/upset_poor/article/details/123215580