Chapter 8: Memory Management 籃玉如

Similar documents
Memory Management Outline. Background Swapping Contiguous Memory Allocation Paging Segmentation Segmented Paging

The Deadlock Problem. Deadlocks. Deadlocks. Bridge Crossing Example

SHAU KEI WAN GOVERNMENT SECONDARY SCHOOL

Protel DXP 2004 Schematic 開 始 所 有 程 式 Altium DXP 2004

The HKICPA Accounting and Business Management Case Competition Secondary School Group (Level 1)

China M&A goes global

EW-7438RPn Mini 安 裝 指 南 / v1.0

LC Paper No. PWSC269/15-16(01)

Ex. Either we must get in line early to buy the tickets, or only scalpers INDEPENDENT CLAUSE 1 INDEPENDENT tickets will be available.

Wi-Drive User Guide. (for use with Amazon s Kindle Fire) Document No. 480WID4KF-001.A01 Kingston Wi-Drive Page 1 of 15

Data Structures Chapter 4 Linked Lists

歐 洲 難 民 潮 對 經 濟 的 影 響 The Economic Implications of Europe s Refugee Influx

Case Study of a New Generation Call Center

Market Access To Taiwan. By Jane Peng TÜV Rheinland Taiwan Ltd.

EFL Business Writing with Task-based Learning Approach: A Case Study of Student Strategies to Overcome Difficulties

Chemistry I -- Final Exam

Kingston MobileLite Wireless. (ßeta Release) Document No. 480WD+MLW.ß01 Kingston MobileLite Wireless (ßeta) Page 1 of 12

Memory management basics (1) Requirements (1) Objectives. Operating Systems Part of E1.9 - Principles of Computers and Software Engineering

Data Structures Chapter 3 Stacks and Queues

Machine Translation for Academic Purposes

Microsoft SQL Server PDW 新世代 MPP 資料倉儲解決方案

weekly Our mission Our history Our footprint Our award-winning content 2015 Media Kit asian northwest

(Chapter 218) APPLICATION FOR A LICENCE BY A BODY CORPORATE

促 進 市 場 競 爭 加 強 保 障 消 費 者

The Government of The Hong Kong Special Administrative Region Procedures for Importation and Registration of Motor Vehicles & Motor Cycles

Tender Document for Procurement of the Security Screening Equipment at MIA (RFQ-151)

轎 車 機 場 接 送 及 往 返 澳 門 與 香 港 機 場 接 送 服 務 禮 遇 ( 推 廣 ) 之 條 款 及 細 則 :

广 东 培 正 学 院 2016 年 本 科 插 班 生 专 业 课 考 试 大 纲 基 础 英 语 课 程 考 试 大 纲

余 雋 禧 仇 慧 琳 宣 教 士 夫 婦

Ringing Ten 寶 安 商 會 王 少 清 中 學 定 期 通 訊 / 通 告,2002 年 創 刊, 逢 每 月 及 30 日 派 發

ZACHYS tel / fax / auction@zachys.com zachys.com

OPERATING SYSTEM - MEMORY MANAGEMENT

亞 洲 地 區 積 極 搶 客 : 澳 門 日 本 韓 國 紛 紛 推 出 割 價 優 惠 及 免 稅 等 搶 客, 香 港 暫 未 有 相 關 措 施

Microsoft Big Data 解決方案與案例分享

How To Be The Legend In Hong Kong

Exploring the Relationship Between Critical Thinking and Active. Participation in Online Discussions and Essays

A Brief Study on Cancellation of Late-Marriage and Late-Childbirth Leaves

HiTi user manual. HiTi Digital, Inc.

Multilingual Version. English 中 文. Français 日 本 語. Deutsch. Italiano

Validity and reliability of the Chinese version of the Insulin Treatment Appraisal Scale among primary care patients in Hong Kong

10th PRO Awards Grace a Plaque of Recognition for Excellence

國 立 中 山 大 學 企 業 管 理 學 系 碩 士 論 文

代 號 (//) ISIN Code Price Price CHIPOW CHINA POWER INTL DEVELOP 4.5 5/9/2017 HK Electric Moderate CHELCP CN ELECTRONI

1.d 是 故 此 氣 也, 不 可 止 以 力, 而 可 安 以 德. 1 民 : should be read as 此 here. 2 乎 : is an exclamation, like an ah! 3 淖 : should be 綽 chùo, meaning spacious.

痴 呆 症. Dementia 如 何 照 顧 患 有 痴 呆 症 的 家 人. How To Care For A Family Member With Dementia

Lot 439. Lot 440. Lots

4.8 Thedo while Repetition Statement Thedo while repetition statement

D R 數 據 研 究. merely mimicking the sciences use of (big) data, the arts and humanities must explore what kind. asdf

OPERATING SYSTEMS MEMORY MANAGEMENT

Wi-Fi SD. Sky Share S10 User Manual

A SERVER-LESS ARCHITECTURE FOR BUILDING SCALABLE, RELIABLE, AND COST-EFFECTIVE VIDEO-ON-DEMAND SYSTEMS

电 信 与 互 联 网 法 律 热 点 问 题

Should lidocaine spray be used to ease nasogastric tube insertion? A double-blind, randomised controlled trial

中 国 石 化 上 海 石 油 化 工 研 究 院 欢 迎 国 内 外 高 层 次 人 才 加 入

Chapter 7 Memory Management

ifuzhen.com, ifortzone.com a product of Edgework Ventures Financial Management Software & Financial Wiki

Multilingual Version. English. 中 文 Français 日 本 語. Deutsch. Español. Italiano

JAPAN PATENT OFFICE AS DESIGNATED (OR ELECTED) OFFICE CONTENTS

美 国 律 师 协 会 知 识 产 权 法 部 和 国 际 法 律 部 关 于 中 华 人 民 共 和 国 专 利 法 修 改 草 案 ( 征 求 意 见 稿 ) 的 联 合 意 见 书

Bodhisattva Path is an inevitable way to

Procedures to file a request to the JPO for Patent Prosecution Highway Pilot Program between the JPO and the HPO

FRESH PRODUCE FORUM CHINA, 1 JUNE 2016, CHENGDU, CHINA 新 鲜 果 蔬 行 业 中 国 高 峰 论 坛,2016 年 6 月 1 日, 成 都 EXHIBITOR REGISTRATION FORM 参 展 商 申 请 表 格

中 国 ( 南 京 ) 软 件 谷 简 介

Terms and Conditions of Purchase- Bosch China [ 采 购 通 则 博 世 ( 中 国 )]

MARGINAL COST OF INDUSTRIAL PRODUCTION

Chapter 7 Memory Management

Bird still caged? China s courts under reform. Workshop, June 3-4, 2016, Vienna, Austria. (University of Vienna, Department of East Asian Studies)

Stress, Rhythm, Tone And Intonation. Ching Kang Liu National Taipei University

Romeo and Juliet 罗 密 欧 与 茱 丽 叶

INFORMATION NOTE. Causes of Poverty in Hong Kong: A Literature Review

Virtual vs Physical Addresses

The Sinica Sense Management System: Design and Implementation

Customers' Trust and Purchase Intention towards. Taobao's Alipay (China online marketplace)

Memory unit sees only the addresses, and not how they are generated (instruction counter, indexing, direct)

English. Copyright DEWALT

Graduate School of Engineering. Master s Program, 2016 (October entrance)

2013 年 6 月 英 语 六 级 真 题 及 答 案 ( 文 都 版 )

CAHPS for PQRS Survey Quality Assurance Guidelines Version 1 Technical Corrections and Clarifications Issued November 23, 2015

REGULATIONS FOR THE DEGREE OF BACHELOR OF ARTS IN ARCHITECTURAL STUDIES (BA[ArchStud])

國 立 交 通 大 學 生 物 科 技 研 究 所 碩 士 論 文 探 討 幽 門 螺 旋 桿 菌 熱 休 克 蛋 白 60 對 人 類 周 邊 血 液 單 核 球 抑 制 增 生 活 性 之 位 置

Quality of. Leadership. Quality Students of Faculty. Infrastructure

EA-N66. 3-in-1 Dual-Band Wireless-N900 Gigabit Access Point / Wi-Fi Bridge / Range Extender. Step-by-Step Setup Manual

RT-AC68R. Quick Start Guide. Wireless-AC1900 Dual Band Gigabit Router. NOTE: For more details, refer to the user manual included in the support

Advancements in Slurry Gasification

ENERGY SERVICE -> GREEN ECONOMICS

~1: 15 /;' J~~~~c...:;.--:.. I. ~ffi ~I J) ':~

The Maryknoll Advantage With Pacific Aviation Museum Pearl Harbor

W4118: segmentation and paging. Instructor: Junfeng Yang

Chinese (Mandarin): World Language

Christy Wegener, Director of Planning & Communications

E-BUSINESS STRATEGY IN SUPPLY CHAIN COLLABORATION: AN EMPIRICAL STUDY OF B2B E-COMMERCE PROJECT IN TAIWAN

Operating Systems, 6 th ed. Test Bank Chapter 7

Lecture 17: Virtual Memory II. Goals of virtual memory

Application Guidelines for International Graduate Programs in Engineering

Memory Management 1. Memory Management. Multitasking without memory management is like having a party in a closet.

Spectrum: Studies in Language, Literature, Translation, and Interpretation, Vol. 2, 85-92

Chapter 9. Subprograms

Transcription:

Chapter 8: Memory Management 籃玉如 Part Four: Memory Management Chap 8 Memory-Management Strategies Chap 9 Virtual-Memory Management 2 1

Chapter 8: Memory Management 8.1 Background 8.2 Swapping 8.3 Contiguous Memory Allocation 8.4 Paging 8.5 Structure of the Page Table 8.6 Segmentation 8.7 Example: The Intel Pentium (X) 3 Background 電腦系統中, 記憶體是系統的重心 記憶體本身是一個大型的字組或位元組陣列, 各字組和位元組都各有其位址,CPU 是根據程式計數器的數值到記憶體的位址擷取指令 這些指令可能會造成對於特殊記憶體位址的額外載入或儲存動作 4 2

8.1.1 Basic Hardware 主記憶體和建立在處理器內的暫存器是 CPU 唯一可以直接存取的儲存體 Machine instructions 使用記憶體位址做為參數, 沒有使用磁碟位址做為參數 因此, 任何執行的指令, 和任何被這些指令使用的資料必須放在這些直接存取儲存裝置之內 如果資料不在記憶體內, 則必須在 CPU 操作它們之前移到記憶體之中 OS process process base process limit Fig. 8.1 A base and a limit register define a logical address space. Fig. 8.2 Hardware address protection with base and limit registers. 5 8.1.2 Address Binding Binding of Instructions and Data to Memory: Address binding of instructions and data to memory addresses can happen at three different stages Compile time: If memory location known a priori, absolute code can be generated; must recompile code if starting location changes Load time: Must generate relocatable code if memory location is not known at compile time Execution time: Binding delayed until run time if the process can be moved during its execution from one memory segment to another. Need hardware support for address maps (e.g., base and limit registers). 6 3

Fig. 8.3 Multistep Processing of a User Program 7 8.3 Logical vs. Physical Address Space Logical address An address generated by the CPU; also referred to as virtual address Physical address an address seen by the memory unit, that is, the address loaded into the memory-address register of the memory. Logical and physical addresses are the same in compile-time and load-time address-binding schemes; logical (virtual) and physical addresses differ in execution-time address-binding scheme 8 4

Memory-Management Management Unit (MMU( MMU) Hardware device that maps virtual to physical address In MMU scheme, the value in the relocation register is added to every address generated by a user process at the time it is sent to memory The user program deals with logical addresses; it never sees the real physical addresses 9 Fig. 8.4 Dynamic relocation using a relocation register 10 5

8.1.4 Dynamic Loading 行程大小受限於實體記憶體大小 要得到較佳之記憶體空間使用效率, 可採行動態載入 (dynamic loading) 主程式儲存在主記憶體並執行, 當需要呼叫其它程式時, 首先看看此程式是不是已經存在記憶體內, 如果不是, 便呼叫重定位鏈結載入程式 (relocatable linking loading), 將所需要的程式載入主記憶體內, 並更新行程位址表的內容 然後控制就轉移給新的載入程式 11 8.1.5 Dynamic Linking and Shared Libraries 採用動態鏈結, 在程式參用程式庫副程式處便做一記號 (stub), 該記號為一小段程式來指示如何去找尋適當的記憶體常駐程式庫副程式, 或是如何載入程式庫副程式 ( 如果不在記憶體中時 ) 當執行到記號處時, 首先檢查所需要的副程式是否已經存在記憶體中 如果該副程式不在記憶體中, 程式會將它載入到記憶體中 12 6

Swapping A process can be swapped temporarily out of memory to a backing store, and then brought back into memory for continued execution Backing store fast disk large enough to accommodate copies of all memory images for all users; must provide direct access to these memory images Roll out, roll in swapping variant used for priority-based scheduling algorithms; lower-priority process is swapped out so higher-priority process can be loaded and executed Major part of swap time is transfer time; total transfer time is directly proportional to the amount of memory swapped 13 Schematic View of Swapping Fig. 8.5 Swapping of two processes using a disk as a backing store. 14 7

Context-Switch time in Swapping System 15 8.3 Contiguous Allocation Main memory usually into two partitions: Resident operating system, usually held in low memory with interrupt vector User processes then held in high memory Memory allocation 的兩個基方式 : Contiguous allocation: each process is contained in a single contiguous section of memory. Non-contiguous allocation: 利用 linked 的方式 16 8

8.3.1 Memory Mapping and Protection Fig. 8.6 HW support for relocation and limit registers 17 8.3.2 Memory Allocation How to satisfy a request of size n from a list of free holes (available memory) First-fit: Allocate the first hole that is big enough Best-fit: Allocate the smallest hole that is big enough; must search entire list unless ordered by size. Produces the smallest leftover hole. Worst-fit: Allocate the largest hole; must also search entire list. Produces the largest leftover hole. First-fit and best-fit better than worst-fit in terms of speed and storage utilization 18 9

8.3.3 Fragmentation External Fragmentation total memory space exists where there is enough total memory space to satisfy a request, but it is not contiguous storage is fragmented into a large numbers of small holes. Depending on the total amount of memory storage and the average process size, external fragmentation may be a minor or a major problem. 例如,first fit 的統計分析顯示縱使具有某些最佳條件, 在給予 N allocated blocks, 由於 fragmentation 也將遺失其它的 0.5N, 那麼三分之一的記憶體可能沒有利用到, 這就是著名的百分之五十規則 (50-percent rule) Internal Fragmentation allocated memory may be slightly larger than requested memory; this size difference is memory internal to a partition, but not being used 19 8.3.3 Fragmentation External Fragmentation total memory space exists where there is enough total memory space to satisfy a request, but it is not contiguous storage is fragmented into a large numbers of small holes. Internal Fragmentation allocated memory may be slightly larger than requested memory; this size difference is memory internal to a partition, but not being used 20 10

8.3.3 Fragmentation The solutions to the problem of external fragmentation: Reduce external fragmentation by compaction Shuffle memory contents to place all free memory together in one large block Compaction is possible only if relocation is dynamic, and is done at execution time Permit the logical address space of the processes to be noncontiguous Paging (8.4) Segmentation (8.6) 21 8.4 Paging Paging is memory-management scheme that permits the physical address space of a process to be noncontiguous. 8.4.1 Basic Method 將 memory 實際區分成固定大小 blocks, 稱為 frames, 而程式欲執行時經由 OS 形成 logical memory 也分成等長的 blocks, 稱為 pages 執行前程式之 pages 必須載入於 available 之 frames, 而且有一個 page table 用來紀錄這些 mapping 的情形 22 11

Fig. 8.7 Paging hardware. 23 Fig. 8.8 Paging Model of logical and physical memory 24 12

The page size (like the frame size) is defined by the hardware. Page 的大小通常是 a power of 2, 從 512 bytes 到 16MB 之間 利用 a power of 2 作為一個 page 的大小的好處為 : 讓 logical address 容易轉換為 a page number & page offset page number p m-n page offset d n 25 Logical address 0 map Physical address 3 4 13 Fig. 8.9 Paging example for a 32-byte memory with 4-byte pages. 26 13

Before allocation After allocation Fig. 8.10 Free frames (a) before allocation and (b) after allocation 27 8.4.2 Hardware Support Translation look-aside buffer (TLB) A fast-lookup hardware cache The TLB contains only a few of the page-table entries. When a logical address is generated by the CPU, its page number is presented to the TLB. If the page number is found, its frame number is immediately available and is used to access memory. If the page number is not in the TLB (known as TLB miss), a memory reference to the page table must be made. When the frame number is obtained, we can use it to access memory. We add the page number and frame number to the TLB, so that they will be found quickly on the next reference. 28 14

Fig. 8.11 Paging hardware with TLB. 29 Effective Access Time Hit ratio: percentage of times that a page number is found in the TLB Assume TLB Lookup time = 20 nanoseconds Assume memory cycle time (access memory)= 100 nanoseconds Hit ratio = 80 Effective Access Time (EAT) =? 30 15

8.4.3 Memory Protection Memory protection implemented by associating protection bit with each frame Valid-invalid bit attached to each entry in the page table: valid indicates that the associated page is in the process logical address space, and is thus a legal page invalid indicates that the page is not in the process logical address space 31 Fig. 8.12 Valid (v) or invalid (i) bit in a page table 32 16

8.4.4 Shared Pages Shared code One copy of read-only (reentrant) code shared among processes (i.e., text editors, compilers, window systems). Shared code must appear in same location in the logical address space of all processes Private code and data Each process keeps a separate copy of the code and data The pages for the private code and data can appear anywhere in the logical address space 33 Fig. 8.13 Sharing of code in a paging environment 34 17

8.5 Structure of Page Table 8.5.1 Hierarchical Paging 8.5.2 Hashed Page Tables 8.5.3 Inverted Page Tables 35 8.5.1 Hierarchical Page Tables Most modern computer systems support a large logical address space The page table itself becomes excessively large We would not want to allocate the page table contiguously in main memory. Solution: Break up the logical address space into multiple page tables A simple technique is a two-level page table 36 18

Fig. 8.14 A two-way page-table scheme. 37 Two-Level Paging Example A logical address (on 32-bit machine with 4K page size) is divided into: a page number consisting of 20 bits a page offset consisting of 12 bits Since the page table is paged, the page number is further divided into: a 10-bit page number a 10-bit page offset Thus, a logical address is as follows: page number page offset p i p 2 d 10 10 12 where p i is an index into the outer page table, and p 2 is the displacement within the page of the outer page table 38 19

Address-Translation Scheme Address-translation scheme for a two-level 32-bit paging architecture Fig. 8.15 39 8.5.2 Hashed Page Tables Common in address spaces > 32 bits The virtual page number is hashed into a page table. This page table contains a chain of elements hashing to the same location. Virtual page numbers are compared in this chain searching for a match. If a match is found, the corresponding physical frame is extracted. 40 20

Fig. 8.16 Hashed page table. 41 8.5.3 Inverted Page Table One entry for each real page of memory Entry consists of the virtual address of the page stored in that real memory location, with information about the process that owns that page Decreases memory needed to store each page table, but increases time needed to search the table when a page reference occurs Use hash table to limit the search to one or at most a few page-table entries 42 21

Fig. 8.17 Inverted page table. 43 8.6 Segmentation A program is a collection of segments. A segment is a logical unit such as: main program, procedure, function, method, object, local variables, global variables, stack, arrays Fig. 8.18 User s view of a program 44 22

8.6.1 Basic Method Segmentation: is a memory-management scheme that supports user view of memory A logical address space is a collection of segments Each segment has a name and a length Implementation: segments are numbered and are referred to by a segment number. A logical address consists of a two tuple: <segment-number, offset> 45 8.6.2 Hardware Logical address consists of a two tuple: <segment-number, offset>, Segment table each table entry has: base contains the starting physical address where the segments reside in memory limit specifies the length of the segment 46 23

Fig. 8.19 Segmentation hardware. 47 Fig. 8. 20 Example of segmentation. 48 24