Virtual Memory with Paging Example A computer system

  • Slides: 45
Download presentation
Virtual Memory with Paging Example: A computer system uses virtual memory with paging with

Virtual Memory with Paging Example: A computer system uses virtual memory with paging with 24 -bit virtual addresses and a page size of 4 K bytes. A process accesses the following virtual addressees (given in hexadecimal): 002 B 2 A - 006123 – 0037 FF - 006127 – 00239 C - 005000 - 002 A 1 B – 00612 B a) Find the number of page faults in accessing the above addresses if 3 RAM frames are available for this process and FIFO replacement is used. b) Repeat part (a) for LRU replacement. c) Assume that the time to access a RAM location is tm, and it takes tf to respond to a page fault and load a page in RAM, with additional tw to write a page to disk. Assume further that the contents of 4 th and 5 th addresses above were modified. Find the time required to execute the memory accesses in parts (a) and (b). ELC 467– Spring 2020 Lecture 8 -Page 13

C) With FIFO, time is 6 faults occurred Modified pages 6 and 2 where

C) With FIFO, time is 6 faults occurred Modified pages 6 and 2 where swapped out and rewritten on disk. With LRU, time is 3 faults occurred Modified pages 6 and 2 where not swapped out

Allocation of Frames to Processes Each process will be assigned a number of frames

Allocation of Frames to Processes Each process will be assigned a number of frames depending on its size and/or priority. ELC 467– Spring 2020 Lecture 9 -Page 1

Allocation of Frames to Processes Each process will be assigned a number of frames

Allocation of Frames to Processes Each process will be assigned a number of frames depending on its size and/or priority. Page replacement may be global (process page can replace a page of another process) or local (page is brought only into a frame used by the same process). ELC 467– Spring 2020 Lecture 9 -Page 1

Allocation of Frames to Processes Each process will be assigned a number of frames

Allocation of Frames to Processes Each process will be assigned a number of frames depending on its size and/or priority. Page replacement may be global (process page can replace a page of another process) or local (page is brought only into a frame used by the same process). With global replacement, the number of frames assigned to a process can change. A minimum number of frames must be assigned to any process to avoid a condition known as thrashing where process spends more time paging than executing. ELC 467– Spring 2020 Lecture 9 -Page 1

Allocation of Frames to Processes Each process will be assigned a number of frames

Allocation of Frames to Processes Each process will be assigned a number of frames depending on its size and/or priority. Page replacement may be global (process page can replace a page of another process) or local (page is brought only into a frame used by the same process). With global replacement, the number of frames assigned to a process can change. A minimum number of frames must be assigned to any process to avoid a condition known as thrashing where process spends more time paging than executing. Some systems modify the number of frames assigned to a process dynamically according to its working set of pages. ELC 467– Spring 2020 Lecture 9 -Page 1

File System Management Operating systems manage the data stored on secondary storage devices, which

File System Management Operating systems manage the data stored on secondary storage devices, which store large amounts of data in a nonvolatile manner. ELC 467– Spring 2020 Lecture 9 -Page 2

File System Management Operating systems manage the data stored on secondary storage devices, which

File System Management Operating systems manage the data stored on secondary storage devices, which store large amounts of data in a nonvolatile manner. The OS simplifies access to data on these devices by providing the abstract view of files, directories or folders, paths, …etc. ELC 467– Spring 2020 Lecture 9 -Page 2

File System Management Operating systems manage the data stored on secondary storage devices, which

File System Management Operating systems manage the data stored on secondary storage devices, which store large amounts of data in a nonvolatile manner. The OS simplifies access to data on these devices by providing the abstract view of files, directories or folders, paths, …etc. The overall system performance is affected by: q Allocation of disk space to files. q Organization of data on disk. q How the OS keeps track of disk space usage. ELC 467– Spring 2020 Lecture 9 -Page 2

File System Management Operating systems manage the data stored on secondary storage devices, which

File System Management Operating systems manage the data stored on secondary storage devices, which store large amounts of data in a nonvolatile manner. The OS simplifies access to data on these devices by providing the abstract view of files, directories or folders, paths, …etc. The overall system performance is affected by: q Allocation of disk space to files. q Organization of data on disk. q How the OS keeps track of disk space usage. Security of files in multi-user systems is also an important design issue. ELC 467– Spring 2020 Lecture 9 -Page 2

Physical Structure of the Magnetic Disk has a number of surfaces, each with a

Physical Structure of the Magnetic Disk has a number of surfaces, each with a read/write head. All surfaces rotate at a fixed speed. ELC 467– Spring 2020 Lecture 9 -Page 3

Physical Structure of the Magnetic Disk has a number of surfaces, each with a

Physical Structure of the Magnetic Disk has a number of surfaces, each with a read/write head. All surfaces rotate at a fixed speed. ELC 467– Spring 2020 Lecture 9 -Page 3

Physical Structure of the Magnetic Disk has a number of surfaces, each with a

Physical Structure of the Magnetic Disk has a number of surfaces, each with a read/write head. All surfaces rotate at a fixed speed. Each surface has a number of tracks, each track has a number of sectors. ELC 467– Spring 2020 Lecture 9 -Page 3

Physical Structure of the Magnetic Disk has a number of surfaces, each with a

Physical Structure of the Magnetic Disk has a number of surfaces, each with a read/write head. All surfaces rotate at a fixed speed. Each surface has a number of tracks, each track has a number of sectors. The sector, which stores a fixed number of bytes is the unit of disk access. ELC 467– Spring 2020 Lecture 9 -Page 3

Delay in Accessing Data from Disk Delay in accessing any sector thus has three

Delay in Accessing Data from Disk Delay in accessing any sector thus has three components: o Seek latency: time to bring the head over the required cylinder. o Rotational latency: time to bring the required sector under the head. o Transfer latency: time to transfer sector contents to/from memory. ELC 467– Spring 2020 Lecture 9 -Page 4

Delay in Accessing Data from Disk Delay in accessing any sector thus has three

Delay in Accessing Data from Disk Delay in accessing any sector thus has three components: o Seek latency: time to bring the head over the required cylinder. o Rotational latency: time to bring the required sector under the head. o Transfer latency: time to transfer sector contents to/from memory. This delay is affected by the arrangement of data on the disk, and the use of some formatting techniques. ELC 467– Spring 2020 Lecture 9 -Page 4

Nonvolatile Memory Devices (NVM) The use of semiconductor NVM for mass storage has the

Nonvolatile Memory Devices (NVM) The use of semiconductor NVM for mass storage has the advantages of faster access speeds, less power consumption, and higher reliability due to the absence of moving parts. Disadvantages are the higher cost and some special requirements e. g. in flash memory based devices overwriting requires block erasure. In addition, erase/write cycles results in quicker wear compared to other storage devices. Thus, wear levelling techniques which distribute access over the storage space and avoid using the same blocks excessively are needed. ECP-622– ELC 467– Spring 2020 Week 10 Page 52 Lecture 9 -Page

Allocation of disk space to files OS assigns each file an integer number of

Allocation of disk space to files OS assigns each file an integer number of assignment units (may be called blocks, clusters, …). The assignment unit is one or more contiguous sectors. ELC 467– Spring 2020 Lecture 9 -Page 6

Allocation of disk space to files OS assigns each file an integer number of

Allocation of disk space to files OS assigns each file an integer number of assignment units (may be called blocks, clusters, …). The assignment unit is one or more contiguous sectors. When selecting the unit size we try to: o reduce lost disk space as a result of partially used units. o reduce the size of the data structure needed to keep track of disk space usage. i. e. a compromise must be made. ELC 467– Spring 2020 Lecture 9 -Page 6

Allocation of disk space to files OS assigns each file an integer number of

Allocation of disk space to files OS assigns each file an integer number of assignment units (may be called blocks, clusters, …). The assignment unit is one or more contiguous sectors. When selecting the unit size we try to: o reduce lost disk space as a result of partially used units. o reduce the size of the data structure needed to keep track of disk space usage. i. e. a compromise must be made. Also, as file size increases, it may be fragmented, i. e. assigned noncontiguous units, which slows down the file access in magnetic disks. ELC 467– Spring 2020 Lecture 9 –Page 6

File Allocation Table (FAT) FAT system was originally developed for small magnetic disks. It

File Allocation Table (FAT) FAT system was originally developed for small magnetic disks. It is not suitable for currently available large-capacity hard disks. However, it is widely used for solid-state storage devices in embedded applications. ELC 467– Spring 2020 Lecture 9 -Page 7

File Allocation Table (FAT) FAT system was originally developed for small magnetic disks. It

File Allocation Table (FAT) FAT system was originally developed for small magnetic disks. It is not suitable for currently available large-capacity hard disks. However, it is widely used for solid-state storage devices in embedded applications. System keeps track of space allocated to files using a table with an entry for each cluster on device. Size of this entry is 8, 12, 16, or 32 bits according to version. Entry contains one of the following: ELC 467– Spring 2020 Lecture 9 -Page 7

File Allocation Table (FAT) FAT system was originally developed for small magnetic disks. It

File Allocation Table (FAT) FAT system was originally developed for small magnetic disks. It is not suitable for currently available large-capacity hard disks. However, it is widely used for solid-state storage devices in embedded applications. System keeps track of space allocated to files using a table with an entry for each cluster on device. Size of this entry is 8, 12, 16, or 32 bits according to version. Entry contains one of the following: o Code for free cluster. o Number of next cluster in file for which this cluster is assigned. o End of File code. o Code for bad cluster. ELC 467– Spring 2020 Lecture 9 -Page 7

File Allocation Table (FAT) 19 free 20 21 21 22 22 26 23 free

File Allocation Table (FAT) 19 free 20 21 21 22 22 26 23 free 24 25 25 56 26 EOF FAT Each file has a chain of clusters in FAT ending by an EOF. ELC 467– Spring 2020 Lecture 9 -Page 8

File Allocation Table (FAT) Directory Entry File name 20 First cluster of file 19

File Allocation Table (FAT) Directory Entry File name 20 First cluster of file 19 free 20 21 21 22 22 26 23 free 24 25 25 56 26 EOF FAT Each file has a chain of clusters in FAT ending by an EOF. ELC 467– Spring 2020 Lecture 9 -Page 8

File Allocation Table (FAT) Example A disk using FAT system has a cluster size

File Allocation Table (FAT) Example A disk using FAT system has a cluster size of 2 K bytes. Directory of this disk indicates that the number of the first cluster in the file FILE 1 is 10 and the first cluster in file FILE 2 is 14. A part of the FAT of this disk is shown below. Cluster no … 10 11 12 13 14 15 16 17 18 19 20 … FAT entry … 11 12 16 free 15 19 17 18 EOF 17 EOF … a) How much disk space is assigned to file FILE 1? How much of this space is wasted if this file contains 11000 bytes of data? b) What is the error in the above FAT? What is its possible cause? ELC 467– Spring 2020 Lecture 9 -Page 9

a) From the table, FILE 1 is assigned clusters 10, 11, 12, 16, 17,

a) From the table, FILE 1 is assigned clusters 10, 11, 12, 16, 17, 18. Thus, it is assigned 6 clusters, or 12 K on disk. This occurred since five clusters will not be enough for the 11000 bytes of the file. The wasted disk space (i. e. assigned to FILE 1 but not holding data, and cannot be used by any other file is b) Both the entries of cluster 16 and 19 point to 17. Thus table indicates that cluster 17 is part of both FILE 1 and FILE 2 (this serious error is called cross-linked files). Such errors occur when system make changes in FAT while in memory but fails to update FAT on disk, e. g. after a power failure or disk not “safely” removed.

File Allocation in UNIX ELC 467– Spring 2020 Lecture 9 -Page 10

File Allocation in UNIX ELC 467– Spring 2020 Lecture 9 -Page 10

File Allocation in UNIX Information about each file in the system is stored in

File Allocation in UNIX Information about each file in the system is stored in a structure called an i-node. ELC 467– Spring 2020 Lecture 9 –Page 10

File Allocation in UNIX Information about each file in the system is stored in

File Allocation in UNIX Information about each file in the system is stored in a structure called an i-node. I-node of a file stores its attributes and control information, as well as addresses of the first blocks assigned to the file. Directory entry of a file points to the place of its i-node on the disk. This is brought to memory when the file is opened. ELC 467– Spring 2020 Lecture 9 -Page 10

File Allocation in UNIX Information about each file in the system is stored in

File Allocation in UNIX Information about each file in the system is stored in a structure called an i-node. I-node of a file stores its attributes and control information, as well as addresses of the first blocks assigned to the file. Directory entry of a file points to the place of its i-node on the disk. This is brought to memory when the file is opened. All i-nodes have a fixed size. To account for larger files, indirect addressing (single, double, …) is used. ELC 467– Spring 2020 Lecture 9 -Page 10

File Allocation in UNIX Directory entry file name i-node ELC 467– Spring 2020 Lecture

File Allocation in UNIX Directory entry file name i-node ELC 467– Spring 2020 Lecture 9 Page 11

File Allocation in UNIX Directory entry file name i-node The maximum file size is

File Allocation in UNIX Directory entry file name i-node The maximum file size is determined by the above arrangement. ELC 467– Spring 2020 Lecture 9 Page 11

File Allocation in UNIX Example A UNIX system has a hard disk with a

File Allocation in UNIX Example A UNIX system has a hard disk with a block size of 2 Kbytes. This system keeps track of disk space assignment using i-nodes containing 10 direct pointers as well as pointers for single and double indirect addressing. Assume that block addresses are 4 -bytes long. a) Find the maximum file size in the above disk. ELC 467– Spring 2020 Lecture 9 -Page 13

File Allocation in UNIX Example A UNIX system has a hard disk with a

File Allocation in UNIX Example A UNIX system has a hard disk with a block size of 2 Kbytes. This system keeps track of disk space assignment using i-nodes containing 10 direct pointers as well as pointers for single and double indirect addressing. Assume that block addresses are 4 -bytes long. a) Find the maximum file size in the above disk. ELC 467– Spring 2020 Lecture 9 -Page 13

File Allocation in UNIX Maximum number of addresses that system can store for a

File Allocation in UNIX Maximum number of addresses that system can store for a file Direct ELC 467– Spring 2020 Single indirect Double indirect Lecture 9 -Page 13

File Allocation in UNIX In addition, system maintains a list of free blocks on

File Allocation in UNIX In addition, system maintains a list of free blocks on the disk. The size of this list shrinks as more data is stored on disk. ELC 467– Spring 2020 Lecture 9 -Page 12

File Allocation in UNIX In addition, system maintains a list of free blocks on

File Allocation in UNIX In addition, system maintains a list of free blocks on the disk. The size of this list shrinks as more data is stored on disk. Errors may result in inconsistencies in the i-nodes and free list information. ELC 467– Spring 2020 Lecture 9 -Page 12

File Allocation in UNIX In addition, system maintains a list of free blocks on

File Allocation in UNIX In addition, system maintains a list of free blocks on the disk. The size of this list shrinks as more data is stored on disk. Errors may result in inconsistencies in the i-nodes and free list information. Compared to FAT, the method used by UNIX is best suited to large disks with small files (Why? ) ELC 467– Spring 2020 Lecture 9 -Page 12

File Allocation in UNIX In addition, system maintains a list of free blocks on

File Allocation in UNIX In addition, system maintains a list of free blocks on the disk. The size of this list shrinks as more data is stored on disk. Errors may result in inconsistencies in the i-nodes and free list information. Compared to FAT, the method used by UNIX is best suited to large disks with small files (Why? ) Directories and subdirectories in UNIX (and most of the other systems) are treated as special files. ELC 467– Spring 2020 Lecture 9 -Page 12

File 1 File 2 Subdir i-node List of files inside subdirectory

File 1 File 2 Subdir i-node List of files inside subdirectory

File Allocation in UNIX Example A UNIX system has a hard disk with a

File Allocation in UNIX Example A UNIX system has a hard disk with a block size of 2 Kbytes. This system keeps track of disk space assignment using i-nodes containing 10 direct pointers as well as pointers for single and double indirect addressing. Assume that block addresses are 4 -bytes long. a) Find the maximum file size in the above disk. b) If a file of 8221 Kbytes is stored in the above disk, find the corresponding wasted disk space. ELC 467– Spring 2020 Lecture 9 -Page 13

File needs 8221/2= 4110. 5 blocks, so it will be assigned 4111 blocks. 4111=

File needs 8221/2= 4110. 5 blocks, so it will be assigned 4111 blocks. 4111= 10+ 512 + 7 x 512+ 5 i node 512 Waste 8 10 512 …. . 512 5 7 Wasted space = 1 K + (512 -8) x 4+ (512 -5) x 4 = 5068 bytes In last block assigned for data In address blocks as in diagram

File Allocation in UNIX Example A UNIX system has a hard disk with a

File Allocation in UNIX Example A UNIX system has a hard disk with a block size of 2 Kbytes. This system keeps track of disk space assignment using i-nodes containing 10 direct pointers as well as pointers for single and double indirect addressing. Assume that block addresses are 4 -bytes long. a) Find the maximum file size in the above disk. b) If a file of 8221 Kbytes is stored in the above disk, find the corresponding wasted disk space. c) What are the number of disk accesses required to open this file? Make any necessary assumptions. ELC 467– Spring 2020 Lecture 9 -Page 13