OS notebook computer memory management ----

A computer architecture / memory hierarchy

1, the basic hardware configuration of the computer

The basic structure of computer hardware

2, the memory hierarchy

Memory Hierarchy

3, the operating system memory management needs to be done target


Abstract : When the application is running in memory can not be considered low-level details (such as:? Physical memory somewhere peripherals in any place?), Just visit a continuous address space, the address space is called a logical address space .
Protection : You can run several different applications, may interfere with each other between different processes in memory, we need a mechanism to protect a process not to be undermined by other processes.
Share : also require interaction between processes (such as: data transfer between processes), the operating system can be guaranteed to be safe and reliable transfer of data between the various processes.
Virtualization : When multiple processes at the same time, the memory may not be enough, then we may not need to access some of the data temporarily placed on the hard disk, in order to ease the tension of memory.

Operating system tasks

In this example we can see is occupying memory in addition to the operating system kernel as well as P1, P2, P3, P4, but not enough main memory space, then the process P4 may be waiting to continue to implement certain data, this data may take some time to get, so in this case we can the data P4 temporarily placed on your hard disk to ensure that the P1, P2, P3 can be executed properly.


4, the basic method of memory management in an operating system

  • Relocates
  • Section
  • Paging
  • Virtual Memory
  • Demand paging virtual memory
Implement the above method is highly dependent on hardware:
  • You must know the memory architecture
  • MMU (memory management unit): a hardware component responsible for handling CPU memory access request

Second, the address space and an address generator


1, the address space defined

Here Insert Picture Description

Address space including physical address space and the logical address space:

Physical address space: the address space is supported by the hardware, including the storage space represented in memory represented by the main memory and a hard disk.
  • Start address 0 to address MAX SYS
Logical address space: a program running owned memory range.
  • Start address 0 to address MAX PROG
The mapping between the two address spaces need to complete the operating system.

2, the address generator

Here Insert Picture Description

For instance, we wrote a C program (.c file), which is a function of position, the variable name is a manifestation of the logical address. After this programCompileAfter getting assembler (.s file), this program is still to represent the logical address with the symbol. After again bycompilationTo give the object file (.o file), to see the program's start address is 0, and the symbol names and function names of symbolic variables will be converted into the corresponding addresses that are zero with respect to a contiguous address space . Multiple .o programlinkInto a single executable that is our .exe program that is currently stored in the hard disk and can be loaded into memory and executing the program, this program has been merged address each .o program addresses different .o program occupy different addresses in the program, but this address is not in the address memory. The final program through the operating system loader programLoadingLoaded into memory to run. Then the file is a more gradual transition from the symbolic address to the logical address of the particular process to run in memory.



When a program needs to perform some instruction, the logical address of the instruction is mapped to physical addresses how to go?

Here Insert Picture Description

CPU side

  1. Operator requires memory contents of logical address
  2. The memory management unit to find the mapping between logical addresses and physical addresses
  3. Transmission request from the bus controller in the physical address of the memory contents
Terms of memory
  1. Physical address of the memory content transmission bus to the CPU
Operating systems
  • Establishing a mapping between the logical addresses and physical addresses (this operation in the CPU MMU)

3, address security check


Here Insert Picture Description

The operating system needs to ensure effective logical address space each program can access, including the starting address and the length of it, these two parameters we can know that there is a logical address space of the program is reasonably accessible, once beyond the region this access is not a legitimate access.

When the requested logical address is located in this area can be found according to the mapping relationship between the content of the corresponding physical address space and the memory taken out; if the request for a logical address space is not within this range, the CPU will generate a memory access exception, then let the operating system for further processing.

Released four original articles · won praise 1 · views 145

Guess you like

Origin blog.csdn.net/qq_42520894/article/details/104536512