Programs and Processes. The Virtual Address Space A typical process VAS space includes: user regions in the lower half V->P mappings specific to each.

Slides:



Advertisements
Similar presentations
Memory.
Advertisements

Part IV: Memory Management
Memory Management Chapter 7.
CS 153 Design of Operating Systems Spring 2015
CS 104 Introduction to Computer Science and Graphics Problems
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.
Memory Management Chapter 5.
CS 333 Introduction to Operating Systems Class 9 - Memory Management
MEMORY MANAGEMENT By KUNAL KADAKIA RISHIT SHAH. Memory Memory is a large array of words or bytes, each with its own address. It is a repository of quickly.
Memory Management CSE451 Andrew Whitaker. Big Picture Up till now, we’ve focused on how multiple programs share the CPU Now: how do multiple programs.
Operating System Chapter 7. Memory Management Lynn Choi School of Electrical Engineering.
Memory Management -1 Background Swapping Memory Management Schemes
Protection and the Kernel: Mode, Space, and Context.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-7 Memory Management (1) Department of Computer Science and Software.
SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally MEMORYMANAGEMNT.
1 Memory Management Memory Management COSC513 – Spring 2004 Student Name: Nan Qiao Student ID#: Professor: Dr. Morteza Anvari.
CS333 Intro to Operating Systems Jonathan Walpole.
Implementing Processes. Review: Threads vs. Processes 1. The process is a kernel abstraction for an independent executing program. includes at least one.
1 Chapter 3.2 : Virtual Memory What is virtual memory? What is virtual memory? Virtual memory management schemes Virtual memory management schemes Paging.
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming  To allocate scarce memory resources.
Chapter 8 – Main Memory (Pgs ). Overview  Everything to do with memory is complicated by the fact that more than 1 program can be in memory.
1 Address Translation Memory Allocation –Linked lists –Bit maps Options for managing memory –Base and Bound –Segmentation –Paging Paged page tables Inverted.
Chapter 4 Memory Management Virtual Memory.
1 Memory Management Chapter 7. 2 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable.
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming.  To allocate scarce memory.
Memory Management Operating Systems CS550. Memory Manager Memory manager - manages allocation and de-allocation of main memory Plays significant impact.
Paging (continued) & Caching CS-3013 A-term Paging (continued) & Caching CS-3013 Operating Systems A-term 2008 (Slides include materials from Modern.
Processes and Virtual Memory
CSC 360, Instructor Kui Wu Memory Management I: Main Memory.
Virtual Memory and Address Translation. Review: the Program and the Process VAS text dataidata wdata header symbol table relocation records program text.
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.
Memory Management Chapter 5 Advanced Operating System.
Virtual Memory 1 Computer Organization II © McQuain Virtual Memory Use main memory as a “cache” for secondary (disk) storage – Managed jointly.
Memory Management.
Requirements, Partitioning, paging, and segmentation
CSE 120 Principles of Operating
PA1 is out Best by Feb , 10:00 pm Enjoy early
Main Memory Management
Chapter 8: Main Memory.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy 11/12/2018.
Operating System Concepts
Lecture 14 Virtual Memory and the Alpha Memory Hierarchy
Memory Management 11/17/2018 A. Berrached:CS4315:UHD.
Segmentation Lecture November 2018.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 8 11/24/2018.
Background Program must be brought into memory and placed within a process for it to be run. Input queue – collection of processes on the disk that are.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 12/1/2018.
So far… Text RO …. printf() RW link printf Linking, loading
Memory Management-I 1.
Main Memory Background Swapping Contiguous Allocation Paging
CS399 New Beginnings Jonathan Walpole.
Lecture 3: Main Memory.
CSE 451: Operating Systems Autumn 2005 Memory Management
Operating System Chapter 7. Memory Management
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
Chapter 8: Memory Management strategies
CSE451 Virtual Memory Paging Autumn 2002
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 4/5/2019.
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
Lecture 7: Flexible Address Translation
Lecture 35 Syed Mansoor Sarwar
CS703 - Advanced Operating Systems
Virtual Memory Use main memory as a “cache” for secondary (disk) storage Managed jointly by CPU hardware and the operating system (OS) Programs share main.
COMP755 Advanced Operating Systems
Page Main Memory.
Presentation transcript:

Programs and Processes

The Virtual Address Space A typical process VAS space includes: user regions in the lower half V->P mappings specific to each process accessible to user or kernel code kernel regions in upper half shared by all processes accessible only to kernel code Nachos: process virtual address space includes only user portions. mappings change on each process switch text data BSS user stack args/env 0 data kernel text and kernel data 2 n-1 0x0 0xffffffff A VAS for a private address space system (e.g., Unix) executing on a typical 32-bit architecture.

The Program and the Process VAS text dataidata wdata header symbol table relocation records program text data BSS user stack args/env kernel u-area data sbrk() jsr process sections segments BSS “Block Started by Symbol” (uninitialized static data) May be removed after final link step and strip. Header “magic number” indicates type of image. Section table an array of (offset, len, startVA) Args/env copied in by kernel on exec.

Linking 101 text dataidata wdata header symbol table relocation records unresolved external text dataidata wdata header symbol table relocation records unresolved external text dataidata wdata header symbol table relocation records unresolved external text dataidata wdata header symbol table relocation records text dataidata wdata header symbol table relocation records link

Virtual Memory Illustrated text dataidata wdata header symbol table, etc. program sections text data BSS user stack args/env kernel data process segments physical page frames virtual memory (big) physical memory (small) executable file backing storage virtual-to-physical translations pageout/eviction page fetch

Nachos: A Peek Under the Hood data user space MIPS instructions executed by SPIM Nachos kernel SPIM MIPS emulator shell cp Machine object fetch/execute examine/deposit SaveState/RestoreState examine/deposit Machine::Run() ExceptionHandler() SP Rn PC registers memory page table process page tables

The User-Mode Context for Nachos text data BSS user stack args/env data PFN 0 PFN 1 PFN i page #i offset user virtual address PFN i + offset boolean Machine::Translate(uva, alignment, &kva) Translate user virtual address to a kernel memory address, checking access and alignment. SP Rn PC registers

Memory Management and Protection

Memory Management 101 Once upon a time...memory was called “core”, and programs (“jobs”) were loaded and executed one by one. load image in contiguous physical memory start execution at a known physical location allocate space in high memory for stack and data address text and data using physical addresses prelink executables for known start address run to completion

Memory and Multiprogramming One day, IBM decided to load multiple jobs in memory at once. improve utilization of that expensive CPU improve system throughput Problem 1: how do programs address their memory space? Problem 2: how does the OS protect memory from other programs?

Base and Bound Registers Goal: isolate jobs from one another, and from their placement in the machine memory. addresses are offsets from the job’s base address stored in a machine base register machine computes effective address on each reference initialized by OS when job is loaded machine checks each offset against job size placed by OS in a bound register

Base and Bound: Pros and Cons Pro: each job is physically contiguous simple hardware and software no need for load-time relocation of linked addresses OS may swap or move jobs as it sees fit Con: memory allocation is a royal pain job size is limited by available memory

Variable Partitioning Variable partitioning is the strategy of parking differently sized cars along a street with no marked parking space dividers. Wasted space from external fragmentation

Fixed Partitioning Wasted space from internal fragmentation

The Storage Allocation Problem fixed partitioning leads to internal fragmentation variable partitioning leads to external fragmentation which partition to choose? first fit, best fit, worst fit, next fit? these strategies don’t help much external fragmentation can be fixed by: compaction (e.g., copying garbage collection) coalescing (e.g., buddy system) these issues arise in heap managers e.g., runtime support for C++ new and delete

Managing Storage with Pages or Blocks Idea: allow noncontiguous allocation in fixed blocks. partition each (file, memory) into blocks of 2**N bytes partition storage into slots of size 2**N bytes blocks are often called logical blocks or pages slots are often called physical blocks or frames Paged allocation simplifies storage management: allocate a slot for each block independently slots are reusable and interchangeable no need to search for a “good” slot; any free one will do no external fragmentation; low internal fragmentation

Translating the Logical Address Space Problem: the system must locate the slot for each block on- the-fly as programs reference their data. Applications name data through a logical address space that isolates them from the details of how storage is allocated. Translate addresses indirectly through a logical-physical map. The map M is a function that maps a logical block number in the address space to a physical slot number in storage. slot_index = Map(logical_address >> N) Block offset (low-order N bits of the address) is unchanged. offset = logical_address & ((2**N) - 1) physical_address = (slot_index << N) + offset

Examples of Logical-to-Physical Maps 1. files: inode block map logical-physical map is part of the file metadata (inode) map grows dynamically; file’s byte length is stored in the inode the block map is stored on disk and cached in memory block size is a power-of-two multiple of the disk sector size 2. virtual memory: page tables virtual address = virtual page number + offset page table is a collection of page table entries (ptes) each valid pte maps a virtual page to a page frame number

Virtual Memory Illustrated text dataidata wdata header symbol table, etc. program sections text data BSS user stack args/env kernel data process segments physical page frames virtual memory (big) physical memory (small) executable file backing storage virtual-to-physical translations pageout/eviction page fetch

Virtual Address Translation VPNoffset Example: typical 32-bit architecture with 8KB pages. address translation Virtual address translation maps a virtual page number (VPN) to a physical page frame number (PFN): the rest is easy. PFN offset + 00 virtual address physical address { Deliver exception to OS if translation is not valid and accessible in requested mode.

Safe System Calls Kernel must validate arguments to system calls. scalar arguments must be valid values, e.g., syscall number, open file number buffer arguments [addr, addr+len-1] must be mapped in current space and accessible from user mode with requested permission string arguments must be null-terminated and [addr, addr+strlen(addr)-1] must be mapped and accessible with requested permission all arguments should be copied into the kernel so they cannot be modified by a different user thread after validation

Handling a System Call (Revisited) 1. Decode and validate by-value arguments. 2. Validate by-reference (pointer) IN arguments. Validate user pointers and copy into kernel memory with copyin. Kernel has access to user memory: syscall executes in process context with user space addresses mapped. 3. Call internal routines that implement the service. 4. Validate by-reference (pointer) OUT arguments. Copy into user memory with copyout. 5. Set up registers with return value(s); return to trap handler.

Nachos: A Peek Under the Hood data user space MIPS instructions executed by SPIM Nachos kernel SPIM MIPS emulator shell cp Machine object fetch/execute examine/deposit SaveState/RestoreState examine/deposit Machine::Run() ExceptionHandler() SP Rn PC registers memory page table process page tables

The User-Mode Context for Nachos text data BSS user stack args/env data PFN 0 PFN 1 PFN i page #i offset user virtual address PFN i + offset boolean Machine::Translate(uva, alignment, &kva) Translate user virtual address to a kernel memory address, checking access and alignment. SP Rn PC registers