6 virtual memory

36
Unit 5-6 Virtual Memory Dr Damitha Karunaratna University of Colombo school of computing Operating Systems 1

Upload: ruwandi-panagoda

Post on 16-Nov-2015

222 views

Category:

Documents


0 download

DESCRIPTION

Virtual Memory

TRANSCRIPT

CS345 02 - Computer Systems

Unit 5-6Virtual MemoryDr Damitha Karunaratna University of Colombo school of computingOperating Systems1

Virtual memoryIs it necessary to load an entire program to the memory for execution?If the size of the program is larger than the available memory how can it be execute?Operating Systems2

Virtual Memory - GoalsAllow applications larger than physical memory to execute.Run partially loaded programs Entire program need not to be in memory all the time.Multiprogramming: Many programs simultaneously reside in memory.Allow re-locatable programs anywhere, anytimeApplication Portability: Applications should not have to manage memory resourcesWrite machine independent code program should not depend on memory architecture.Permit sharing of memory segments or regions. For example, read-only code segments should be shared between program instances.Operating Systems3

Virtual MemoryOperating Systems4

Virtual memoryVirtual memory is partitioned in to equal size pages.Main memory is also partitions into equal size page frames.

Size of a page = size of a page frame

Programs are also partitioned into pages at the time of loading.Operating Systems5

Logical ViewOperating Systems6

Virtual MemoryProcess runs on a virtual machine as defined by the underlying hardware.Focus is on Hardware support for a virtual address spacevirtual addresses independent of physical memoryKey hardware component is the Memory Management Unit (MMU)address translation: virtual to physical memoryensures virtual address space protection

Operating Systems7

Virtual MemoryOperating Systems8

Keep track of whether a page is in a physical page frame or not.Page tablePage table may maintain a bit in each entry to indicate whether the page is in the memory or not.

Handling missing pagesWhen a page fault occurs, the Operating System:moves the current process to the blocked/waiting state (since it must wait for a page to be made resident).finds an empty frame or, if necessary, makes a frame empty in main memory by swapping out a page in the main memory.determines the location of the requested page on the paging device.schedules a disk read operation to load the page into the selected main memory frame (via a pagein)later handles page fetch completion (which is recognized via an I/O completion interrupt) and then moves the blocked process back to the ready state.Operating Systems9

Using Virtual Memory

Operating Systems10

http://www.tutorialspoint.com/operating_system/os_virtual_memory.htm

Virtual AddressesOperating Systems11

Virtual address to Real Address

Operating Systems12

Paging ExampleOperating Systems13ABCd123

CCEf4

Virtual MemoryPage 0Page n10

Page tablerow 0row nCCEfABCD

Physical MemoryPage frame 0Page frame 3CPU24MMU04

Using Virtual MemoryCheck an internal table for this process, to determine whether the reference was a valid or it was an invalid memory access. If the reference was invalid, terminate the process. If it was valid, but page have not yet brought in, page in the latter.Find a free frame.Schedule a disk operation to read the desired page into the newly allocated frame.When the disk read is complete, modify the internal table kept with the process and the page table to indicate that the page is now in memory.Restart the instruction that was interrupted by the illegal address trap. The process can now access the page as though it had always been in memory. Therefore, the operating system reads the desired page into memory and restarts the process as though the page had always been in memory.Operating Systems14

Virtual Memory - DisadvantagesSpace: Translation tables and other data used by VM system reduce available memory to programsTime: Address translation time is added to the cost (execution time) of each instruction. Overhead: Memory management operations have been measured to consume up to 10% of the CPU time on a busy system.Efficiency: Allocating memory in pages may result in fragmentationOperating Systems15

Virtual MemoryAllows programmers to address memory from a logical point of viewAnother layer of indirectionAllow the illusion of operating with a larger memory space than what is available in realityBy storing some of the information on the file system

Operating Systems16

Device DriversOperating Systems17

Device driver is a software.The computer communicates with peripheral devices through device drivers.

A driver provides a software interface to hardware devices, enabling operating systems and other computer programs to access hardware functions without knowing the precise hardware details.

Device drivers depends on both the hardware and the operating system loaded in to the computer

Secondary Storage ManagementSecondary storage is the non-volatile repository for both user and system data and programs.Secondary storage is typically used to storeSource programExecutable programsData for the programTemporaty data Operating Systems18

FilesA file is a named collection of related information, usually a sequence of bytes A file can be viewed in two different ways. Logical (programmers) view: how the users see the file.Liners collection of records.Image File rows of intensity valuesLinear sequence of bytes. Physical (operating system) view: how the file is stored on secondary storage. Many possibilities, not necessarily contiguousOperating Systems19

File AttributesEach file has an associated collection of information(attributes)file nameOwnertype (e.g., source, data, executable)location(s) on the secondary storage.organization (e.g. sequential, indexed, random)access permissions who is permitted to read/write/delete data in the file.time and date of creation, modification, last accessfile sizeOperating Systems20

File TypesFile can be classified into various types based on the content.ExecutableTextSourceLibraryCompressedWord ProcessorSpread sheet.One of the possible implementation technique of file type is to include the type as an extension to the file name.Operating Systems21

File Access MethodsFile access methods describe how the data stored in a file can be accessedSequential: access in order, one record after another.Direct (random): access in any order, skipping over uninteresting recordsIndexed : access in any order, but based on key value(s)Operating Systems22

DirectoriesDirectories are used to organize file to logical categories.A directory is a file that can be searched for information about other files.Entries in the directory file are created, deleted and modified when the files they describe are create, deleted and modified.Operating Systems23

Unix Directory structure

Operating Systems24

File allocationCommon file allocation techniquesContiguousLinkedIndexedTypically the allocation techniques allocate storage space on the basis of fixed size addressable units. Operating Systems25

File allocation - ContiguousAllocate disk space as a collection of adjacent/contiguous blocks.This technique needs to keep track of unused disk space.Operating Systems26

File NameStart Block NoNo of Blocksfile10003file21206file32011

Directory

File allocation - ContiguousAdvantages:Simple easy access.Easy Access.DisadvantageFile size is not known at the time of creation.Extending file size is difficultExternal fragmentationOperating Systems27

File allocation - LinkedInside each block a link is maintained to point to the next block of the fileOperating Systems28

File NameStart Block NoNo of Blocksfile10003

Directory

File allocation - LinkedOperating Systems29

Advantages:No external fragmentation.Files can grow easily.DisadvantageMany seek are required to access file data

Example : MSDOS FAT file system

File allocation - IndexedCreates a table of pointers(index) at the time of the file creation. This table is modified as new blocks are allocated for the file or removed from the file.The index table is also saved in a block/s.Example : UNIX file systemOperating Systems30

Formatting a storage deviceHard disks, need to be formatted before using. Formatting a disk configures the disk with a file system so that OS can store information on the disk.Operating Systems31

File Allocation Table(FAT)FAT is the file systems used by Windows NT operating system. FAT uses a file allocation table (FAT) to keep track of files in the storage devicesFAT and the root directory reside at a fixed location of the volume so that the system's boot files can be correctly located. To protect a volume, two copies of the FAT are kept. Operating Systems32

New Technology File SystemNTFS (New Technology File System) is a proprietary file system developed by Microsoft. This is improvement of FAT. This improvements includesThe capability to recover from some disk-related errors automatically, which FAT cannot.Improved support for larger hard disks.Better security because you can use permissions and encryption to restrict access to specific files to approved users.NTFS is a recoverable file system which keeps track of transactions against the file system in a log.Operating Systems33http://windows.microsoft.com/en-us/windows-vista/comparing-ntfs-and-fat-file-systems

Memory FragmentationFragmentation is the unintentional division of memory into many small free areas that cannot be used effectively.External Fragmentation total memory space exists to satisfy a request, but it is not contiguous.Internal Fragmentation allocated memory may be slightly larger than requested memoryThis size difference is in memory internal to a partition, hence cannot be used for any other process.Operating Systems34

Memory Fragmentation .Compaction is a technique that can be used to deal with (external) fragmentation by moving partitions to bring many small free areas together to form a single large free area.Operating Systems35

ReferencesOperating System Concepts by Avi Silberschat, Peter Baer Galvin and Greg Gagnehttp://codex.cs.yale.edu/avi/os-book/OS8/os8c/slide-dir/Operating Systems36