DOC PREVIEW
U of I CS 241 - Virtual Memory

This preview shows page 1-2-17-18-19-36-37 out of 37 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Virtual MemoryContentsMemory Mapped FilesUses of Memory Mapped FilesSlide 5POSIX <sys/mman.h>Protection AttributesMap first 4kb of file and read intSlide 9munmap, msyncSharing PagesShared PagesProtectionPage Protection via PTEVirtual Memory Under MultiprogrammingTerminologyIssue: EvictionPage Replacement StrategiesPrincipal of OptimalityFrame Allocation for Multiple ProcessesMulti-Programming Frame AllocationSlide 22ThrashingPage Fault Rate vs. Size CurveWhy Thrashing?Results of ThrashingWhy?Solution: Working SetWorking set (1968, Denning)Working SetCalculating Working SetWorking Set in Action to Prevent ThrashingWorking sets of real programsWorking Set Implementation IssuesPage Fault Frequency Working SetSlide 36SummaryCS 241 Fall 2007System Programming 1Virtual MemoryLawrence Angrave and Vikram Adve2ContentsMemory mapped filesPage sharingPage protectionVirtual Memory and MultiprogrammingPage eviction policiesPage frame allocation and thrashingWorking set model and implementation3Memory Mapped FilesMemory Mapped FileIn BlocksVM of UserMmap requestsDiskFileBlocks of dataFrom file mappedTo VM4Uses of Memory Mapped FilesDynamic loading. By mapping executable files and shared libraries into its address space, a program can load and unload executable code sections dynamically. Fast File I/O. When you call file I/O functions, such as read() and write(), the data is copied to a kernel's intermediary buffer before it is transferred to the physical file or the process. This intermediary buffering is slow and expensive. Memory mapping eliminates this intermediary buffering, thereby improving performance significantly.5Uses of Memory Mapped FilesStreamlining file access. Once you map a file to a memory region, you access it via pointers, just as you would access ordinary variables and objects. Memory sharing. Memory mapping enables different processes to share physical memory pagesMemory persistence. Memory mapping enables processes to share memory sections that persist independently of the lifetime of a certain process.6POSIX <sys/mman.h> caddr_t mmap( caddress_t map_addr, /* VM address hint;0 for no preference */ size_t length, /* Length of file map*/int protection, /* types of access*/int flags, /*attributes*/int fd, /*file descriptor*/off_t offset); /*Offset file map start*/7Protection AttributesPROT_READ /* the mapped region may be read */PROT_WRITE /* the mapped region may be written */PROT_EXEC /* the mapped region may be executed */SIGSEGV signal if you reference memory with wrong protection mode.8Map first 4kb of file and read int#include <errno.h> #include <fcntl.h> #include <sys/mman.h> #include <sys/types.h> int main(int argc, char *argv[]) { int fd; void * pregion; if (fd= open(argv[1], O_RDONLY) <0) { perror("failed on open"); return –1; }9Map first 4kb of file and read int/*map first 4 kilobytes of fd*/ pregion =mmap(NULL, 4096, PROT_READ, MAP_SHARED, fd, 0); if (pregion==(caddr_t)-1) { perror("mmap failed") return –1; } close(fd); /*close physical file: we don't need it *//* access mapped memory; read the first int in the mapped file */int val= *((int*) pregion); }10munmap, msyncint munmap(caddr_t addr, int length);int msync (caddr_t addr, size_t length, int flags);addr must be multiple of page size:size_t page_size = (size_t) sysconf (_SC_PAGESIZE);11Sharing PagesCode and data can be sharedMap common page frame in two processesCode, data must be position-independent VM mappings for same code, data in different processes are different12Shared Pages13ProtectionWhy Page Protection?Implementing Page ProtectionRead, Write, eXecute bits in page table entryCheck is done by hardware during accessIllegal access generates SIGSEGVEach process can have different protection bits14Page Protection via PTELegend: Reference - page has been accessed Valid - page exists Resident - page is cached in primary memory Dirty - page has been changed since page in15Virtual Memory Under MultiprogrammingEviction of Virtual PagesOn page fault: Choose VM page to page outHow to choose which data to page out?Allocation of Physical Page FramesHow to assign frames to processes?16TerminologyReference string: memory reference sequence generated by a program:Reference = (R/W, address)Paging – moving pages to or from diskDemand Paging – moving pages only when neededOptimal – the best (theoretical) strategyEviction – throwing something outPollution – bringing in useless pages/lines17Issue: EvictionHopefully, kick out a less-useful pageDirty pages require writing, clean pages don’tGoal: kick out the page that’s least usefulProblem: how do you determine utility?Heuristic: temporal locality existsKick out pages that aren’t likely to be used again18Page Replacement StrategiesThe Principle of Optimality Replace page that will be used the farthest in the future. Random page replacement Choose a page randomly FIFO - First in First Out Replace the page that has been in primary memory the longest LRU - Least Recently Used Replace the page that has not been used for the longest time LFU - Least Frequently Used Replace the page that has been used least often NRU - Not Recently Used An approximation to LRU. Working Set Keep in memory those pages that the process is actively using.19Principal of Optimality Description: Assume each page can be labeled with number of references that will be executed before that page is first referenced.Then the optimal page algorithm would choose the page with the highest label to be removed from the memory. Impractical! Why? Provides a basis for comparison with other schemes.If future references are knownshould not use demand paging should use “pre-paging” to overlap paging with computation.20Frame Allocation for Multiple ProcessesHow are the page frames allocated to individual virtual memories of the various jobs running in a multi-programmed environment?Simple solution Allocate a minimum number (??) of frames per process. One page from the current executed instructionMost instructions require two operandsinclude an extra page for paging out and one for paging in21Multi-Programming Frame AllocationSolution 2allocate an equal number of frames per job but jobs use memory unequallyhigh priority jobs have same number of page frames as low priority jobsdegree of


View Full Document

U of I CS 241 - Virtual Memory

Documents in this Course
Process

Process

28 pages

Files

Files

37 pages

File I/O

File I/O

52 pages

C Basics

C Basics

69 pages

Memory

Memory

23 pages

Threads

Threads

14 pages

Lecture

Lecture

55 pages

C Basics

C Basics

24 pages

Signals

Signals

27 pages

Memory

Memory

45 pages

Threads

Threads

47 pages

Threads

Threads

28 pages

LECTURE

LECTURE

45 pages

Threads

Threads

30 pages

Threads

Threads

55 pages

Files

Files

37 pages

SIGNALS

SIGNALS

22 pages

Files

Files

37 pages

Threads

Threads

14 pages

Threads

Threads

13 pages

Load more
Download Virtual Memory
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Virtual Memory and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Virtual Memory 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?