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.
- LRU algorithm LeetCode146 question, the headline requires hand tearing, and Ali also required hand tearing last year
- Least Recently Used
- Hash table (guaranteed lookup operation O(1)) + linked list (guaranteed sorting operation and new operation O(1)))
- Doubly linked list (guarantee that the left pointer points to the right block)
Virtual memory ( to solve the problem of mutual interference )
- DOS Win31 … kill each other
- 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
- How big is the virtual space? Addressing space - 2^64 on 64-bit systems, much larger than physical space, in bytes
- From a virtual point of view, the process is exclusive to the entire system + CPU
- Memory map: offset + base address of segment = linear address (virtual space)
- Linear address via OS + MMU (Hardware Memory Management Unit)
Why use virtual memory?
- 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
- 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
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