Operating System (2) - the physical memory (continuous non-continuous) administration

Operating System (2) - Physical Memory (continuous / non-continuous) administration

A computer architecture

  • The basic hardware configuration: the CPU , memory , peripherals (O / I).
  • Memory hierarchy: CPU (access register and Cache, faster), memory (main memory / physical memory, large capacity, slower).
  • OS target completion:
    • Abstract : Access contiguous address space, i.e., logical address space
    • Protection : separate address space
    • Share : same access memory
    • Virtualization : more address space, temporarily do not have the data into the hard disk (virtual memory)
  • In the OS manages memory of different methods
    • Relocates
    • Section
    • Paging
    • Virtual Memory
    • Demand paging virtual memory
  • Achieve highly dependent on hardware
    • You must know the memory architecture
    • MMU (memory management unit): a hardware component responsible for handling CPU memory access request

II. Address Space / address generating

1. The address space defined
  • Physical address space: hardware support for address space. It includes a start address and length.
  • Logical address space: a program running owned memory range.
2. Address Generation
  • The logical address generation: the compiler, assembler, linker, loaded.
  • Physical address generation: a logical address mapping from the control by the OS.
3. Address security check
  • Establish a table (map), access address specified area.

III. Contiguous memory allocation

1. memory fragmentation issues: free memory can not be used
  • External fragmentation: in between the distribution unit unused memory.
  • Internal fragmentation: the allocation unit unused memory.
2. A simple memory management - dynamically allocated partitions
  • When a program is allowed to run in memory, assign a continuous range.
  • Program allocates a contiguous memory range to run to access the data.
3. Allocation Strategy
  • First adaptation : use address ordering the first free memory block allocation request satisfied.

    Advantages: simple, easy to produce large free block;

    Disadvantages: prone to external fragmentation; uncertainty.

  • Optimal adaptation : use the most suitable to satisfy the allocation request free blocks.

    Advantage: When most of the distribution is very effective when small size; relatively simple.

    Disadvantages: generating external fragmentation; slow redistribution; easy to produce a plurality of tiny fragments useless.

  • Worst adaptation : use the largest available free block.

    Advantages: a medium size distribution, the best

    Disadvantages: slow redistribution; a plurality of external fragmentation; easy mass destruction free block large partition that can not be assigned.

4. compression Defragmentation
  • Reset procedure to incorporate holes;
  • It requires that all programs are dynamically reset to.
5. switched defragmentation
  • Need more memory to run the program, the next program is waiting to seize recovered their memory;
  • To seize the program memory to the hard disk (virtual memory) inside.

IV. Non-contiguous memory allocation

Contiguous memory allocation drawbacks:
  • Physical memory assigned to a program is continuous;
  • Memory utilization is low;
  • In the presence of debris, a problem outside debris.
Advantage of non-continuous memory allocation:
  • A physical address space of the program is non-continuous;
  • Better memory utilization and management;
  • Allows sharing of code and data, database and the like;
  • Supports dynamic loading and dynamic linking.
Non-contiguous memory allocation drawbacks:
  • How to create a conversion between virtual and physical addresses: Software programs / hardware solution
  • Two hardware solutions: segmentation / tab
1. segment - better separation and shared
  • Segmented address space : the address space contiguous logical dispersed to a plurality of physical address space.
  • Segmented addressing scheme
    • Segment access mechanisms: accessing the program memory address tuple requires a two-dimensional ( segment number and offset within the segment ).
    • The logical address is divided into two, were placed within the segment offset and segment number, called a segment table .
2. Paging
  • Paging address space :

    • Partitioning the physical memory to a fixed frame size , the size is a power of 2, such as 512,4096,8192.

      Page frames (frame number / offset frame, the physical address can be calculated)

    • Dividing the logical address space into pages of equal size , the size is a power of 2, such as 512,4096,8192.

      Size of the offset within the page frame Offset Size =

      A frame number corresponding to the size of the page number size

    • Establishing program converts the logical address to a physical address (pages to frames)

      • Page table
      • MMU/TLB
  • Page addressing scheme

    • Page table contains mappings between logical and physical addresses
    • Page mapped to the frame
    • Pages are contiguous virtual memory (logic)
    • Non-contiguous physical memory frames
    • Not all pages have a corresponding frame
  • Page table

    • Each program has run a page table, part of the program running, the dynamic will change.
    • Examples of address translation: 32kb physical memory, each page 1024bytes.
  • Performance issues (time / space)

    • Accessing a memory cell requires two memory accesses, respectively, to obtain the page table entry and access data
    • Page table can be quite large - multi-level page table, inverted page table
  • TLB(Translation Look-aside Buffer)

    • Cached page frame translation table entry recently visited
    • Using the associated memory implementation, with fast access performance
    • If a TLB hit, physical page number may be acquired quickly; if not hit, the corresponding entry is updated to the TLB.
  • Problem of multi-level page table: a large address space problem, before becoming cumbersome to map the page table

    Not to make the page table corresponding to the logical address space size, but to the size of the corresponding page table with the physical address. Resulting in growth rate is faster than the logical address space of the physical address space.

    • Solution: Reverse the page table. Conversely, to do with the physical address space (frame) index, find the logical address space (page), accounting for a small space.

      • Use Page Register : for each frame and an associated register, which includes whether the frame is occupied, the corresponding page number and a protection bit.
    • Advantages: small size conversion table, regardless of size as the logical address space to physical memory translation table is relative.

      Disadvantages: the information needs of the swap, namely to find the page number based on the frame number . When implementing the design cost, high hardware cost, small capacity.

    • Register becomes the page based on the hash (hash) to find solutions to save space, but more than a calculated hash function hardware.

Published 76 original articles · won praise 30 · views 5835

Guess you like

Origin blog.csdn.net/weixin_45926367/article/details/104776547