Memory Management. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Size: px
Start display at page:

Download "Memory Management. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University"

Transcription

1 Memory Management Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

2 Topics Why is memory management difficult? Old memory management techniques: Fixed partitions Variable partitions Introduction to virtual memory 2

3 Memory Management (1) Goals To provide a convenient abstraction for programming. To allocate scarce memory resources among competing processes to maximize performance with minimal overhead. To provide isolation between processes. 3

4 Single/Batch Programming An OS with one user process 0xFFFF.. Programs use physical addresses directly. OS loads job, runs it, unloads it. User Program Operating System in ROM User Program Device Drivers in ROM User Program 0 Operating System in RAM Operating System in RAM 4

5 Multiprogramming (1) Example #include <stdio.h> int n = 0; int main () { printf ( &n = 0x%08x\n, &n); } %./a.out &n = 0x %./a.out &n = 0x What happens if two users simultaneously run this application? 5

6 Multiprogramming (2) Multiprogramming Need multiple processes in memory at once. To overlap I/O and CPU of multiple jobs Each process requires variable-sized and contiguous space. Requirements Protection: restrict which addresses processes can use. Fast translation: memory lookups must be fast, in spite of protection scheme. Fast context switching: updating memory hardware (for protection and translation) should be quick. 6

7 Fixed Partitions (1) Partition 4 0x5000 Base register 0x2000 Virtual address 0x x2362 Partition 3 Partition 2 Partition 1 Partition 0 Operating System 0x4000 0x3000 0x2000 0x

8 Fixed Partitions (2) Physical memory is broken up into fixed partitions Size of each partition is the same and fixed the number of partitions = degree of multiprogramming Hardware requirements: base register Physical address = virtual address + base register Base register loaded by OS when it switches to a process Advantages Easy to implement, fast context switch Problems Internal fragmentation: memory in a partition not used by a process is not available to other processes Partition size: one size does not fit all Fragmentation vs. fitting large programs 8

9 Fixed Partitions (3) Improvement Partition size need not be equal. Allocation strategies Maintain a separate queue for each partition size Maintain a single queue and allocate to the closest job whose size fits in an empty partition (first fit) Search the whole input queue and pick the largest job that fits in an empty partition (best fit) IBM OS/MFT (Multiprogramming with a Fixed number of Tasks) Partition 4 Partition 2 Partition 1 Partition 0 Operating System 0x8000 0x4000 0x2000 0x

10 Variable Partitions (1) Limit register P1 s Limit Base register P1 s Base Partition 3 Virtual address offset <? Yes + Partition 2 Partition 1 No protection fault Partition 0 Operating System 10

11 Variable Partitions (2) Physical memory is broken up into variable-sized partitions IBM OS/MVT Hardware requirements: base register and limit register Physical address = virtual address + base register Base register loaded by OS when it switches to a process The role of limit register: protection If (physical address > base + limit), then raise a protection fault. Allocation strategies First fit: Allocate the first hole that is big enough Best fit: Allocate the smallest hole that is big enough Worst fit: Allocate the largest hole 11

12 Variable Partitions (3) Advantages No internal fragmentation Simply allocate partition size to be just big enough for process But, if we break the physical memory into fixed-sized blocks and allocate memory in unit of block sizes (in order to reduce bookkeeping), we have internal fragmentation. Problems External fragmentation As we load and unload jobs, holes are left scattered throughout physical memory Solutions to external fragmentation: Compaction Paging and segmentation 12

13 Virtual Memory (1) Example #include <stdio.h> int n = 0; int main () { printf ( &n = 0x%08x\n, &n); } %./a.out &n = 0x %./a.out &n = 0x What happens if two users simultaneously run this application? 13

14 Virtual Memory (2) Virtual Memory (VM) Use virtual addresses for memory references. Large and contiguous CPU performs address translation at run time. Instructions executed by the CPU issue virtual addresses. Virtual addresses are translated by hardware into physical addresses (with help from OS). Virtual addresses are independent of the actual physical location of data referenced. OS determines location of data in physical memory 14

15 Virtual Memory (3) Virtual Memory (VM) Physical memory is dynamically allocated or released on demand. Programs execute without requiring their entire address space to be resident in physical memory. Lazy loading Virtual addresses are private to each process. Each process has its own isolated virtual address space. One process cannot name addresses visible to others. Many ways to translate virtual addresses into physical addresses 15

16 Virtual Memory (4) Advantages Separates user s logical memory from physical memory. Abstracts main memory into an extremely large, uniform array of storage. Frees programmers from the concerns of memory-storage limitations. Allows the execution of processes that may not be completely in memory. Programs can be larger than physical memory. More programs could be run at the same time. Less I/O would be needed to load or swap each user program into memory. Allows processes to easily share files and address spaces. Provides an efficient mechanism for protection and process creation. 16

17 Virtual Memory (5) Disadvantages Performance!!! In terms of time and space Implementation Paging Segmentation 17

18 Paging Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

19 Topics Virtual memory implementation Paging Demand paging Advanced VM techniques Shared memory Copy-on-write Memory-mapped files 19

20 Paging (1) Paging Permits the physical address space of a process to be noncontiguous. Divide physical memory into fixed-sized blocks called frames. Divide logical memory into blocks of same size called pages. Page (or frame) size is power of 2 (typically, 512B 8KB) To run a program of size n pages, need to find n free frames and load program. OS keeps track of all free frames. Set up a page table to translate virtual to physical addresses. 20

21 Paging (2) Physical memory Process B Virtual memory Page 3 Page 2 Frame 11 Frame 10 Frame 9 Page 1 Frame 8 Process A Page 0 Page 5 Page 4 Page tables Frame 7 Frame 6 Frame 5 Frame 4 Page 3 Frame 3 Page 2 Frame 2 Page 1 Frame 1 Page 0 Frame 0 21

22 Paging (3) User s perspective Users (and processes) view memory as one contiguous address space from 0 through N. Virtual address space (VAS) In reality, pages are scattered throughout the physical memory. Virtual-to-physical mapping This mapping is invisible to the program. Protection is provided because a program cannot reference memory outside of its VAS. The virtual address 0xdeadcafe maps to different physical addresses for different processes. 22

23 Paging (4) Logical to physical memory 23

24 Paging (5) Translating addresses A virtual address has two parts: <virtual page number (VPN)::offset> VPN is an index into a page table Page table determines page frame number (PFN) Physical address is <PFN::offset> Page tables Managed by OS Map VPN to PFN VPN is the index into the table that determines PFN One page table entry (PTE) per page in virtual address space, i.e. one PTE per VPN 24

25 Paging (6) Address translation hardware 25

26 Paging (7) Paging example Virtual address: 32 bits Physical address: 20 bits Page size: 4KB Offset: 12 bits VPN: 20 bits Page table entries: Virtual address (32bits) A F E VPN 2 7 D F E 4 6 A 4 Page tables PFN Offset 4 6 A F E Physical address (20bits) 26

27 Paging (8) Protection Memory protection is implemented by associating protection bit with each frame. Valid / Invalid bit Valid indicates that the associated page is in the process virtual address space, and is thus a legal page. Invalid indicates that the page is not in the process virtual address space. Finer level of protection is possible for valid pages. Provide read-only, read-write, or execute-only protection. 27

28 Paging (9) Page Table Entries (PTEs) V R M Prot Page Frame Number (PFN) Valid bit (V) says whether or not the PTE can be used. It is checked each time a virtual address is used. Reference bit (R) says whether the page has been accessed. It is set when a read or write to the page occurs. Modify bit (M) says whether or not the page is dirty. It is set when a write to the page occurs. Protection bits (Prot) control which operations are allowed on the page. Read, Write, Execute, etc. Page frame number (PFN) determines physical page. 28

29 Paging (10) Advantages Easy to allocate physical memory. Physical memory is allocated from free list of frames To allocate a frame, just remove it from its free list No external fragmentation. Easy to page out chunks of a program. All chunks are the same size (page size). Use valid bit to detect reference to paged-out pages. Page size is usually chosen to be convenient multiple of disk block sizes. Easy to protect pages from illegal accesses. Easy to share pages. 29

30 Paging (11) Disadvantages Can still have internal fragmentation Process may not use memory in exact multiple of pages. Memory reference overhead 2 references per address lookup (page table, then memory) Solution: get a hardware support (TLB) Memory required to hold page tables can be large Need one PTE per page in virtual address space 32-bit address space with 4KB pages = 2 20 PTEs 4 bytes/pte = 4MB per page table OS s typically have separate page tables per process (25 processes = 100MB of page tables) Solution: page the page tables, multi-level page tables, inverted page tables, etc. 30

31 Demand Paging (1) Demand paging Bring a page into memory only when it is needed. Less I/O needed Less memory needed Faster response More users OS uses main memory as a (page) cache of all of the data allocated by processes in the system. Initially, pages are allocated from physical memory frames. When physical memory fills up, allocating a page requires some other page to be evicted from its physical memory frame. Evicted pages go to disk (only need to write if they are dirty) To a swap file Movement of pages between memory/disks is done by the OS Transparent to the application 31

32 Demand Paging (2) Page faults What happens to a process that references a virtual address in a page that has been evicted? When the page was evicted, the OS sets the PTE as invalid and stores (in PTE) the location of the page in the swap file. When a process accesses the page, the invalid PTE will cause an exception (fault) The page fault handler (in kernel) is invoked by the fault. Handler uses invalid PTE to locate page in swap file. Handler reads page into a physical frame, updates PTE to point to it and to be valid. Handler restarts the faulted process. Where does the page that s read in go? Have to evict something else (page replacement algorithm) OS typically tries to keep a pool of free pages around so that allocations don t inevitably cause evictions. 32

33 Demand Paging (3) Handling a page fault 33

34 Demand Paging (4) Why does this work? Locality Temporal locality: locations referenced recently tend to be referenced again soon. Spatial locality: locations near recently referenced locations are likely to be referenced soon. Locality means paging can be infrequent. Once you ve paged something in, it will be used many times. On average, you use things that are paged in. But this depends on many things: - Degree of locality in application - Page replacement policy - Amount of physical memory - Application s reference pattern and memory footprint 34

35 Demand Paging (5) Why is this demand paging? When a process first starts up, it has a brand new page table, with all PTE valid bits false. No pages are yet mapped to physical memory. When the process starts executing: Instructions immediately fault on both code and data pages. Faults stop when all necessary code/data pages are in memory. Only the code/data that is needed (demanded!!) by process needs to be loaded. What is needed changes over time, of course 35

36 Advanced VM Functionality Virtual memory tricks Shared memory Copy on write Memory-mapped files 36

37 Shared Memory (1) Shared memory Private virtual address spaces protect applications from each other. But this makes it difficult to share data. Parents and children in a forking Web server or proxy will want to share an in-memory cache without copying. Read/Write (access to share data) Execute (shared libraries) We can use shared memory to allow processes to share data using direct memory reference. Both processes see updates to the shared memory segment. How are we going to coordinate access to shared data? 37

38 Shared Memory (2) Implementation How can we implement shared memory using page tables? Have PTEs in both tables map to the same physical frame. Each PTE can have different protection values. Must update both PTEs when page becomes invalid. Can map shared memory at same or different virtual addresses in each process address space Different: Flexible (no address space conflicts), but pointers inside the shared memory segment are invalid. Same: Less flexible, but shared pointers are valid. 38

39 Copy On Write (1) Process creation requires copying the entire address space of the parent process to the child process. Very slow and inefficient! Solution 1: Use threads Sharing address space is free. Solution 2: Use vfork() system call vfork() creates a process that shares the memory address space of its parent. To prevent the parent from overwriting data needed by the child, the parent s execution is blocked until the child exits or executes a new program. Any change by the child is visible to the parent once it resumes. Useful when the child immediately executes exec(). 39

40 Copy On Write (2) Solution 3: Copy On Write (COW) Instead of copying all pages, create shared mappings of parent pages in child address space. Shared pages are protected as read-only in child. Reads happen as usual Writes generate a protection fault, trap to OS, and OS copies the page, changes page mapping in client page table, restarts write instruction write Process fork Page table COW COW Physical memory copied child process 40

41 Memory-Mapped Files (1) Memory-mapped files Mapped files enable processes to do file I/O using memory references. Instead of open(), read(), write(), close() mmap(): bind a file to a virtual memory region PTEs map virtual addresses to physical frames holding file data <Virtual address base + N> refers to offset N in file Initially, all pages in mapped region marked as invalid. OS reads a page from file whenever invalid page is accessed. OS writes a page to file when evicted from physical memory. If page is not dirty, no write needed. 41

42 Memory-Mapped Files (2) Note: File is essentially backing store for that region of the virtual address space (instead of using the swap file). Virtual address space not backed by real files also called anonymous VM. Advantages Uniform access for files and memory (just use pointers) Less copying Several processes can map the same file allowing the pages in memory to be shared. Drawbacks Process has less control over data movement. Does not generalize to streamed I/O (pipes, sockets, etc.) 42

43 Address Translation Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

44 Topics How to reduce the size of page tables? How to reduce the time for address translation? 44

45 Page Tables Managing page tables Space overhead of page tables The size of the page table for a 32-bit address space with 4KB pages = 4MB (per process) How can we reduce this overhead? Observation: Only need to map the portion of the address space actually being used (tiny fraction of entire address space) How do we only map what is being used? Make the page table structure dynamically extensible Use another level of indirection:» Two-level, hierarchical, hashed, etc. 45

46 Two-level Page Tables (1) 46

47 Two-level Page Tables (2) Two-level page tables Virtual addresses have 3 parts: Master page # Secondary page # Offset Master page table: master page number à secondary page table. Secondary page table: secondary page number à page frame number. 47

48 Two-level Page Tables (3) Example 32-bit address space, 4KB pages, 4bytes/PTE Want master page table in one page Master page # Secondary page # Offset 12 Physical memory Page frame N Page frame Offset Physical address. Page frame 6 Page frame 5 Page frame 4 Page frame 3 Page frame 2 Page frame 1 Master page table Secondary page table Page frame 0 48

49 Multi-level Page Tables Address translation in Alpha AXP Architecture Three-level page tables 64-bit address divided into 3 segments (coded in bits63/62) seg0 (0x): user code seg1 (11): user stack kseg (10): kernel Alpha Page size: 8KB Virtual address: 43bits Each page table is one page long. 49

50 TLBs (1) Making address translation efficient Original page table scheme doubled the cost of memory lookups One lookup into the page table, another to fetch the data Two-level page tables triple the cost! Two lookups into the page tables, a third to fetch the data And this assumes the page table is in memory How can we make this more efficient? Goal: make fetching from a virtual address about as efficient as fetching from a physical address Solutions: - Cache the virtual-to-physical translation in hardware - Translation Lookaside Buffer (TLB) - TLB managed by the Memory Management Unit (MMU) 50

51 TLBs (2) Translation Lookaside Buffers Translate virtual page #s into PTEs (not physical address) Can be done in a single machine cycle 51

52 TLBs (3) TLB is implemented in hardware Fully associative cache (all entries looked up in parallel) Cache tags are virtual page numbers. Cache values are PTEs (entries from page tables). With PTE+offset, MMU can directly calculate the physical address. TLBs exploit locality Processes only use a handful of pages at a time entries in TLB is typical (64-192KB) Can hold the hot set or working set of process Hit rates are therefore really important. 52

53 TLBs (4) Address translation with TLB 53

54 TLBs (5) Handling TLB misses Address translations are mostly handled by the TLB > 99% of translations, but there are TLB misses occasionally In case of a miss, who places translations into the TLB? Hardware (MMU): Intel x86 Knows where page tables are in memory OS maintains tables, HW access them directly Page tables have to be in hardware-defined format Software loaded TLB (OS) TLB miss faults to OS, OS finds right PTE and loads TLB Must be fast (but, cycles typically) CPU ISA has instructions for TLB manipulation Page tables can be in any format convenient for OS (flexible) 54

55 TLBs (6) Managing TLBs OS ensures that TLB and page tables are consistent. When OS changes the protection bits of a PTE, it needs to invalidate the PTE if it is in the TLB. Reload TLB on a process context switch. Remember, each process typically has its own page tables. Need to invalidate all the entries in TLB. (flush TLB) In IA-32, TLB is flushed automatically when the contents of CR3 (page directory base register) is changed. (cf.) Alternatively, we can store the PID as part of the TLB entry, but this is expensive. When the TLB misses, and a new PTE is loaded, a cached PTE must be evicted. Choosing a victim PTE called the TLB replacement policy. Implemented in hardware, usually simple (e.g., LRU) 55

56 Memory Reference (1) Situation Process is executing on the CPU, and it issues a read to a (virtual) address. VA TLB TLB hit PA Memory page fault protection fault TLB miss Page tables data PTE 56

57 Memory Reference (2) The common case The read goes to the TLB in the MMU. TLB does a lookup using the page number of the address. The page number matches, returning a PTE. TLB validates that the PTE protection allows reads. PTE specifies which physical frame holds the page. MMU combines the physical frame and offset into a physical address. MMU then reads from that physical address, returns value to CPU. 57

58 Memory Reference (3) TLB misses: two possibilities (1) MMU loads PTE from page table in memory. Hardware managed TLB, OS not involved in this step. OS has already set up the page tables so that the hardware can access it directly. (2) Trap to the OS. Software managed TLB, OS intervenes at this point. OS does lookup in page tables, loads PTE into TLB. OS returns from exception, TLB continues. At this point, there is a valid PTE for the address in the TLB. 58

59 Memory Reference (4) TLB misses Page table lookup (by HW or OS) can cause a recursive fault if page table is paged out. Assuming page tables are in OS virtual address space. Not a problem if tables are in physical memory. When TLB has PTE, it restarts translation. Common case is that the PTE refers to a valid page in memory. Uncommon case is that TLB faults again on PTE because of PTE protection bits. (e.g., page is invalid) 59

60 Memory Reference (5) Page faults PTE can indicate a protection fault Read/Write/Execute operation not permitted on page Invalid virtual page not allocated, or page not in physical memory. TLB traps to the OS (software takes over) Read/Write/Execute OS usually will send fault back to the process, or might be playing tricks (e.g., copy on write, mapped files). Invalid (Not allocated) OS sends fault to the process (e.g., segmentation fault). Invalid (Not in physical memory) OS allocates a frame, reads from disk, and maps PTE to physical frame. 60

61 Page Replacement Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

62 Topics What if the physical memory becomes full? Page replacement algorithms How to manage memory among competing processes? 62

63 Page Replacement (1) Page replacement When a page fault occurs, the OS loads the faulted page from disk into a page frame of memory. At some point, the process has used all of the page frames it is allowed to use. When this happens, the OS must replace a page for each page faulted in. It must evict a page to free up a page frame. The page replacement algorithm determines how this is done. 63

64 Page Replacement (2) Evicting the best page The goal of the replacement algorithm is to reduce the fault rate by selecting the best victim page to remove. The best page to evict is the one never touched again. as process will never again fault on it. Never is a long time, so picking the page closest to never is the next best thing Belady s proof: Evicting the page that won t be used for the longest period of time minimizes the number of page faults. 64

65 Belady s Algorithm Optimal page replacement Replace the page that will not be used for the longest time in the future. Has the lowest fault rate for any page reference stream. Problem: have to predict the future Why is Belady s useful? Use it as a yardstick! Compare other algorithms with the optimal to gauge room for improvement. If optimal is not much better, then algorithm is pretty good, otherwise algorithm could use some work. Lower bound depends on workload, but random replacement is pretty bad. 65

66 FIFO (1) First-In First-Out Obvious and simple to implement Maintain a list of pages in order they were paged in On replacement, evict the one brought in longest time ago Why might this be good? Maybe the one brought in the longest ago is not being used. Why might this be bad? Maybe, it s not the case. We don t have any information either way. FIFO suffers from Belady s Anomaly The fault rate might increase when the algorithm is given more memory. 66

67 FIFO (2) Example: Belady s anomaly Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 3 frames: 9 faults frames: 10 faults

68 LRU (1) Least Recently Used LRU uses reference information to make a more informed replacement decision. Idea: past experience gives us a guess of future behavior. On replacement, evict the page that has not been used for the longest time in the past. LRU looks at the past, Belady s wants to look at future. Implementation Counter implementation: put a timestamp Stack implementation: maintain a stack Why do we need an approximation? 68

69 LRU (2) Approximating LRU Many LRU approximations use the PTE reference (R) bit. R bit is set whenever the page is referenced (read or written) Counter-based approach Keep a counter for each page. At regular intervals, for every page, do: - If R = 0, increment the counter (hasn t been used) - If R = 1, zero the counter (has been used) - Zero the R bit The counter will contain the number of intervals since the last reference to the page. The page with the largest counter is the least recently used. 69

70 Second Chance (1) Second chance or LRU clock FIFO with giving a second chance to a recently referenced page. Arrange all of physical page frames in a big circle (clock). A clock hand is used to select a good LRU candidate. Sweep through the pages in circular order like a clock If the R bit is off, it hasn t been used recently and we have a victim. If the R bit is on, turn it off and go to next page. Arm moves quickly when pages are needed. Low overhead if we have plenty of memory. If memory is large, accuracy of information degrades. 70

71 Second Chance (2) 71

72 Not Recently Used (1) NRU or enhanced second chance Use R (reference) and M (modify) bits Periodically, (e.g., on each clock interrupt), R is cleared, to distinguish pages that have not been referenced recently from those that have been. interrupt Read Read Class 0 R=0, M=0 Class 2 R=1, M=0 interrupt Paged-in Write Write Read Write Class 1 R=0, M=1 Class 3 R=1, M=1 interrupt interrupt Read Write 72

73 Not Recently Used (2) Algorithm Removes a page at random from the lowest numbered nonempty class. It is better to remove a modified page that has not been referenced in at least one clock tick than a clean page that is in heavy use. Used in Macintosh. Advantages Easy to understand. Moderately efficient to implement. Gives a performance that, while certainly not optimal, may be adequate. 73

74 LFU (1) Counting-based page replacement A software counter is associated with each page. At each clock interrupt, for each page, the R bit is added to the counter. The counters denote how often each page has been referenced. Least frequently used (LFU) The page with the smallest count will be replaced. (cf.) Most frequently used (MFU) page replacement The page with the largest count will be replaced Based on the argument that the page with the smallest count was probably just brought in and has yet to be used. It never forgets anything. A page may be heavily used during the initial phase of a process, but then is never used again 74

75 LFU (2) Aging The counters are shifted right by 1 bit before the R bit is added to the leftmost. 75

76 Allocation of Frames Problem In a multiprogramming system, we need a way to allocate physical memory to competing processes. What if a victim page belongs to another process? How to determine how much memory to give to each process? Fixed space algorithms Each process is given a limit of pages it can use. When it reaches its limit, it replaces from its own pages. Local replacement: some process may do well, others suffer. Variable space algorithms Processes set of pages grows and shrinks dynamically. Global replacement: one process can ruin it for the rest (Linux) 76

77 Thrashing (1) Thrashing What the OS does if page replacement algorithms fail. Most of the time is spent by an OS paging data back and forth from disk. No time is spent doing useful work. The system is overcommitted. No idea which pages should be in memory to reduce faults. Could be that there just isn t enough physical memory for all processes. Possible solutions Swapping write out all pages of a process Buy more memory. 77

78 Thrashing (2) 78

79 Working Set Model (1) Working set A working set of a process is used to model the dynamic locality of its memory usage. i.e., working set = set of pages process currently needs Peter Denning, Definition WS(t,w) = {pages P such that P was referenced in the time interval (t, t-w)} t: time, w: working set window size (measured in page references) A page is in the working set only if it was referenced in the last w references. 79

80 Working Set Model (2) Working set size (WSS) The number of pages in the working set = The number of pages referenced in the interval (t, t-w) The working set size changes with program locality. During periods of poor locality, more pages are referenced. Within that period of time, the working set size is larger. Intuitively, working set must be in memory to prevent heavy faulting (thrashing). 80

81 Working Sets and Page Fault Rates Direct relationship between working set of a process and its page-fault rate Working set changes over time Peaks and valleys over time 81

82 Summary (1) VM mechanisms Physical and virtual addressing Partitioning, Paging, Segmentation Page table management, TLBs, etc. VM policies Page replacement algorithms Memory allocation policies VM requires hardware and OS support MMU (Memory Management Unit) TLB (Translation Lookaside Buffer) Page tables, etc. 82

83 Summary (2) VM optimizations Demand paging (space) Managing page tables (space) Efficient translation using TLBs (time) Page replacement policy (time) Advanced functionality Sharing memory Copy on write Mapped files 83

PAGE REPLACEMENT. Operating Systems 2015 Spring by Euiseong Seo

PAGE REPLACEMENT. Operating Systems 2015 Spring by Euiseong Seo PAGE REPLACEMENT Operating Systems 2015 Spring by Euiseong Seo Today s Topics What if the physical memory becomes full? Page replacement algorithms How to manage memory among competing processes? Advanced

More information

Virtual Memory III. Jo, Heeseung

Virtual Memory III. Jo, Heeseung Virtual Memory III Jo, Heeseung Today's Topics What if the physical memory becomes full? Page replacement algorithms How to manage memory among competing processes? Advanced virtual memory techniques Shared

More information

Lecture 12: Demand Paging

Lecture 12: Demand Paging Lecture 1: Demand Paging CSE 10: Principles of Operating Systems Alex C. Snoeren HW 3 Due 11/9 Complete Address Translation We started this topic with the high-level problem of translating virtual addresses

More information

Paging. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Paging. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University Paging Jinkyu Jeong (jinkyu@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Today s Topics Virtual memory implementation Paging Segmentation 2 Paging (1) Paging Permits

More information

Address Translation. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Address Translation. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University Address Translation Jinkyu Jeong (jinkyu@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Today s Topics How to reduce the size of page tables? How to reduce the time for

More information

Virtual Memory I. Jo, Heeseung

Virtual Memory I. Jo, Heeseung Virtual Memory I Jo, Heeseung Today's Topics Virtual memory implementation Paging Segmentation 2 Paging Introduction Physical memory Process A Virtual memory Page 3 Page 2 Frame 11 Frame 10 Frame 9 4KB

More information

Paging. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Paging. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University Paging Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Today s Topics Virtual memory implementation Paging Segmentation 2 Paging (1) Paging Permits

More information

CS 153 Design of Operating Systems Winter 2016

CS 153 Design of Operating Systems Winter 2016 CS 153 Design of Operating Systems Winter 2016 Lecture 18: Page Replacement Terminology in Paging A virtual page corresponds to physical page/frame Segment should not be used anywhere Page out = Page eviction

More information

Operating Systems. Operating Systems Sina Meraji U of T

Operating Systems. Operating Systems Sina Meraji U of T Operating Systems Operating Systems Sina Meraji U of T Recap Last time we looked at memory management techniques Fixed partitioning Dynamic partitioning Paging Example Address Translation Suppose addresses

More information

CSE 120 Principles of Operating Systems

CSE 120 Principles of Operating Systems CSE 120 Principles of Operating Systems Fall 2016 Lecture 11: Page Replacement Geoffrey M. Voelker Administrivia Lab time This week: Thu 4pm, Sat 2pm Next week: Tue, Wed At Washington University in St.

More information

VIRTUAL MEMORY. Operating Systems 2015 Spring by Euiseong Seo

VIRTUAL MEMORY. Operating Systems 2015 Spring by Euiseong Seo VIRTUAL MEMORY Operating Systems 2015 Spring by Euiseong Seo Today s Topics Virtual memory implementation Paging Segmentation Paging Permits the physical address space of a process to be noncontiguous

More information

CSE 153 Design of Operating Systems

CSE 153 Design of Operating Systems CSE 153 Design of Operating Systems Winter 18 Lecture 18/19: Page Replacement Memory Management Memory management systems Physical and virtual addressing; address translation Techniques: Partitioning,

More information

Memory Management. Jo, Heeseung

Memory Management. Jo, Heeseung Memory Management Jo, Heeseung Today's Topics Why is memory management difficult? Old memory management techniques: Fixed partitions Variable partitions Swapping Introduction to virtual memory 2 Memory

More information

VIRTUAL MEMORY II. Jo, Heeseung

VIRTUAL MEMORY II. Jo, Heeseung VIRTUAL MEMORY II Jo, Heeseung TODAY'S TOPICS How to reduce the size of page tables? How to reduce the time for address translation? 2 PAGE TABLES Space overhead of page tables The size of the page table

More information

MEMORY MANAGEMENT. Jo, Heeseung

MEMORY MANAGEMENT. Jo, Heeseung MEMORY MANAGEMENT Jo, Heeseung TODAY'S TOPICS Why is memory management difficult? Old memory management techniques: Fixed partitions Variable partitions Swapping Introduction to virtual memory 2 MEMORY

More information

CSE 120 Principles of Operating Systems Spring 2017

CSE 120 Principles of Operating Systems Spring 2017 CSE 120 Principles of Operating Systems Spring 2017 Lecture 12: Paging Lecture Overview Today we ll cover more paging mechanisms: Optimizations Managing page tables (space) Efficient translations (TLBs)

More information

CSE 120 Principles of Operating Systems

CSE 120 Principles of Operating Systems CSE 120 Principles of Operating Systems Spring 2018 Lecture 10: Paging Geoffrey M. Voelker Lecture Overview Today we ll cover more paging mechanisms: Optimizations Managing page tables (space) Efficient

More information

Reminder: Mechanics of address translation. Paged virtual memory. Reminder: Page Table Entries (PTEs) Demand paging. Page faults

Reminder: Mechanics of address translation. Paged virtual memory. Reminder: Page Table Entries (PTEs) Demand paging. Page faults CSE 451: Operating Systems Autumn 2012 Module 12 Virtual Memory, Page Faults, Demand Paging, and Page Replacement Reminder: Mechanics of address translation virtual address virtual # offset table frame

More information

All Paging Schemes Depend on Locality. VM Page Replacement. Paging. Demand Paging

All Paging Schemes Depend on Locality. VM Page Replacement. Paging. Demand Paging 3/14/2001 1 All Paging Schemes Depend on Locality VM Page Replacement Emin Gun Sirer Processes tend to reference pages in localized patterns Temporal locality» locations referenced recently likely to be

More information

Paging. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Paging. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University Paging Jinkyu Jeong (jinkyu@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu SSE3044: Operating Systems, Fall 2016, Jinkyu Jeong (jinkyu@skku.edu) Paging Allows the physical

More information

Operating Systems Virtual Memory. Lecture 11 Michael O Boyle

Operating Systems Virtual Memory. Lecture 11 Michael O Boyle Operating Systems Virtual Memory Lecture 11 Michael O Boyle 1 Paged virtual memory Allows a larger logical address space than physical memory All pages of address space do not need to be in memory the

More information

Swapping. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Swapping. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University Swapping Jinkyu Jeong (jinkyu@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu EEE0: Introduction to Operating Systems, Fall 07, Jinkyu Jeong (jinkyu@skku.edu) Swapping

More information

CS 318 Principles of Operating Systems

CS 318 Principles of Operating Systems CS 318 Principles of Operating Systems Fall 2018 Lecture 10: Virtual Memory II Ryan Huang Slides adapted from Geoff Voelker s lectures Administrivia Next Tuesday project hacking day No class My office

More information

ECE 7650 Scalable and Secure Internet Services and Architecture ---- A Systems Perspective. Part I: Operating system overview: Memory Management

ECE 7650 Scalable and Secure Internet Services and Architecture ---- A Systems Perspective. Part I: Operating system overview: Memory Management ECE 7650 Scalable and Secure Internet Services and Architecture ---- A Systems Perspective Part I: Operating system overview: Memory Management 1 Hardware background The role of primary memory Program

More information

Memory Management Topics. CS 537 Lecture 11 Memory. Virtualizing Resources

Memory Management Topics. CS 537 Lecture 11 Memory. Virtualizing Resources Memory Management Topics CS 537 Lecture Memory Michael Swift Goals of memory management convenient abstraction for programming isolation between processes allocate scarce memory resources between competing

More information

Recap: Memory Management

Recap: Memory Management , 4/13/2018 EE445M/EE360L.12 Embedded and Real-Time Systems/ Real-Time Operating Systems : Memory Protection, Virtual Memory, Paging References: T. Anderson, M. Dahlin, Operating Systems: Principles and

More information

Basic Memory Management

Basic Memory Management Basic Memory Management CS 256/456 Dept. of Computer Science, University of Rochester 10/15/14 CSC 2/456 1 Basic Memory Management Program must be brought into memory and placed within a process for it

More information

CSE 120. Translation Lookaside Buffer (TLB) Implemented in Hardware. July 18, Day 5 Memory. Instructor: Neil Rhodes. Software TLB Management

CSE 120. Translation Lookaside Buffer (TLB) Implemented in Hardware. July 18, Day 5 Memory. Instructor: Neil Rhodes. Software TLB Management CSE 120 July 18, 2006 Day 5 Memory Instructor: Neil Rhodes Translation Lookaside Buffer (TLB) Implemented in Hardware Cache to map virtual page numbers to page frame Associative memory: HW looks up in

More information

Swapping. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Swapping. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University Swapping Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Swapping Support processes when not enough physical memory User program should be independent

More information

CS370 Operating Systems

CS370 Operating Systems CS370 Operating Systems Colorado State University Yashwant K Malaiya Spring 2018 L20 Virtual Memory Slides based on Text by Silberschatz, Galvin, Gagne Various sources 1 1 Questions from last time Page

More information

Virtual or Logical. Logical Addr. MMU (Memory Mgt. Unit) Physical. Addr. 1. (50 ns access)

Virtual or Logical. Logical Addr. MMU (Memory Mgt. Unit) Physical. Addr. 1. (50 ns access) Virtual Memory - programmer views memory as large address space without concerns about the amount of physical memory or memory management. (What do the terms 3-bit (or 6-bit) operating system or overlays

More information

MEMORY MANAGEMENT/1 CS 409, FALL 2013

MEMORY MANAGEMENT/1 CS 409, FALL 2013 MEMORY MANAGEMENT Requirements: Relocation (to different memory areas) Protection (run time, usually implemented together with relocation) Sharing (and also protection) Logical organization Physical organization

More information

Chapter 9: Virtual Memory

Chapter 9: Virtual Memory Chapter 9: Virtual Memory Silberschatz, Galvin and Gagne 2013 Chapter 9: Virtual Memory Background Demand Paging Copy-on-Write Page Replacement Allocation of Frames Thrashing Memory-Mapped Files Allocating

More information

CSE 451: Operating Systems Winter Page Table Management, TLBs and Other Pragmatics. Gary Kimura

CSE 451: Operating Systems Winter Page Table Management, TLBs and Other Pragmatics. Gary Kimura CSE 451: Operating Systems Winter 2013 Page Table Management, TLBs and Other Pragmatics Gary Kimura Moving now from Hardware to how the OS manages memory Two main areas to discuss Page table management,

More information

ADRIAN PERRIG & TORSTEN HOEFLER Networks and Operating Systems ( ) Chapter 6: Demand Paging

ADRIAN PERRIG & TORSTEN HOEFLER Networks and Operating Systems ( ) Chapter 6: Demand Paging ADRIAN PERRIG & TORSTEN HOEFLER Networks and Operating Systems (5-006-00) Chapter 6: Demand Paging http://redmine.replicant.us/projects/replicant/wiki/samsunggalaxybackdoor (0) # Inverted page table One

More information

Paging. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Paging. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University Paging Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Paging Allows the physical address space of a process to be noncontiguous Divide virtual

More information

Recall: Address Space Map. 13: Memory Management. Let s be reasonable. Processes Address Space. Send it to disk. Freeing up System Memory

Recall: Address Space Map. 13: Memory Management. Let s be reasonable. Processes Address Space. Send it to disk. Freeing up System Memory Recall: Address Space Map 13: Memory Management Biggest Virtual Address Stack (Space for local variables etc. For each nested procedure call) Sometimes Reserved for OS Stack Pointer Last Modified: 6/21/2004

More information

Virtual Memory Management

Virtual Memory Management Virtual Memory Management CS-3013 Operating Systems Hugh C. Lauer (Slides include materials from Slides include materials from Modern Operating Systems, 3 rd ed., by Andrew Tanenbaum and from Operating

More information

Chapter 8: Virtual Memory. Operating System Concepts Essentials 2 nd Edition

Chapter 8: Virtual Memory. Operating System Concepts Essentials 2 nd Edition Chapter 8: Virtual Memory Silberschatz, Galvin and Gagne 2013 Chapter 8: Virtual Memory Background Demand Paging Copy-on-Write Page Replacement Allocation of Frames Thrashing Memory-Mapped Files Allocating

More information

Chapter 4: Memory Management. Part 1: Mechanisms for Managing Memory

Chapter 4: Memory Management. Part 1: Mechanisms for Managing Memory Chapter 4: Memory Management Part 1: Mechanisms for Managing Memory Memory management Basic memory management Swapping Virtual memory Page replacement algorithms Modeling page replacement algorithms Design

More information

Chapter 8: Virtual Memory. Operating System Concepts

Chapter 8: Virtual Memory. Operating System Concepts Chapter 8: Virtual Memory Silberschatz, Galvin and Gagne 2009 Chapter 8: Virtual Memory Background Demand Paging Copy-on-Write Page Replacement Allocation of Frames Thrashing Memory-Mapped Files Allocating

More information

Address spaces and memory management

Address spaces and memory management Address spaces and memory management Review of processes Process = one or more threads in an address space Thread = stream of executing instructions Address space = memory space used by threads Address

More information

Virtual Memory. CSCI 315 Operating Systems Design Department of Computer Science

Virtual Memory. CSCI 315 Operating Systems Design Department of Computer Science Virtual Memory CSCI 315 Operating Systems Design Department of Computer Science Notice: The slides for this lecture have been largely based on those from an earlier edition of the course text Operating

More information

Chapters 9 & 10: Memory Management and Virtual Memory

Chapters 9 & 10: Memory Management and Virtual Memory Chapters 9 & 10: Memory Management and Virtual Memory Important concepts (for final, projects, papers) addressing: physical/absolute, logical/relative/virtual overlays swapping and paging memory protection

More information

Memory Management. To improve CPU utilization in a multiprogramming environment we need multiple programs in main memory at the same time.

Memory Management. To improve CPU utilization in a multiprogramming environment we need multiple programs in main memory at the same time. Memory Management To improve CPU utilization in a multiprogramming environment we need multiple programs in main memory at the same time. Basic CPUs and Physical Memory CPU cache Physical memory

More information

Memory management, part 2: outline

Memory management, part 2: outline Memory management, part 2: outline Page replacement algorithms Modeling PR algorithms o Working-set model and algorithms Virtual memory implementation issues 1 Page Replacement Algorithms Page fault forces

More information

Virtual Memory - II. Roadmap. Tevfik Koşar. CSE 421/521 - Operating Systems Fall Lecture - XVI. University at Buffalo.

Virtual Memory - II. Roadmap. Tevfik Koşar. CSE 421/521 - Operating Systems Fall Lecture - XVI. University at Buffalo. CSE 421/521 - Operating Systems Fall 2012 Lecture - XVI Virtual Memory - II Tevfik Koşar University at Buffalo October 25 th, 2012 1 Roadmap Virtual Memory Page Replacement Algorithms Optimal Algorithm

More information

Operating System Concepts

Operating System Concepts Chapter 9: Virtual-Memory Management 9.1 Silberschatz, Galvin and Gagne 2005 Chapter 9: Virtual Memory Background Demand Paging Copy-on-Write Page Replacement Allocation of Frames Thrashing Memory-Mapped

More information

How to create a process? What does process look like?

How to create a process? What does process look like? How to create a process? On Unix systems, executable read by loader Compile time runtime Ken Birman ld loader Cache Compiler: generates one object file per source file Linker: combines all object files

More information

Addresses in the source program are generally symbolic. A compiler will typically bind these symbolic addresses to re-locatable addresses.

Addresses in the source program are generally symbolic. A compiler will typically bind these symbolic addresses to re-locatable addresses. 1 Memory Management Address Binding The normal procedures is to select one of the processes in the input queue and to load that process into memory. As the process executed, it accesses instructions and

More information

Virtual Memory Outline

Virtual Memory Outline Virtual Memory Outline Background Demand Paging Copy-on-Write Page Replacement Allocation of Frames Thrashing Memory-Mapped Files Allocating Kernel Memory Other Considerations Operating-System Examples

More information

Basic Memory Management. Basic Memory Management. Address Binding. Running a user program. Operating Systems 10/14/2018 CSC 256/456 1

Basic Memory Management. Basic Memory Management. Address Binding. Running a user program. Operating Systems 10/14/2018 CSC 256/456 1 Basic Memory Management Program must be brought into memory and placed within a process for it to be run Basic Memory Management CS 256/456 Dept. of Computer Science, University of Rochester Mono-programming

More information

Chapter 6: Demand Paging

Chapter 6: Demand Paging ADRIAN PERRIG & TORSTEN HOEFLER ( 5-006-00 ) Networks and Operating Systems Chapter 6: Demand Paging Source: http://redmine.replicant.us/projects/replicant/wiki/samsunggalaxybackdoor If you miss a key

More information

Memory management, part 2: outline. Operating Systems, 2017, Danny Hendler and Amnon Meisels

Memory management, part 2: outline. Operating Systems, 2017, Danny Hendler and Amnon Meisels Memory management, part 2: outline 1 Page Replacement Algorithms Page fault forces choice o which page must be removed to make room for incoming page? Modified page must first be saved o unmodified just

More information

Chapter 9: Virtual Memory. Operating System Concepts 9 th Edition

Chapter 9: Virtual Memory. Operating System Concepts 9 th Edition Chapter 9: Virtual Memory Silberschatz, Galvin and Gagne 2013 Chapter 9: Virtual Memory Background Demand Paging Copy-on-Write Page Replacement Allocation of Frames Thrashing Memory-Mapped Files Allocating

More information

Course Outline. Processes CPU Scheduling Synchronization & Deadlock Memory Management File Systems & I/O Distributed Systems

Course Outline. Processes CPU Scheduling Synchronization & Deadlock Memory Management File Systems & I/O Distributed Systems Course Outline Processes CPU Scheduling Synchronization & Deadlock Memory Management File Systems & I/O Distributed Systems 1 Today: Memory Management Terminology Uniprogramming Multiprogramming Contiguous

More information

Page Tables. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Page Tables. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University Page Tables Jinkyu Jeong (jinkyu@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu EEE3052: Introduction to Operating Systems, Fall 2017, Jinkyu Jeong (jinkyu@skku.edu)

More information

OPERATING SYSTEM. Chapter 9: Virtual Memory

OPERATING SYSTEM. Chapter 9: Virtual Memory OPERATING SYSTEM Chapter 9: Virtual Memory Chapter 9: Virtual Memory Background Demand Paging Copy-on-Write Page Replacement Allocation of Frames Thrashing Memory-Mapped Files Allocating Kernel Memory

More information

CS 153 Design of Operating Systems Winter 2016

CS 153 Design of Operating Systems Winter 2016 CS 153 Design of Operating Systems Winter 2016 Lecture 17: Paging Lecture Overview Recap: Today: Goal of virtual memory management: map 2^32 byte address space to physical memory Internal fragmentation

More information

Virtual Memory Design and Implementation

Virtual Memory Design and Implementation Virtual Memory Design and Implementation To do q Page replacement algorithms q Design and implementation issues q Next: Last on virtualization VMMs Loading pages When should the OS load pages? On demand

More information

VIRTUAL MEMORY READING: CHAPTER 9

VIRTUAL MEMORY READING: CHAPTER 9 VIRTUAL MEMORY READING: CHAPTER 9 9 MEMORY HIERARCHY Core! Processor! Core! Caching! Main! Memory! (DRAM)!! Caching!! Secondary Storage (SSD)!!!! Secondary Storage (Disk)! L cache exclusive to a single

More information

Virtual Memory. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Virtual Memory. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University Virtual Memory Jinkyu Jeong (jinkyu@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu SSE3044: Operating Systems, Fall 2017, Jinkyu Jeong (jinkyu@skku.edu) Virtual Memory:

More information

CS 153 Design of Operating Systems Winter 2016

CS 153 Design of Operating Systems Winter 2016 CS 153 Design of Operating Systems Winter 2016 Lecture 16: Memory Management and Paging Announcement Homework 2 is out To be posted on ilearn today Due in a week (the end of Feb 19 th ). 2 Recap: Fixed

More information

Virtual Memory. Today.! Virtual memory! Page replacement algorithms! Modeling page replacement algorithms

Virtual Memory. Today.! Virtual memory! Page replacement algorithms! Modeling page replacement algorithms Virtual Memory Today! Virtual memory! Page replacement algorithms! Modeling page replacement algorithms Reminder: virtual memory with paging! Hide the complexity let the OS do the job! Virtual address

More information

Chapter 9: Virtual-Memory

Chapter 9: Virtual-Memory Chapter 9: Virtual-Memory Management Chapter 9: Virtual-Memory Management Background Demand Paging Page Replacement Allocation of Frames Thrashing Other Considerations Silberschatz, Galvin and Gagne 2013

More information

Operating Systems. Overview Virtual memory part 2. Page replacement algorithms. Lecture 7 Memory management 3: Virtual memory

Operating Systems. Overview Virtual memory part 2. Page replacement algorithms. Lecture 7 Memory management 3: Virtual memory Operating Systems Lecture 7 Memory management : Virtual memory Overview Virtual memory part Page replacement algorithms Frame allocation Thrashing Other considerations Memory over-allocation Efficient

More information

Goals of memory management

Goals of memory management CSE 451: Operating Systems Winter 2004 Module 10 Memory Management Ed Lazowska lazowska@cs.washington.edu Allen Center 570 Goals of memory management Allocate scarce memory resources among competing processes,

More information

Virtual Memory COMPSCI 386

Virtual Memory COMPSCI 386 Virtual Memory COMPSCI 386 Motivation An instruction to be executed must be in physical memory, but there may not be enough space for all ready processes. Typically the entire program is not needed. Exception

More information

Chapter 8. Virtual Memory

Chapter 8. Virtual Memory Operating System Chapter 8. Virtual Memory Lynn Choi School of Electrical Engineering Motivated by Memory Hierarchy Principles of Locality Speed vs. size vs. cost tradeoff Locality principle Spatial Locality:

More information

CISC 7310X. C08: Virtual Memory. Hui Chen Department of Computer & Information Science CUNY Brooklyn College. 3/22/2018 CUNY Brooklyn College

CISC 7310X. C08: Virtual Memory. Hui Chen Department of Computer & Information Science CUNY Brooklyn College. 3/22/2018 CUNY Brooklyn College CISC 7310X C08: Virtual Memory Hui Chen Department of Computer & Information Science CUNY Brooklyn College 3/22/2018 CUNY Brooklyn College 1 Outline Concepts of virtual address space, paging, virtual page,

More information

CS420: Operating Systems

CS420: Operating Systems Virtual Memory James Moscola Department of Physical Sciences York College of Pennsylvania Based on Operating System Concepts, 9th Edition by Silberschatz, Galvin, Gagne Background Code needs to be in memory

More information

Page Replacement Algorithms

Page Replacement Algorithms Page Replacement Algorithms MIN, OPT (optimal) RANDOM evict random page FIFO (first-in, first-out) give every page equal residency LRU (least-recently used) MRU (most-recently used) 1 9.1 Silberschatz,

More information

Memory Allocation. Copyright : University of Illinois CS 241 Staff 1

Memory Allocation. Copyright : University of Illinois CS 241 Staff 1 Memory Allocation Copyright : University of Illinois CS 241 Staff 1 Recap: Virtual Addresses A virtual address is a memory address that a process uses to access its own memory Virtual address actual physical

More information

CS450/550 Operating Systems

CS450/550 Operating Systems CS450/550 Operating Systems Lecture 4 memory Palden Lama Department of Computer Science CS450/550 Memory.1 Review: Summary of Chapter 3 Deadlocks and its modeling Deadlock detection Deadlock recovery Deadlock

More information

Move back and forth between memory and disk. Memory Hierarchy. Two Classes. Don t

Move back and forth between memory and disk. Memory Hierarchy. Two Classes. Don t Memory Management Ch. 3 Memory Hierarchy Cache RAM Disk Compromise between speed and cost. Hardware manages the cache. OS has to manage disk. Memory Manager Memory Hierarchy Cache CPU Main Swap Area Memory

More information

Memory Management Ch. 3

Memory Management Ch. 3 Memory Management Ch. 3 Ë ¾¾ Ì Ï ÒÒØ Å ÔÔ ÓÐÐ 1 Memory Hierarchy Cache RAM Disk Compromise between speed and cost. Hardware manages the cache. OS has to manage disk. Memory Manager Ë ¾¾ Ì Ï ÒÒØ Å ÔÔ ÓÐÐ

More information

Virtual Memory. ICS332 Operating Systems

Virtual Memory. ICS332 Operating Systems Virtual Memory ICS332 Operating Systems Virtual Memory Allow a process to execute while not completely in memory Part of the address space is kept on disk So far, we have assumed that the full address

More information

Chapter 9: Virtual Memory

Chapter 9: Virtual Memory Chapter 9: Virtual Memory Chapter 9: Virtual Memory 9.1 Background 9.2 Demand Paging 9.3 Copy-on-Write 9.4 Page Replacement 9.5 Allocation of Frames 9.6 Thrashing 9.7 Memory-Mapped Files 9.8 Allocating

More information

Chapter 4 Memory Management. Memory Management

Chapter 4 Memory Management. Memory Management Chapter 4 Memory Management 4.1 Basic memory management 4.2 Swapping 4.3 Virtual memory 4.4 Page replacement algorithms 4.5 Modeling page replacement algorithms 4.6 Design issues for paging systems 4.7

More information

Memory Management Cache Base and Limit Registers base limit Binding of Instructions and Data to Memory Compile time absolute code Load time

Memory Management Cache Base and Limit Registers base limit Binding of Instructions and Data to Memory Compile time absolute code Load time Memory Management To provide a detailed description of various ways of organizing memory hardware To discuss various memory-management techniques, including paging and segmentation To provide a detailed

More information

Chapter 8 Virtual Memory

Chapter 8 Virtual Memory Chapter 8 Virtual Memory Contents Hardware and control structures Operating system software Unix and Solaris memory management Linux memory management Windows 2000 memory management Characteristics of

More information

Memory Management Prof. James L. Frankel Harvard University

Memory Management Prof. James L. Frankel Harvard University Memory Management Prof. James L. Frankel Harvard University Version of 5:42 PM 25-Feb-2017 Copyright 2017, 2015 James L. Frankel. All rights reserved. Memory Management Ideal memory Large Fast Non-volatile

More information

CS6401- Operating System UNIT-III STORAGE MANAGEMENT

CS6401- Operating System UNIT-III STORAGE MANAGEMENT UNIT-III STORAGE MANAGEMENT Memory Management: Background In general, to rum a program, it must be brought into memory. Input queue collection of processes on the disk that are waiting to be brought into

More information

Chapter 8 & Chapter 9 Main Memory & Virtual Memory

Chapter 8 & Chapter 9 Main Memory & Virtual Memory Chapter 8 & Chapter 9 Main Memory & Virtual Memory 1. Various ways of organizing memory hardware. 2. Memory-management techniques: 1. Paging 2. Segmentation. Introduction Memory consists of a large array

More information

Page Replacement Chap 21, 22. Dongkun Shin, SKKU

Page Replacement Chap 21, 22. Dongkun Shin, SKKU Page Replacement Chap 21, 22 1 Virtual Memory Concept Virtual memory Concept A technique that allows the execution of processes that are not completely in memory Partition each user s program into multiple

More information

!! What is virtual memory and when is it useful? !! What is demand paging? !! When should pages in memory be replaced?

!! What is virtual memory and when is it useful? !! What is demand paging? !! When should pages in memory be replaced? Chapter 10: Virtual Memory Questions? CSCI [4 6] 730 Operating Systems Virtual Memory!! What is virtual memory and when is it useful?!! What is demand paging?!! When should pages in memory be replaced?!!

More information

Memory: Paging System

Memory: Paging System Memory: Paging System Instructor: Hengming Zou, Ph.D. In Pursuit of Absolute Simplicity 求于至简, 归于永恒 Content Paging Page table Multi-level translation Page replacement 2 Paging Allocate physical memory in

More information

CS307: Operating Systems

CS307: Operating Systems CS307: Operating Systems Chentao Wu 吴晨涛 Associate Professor Dept. of Computer Science and Engineering Shanghai Jiao Tong University SEIEE Building 3-513 wuct@cs.sjtu.edu.cn Download Lectures ftp://public.sjtu.edu.cn

More information

Virtual Memory. Overview: Virtual Memory. Virtual address space of a process. Virtual Memory. Demand Paging

Virtual Memory. Overview: Virtual Memory. Virtual address space of a process. Virtual Memory. Demand Paging TDDB68 Concurrent programming and operating systems Overview: Virtual Memory Virtual Memory [SGG7/8] Chapter 9 Background Demand Paging Page Replacement Allocation of Frames Thrashing and Data Access Locality

More information

Operating Systems CSE 410, Spring Virtual Memory. Stephen Wagner Michigan State University

Operating Systems CSE 410, Spring Virtual Memory. Stephen Wagner Michigan State University Operating Systems CSE 410, Spring 2004 Virtual Memory Stephen Wagner Michigan State University Virtual Memory Provide User an address space that is larger than main memory Secondary storage is used to

More information

Memory Management. Disclaimer: some slides are adopted from book authors slides with permission 1

Memory Management. Disclaimer: some slides are adopted from book authors slides with permission 1 Memory Management Disclaimer: some slides are adopted from book authors slides with permission 1 CPU management Roadmap Process, thread, synchronization, scheduling Memory management Virtual memory Disk

More information

Memory Management. Chapter 4 Memory Management. Multiprogramming with Fixed Partitions. Ideally programmers want memory that is.

Memory Management. Chapter 4 Memory Management. Multiprogramming with Fixed Partitions. Ideally programmers want memory that is. Chapter 4 Memory Management Ideally programmers want memory that is Memory Management large fast non volatile 4.1 Basic memory management 4.2 Swapping 4.3 Virtual memory 4.4 Page replacement algorithms

More information

CS370 Operating Systems

CS370 Operating Systems CS370 Operating Systems Colorado State University Yashwant K Malaiya Fall 2017 Lecture 23 Virtual memory Slides based on Text by Silberschatz, Galvin, Gagne Various sources 1 1 FAQ Is a page replaces when

More information

Memory Management Virtual Memory

Memory Management Virtual Memory Background; key issues Memory Management Virtual Memory Memory allocation schemes Virtual memory Memory management design and implementation issues 1 Remember Basic OS structures: intro in historical order

More information

Page Replacement. (and other virtual memory policies) Kevin Webb Swarthmore College March 27, 2018

Page Replacement. (and other virtual memory policies) Kevin Webb Swarthmore College March 27, 2018 Page Replacement (and other virtual memory policies) Kevin Webb Swarthmore College March 27, 2018 Today s Goals Making virtual memory virtual : incorporating disk backing. Explore page replacement policies

More information

Paging algorithms. CS 241 February 10, Copyright : University of Illinois CS 241 Staff 1

Paging algorithms. CS 241 February 10, Copyright : University of Illinois CS 241 Staff 1 Paging algorithms CS 241 February 10, 2012 Copyright : University of Illinois CS 241 Staff 1 Announcements MP2 due Tuesday Fabulous Prizes Wednesday! 2 Paging On heavily-loaded systems, memory can fill

More information

Operating Systems Lecture 6: Memory Management II

Operating Systems Lecture 6: Memory Management II CSCI-GA.2250-001 Operating Systems Lecture 6: Memory Management II Hubertus Franke frankeh@cims.nyu.edu What is the problem? Not enough memory Have enough memory is not possible with current technology

More information

Multi-Process Systems: Memory (2) Memory & paging structures: free frames. Memory & paging structures. Physical memory

Multi-Process Systems: Memory (2) Memory & paging structures: free frames. Memory & paging structures. Physical memory Multi-Process Systems: Memory (2) What we will learn A detailed description of various ways of organizing memory Discuss various memory-management techniques, including paging and segmentation To provide

More information

Chapter 4 Memory Management

Chapter 4 Memory Management Chapter 4 Memory Management 4.1 Basic memory management 4.2 Swapping 4.3 Virtual memory 4.4 Page replacement algorithms 4.5 Modeling page replacement algorithms 4.6 Design issues for paging systems 4.7

More information

Background. Demand Paging. valid-invalid bit. Tevfik Koşar. CSC Operating Systems Spring 2007

Background. Demand Paging. valid-invalid bit. Tevfik Koşar. CSC Operating Systems Spring 2007 CSC 0 - Operating Systems Spring 007 Lecture - XIII Virtual Memory Tevfik Koşar Background Virtual memory separation of user logical memory from physical memory. Only part of the program needs to be in

More information