操作系統 ShanghaiTech CS130 | Main memory

 

ShanghaiTech CS130 | Lecture Note 02 | Main memory

Topic: 

Keyword: 

說明:筆記旨在整理我校CS130課程的基本概念。由於授課及考試語言爲英文,故用英文爲主,中文爲輔的方式整理。由於是整理,盡提供最低限度的解釋,以便提供簡潔快速的查閱。

1 Names and Binding

1.1 Definition of names

Symbolic->Logical->Physical names

Def: Symbolic names: known in a context or path

  • file names, program names, printer/device names, usernames

Def: Logical names: used to label a specific entity

  • inodes, job number, major/minor device number, pid, uid, gid, ...

Def: Physical names: address of entity

  • inode address on disk or memory, entry point or variable address, PC address

1.2 Timing of binding to memory(恐龍書9.1.2 Address binding)

1.Intuition: bind symbolic address(variable name) to some address. CA(computer architecture) has taught us that a complier binds the symbolic address to relocatable address. The linker or loader in turn binds the relocatable addresses to absolute address. Each binding is a mapping from one address space to another.

2. Binding occurs at 3 different stages:

  • Compile time
    • Generate absolute code
    • Must recompile code if starting location changes
  • Load time
    • Must generate relocateable code
  • Execution time
    • Binding delayed until runtime(process can be moved during its execution)
    • Need HW support for address maps

3. Binding time tradeoffs

  • Early binding(At compile time)
    • Compiler: produces efficient code
    • Allows checking to be done early
    • Allows estimates of running time and space
  • Delayed binding(at load time)
    • linker, loader
    • produces efficient code, allows separate compliation(for library)
    • portability and sharing of object codes
  • Late binding
    • VM, dynamic linking/loading, overlaying, interpreting
    • code less efficient, checks done at runtime
    • flexible, allows dynamic reconfiguration
bind時間圖示

1.3 Dynamic Loading(恐龍書9.1.4)

Def: Routine is not loaded until it is called. All routines are kept on disk in a relocatable load format.

Pros: Better memoery-space utilization. Unused routine is never loaded. Useful when large code, infrequently

Cons: No special support from OS. Implemented through program design(by providing library routines).

1.4 Dynamic Linking(恐龍書9.1.5)

Def: Linking postponed until execution time, can be shared among processes (like C std library).

Introduction to stub: to locate the memory-resident library routine. stub replaces itself with the address of the routine, and executes the routine. OS needed to check if routine in memory.

1.5 Overlay

WIKI

the process of transferring a block of program code or other data into main memory, replacing what is already stored

Keep in memory only needed. The policy is implemented by user and complex, due to the issue that process is too large. 

2 Logical vs. Physical address(恐龍書9.1.3)

2.1 priminal defintion of logical address and physical address

Def: Logical address generated by CPU.

Def: Physical address seen by memory unit.

Same when compiling and load-time binding.

Differs in execution-time address-binding(due to efficient implementation of memory loading policy). Therefore, it is "fake" w.r.t. real address in memory unit. we call it virtual address.

2.2 Memory Mangement Unit (MMU)

 Def: A HW that maps virtual to phsyical address.

Property: be transparent to user program(never get touched with real physical address)

3 Swapping(恐龍書9.5)

3.1 常見術語

Def: Swapping: process swap out/ brought back for continued execution

  • backing store: must provide DMA
  • roll out/in: lower priority out, higher ones in
  • transfer time: major part of swap time
  • ready queue: ready-to-run processes

3.2 Implementation convention

Modified versions of swapping on many systems(i.e. Unix, Linux, and Windows)

  • Normally disabled
  • Started if more memory allocated (threshold)
  • disabled once memory demand reduce.

Remark: swapping 就是用來應對內存不足的情況,把優先級低的弟弟進程放到二級存儲當中。

3.3 Context switch time including swapping

If next process is not in memory,swap out a process. context switch time can be very high.

can reduce the context switch time by knowning how much memory being used.

4 Contiguous Allocation(恐龍書9.2)

4.1 Single-partition allocation vs. Multiple-partitoin allocation

1. Single partition allocation

  • relcation register contains smallest physical address
  • limit register contains range logical address

2. Multiple partitoin allocation:

  • main memory is divided into a number of fixed-sized partitions
  • each partition should contain only one process

3. def MFT: Multiprogramming with a Fixed number of Tasks.

4. def MVT: Multiprogramming with a Variable number of Tasks

5. def Holes: block of available memory

4.2 Dynamic storage allocation(恐龍書9.2.2)

  1. First-fit: Allocate the first hole that is big enough
  2. Best-fit: Allocate the smallest hole which is big enough
  3. Worst-fit: Allocate the largest hole

First-fit and best-fit are better than worst-fit in practice

4.3 Fragmentation(恐龍書9.2.3)

1. External fragmentation: total memory space exists to satisfy a request/ not contiguous.

2. Internal fragmentation: allocate memory slightly larger than requested/ memory internal to a partition, not being used

3. compact:(恐龍書p360) shuffle memory contents, place free memory toghether in one large block

5 Paging(恐龍書9.3)

 

 

Reference

1. Operating System Concepts 10th Edition. WILEY

2. ShanghaiTech CS130 Operating system, Topic 9, Main memory. Shu-Yin.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章