CSCI 380: Operating Systems William Killian

Slides:



Advertisements
Similar presentations
May 7, A Real Problem  What if you wanted to run a program that needs more memory than you have?
Advertisements

1 A Real Problem  What if you wanted to run a program that needs more memory than you have?
Carnegie Mellon 1 Virtual Memory: Concepts : Introduction to Computer Systems 15 th Lecture, Oct. 14, 2010 Instructors: Randy Bryant and Dave O’Hallaron.
Memory Management (II)
Memory Management. 2 How to create a process? On Unix systems, executable read by loader Compiler: generates one object file per source file Linker: combines.
Chapter 3.2 : Virtual Memory
Memory Management 1 CS502 Spring 2006 Memory Management CS-502 Spring 2006.
CS-3013 & CS-502, Summer 2006 Memory Management1 CS-3013 & CS-502 Summer 2006.
Recitation 7 Greg Reshko Office Hours: Wed 2:00-3:00PM March 31 st, 2003.
Carnegie Mellon 1 Virtual Memory / : Introduction to Computer Systems 10 th Recitation, October 29th, 2012 Grant Skudlarek Section G.
Carnegie Mellon 1 Virtual Memory: Concepts / : Introduction to Computer Systems 16 th Lecture, Oct. 21, 2014 Instructors: Greg Ganger, Greg.
Virtual Memory: Concepts
Virtual & Dynamic Memory Management Summer 2014 COMP 2130 Intro Computer Systems Computing Science Thompson Rivers University.
1 Chapter 3.2 : Virtual Memory What is virtual memory? What is virtual memory? Virtual memory management schemes Virtual memory management schemes Paging.
1 Virtual Memory: Concepts Andrew Case Slides adapted from Jinyang Li, Randy Bryant and Dave O’Hallaron.
Virtual Memory 1 Chapter 13. Virtual Memory Introduction Demand Paging Hardware Requirements 4.3 BSD Virtual Memory 4.3 BSD Memory Management Operations.
CSE 351 Virtual Memory. Agenda Today … Review on VM Example problems on VM accesses.
Malloc & VM By sseshadr. Agenda Administration – Process lab code will be inked by Thursday (pick up in ECE hub) – Malloc due soon (Thursday, November.
1 Some Real Problem  What if a program needs more memory than the machine has? —even if individual programs fit in memory, how can we run multiple programs?
University of Amsterdam Computer Systems – virtual memory Arnoud Visser 1 Computer Systems Virtual Memory.
Recitation: Signaling S04, Recitation, Section A Debug Multiple Processes using GDB Debug Multiple Processes using GDB Dup2 Dup2 Signaling Signaling.
Virtual Memory.  Next in memory hierarchy  Motivations:  to remove programming burdens of a small, limited amount of main memory  to allow efficient.
Carnegie Mellon 1 Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Virtual Memory: Concepts Slides adapted from Bryant.
Virtual Memory : Introduction to Computer Systems Recitation 10: Oct. 28, 2013 Marjorie Carlson Recitation A.
Carnegie Mellon Introduction to Computer Systems / Spring 2009 March 23, 2009 Virtual Memory.
1 Virtual Memory (I). 2 Outline Physical and Virtual Addressing Address Spaces VM as a Tool for Caching VM as a Tool for Memory Management VM as a Tool.
Memory Management. 2 How to create a process? On Unix systems, executable read by loader Compiler: generates one object file per source file Linker: combines.
1 Virtual Memory. 2 Outline Case analysis –Pentium/Linux Memory System –Core i7 Suggested reading: 9.7.
A Real Problem What if you wanted to run a program that needs more memory than you have? September 11, 2018.
Virtual Memory: Systems
Today How was the midterm review? Lab4 due today.
Virtual Memory: Concepts CENG331 - Computer Organization
Virtual Memory.
CS 105 “Tour of the Black Holes of Computing!”
Virtual Memory : Introduction to Computer Systems Recitation 10: Nov. 2, 2015 Karthic Palaniappan.
Some Real Problem What if a program needs more memory than the machine has? even if individual programs fit in memory, how can we run multiple programs?
CSE 153 Design of Operating Systems Winter 2018
Paging and Segmentation
Virtual Memory: Systems /18-213/14-513/15-513: Introduction to Computer Systems 18th Lecture, October 25, 2018.
CS 105 “Tour of the Black Holes of Computing!”
Virtual Memory II CSE 351 Autumn 2016
CSE 153 Design of Operating Systems Winter 2018
Virtual Memory: Concepts /18-213/14-513/15-513: Introduction to Computer Systems 17th Lecture, October 23, 2018.
Virtual Memory: Systems
Virtual Memory: Systems
CS 105 “Tour of the Black Holes of Computing!”
CSE 351 Section 10 The END…Almost 3/7/12
Pentium/Linux Memory System
P6 (PentiumPro,II,III,Celeron) memory system
Virtual Memory CSCI 380: Operating Systems Lecture #7 -- Review and Lab Suggestions William Killian.
Instructors: Majd Sakr and Khaled Harras
Pentium III / Linux Memory System April 4, 2000
Virtual Memory.
Virtual Memory Nov 27, 2007 Slide Source:
Instructor: Phil Gibbons
IPC Prof. Ikjun Yeom TA – Hoyoun
Operating System Chapter 7. Memory Management
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
Virtual Memory Prof. Eric Rotenberg
Virtual Memory: Systems CSCI 380: Operating Systems
Virtual Memory II CSE 351 Winter 2018
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
CS 105 “Tour of the Black Holes of Computing!”
CS 105 “Tour of the Black Holes of Computing!”
CSE 153 Design of Operating Systems Winter 2019
CS703 - Advanced Operating Systems
CSE 153 Design of Operating Systems Winter 2019
Cache writes and examples
Instructor: Phil Gibbons
P6 (PentiumPro,II,III,Celeron) memory system
Presentation transcript:

CSCI 380: Operating Systems William Killian Virtual Memory CSCI 380: Operating Systems William Killian

I/O Basics Four basic operations: What’s a file descriptor? open close read write What’s a file descriptor? Returned by open. int fd = open(“/path/to/file”, O_RDONLY); fd is some positive value or -1 to denote error Every process starts with 3 open file descriptors that can be accessed macros like STDOUT_FILENO 0  - STDIN 1  - STDOUT 2  - STDERR

How the Unix Kernel Represents Open Files Two descriptors referencing two distinct open files. Descriptor 1 (stdout) points to terminal, and descriptor 4 points to open disk file Descriptor table [one table per process] Open file table [shared by all processes] v-node table [shared by all processes] File A (terminal) stdin fd 0 File access stdout fd 1 Info in stat struct File pos File size stderr fd 2 refcnt=1 File type fd 3 fd 4 ... ... File B (disk) File access File size File pos File type refcnt=1 ... ...

File Sharing Two distinct descriptors sharing the same disk file through two distinct open file table entries E.g., Calling open twice with the same filename argument Descriptor table [one table per process] Open file table [shared by all processes] v-node table [shared by all processes] File A (disk) stdin fd 0 File access stdout fd 1 File pos File size stderr fd 2 refcnt=1 File type fd 3 fd 4 ... ... File B (disk) File pos refcnt=1 ...

How Processes Share Files: fork A child process inherits its parent’s open files Note: situation unchanged by exec functions (use fcntl to change) Before fork call: Descriptor table [one table per process] Open file table [shared by all processes] v-node table [shared by all processes] File A (terminal) stdin fd 0 File access stdout fd 1 File pos File size stderr fd 2 refcnt=1 File type fd 3 fd 4 ... ... File B (disk) File access File size File pos File type refcnt=1 ... ...

How Processes Share Files: fork A child process inherits its parent’s open files After fork: Child’s table same as parent’s, and +1 to each refcnt Descriptor table [one table per process] Open file table [shared by all processes] v-node table [shared by all processes] Parent File A (terminal) fd 0 File access fd 1 File pos File size fd 2 refcnt=2 File type fd 3 fd 4 ... ... File B (disk) Child File access fd 0 File size fd 1 File pos fd 2 File type refcnt=2 fd 3 ... ... fd 4

I/O Redirection Question: How does a shell implement I/O redirection? linux> ls > foo.txt Answer: By calling the dup2(oldfd, newfd) function Copies (per-process) descriptor table entry oldfd to entry newfd Descriptor table before dup2(4,1) b fd 0 fd 1 fd 2 fd 3 fd 4 Descriptor table after dup2(4,1) a b fd 0 fd 1 fd 2 fd 3 fd 4

I/O Redirection Example Step #1: open file to which stdout should be redirected Happens in child executing shell code, before exec Descriptor table [one table per process] Open file table [shared by all processes] v-node table [shared by all processes] File A stdin fd 0 File access stdout fd 1 File pos File size stderr fd 2 refcnt=1 File type fd 3 fd 4 ... ... File pos refcnt=1 ... File access File size File type File B

I/O Redirection Example (cont.) Step #2: call dup2(4,1) cause fd=1 (stdout) to refer to disk file pointed at by fd=4 Descriptor table [one table per process] Open file table [shared by all processes] v-node table [shared by all processes] File A stdin fd 0 File access stdout fd 1 File pos File size stderr fd 2 refcnt=0 File type fd 3 fd 4 ... ... File B File access File size File pos File type refcnt=2 ... ...

Malloc Lab Sneak Preview You will write your own dynamic storage allocator – i.e., your own malloc, free, realloc, calloc. This week in class, you will learn about different ways to keep track of free and allocated blocks of memory. Implicit linked list of blocks. Explicit linked list of free blocks. Segregated lists of different size free blocks. Other design decisions: How will you look for free blocks? (First fit, next fit, best fit…) Should the linked lists be doubly linked? When do you coalesce blocks? This is exactly what you’ll do in this lab, so pay lots of attention in class. 

Malloc Lab Sneak Preview If you haven’t been using version control so far, this is a good time to start. Workflow: Implement indirect linked lists. Make sure it works. Implement explicit linked lists. Make sure it still works. Implement segregated lists. Make sure it still works. You WILL break things and need to revert. Barebones guide to using git: git init starts a local repository. git add foo.c adds foo.c to that repository. git commit -a –m ‘Describe changes here’ updates your repository with the current state of all files you’ve added.

Agenda Shell Lab FAQs Malloc Lab Sneak Preview Virtual Memory Concepts Address Translation

Virtual Memory Concepts Unused Kernel virtual memory Memory-mapped region for shared libraries Run-time heap (created by malloc) User stack (created at runtime) %esp (stack pointer) Memory invisible to user code brk 0xC0000000 0x08048000 0x40000000 Read/write segment (.data, .bss) Read-only segment (.init, .text, .rodata) Loaded from the executable file We’ve been viewing memory as a linear array. But wait! If you’re running 5 processes with stacks at 0xC0000000, don’t their addresses conflict? Nope! Each process has its own address space. How???

Virtual memory concepts We define a mapping from the virtual address used by the process to the actual physical address of the data in memory. Image: http://en.wikipedia.org/wiki/File:Virtual_address_space_and_physical_address_space_relationship.svg

Virtual memory concepts This explains why two different processes can use the same address. It also lets them share data and protects their data from illegal accesses. Hooray for virtual memory! N-1 M-1 Virtual Address Space for Process 1: Physical Address Space (DRAM) (e.g., read-only library code) Virtual Address Space for Process 2: VP 1 VP 2 ... PP 2 PP 6 PP 8 translation

Virtual memory concepts Page table Lets us look up the physical address corresponding to any virtual address. (Array of physical addresses, indexed by virtual address.) TLB (Translation Lookaside Buffer) A special tiny cache just for page table entries. Speeds up translation. Multi-level page tables The address space is often sparse. Use page directory to map large chunks of memory to a page table. Mark large unmapped regions as non-present in page directory instead of storing page tables full of invalid entries.

Agenda Shell Lab FAQs Malloc Lab Sneak Preview Virtual Memory Concepts Address Translation

VM Address Translation Virtual Address Space V = {0, 1, …, N–1} There are N possible virtual addresses. Virtual addresses are n bits long; 2n = N. Physical Address Space P = {0, 1, …, M–1} There are M possible physical addresses. Virtual addresses are m bits long; 2m = M. Memory is grouped into “pages.” Page size is P bytes. The address offset is p bytes; 2p = P. Since the virtual offset (VPO) and physical offset (PPO) are the same, the offset doesn’t need to be translated.

VM Address Translation Virtual address n-1 p p-1 Page table base register (PTBR) Virtual page number (VPN) Virtual page offset (VPO) Page table address for process Page table Valid Physical page number (PPN) Valid bit = 0: page not in memory (page fault) m-1 p p-1 Physical page number (PPN) Physical page offset (PPO) Physical address

VM Address Translation Addressing 14-bit virtual addresses 12-bit physical address Page size = 64 bytes 13 12 11 10 9 8 7 6 5 4 3 2 1 VPN VPO Virtual Page Number Virtual Page Offset 11 10 9 8 7 6 5 4 3 2 1 PPN PPO Physical Page Number Physical Page Offset

Example: Address Translation Pages are 64 bytes. How many bits is the offset? Find 0x03D4. VPN: _____ PPN: ______ Physical address: ___________ 13 12 11 10 9 8 7 6 5 4 3 2 1 VPO VPN 1 0D 0F 11 0E 2D – 0C 0B 09 0A 17 13 08 Valid PPN VPN 07 06 16 05 04 02 03 33 01 28 00 PPO PPN

Example: Address Translation Pages are 64 bytes. How many bits is the offset? Find 0x03D4. VPN: _____ PPN: ______ Physical address: ___________ log2 64 = 6 13 12 11 10 9 8 7 6 5 4 3 2 1 1 1 1 VPO VPN 1 0D 0F 11 0E 2D – 0C 0B 09 0A 17 13 08 Valid PPN VPN 07 06 16 05 04 02 03 33 01 28 00 0x0F 0x0D 0x0354 1 1 PPO PPN