ILLINOIS CS 241 - Paging and Segmentation

Unformatted text preview:

Paging and SegmentationContentsMemory Mapped FilesSlide 4POSIX <sys/mman.h>Protection AttributesMap first 4kb of file and read intSlide 8munmapImitating VM at the user levelMultilevel PagingExample Addressing on a Multilevel Page Table SystemAddressing on Multilevel Page TableMultilevel Paging and PerformanceTwo Level Page Table CachingSlide 16Sharing and Two Level PagingSlide 18Sharing and Two Level Page SchemeInverted Page TableSlide 21Slide 22Slide 23Sharing PagesSlide 25Shared PagesIncorrect SharingProtectionPage ProtectionSlide 30Slide 31Keys and LocksSegmentation (pp249-261)Segmentation Implementation IssuesSlide 35Slide 36DiscussionSharing SegmentsSlide 39Slide 40Segment ProtectionSegmented Paged Virtual MemorySlide 43Slide 44NS32332 Example of VM HardwareSun Example of VM SchemeNT VM - PentiumSegmentation with Paging: Pentium (5)Summary01/15/19 CS241 © 2005 Roy Campbell, All Rights Reserved1Paging and SegmentationCS 241 Lecture 29T: Ch 4Roy Campbell01/15/19 CS241 © 2005 Roy Campbell, All Rights Reserved2ContentsMemory Mapped FilesMultilevel PagingSharingProtectionInverse Page TablesSegmentation01/15/19 CS241 © 2005 Roy Campbell, All Rights Reserved3Memory Mapped FilesMemory Mapped FileIn BlocksVM of UserMmap requestsDiskFileBlocks of dataFrom file mappedTo VM01/15/19 CS241 © 2005 Roy Campbell, All Rights Reserved4Memory Mapped FilesDynamic 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. Streamlining 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 persistence. Memory mapping enables processes to share memory sections that persist independently of the lifetime of a certain process.01/15/19 CS241 © 2005 Roy Campbell, All Rights Reserved5POSIX <sys/mman.h> caddr_t mmap(caddress_t map_addr, /* map_addr is VM address to map file, use 0 to allow system to choose*/ 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*/01/15/19 CS241 © 2005 Roy Campbell, All Rights Reserved6Protection AttributesPROT_READ //the mapped region may be read PROT_WRITE //the mapped region may be written PROT_EXEC //the mapped region may be executed01/15/19 CS241 © 2005 Roy Campbell, All Rights Reserved7Map 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; } /*map first 4 kilobytes of fd*/ pregion=mmap(NULL, 4096,01/15/19 CS241 © 2005 Roy Campbell, All Rights Reserved8Map 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 the physical file because we don't need it //access mapped memory; read the first int in the mapped file int val= *((int*) pregion); }01/15/19 CS241 © 2005 Roy Campbell, All Rights Reserved9munmapint munmap(caddr_t addr, int length); int msync (void *address, size_t length, int flags)size_t page_size = (size_t) sysconf (_SC_PAGESIZE); SIGSEGV signal allows you to catch references to memory that have the wrong protection mode.01/15/19 CS241 © 2005 Roy Campbell, All Rights Reserved10Imitating VM at the user levelUser VM Stored on Disk as File Memory Mapped FileSimulated VM for UserOS ServicesVirtual OSMmap requestsSignals for page faultsVirtual User Env01/15/19 CS241 © 2005 Roy Campbell, All Rights Reserved11Multilevel Paging01/15/19 CS241 © 2005 Roy Campbell, All Rights Reserved12Example Addressing on a Multilevel Page Table SystemA logical address (on 32 bit machine with 4k page size) is divided into A page number consisting of 20 bitsA page offset consisting of 12 bits Divide the page number into A 10-bit page numberA 10-bit page offset01/15/19 CS241 © 2005 Roy Campbell, All Rights Reserved13Addressing on Multilevel Page Table01/15/19 CS241 © 2005 Roy Campbell, All Rights Reserved14Multilevel Paging and PerformanceSince each level is stored as a separate table in memory, converting a logical address to a physical one in a two level paging system may take up to four memory accesses01/15/19 CS241 © 2005 Roy Campbell, All Rights Reserved15Two Level Page Table CachingCheck cache for base address of 1st level cache. Fetch as necessary ( 1 ref)Check cache for address of 2nd level page base address in 1st level page table. Fetch as necessary (1 ref)01/15/19 CS241 © 2005 Roy Campbell, All Rights Reserved16Two Level Page Table CachingCheck cache for address of 2nd level page table entry. Fetch as necessary (1 ref)Check cache for address of page stored in 2nd level page table. Fetch as necessary ( 1 ref)01/15/19 CS241 © 2005 Roy Campbell, All Rights Reserved17Sharing and Two Level Paginglinear memory spacefirst level page table contains size of second level page table and this is checked on accessallows address space to be sparse (can allocate regions in VM without requiring all of the page tables for VM to be built.)01/15/19 CS241 © 2005 Roy Campbell, All Rights Reserved18Sharing and Two Level Pagingallows sharing of data by using first level page tables of different vms to share second level page tableallows second level page tables to be paged01/15/19 CS241 © 2005 Roy Campbell, All Rights Reserved19Sharing and Two Level Page Scheme01/15/19 CS241 © 2005 Roy Campbell, All Rights Reserved20Inverted Page Tableone entry for each real page of memoryentry consists of the virtual address of the page stored in that real memory location, with information about the process that owns that page01/15/19 CS241 © 2005 Roy Campbell, All Rights Reserved21Inverted Page TableDecreases memory needed to store each page table, but increases time needed to search table when a page reference occursUse hash table to limit


View Full Document

ILLINOIS CS 241 - Paging and Segmentation

Download Paging and Segmentation
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 Paging and Segmentation 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 Paging and Segmentation 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?