1 / 13

Operating Systems 8 – virtual memory

Operating Systems 8 – virtual memory. PIETER HARTEL. Principle of locality: memory references tend to cluster. Only resident set of pages in memory Page fault brings in a missing page Page fault may need to free a frame Advantages Process size can be > memory size

gage-hall
Download Presentation

Operating Systems 8 – virtual memory

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Operating Systems 8 – virtual memory PIETER HARTEL

  2. Principle of locality: memory references tend to cluster • Only resident set of pages in memory • Page fault brings in a missing page • Page fault may need to free a frame • Advantages • Process size can be > memory size • The resident set of many processes in memory at the same time • Challenges • OS has to predict future • Avoid thrashing • Concurrency may spoil locality pages time

  3. Principle of separation: mechanism and policy • A policy describes what is allowed to be done • A mechanism describes how it is done • Examples: $ ls-l total 5320 -rw-r--r-- 1 pieterewi574825 2012-07-29 12:00 1-Hardware.pptx -rw-r--r-- 1 pieterewi623208 2012-07-29 11:58 2-Overview.pptx $ ps -l F S UID PID PPID PRI NI SZ TTY TIME CMD 1 S 0 46 2 75 -5 0 ? 00:00:00 cqueue 5 S pieter5908 5899 80 0 27341 ? 00:00:00 sshd 0 S pieter59095908 80 0 12805 pts/1 00:00:00 bash 0 R pieter 6076 590980 0 11040 pts/1 00:00:00 ps

  4. Paging address translation mechanism • Page table per process (how large?) • Cache page table entries in Translation Look aside buffer (TLB)

  5. Always in memory Hierarchical page table • Page table in virtual memory • Disadvantage?

  6. Alternative mechanism: Inverted page table • One entry per frame instead of one entry per page (n > m) • Disadvantage?

  7. Policies • Replacement policies • Optimal, LRU, FIFO, and Clock (more…) • Resident set policies • Fixed and variable (more…) • Others…

  8. Page replacement policies Difficult Easy

  9. Resident set management policies • Choices: Fixed vs variable allocation and Local vs global scope • Working set size depends on the time t (can we measure this?) • Use page fault frequency changes as a trigger (how?)

  10. Linux • Three level page table • Clock algorithm with 8 bit age

  11. Page faults int main(intargc, char* argv[]) { intcnt, flt; char buffer[N*P]; structrusage usage; if(argc > 1) mlock(buffer, N*P); getrusage(RUSAGE_SELF, &usage); flt= usage.ru_minflt; for (cnt=0; cnt< N*P; cnt++) { buffer[cnt] = 0; getrusage(RUSAGE_SELF, &usage); if( flt!= usage.ru_minflt ) { flt= usage.ru_minflt; /* save cnt and flt to print later */ } } /* print table of cnt and flt */ } • gccGetrusage.c • ./a.out • ./a.outxx • cd /usr/include/bits/ • more resource.h • man mlock

  12. int main(intargc, char *argv[]) { void *src, *tgt; int in = open(argv[1], O_RDONLY); int out = open(argv[2], O_RDWR| O_CREAT|O_TRUNC, 0666); int flags = (argc > 3 ? MAP_PRIVATE : MAP_SHARED); size_tsz = lseek(in, 0, SEEK_END); lseek(out, sz - 1, SEEK_SET); write(out, "\0", 1); src = mmap(NULL, sz, PROT_READ, MAP_PRIVATE, in, 0); tgt = mmap(NULL, sz, PROT_WRITE, flags, out, 0); memcpy(tgt, src, sz); munmap(src, sz); munmap(tgt, sz); close(in); close(out); return 0; } Sharing • Output? • gccMmap.c • strace./a.outMmap.cFoo.c • ./a.outMmap.cBar.c xx • diffMmap.cFoo.c • diff Mmap.cBar.c • od –c Bar.c • man mmap

  13. Summary • Principles of locality and separation • Memory management necessary to match slow I/O to fast processor • Clean separation of logical from physical addresses • Every modern system has virtual memory

More Related