29
CMPT 300: Final Review CMPT 300: Final Review Chapters 8 – 14 Chapters 8 – 14

CMPT 300: Final Review Chapters 8 – 14

  • Upload
    danton

  • View
    42

  • Download
    0

Embed Size (px)

DESCRIPTION

CMPT 300: Final Review Chapters 8 – 14. Memory Management: Ch. 8, 9. Address spaces Logical (virtual): generated by the CPU Physical: seen by the memory unit User program deals with logical addresses; never sees physical addresses Mapping from logical to physical addresses - PowerPoint PPT Presentation

Citation preview

Page 1: CMPT 300: Final Review  Chapters 8 – 14

CMPT 300: Final Review CMPT 300: Final Review

Chapters 8 – 14 Chapters 8 – 14

Page 2: CMPT 300: Final Review  Chapters 8 – 14

2

Memory Management: Ch. 8, 9Memory Management: Ch. 8, 9

Address spaces

Logical (virtual): generated by the CPU

Physical: seen by the memory unit

User program deals with logical addresses; never sees physical addresses

Mapping from logical to physical addresses

Static: done at compile-time

Dynamic: done at load or execution time

Page 3: CMPT 300: Final Review  Chapters 8 – 14

3

Memory AllocationMemory Allocation

Memory is usually divided into two partitions for:

Kernel: usually held in low memory

User processes: usually held in high memory

Typically, the two partitions are managed differently

Memory allocation

Contiguous

First-, Best-, Worst-fit

Fragmentation: external and internal

Paging, segmentation, virtual memory

Page 4: CMPT 300: Final Review  Chapters 8 – 14

4

PagingPaging

Page 5: CMPT 300: Final Review  Chapters 8 – 14

5

SegmentationSegmentation

1

3

2

4

1

4

2

3

user space physical memory space

Page 6: CMPT 300: Final Review  Chapters 8 – 14

6

Segmentation HardwareSegmentation Hardware

Page 7: CMPT 300: Final Review  Chapters 8 – 14

7

Paging and SegmentationPaging and Segmentation

Paging issues:

Page size

Internal fragmentation and page table size

Page table (one table for each process)

Access time: use cache (TLB)

Size: use two- or three-levels page tables use hashed or inverted page tables for > 32 bits architectures

Segmentation: variable size

External fragmentation

Facilitates sharing of code and data (share the whole segment)

Combined Segmentation + paging:

Example Intel Pentium

Page 8: CMPT 300: Final Review  Chapters 8 – 14

8

Virtual MemoryVirtual Memory

Logical address space can be much larger than physical address space

Only the needed parts of the program are brought to memory for execution

Allows address spaces to be shared by several processes

Allows for more efficient process creation

Virtual memory can be implemented via

Demand paging

Demand segmentation

Page 9: CMPT 300: Final Review  Chapters 8 – 14

9

Virtual Memory and Page FaultVirtual Memory and Page Fault

Page 10: CMPT 300: Final Review  Chapters 8 – 14

10

Page Replacement Page Replacement

When we need to bring a page from disk and there is no free frame:

Find a victim page to evict from memory

Objective: minimize number of page faults (they are very costly)

Replacement algorithms

FIFO, OPT, LRU, second-chance, …

Page 11: CMPT 300: Final Review  Chapters 8 – 14

11

ThrashingThrashing

Thrashing a process is busy swapping pages in and out more than executing (because OS allocated too few frames to it)

Page 12: CMPT 300: Final Review  Chapters 8 – 14

12

Locality ModelLocality Model

As a process executes, it moves from locality to locality, where a locality is a set of pages that are actively used together

Locality could be: function, module, segment of code, …

Locality model helps us to estimate the working set of a process

Working set: pages that are actively being used (within a window)

Page 13: CMPT 300: Final Review  Chapters 8 – 14

13

Allocating Kernel MemoryAllocating Kernel Memory

Treated differently from user memory because

Kernel requests memory for structures of varying sizes

Process descriptors (PCB), semaphores, file descriptors, …

Some of them are less than a page

Some kernel memory needs to be contiguous

some hardware devices interact directly with physical memory without using virtual memory

Virtual memory may just be too expensive for the kernel (cannot afford a page fault)

Page 14: CMPT 300: Final Review  Chapters 8 – 14

14

Kernel Memory: Buddy SystemKernel Memory: Buddy System

Page 15: CMPT 300: Final Review  Chapters 8 – 14

15

Kernel Memory: Slab AllocationKernel Memory: Slab Allocation

Page 16: CMPT 300: Final Review  Chapters 8 – 14

16

File Systems: Ch. 10, 11, 12File Systems: Ch. 10, 11, 12

Interface: file and directory structure Maintains pointers to logical block addresses

Application Programs

Logical File System

File-organization Module

Device Drivers

Storage Devices

Implementation: device-specific instructions Writes specific bit patterns to device controller

Implementation: block allocation, … Maps logical into physical addresses

Page 17: CMPT 300: Final Review  Chapters 8 – 14

17

File System InterfaceFile System Interface

Files

The smallest storage unit from the user’s perspective

A collection of blocks on the disk from OS’ perspective

Directory structure

Tree-structured with links (general graphs)

Each file has an entry in the directory

Page 18: CMPT 300: Final Review  Chapters 8 – 14

18

File System ImplementationFile System Implementation

To implement a file system, we need

On-disk structures, e.g.,

directory structure, number of blocks, location of free blocks, boot information, …

(In addition to data blocks, of course)

In-memory structures to:

improve performance (caching)

manage file system

Page 19: CMPT 300: Final Review  Chapters 8 – 14

19

On-disk StructuresOn-disk Structures

Boot block

Superblock

Directory structure

Free block

File control block

Data block

Page 20: CMPT 300: Final Review  Chapters 8 – 14

20

Opening and Reading from a FileOpening and Reading from a File

Page 21: CMPT 300: Final Review  Chapters 8 – 14

21

Block AllocationBlock Allocation

Allocate free blocks to files to achieve efficient disk space utilization, and fast file access

Three common allocation methods

Contiguous

Linked

Indexed

OS keeps track of free blocks using

Bitmaps

Linked lists

Page 22: CMPT 300: Final Review  Chapters 8 – 14

22

Combined Scheme: UNIX inodeCombined Scheme: UNIX inode

Page 23: CMPT 300: Final Review  Chapters 8 – 14

23

Disk Structure and SchedulingDisk Structure and Scheduling

Disk structure

cylinders, tracks, sectors, logical blocks

Disk operation

Move the head to desired track (seek time)

Wait for desired sector to rotate under the head (rotational latency time)

Transfer the block to a local buffer, then to main memory (transfer time)

Disk scheduling

To minimize seek time (head movements)

Algorithms: FCFC, SSTF, SCAN, LOOK

Page 24: CMPT 300: Final Review  Chapters 8 – 14

24

Protection: Ch. 14Protection: Ch. 14

Protection: Ensure that each object is accessed correctly and only by those processes that are allowed to do so

A process operates within a protection domain

Domain = set of access rights (= user-id in UNIX)

Page 25: CMPT 300: Final Review  Chapters 8 – 14

25

Access MatrixAccess Matrix

Protection as a matrix

Implemented as Access Control List (columns), or Capability List (rows)

Page 26: CMPT 300: Final Review  Chapters 8 – 14

26

Protection in UNIXProtection in UNIX

Default: Coarse-grained protection using 9 bits

rwx rwx rwx filename

Owner group all_others

Optional: fine-grained protection using Access Control List

Page 27: CMPT 300: Final Review  Chapters 8 – 14

27

Warp Up: What We Have CoveredWarp Up: What We Have Covered

How to manage resources in a single computer

Page 28: CMPT 300: Final Review  Chapters 8 – 14

28

Warp Up: What We Have Warp Up: What We Have NOTNOT Covered Covered

How to manage resources distributed over multiple computers

CMPT 371: Computer Networks

Protocols and algorithms to make computers talk to each other

CMPT 401: Operating Systems II

Distributed file systems, distributed synchronization, inter-process communications, consistency and reliability, security

Special-purpose operating systems, e.g.,

Real-time OS

OS on small devices (PDAs, sensors,…)

Page 29: CMPT 300: Final Review  Chapters 8 – 14

29

That is it with CMPT 300!That is it with CMPT 300!

Good Luck on Your Final