メモリに関する 話題( 2 ) - 仮想メモリ memory (2) – virtual memory

22
福福 福 ; Chikara Fukunaga 1 福福福福福福福福福2 - 福福福福福 Memory (2) – Virtual Memory • Multi-Process System 福福福福福 (and Interrupt) • 福福福福福福福福福福福福福 Logical address (virtual memory) and physical address (real memory) • Segment and page • 福福福福福福福福福福 Mechanism of Dynamic Address Translation (DAT) • Translation Look-aside Buffer (TLB)

Upload: lee-gray

Post on 31-Dec-2015

38 views

Category:

Documents


3 download

DESCRIPTION

メモリに関する 話題( 2 ) - 仮想メモリ Memory (2) – Virtual Memory. Multi-Process System と割り込み (and Interrupt) 論理アドレスと物理アドレス Logical address (virtual memory) and physical address (real memory) Segment and page 動的アドレス変換方式 Mechanism of Dynamic Address Translation (DAT) Translation Look-aside Buffer (TLB). - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: メモリに関する 話題( 2 )  -  仮想メモリ Memory (2) – Virtual Memory

福永 力 ; Chikara Fukunaga 1

メモリに関する話題( 2 ) - 仮想メモリ

Memory (2) – Virtual Memory• Multi-Process System と割り込み (and Interrupt)• 論理アドレスと物理アドレス

Logical address (virtual memory) and physical address (real memory)

• Segment and page• 動的アドレス変換方式

Mechanism of Dynamic Address Translation (DAT)• Translation Look-aside Buffer (TLB)

Page 2: メモリに関する 話題( 2 )  -  仮想メモリ Memory (2) – Virtual Memory

バーチャルメモリの発展Ideas behind the virtual memory

• 実際のメモリサイズに制限されずに大きなプログラムを実行させたい.Requirement to run a large scale program without the limitation of actual memory size

• もしサイズが大きくて全部ロードできない場合一部はディスクなど 2 次補助記憶装置に待避させるUse the 2ndary (auxiliary) memory device (disk) for temporally storage if the program size is larger than a limit.

• もし multi-programming 環境になればメモリの管理が複雑になる.使えるメモリも制限される.またプロセスが実行されるたびに異なるメモリ空間にプログラムは Load される.Memory management will be complicated under the multi-programming environment. The size of the memory for a process will be also limited. The program will be loaded each time on a different memory space.

• プロセス(プログラム)を一貫したメモリ空間で管理(論理スペース)Management of a process in a coherent space (logical space)

• 論理スペースを細かく分離させて管理しメモリの効率の良い利用を図るLogical space for the program will be segmented in order to use the real memory as effective as possible

福永 力 ; Chikara Fukunaga 2

Page 3: メモリに関する 話題( 2 )  -  仮想メモリ Memory (2) – Virtual Memory

福永 力 ; Chikara Fukunaga 3

Multi-program 環境( Environment )と割り込み( and Interrupt )

• CPU 処理速度と I/O 処理の大きな違いを利用した複数(あたかも)同時処理システムをマルチプログラミング環境The environment for program(s) to be able to be loaded and run during the I/O processing of the currently running program is called “the multi-programming environment” .

Page 4: メモリに関する 話題( 2 )  -  仮想メモリ Memory (2) – Virtual Memory

福永 力 ; Chikara Fukunaga 4

Multi-programming 環境( Environment )

• Definitions of several terms• Process =

プログラム + データ

• Task =プロセスの一部、 OS が自分でしきりやすいように切り取る.

• Thread = プロセスの一部、同時に多数の Thread が並列的に実行可能、プログラマによって準備される

Page 5: メモリに関する 話題( 2 )  -  仮想メモリ Memory (2) – Virtual Memory

福永 力 ; Chikara Fukunaga 5

割り込みフロー( Interrupt flow )• 割り込みが起きた場合のプロセスの流れ

Flow diagram for interruption• Interrupt の元の解析で Interrupt Vector のアドレスが解明されそこに記録された

割り込みアドレスに制御が飛ぶAn address of interrupt vector will be identified from the origin of interrupt. The address registered there will be executed.

Page 6: メモリに関する 話題( 2 )  -  仮想メモリ Memory (2) – Virtual Memory

割り込みの種類(例)Origins of Interruption (examples)

• I/O interrupt : I/O 動作の(正常、異常)終了Normal/abnormal completion of I/O actions

• Program interrupt :計算例外事象の発生Exceptional events like overflow/underflow

• Abnormal instructions 、 addressing error• プログラム割り込み /program interrupt

• 割り込み命令( trap ) /Interrupt by trap Instruction• Segmentation/page faults• Access control error• Event handling

• SVC ( SuperVisor Call ):優先度の高いシステムコールの利用I/O System call with special high priorities

• External interrupt ( timer for time sharing, h/w ) 福永 力 ; Chikara Fukunaga 6

Page 7: メモリに関する 話題( 2 )  -  仮想メモリ Memory (2) – Virtual Memory

福永 力 ; Chikara Fukunaga 7

• プログラムがコンパイルされ実行形式のプログラムが作られるとプログラムパート、データパート、実行時の作業領域などがいくつかのセグメントに分類される.At the completion of compiling, an executable program module is divided into several segments with program, data and/or working parts.

• 一般にセグメントはさらに一定長をもつページにさらに分割される.セグメントの長さに決まりはない.A Segment is further divided into several pages with constant size. The size of a segment is not constant but normally variable.

プロセスセグメンテーションSegmentation of a process

Page 8: メモリに関する 話題( 2 )  -  仮想メモリ Memory (2) – Virtual Memory

プロセスの実空間へのマッピングMapping of processes onto the physical space• ひとつひとつのプロセスは実空

間にロードされて実行がなされるが自分が利用できる空間は限られていて実行形式イメージすべてが実空間に載せられるわけではない.Each process will be executed on the physical space after it is loaded on MS. But the whole image is not loaded since the space is limited.

• プロセスはセグメント単位で論理空間(プロセスごとにほぼ無限に設定できる)にアドレスされる.Once a process is assigned in an infinite logical space with unit of segment base.

福永 力 ; Chikara Fukunaga 8

Page 9: メモリに関する 話題( 2 )  -  仮想メモリ Memory (2) – Virtual Memory

福永 力 ; Chikara Fukunaga 9

論理アドレスへのプロセスセグメント配置Segmentation deployment on the logical space

• すべてのセグメントは論理空間に連続的に分配されるのではなくのちの物理空間のアドレスと対応しやすいようにとびとびのアドレスをもって論理空間に配置される.All the segments will not be normally allocated contiguously, but addressing for a segment is determined conveniently for real adress mapping.

• したがって論理空間にはどのセグメントにも利用されない空間ができうる可能性があるThere will be spaces not used for any segments in the logical addressing space.

Page 10: メモリに関する 話題( 2 )  -  仮想メモリ Memory (2) – Virtual Memory

福永 力 ; Chikara Fukunaga 10

論理空間と物理空間をマップするDynamic Address Translation (DAT)

Mapping between Logical and Physical spaces• OS はプロセスに記載されているプロセス

のセグメント、ページデータを読み取りセグメントごと、またその中のページごとに表を MS に用意する.セグメントテーブル、ページテーブルなどと呼ぶ.OS makes two tables called segment and page tables in MS. A segment table for a segment, a page table for each page in the segment.

• セグメントテーブルの MS でのアドレスSTO はレジスタ( CR1 )に入れる.OS puts the starting address of the segment table (STO) in a register (called, say CR1 in this case).

• SX ( Segment index )、 PX ( Page index )および BX ( Byte index )にもとづき表を作成する.An entry in the table is created with its virtual address (SX,PX).

• 最後に PFA+BX で実際のアドレスが決定される. PFA は OS が供給PFA+BX is used for address in physical space.PFA is supplied by the OS

Page 11: メモリに関する 話題( 2 )  -  仮想メモリ Memory (2) – Virtual Memory

DAT several words• この DAT 解説図に出てくることばの意味

Explanation of words used in this figure

福永 力 ; Chikara Fukunaga 11

Page 12: メモリに関する 話題( 2 )  -  仮想メモリ Memory (2) – Virtual Memory

福永 力 ; Chikara Fukunaga 12

Translation Look-aside Buffer ( TLB )

• MS にロードされているセグメントやページのデータをDAT を使わずに素早くアクセスするため Translation Look-aside Buffer が利用される.原理は Cache と同じである.For quick reference of Data in a segment or page already loaded in MS, Translation Look-aside Buffer is prepared. The principle is more-or-less similar to Cache.

Page 13: メモリに関する 話題( 2 )  -  仮想メモリ Memory (2) – Virtual Memory

• Replacement 方式Cache memory replacement method

• Restore 動作 - 更新アルゴリズムRestoring of Cache data – rewrite algorithm

• Compulsory (初動遅延 ; Initial delay; cache initial state )

• Conflict :ブロック集中アクセスによるミス(ダイレクトマップ,セットアソシエーティブ)Conflict: Miss with concentrated access of particular blocks (Direct, Set-associative Mapping)

• 実行プログラムの特性(データアクセスの効率)Data access characteristics of programs run on the machine 福永 力 ; Chikara Fukunaga 13

Cache 構成のキーポイント( 2 )Optimization of Cache (2)

Page 14: メモリに関する 話題( 2 )  -  仮想メモリ Memory (2) – Virtual Memory

福永 力 ; Chikara Fukunaga 14

Cache パラメータ変更による Miss rate 実測値例Measurement of Miss rate with Cache parameters

From Hennessy & Patterson, CA A Quantum Approach 4th ed.

• Cache capacity → increase, capacity miss , conflict miss → decrease (Fig. C9)

• Number of ways → increase, conflict miss rate → decrease (Fig. C9)

• Block size → decrease, inefficient (Fig. C10)• Block size → increase, miss rate → increase

(Fig. C10)• 1 ways miss rate ~ cache size 50% of 2 ways

(Fig. C9) • Cache size double → miss rate sqrt(2) (Fig. C9)

8,4,2, 1

Cac

he s

ize

Page 15: メモリに関する 話題( 2 )  -  仮想メモリ Memory (2) – Virtual Memory

福永 力 ; Chikara Fukunaga 15

リプレースメント(旧データの追出し)方式

Replacement (Kick out) of old unused contents• ミスヒットによる cache 更新時のデータ追出しアルゴリズム

Algorithm for the kick-out of old data with miss-hit • Invalid bit タグのブロックの追放

Invalid tag bit to indicate the useless block• LRU ( Least Recently Used )ブロックの認定・追放

Recognition of Least Recently Used Block, and kick it out • 履歴用(タイムスタンプ)の tag bit を必要とする

need a time stamp information for each block• FIFO ( First-In First-Out )

• 最古参ブロックから追い出しThe block entered first must be purged out first

• LRU より制御機構が簡単 (Simpler control logic than LRU, just sequence)• ブロックのランダム抽出( Random Selection )

• 時間にかかわらずどのブロックのアクセス頻度は同じであろうという考え方The frequency of access to any blocks will be more-or-less constant regardless of the time

• Cache Access Counter for each block• cache アクセスごと,あるいはクロックごとにカウンターを増やす.カウンター値と同じラインのブロックを追放,そしてカウンターリセットCount up with clock or access, and if it exceeds some limit, it will be candidate to be purged

Page 16: メモリに関する 話題( 2 )  -  仮想メモリ Memory (2) – Virtual Memory

福永 力 ; Chikara Fukunaga 16

データ Cache 書き込み制御Restoring Control

• キャッシュ一貫性制御ともいうIt is also called “Cache Coherence Control”.

• Data cache のみが対象The operation is applied to the Data cache.

• データ更新にともなうメインストレージへの再書き込み

• ストアスルーあるいはライトスルー( Store-Through or Write-Through )

• ストアイン,ライトバックあるいはコピーバック( Store-In,Write-Back or Copy-Back )

Page 17: メモリに関する 話題( 2 )  -  仮想メモリ Memory (2) – Virtual Memory

福永 力 ; Chikara Fukunaga 17

ストア(ライト)スルーStore ( Write ) -Through

• 書き込みデータのブロックが cache でヒット( Write Cache hit )した場合, cache データと MS ともに更新( Write )If the block to be modified by write is found in Cache (Write Cache hit), Both contents in cache and MS are modified.

• Write Cache miss した場合, MS の対応ブロックのデータ更新するとともにIf Write Cache miss, the corresponding block in the MS is updated but also

• cache に当該ブロックを読込み MS と cache をともに更新( Write Allocate ),あるいはThe block is also refilled into the cache, and it is updated, or

• cache は何もせず MS のみ変更No touch with the cache (only the MS will be affected).

• ライトバッファ( Write Buffer )• メインストレージへのアクセス中 CPU 処理がストールされてしま

う.この期間を最小限にするために中間バッファ(ライトバッファ)を持つ必要がある.We need a special buffer called “Write Buffer” in order to keep minimize the access time of the MS to avoid stalls in the CPU pipeline.

Page 18: メモリに関する 話題( 2 )  -  仮想メモリ Memory (2) – Virtual Memory

福永 力 ; Chikara Fukunaga 18

ストアインあるいはライト(コピー)バック

( Store In or Write ( Copy ) -Back )• Write Cache hit した場合, cache のみ変更( Dirty )

If write Cache hit, only Cache is modified (Dirty)• Write Cache miss した場合,必ず MS から cache へ当該ブロック

を読込み, cache のみを変更し cache と MS とで当該ブロックのある値が異なるという旨をマークしておく.( clean bit を OFF → dirty )If Write Cache miss, always the corresponding block is load into the Cache from the MS and is modified only in the cache. The block is marked up with “dirty” from “clean”.

• このブロックが cache から追出されるときにメインストレージを更新する(ライトバック).( clean bit を ON → clean )If this block is once kicked out, the MS is updated, and the block is backed to “clean”.

• Read では cache の hit/miss にかかわらず cleanThe block is kept “clean” for Read case regardless of the hit/miss.

Page 19: メモリに関する 話題( 2 )  -  仮想メモリ Memory (2) – Virtual Memory

福永 力 ; Chikara Fukunaga 19

ストアイン(ライトバック)キャッシュの状態遷移

State Transition Diagram for Store In (Write back) Cache mechanism

Page 20: メモリに関する 話題( 2 )  -  仮想メモリ Memory (2) – Virtual Memory

福永 力 ; Chikara Fukunaga 20

cache の多重(マルチ)レベル化

Multi-Level Cache• L1 , L2• Victim ( n-way セットアソシエーティ

ブ法 cache の追い出されたデータ保持用)Victim buffer for temporal storage buffer for blocks kicked out in the n-way set associative mapping.

Page 21: メモリに関する 話題( 2 )  -  仮想メモリ Memory (2) – Virtual Memory

福永 力 ; Chikara Fukunaga 21

cache が有効でない場合( 1 )Some cases that the cache is not effective (1)

• 長い(要素の多い)ベクトル計算Calculation of Long one dimensional arrays

• データ量が cache サイズを越えるとパフォーマンスの低下が見えるIf the size exceeds the cache block size, the degradation of the performance

• サイズのみでなく cache の構成をも考慮したプログラミングの配慮が必要If the cache is structured in multi-level, the programming must be optimized with this structure.

MF

LO

PS

配列長 Array size

Pe

rfo

rman

ce (

rate

)配列長 Array size

C=C + A[i] * B[i]

QCD (Physics)

Page 22: メモリに関する 話題( 2 )  -  仮想メモリ Memory (2) – Virtual Memory

福永 力 ; Chikara Fukunaga 22

cache が有効でない場合( 2 )Some cases that the cache is not effective (2)

• 行列計算の繰り返し順序Loop order for Matrix multiplication of Zij=ΣXik・ Ykj

• C と Fortran では異なることも.Optimization of C and Fortran is different.