76
1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

Embed Size (px)

Citation preview

Page 1: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

1

Paging Example

Assume a page size of 1K and a 15-bit logical address space.

How many pages are in the system?

Page 2: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

2

Answer: 2^5 = 32. Assuming a 15-bit address space with 8 logical

pages. How large are the pages?

Page 3: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

3

Answer: 2^5 = 32. Assuming a 15-bit address space with 8 logical

pages. How large are the pages? Answer: 2^12 = 4K. It takes 3 bits to reference

8 logical pages (2^3 = 8). This leaves 12 bits for the page size thus pages are 2^12.

Page 4: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

4

Consider logical address 1025 and the following

page table for some process P0. Assume a 15-bit address space with a page size of 1K. What is the physical address to which logical address 1025 will be mapped?

8

0

2

Page 5: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

5

Consider logical address 1025 and the following

page table for some process P0. Assume a 15-bit address space with a page size of 1K. What is the physical address to which logical address 1025 maps?

8

0

2

Step 1. Convert to binary:

000010000000001

Page 6: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

6

Consider logical address 1025 and the following

page table for some process P0. Assume a 15-bit address space with a page size of 1K. What is the physical address to which logical address 1025 maps?

8

0

2

Step2. Determine the logical page number:

Since there are 5-bits allocated to the logical page, the address is broken up as follows:

00001 0000000001

Logical page number offset within page

Page 7: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

7

Consider logical address 1025 and the following

page table for some process P0. What is the physical address?

8

0

2

Step 3. Use logical page number as an index into the page table.

00001 0000000001

00001

Page 8: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

8

Consider logical address 1025 and the following

page table for some process P0. What is the physical address?

8

0

2

Take physical page number from the page table and concatenate the offset.

So the physical address is byte 1.

000000000000001

00001

Page 9: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

9

Long-term Information Storage

1. Must store large amounts of data

2. Information stored must survive the termination of the process using it

3. Multiple processes must be able to access the information concurrently. In short:

Page 10: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

10

Long-term Information Storage

Files: Good!

Page 11: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

11

Long-term Information Storage

Files: Good! No Files: Bad!

Page 12: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

12

File System

Operating system determines how files are: Structured Named Accessed Used Protected Implemented

Most important aspect to users is how files appear to them: naming convention, available operations, protection, etc. (Not implementation!!).

Page 13: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

13

File Naming

Unix: Case sensitive. Allows, but does not require, extensions (e.g., prog.c).

Assigns no meaning to extensions. Add as many extensions as desired (e.g.,

prog.back.stupid.c). Does not allow spaces in name (unless “\ “) ;

Windows: Not case sensitive. Allows 1-3 character extensions. Extensions have meaning (to other application codes,

not to the OS) Allows spaces in file name.

Page 14: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

14

File Naming

Typical file extensions.

Page 15: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

15

File Structure None - sequence of words, bytes Simple record structure

Lines Fixed length Variable length

Complex Structures Formatted document Relocatable load file

Page 16: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

16

File Structure

Three kinds of files byte sequence (i.e., no structure). record sequence Tree (e.g., data base)

Page 17: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

17

File Structure Can simulate last two with first method by

inserting appropriate control characters Who decides:

Operating system Program (i.e., programs can support any

model they want) Unix and Windows support only the

sequence of bytes functionality.

Page 18: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

18

File Types: Text and Binary

An executable file (Unix)

Page 19: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

19

File Access

Sequential access read all bytes/records from the beginning cannot jump around, could rewind or back up convenient when medium was mag tape

Random access bytes/records read in any order essential for data base systems read can be …

move file marker (seek), then read or … read and then move file marker

Page 20: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

20

File Attributes Name – only information kept in human-

readable form Identifier (file descriptor) – unique tag

(number) identifies file within file system Type – needed for systems that support

different types Location – pointer to file location on device Size – current file size

Page 21: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

21

File Attributes Protection – controls who can do reading,

writing, executing Time, date, and user identification – data

for protection, security, and usage monitoring Information about files are kept in the

directory structure, which is maintained on the disk (although generally cached).

Page 22: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

22

File Operations Create Write Read Reposition within file Delete Truncate

Page 23: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

23

File Operations in Unix

int fd = open(Fi) – search the directory structure on disk for entry Fi, and move the content of entry to memory

fd is a file descriptor (integer).

close (fd) – move the content of entry Fi in memory to directory structure on disk

seek() // change pointer to current location in file. read(fd, buf, num_bytes)

Page 24: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

24

Open Files Several pieces of data are needed to manage

open files: File pointer: pointer to last read/write location, per

process that has the file open File-open count: counter of number of times a file is

open – to allow removal of data from open-file table when last processes closes it

Disk location of the file: cache of data access information

Access rights: per-process access mode information

Page 25: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

25

Open Files

Unix maintains an open-file table for each process and for the whole system.

File descriptor is used as an index into the process open-file table. Entries are items that have to do with that particular process (e.g., file pointer, access rights, etc.).

A pointer to the system-wide open-file table is also in the process open-file table.

System-wide open-file table holds process-independent information (e.g., location on disk, last access time, file size, count of the number of processes using the file).

Page 26: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

26

Open File Locking

Provided by some operating systems and file systems

Mediates access to a file Mandatory or advisory:

Mandatory – access is denied depending on locks held and requested

Advisory – processes can find status of locks and decide what to do

Page 27: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

27

Directory A collection of data structures containing information about files

F 1 F 2F 3

F 4

F n

Directory

Files

Both the directory structure and the files reside on diskBackups of these two structures are kept on tapes

Page 28: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

28

Operations Performed on Directory

Search for a file Create a file Delete a file List a directory Rename a file Traverse the file system

Page 29: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

29

Organize the Directory (Logically) to Obtain

Efficiency – locating a file quickly Naming – convenient to users

Two users can have same name for different files

The same file can have several different names

Grouping – logical grouping of files by properties, (e.g., all Java programs, all games, …)

Page 30: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

30

Single-Level Directory

Naming problem

Grouping problem

Page 31: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

31

Two-Level Directory Separate directory for each user

Path name

Can have the same file name for different user

Efficient searching

No grouping capability

Page 32: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

32

Tree-Structured Directories

Page 33: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

33

Tree-Structured Directories (Cont)

Efficient searching

Grouping Capability

In Unix, a directory is a file that contains meta-data about the files it contains.

Page 34: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

34

Tree-Structured Directories (Cont)

Most OS support absolute and relative path names.

Unix has two pre-defined relative path names: . Represents current directory .. Represents parent directory

Current directory (working directory) cd /spell/mail/prog or cd .. (relative to CD)

Page 35: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

35A UNIX directory tree

Path Names

Page 36: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

36

To Open dict the absolute path name is: /usr/lib/dict.

Page 37: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

37

Assume Current Directory is /usr/jim. Then .. is /usr, . is /usr/jimTo access dict: ../lib/dict.

Relative Path Name

Page 38: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

38

Unix: mkdir creates a new sub-directory below the current working directory.

rmdir removes an entire directory (and all sub-directories).

rm deletes a file If someone suggests that you try out a cool

command calledrm –r * don’t do it!!

Page 39: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

39

Shared Files (1)

File system containing a shared file

Page 40: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

40

Links

This is termed a hard link. Both directory entry pointing to the same inode.

(a) Situation prior to linking(b) After the link is created(c) After the original owner removes the file

Page 41: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

41

Symbolic Links

Provide the path name of the target file in the linked file.

Other processes do not have access to the inode (i.e., directory structure).

What happens when file deleted by owner?

Page 42: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

42

Operations Performed on Directory

Search for a file Create a file Delete a file List a directory Rename a file Traverse the file system

Page 43: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

43

Implementing Directories (1)

(a) A simple directory fixed size entriesdisk addresses and attributes in directory entry

(b) Directory in which each entry just refers to an i-node

Page 44: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

44

Page 45: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

45

File Control Block

Page 46: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

46

Accessing a File

Page 47: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

47

Allocation of File Blocks

Contiguous allocation Linked-list allocation FAT Indexed (inodes).

Page 48: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

48

Directory Structure with Contiguous Allocation of File Blocks

Page 49: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

49

Implementing Files: Contiguous Allocation

(a) Contiguous allocation of disk space for 7 files(b) State of the disk after files D and E have been removed

Page 50: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

50

Linked-list Allocation

Page 51: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

51

File Allocation Table

Page 52: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

52

Entry 4 bytes. Blocks 1K. 20 Million Entries (not files!) == 80 MB for table.

Page 53: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

53

Indexed Allocation

Page 54: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

54

File Allocation Table

Page 55: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

55

Unix inode

Page 56: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

56

Unix Directory Entry

15 Tester

inode number File Name

Page 57: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

57

Unix File System

Unix File System: 1 inode for each file/directory.

B S Inode list Data blocks

Boot area superblock

Page 58: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

58

File Attributes

Disk block addresses (NOT inode addresses)

File Attributes

File Attributes

File Attributes

0 1 2 3

100

Open file /usr/pmd

Page 59: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

59

File Attributes

File Attributes

File Attributes

File Attributes

0 1 2 3

100

400

Open file /usr/pmdStep 1: Fetch inode for root directory (will be stored in memory).

Four inodes in a Unix system

800 180

769

253

127

Page 60: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

60

File Attributes

File Attributes

File Attributes

File Attributes

0 1 2 3

100

400

Open file /usr/pmd

Step 1: Fetch inode for root directory (will be stored in memory).

inodes in a Unix system

800 180

769

253

127

Page 61: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

61

File Attributes

File Attributes

File Attributes

File Attributes

0 1 2 3

Bin 1

usr 2

Disk block 100

100

400

Open file /usr/pmd

Step 1: Fetch inode for root directory (will be stored in memory).

inodes in a Unix system

800 180

769

253

127

Step 2. Fetch disk block 100 and search for file usr.

Directory

Page 62: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

62

File Attributes

File Attributes

File Attributes

File Attributes

0 1 2 3

Bin 1

usr 2

Disk block 100

100

400

Open file /usr/pmd

Step 1: Fetch inode for root directory (will be stored in memory).

inodes in a Unix system

800 180

769

253

127

Step 2. Fetch disk block 100 and search for file usr.

Step 3. Fetch inode 2.

Directory

Page 63: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

63

File Attributes

File Attributes

File Attributes

File Attributes

0 1 2 3

100

400

Open file /usr/pmd

Step 1: Fetch inode for root directory (will be stored in memory).

inodes in a Unix system

800

180

769

253

127

Step 2. Fetch disk block 100 and search for file usr.

Step 3. Fetch inode 2. Retrieve disk block 180.

Page 64: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

64

File Attributes

File Attributes

File Attributes

File Attributes

0 1 2 3

100

400

Open file /usr/pmd

Step 1: Fetch inode for root directory (will be stored in memory).

inodes in a Unix system

800 180

769

253

127

Step 2. Fetch disk block 100 and search for file usr.

Step 3. Fetch inode 2. Retrieve disk block 180.

pmd 3

B_Man 21

Jtm 34

Page 65: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

65

File Attributes

File Attributes

File Attributes

File Attributes

0 1 2 3

100

400

Open file /usr/pmdStep 1: Fetch inode for root directory (will be stored in memory).

inodes in a Unix system

800 180

769

253

127

Step 2. Fetch disk block 100 and search for file usr.

Step 3. Fetch inode 2. Retrieve disk block 180.

Step 4. Retrieve inode 3. This points to my home directory starting at block 253.

pmd 3

B_Man 21

Jtm 34

Page 66: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

66

Miscellaneous

If you lost credit for question 6.4 or 5.8 please see me to get those points back.

Please check your email and notify me ASAP if your records disagree with mine!

Some students still have not demoed project 2. Please make arrangements with the TA to do so today.

Page 67: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

67

Grading

Test average: 25% Prelim I, 25% Prelim II, and 50%

final exam. Assignment average:

75% BRAIN, 15% programming assignments, and 10% homework.

Each will account for 50% of the final grade.

Page 68: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

68

Final Exam

New Material Virtual Memory: Sections 9.1 up to but not including

(UT) 9.2.2, 9.4 UT 9.5.2, 9.6 UT 9.7.2, 9.9.1 UT 9.9.4. File Systems: 10.3 UT 10.4, 11.1 UT 11.4.4, 11.5 UT

11.6. Also, there was material not in the Text but in slides: Understand the differences between the Unix file system and Windows file system. This includes differences in directory entries, methods for keeping track of blocks belonging to a file, and approaches to locating and opening a file.

Page 69: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

69

Final Exam

Earlier Material Make sure you understand the scheduling algorithms we

discussed (FIFO, SJF, SJF-preemptive, RR). Please understand semaphores and the TestandSet

instruction, how they are used and what can be done with them!!

Page 70: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

70

File Allocation Table

Page 71: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

71

Unix inode

Page 72: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

72

Unix Directory Entry

15 Tester

inode number File Name

Page 73: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

73

The UNIX File System

The steps in looking up /usr/ast/mbox

Page 74: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

74

Disk Space Management (1)

Dark line (left hand scale) gives data rate of a disk Dotted line (right hand scale) gives disk space efficiency All files 2KB

Block size

Page 75: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

75

Tracking Free Disk Blocks

Bit Vector

000111000000000111111000011

Page 76: 1 Paging Example Assume a page size of 1K and a 15-bit logical address space. How many pages are in the system?

76

Linked-list