PA0 due today Anyone tried to submit?. Scheduling Workload assumptions Arrive time, run time, I/O, etc. Policies: FIFO, SJF, STCF, RR, MLFQ, and lottery.

Slides:



Advertisements
Similar presentations
Memory.
Advertisements

Part IV: Memory Management
Chapter 6: Memory Management
CSS430 Memory Management Textbook Ch8
Memory Management Chapter 7.
Fixed/Variable Partitioning
Memory Management Chapter 7. Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated efficiently to pack as.
CS 311 – Lecture 21 Outline Memory management in UNIX
Memory Management Chapter 4. Memory hierarchy Programmers want a lot of fast, non- volatile memory But, here is what we have:
Memory Management Chapter 7. Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated efficiently to pack as.
Multiprocessing Memory Management
1 Memory Management Chapter 7. 2 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable.
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.
Silberschatz, Galvin and Gagne  Operating System Concepts Multistep Processing of a User Program User programs go through several steps before.
1 Lecture 8: Memory Mangement Operating System I Spring 2008.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 32 Paging Read Ch. 9.4.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-7 Memory Management (1) Department of Computer Science and Software.
Swapping and Contiguous Memory Allocation. Multistep Processing of a User Program User programs go through several steps before being run. Program components.
Memory Management Chapter 7.
CGS 3763 Operating Systems Concepts Spring 2013 Dan C. Marinescu Office: HEC 304 Office hours: M-Wd 11: :30 AM.
CIS250 OPERATING SYSTEMS Memory Management Since we share memory, we need to manage it Memory manager only sees the address A program counter value indicates.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 9: Memory Management Background Swapping Contiguous Allocation Paging Segmentation.
Memory Management. Roadmap Basic requirements of Memory Management Memory Partitioning Basic blocks of memory management –Paging –Segmentation.
1 Address Translation Memory Allocation –Linked lists –Bit maps Options for managing memory –Base and Bound –Segmentation –Paging Paged page tables Inverted.
CE Operating Systems Lecture 14 Memory management.
PA0 due 60 hours. Lecture 4 Memory Management OSTEP Virtualization CPU: illusion of private CPU RAM: illusion of private memory Concurrency Persistence.
Memory. Chapter 8: Memory Management Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation.
1 Memory Management Chapter 7. 2 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable.
1 Memory Management Chapter 7. 2 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable.
Main Memory. Chapter 8: Memory Management Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation Example: The.
Chapter 8: Main Memory. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 22, 2005 Memory and Addressing It all starts.
Memory Management Chapter 5 Advanced Operating System.
Memory management The main purpose of a computer system is to execute programs. These programs, together with the data they access, must be in main memory.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 8: Main Memory.
Chapter 8: Memory Management. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 8: Memory Management Background Swapping Contiguous.
Main Memory CSSE 332 Operating Systems Rose-Hulman Institute of Technology.
Memory Management Chapter 7.
Memory Management Chapter 7.
Memory Management.
Virtualization Virtualize hardware resources through abstraction CPU
Chien-Chung Shen CIS/UD
PA1 is out Best by Feb , 10:00 pm Enjoy early
Main Memory Management
Chapter 8: Main Memory.
Process management Information maintained by OS for process management
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy 11/12/2018.
Operating System Concepts
Lecture 6 Memory Management
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.
Multistep Processing of a User Program
PA0 is due in 12 hours PA1 will be out in 12 hours
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.
Chapter 8: Memory management
Outline Module 1 and 2 dealt with processes, scheduling and synchronization Next two modules will deal with memory and storage Processes require data to.
Lecture 3: Main Memory.
Chapter 8: Memory Management strategies
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 4/5/2019.
COMP755 Advanced Operating Systems
CSE 542: Operating Systems
Page Main Memory.
Presentation transcript:

PA0 due today Anyone tried to submit?

Scheduling Workload assumptions Arrive time, run time, I/O, etc. Policies: FIFO, SJF, STCF, RR, MLFQ, and lottery scheduling. Metrics: Turnaround time, response time Proportional-share

XINU Scheduling Policy enforced as a system-wide invariant At any time, the CPU must run the highest priority eligible process. Among processes with equal priority, scheduling is round robin Each process assigned a priority (in the prprio field) Non-negative integer value Initialized when process created Can be changed Scheduler chooses process with the highest priority Function resched makes the selection

Implementation Process eligible if state is ready or current To avoid searching process table Keep ready processes on a linked list called a ready list Order ready list by priority Selection in constant time The current process does not appear on the ready list Global integer currpid

int resched() { register struct pentry *optr; /* pointer to old process entry */ register struct pentry *nptr; /* pointer to new process entry */ /* no switch needed if current process priority higher than next*/ if ( ( (optr= &proctab[currpid])->pstate == PRCURR) && (lastkey(rdytail) pprio)) { return(OK); } /* force context switch */ if (optr->pstate == PRCURR) { optr->pstate = PRREADY; insert(currpid,rdyhead,optr->pprio); } /* remove highest priority process at end of ready list */ nptr = &proctab[ (currpid = getlast(rdytail)) ]; nptr->pstate = PRCURR; /* mark it currently running */ #ifdef RTCLOCK preempt = QUANTUM; /* reset preemption counter */ #endif ctxsw((int)&optr->pesp, (int)optr->pirmask, (int)&nptr->pesp, (int)nptr->pirmask); /* The OLD process returns here when resumed. */ return OK; }

What if all processes are idle? OS needs an extra process Called NULL process with ID zero and priority zero Never terminates Cannot make a system call that takes it out of ready or current state An infinite loop

Project 1 – Process Scheduling Revisit Xinu scheduling invariant: At any time, the CPU must run the highest priority eligible process. Among processes with equal priority, scheduling is round robin Problem with resched?

XINU Code to Read Read relevant source code in Xinu Process queue management h/q.h sys/queue.c sys/insert.c, … Proc. creation/suspension/resumption/termination: sys/create.c, sys/suspend.c sys/resume.c, sys/kill.c Priority change sys/chprio.c Process scheduling sys/resched.c Other code sys/initialize.c, sys/ready.c

Lecture 4 Memory Management

OSTEP Virtualization CPU: illusion of private CPU register RAM: illusion of private memory Concurrency Persistence

Early Systems Operating System (code, data, etc.) Current Program (code, data, etc.) 0KB 64KB max

Multiprogramming and Time Sharing We give the illusion of many virtual CPUs by saving CPU registers to memory when a process isn’t running We give the illusion of many virtual memories by saving memory to disk when a process isn’t running

Space Sharing Memory Operating System (code, data, etc.) (free) Process C (code, data, etc.) Process B (code, data, etc.) (free) Process A (code, data, etc.) (free)

The Abstraction The process address space a set of addresses that map to RAM cell private int x; int main(int argc, char *argv[]) { int y; int *z = malloc(1); } Code Data Heap (free) Stack 0KB 1KB 2KB 15KB 16KB

Demo Location of code: Location of data: Location of heap: Location of stack:

Memory Accesses _main: pushq %rbp … movl -0x14(%rbp), %r8d addl $0x1, %r8d movl %r8d, -0x14(%rbp) … x = x + 3; …

Memory Accesses %rip starts with 0x10 %rbp starts with 0x200 0x10 movl -0x14(%rbp), %r8d 0x14 addl $0x1, %r8d 0x17 movl %r8d, -0x14(%rbp) Fetch inst at 0x10 Exec inst, load from 0x186 Fetch inst at 0x14 Exec inst, no memory access Fetch inst at 0x17 Exec inst, store to 0x186

How to Run Multiple Processes Time Sharing Static Relocation Base Base+Bounds Segmentation

Static Relocation 0x10 movl -0x14(%rbp), %r8d 0x14 addl $0x1, %r8d 0x17 movl %r8d, -0x14(%rbp) Rewrite each program before loading it as a process 0x1010 movl -0x14(%rbp), %r8d 0x1014 addl $0x1, %r8d 0x1017 movl %r8d, -0x14(%rbp) 0x3010 movl -0x14(%rbp), %r8d 0x3014 addl $0x1, %r8d 0x3017 movl %r8d, -0x14(%rbp)

(free) code, data heap (free) stack (free) code, data heap (free) stack (free) 0KB 4KB 8KB 12KB 16KB 0x1010 movl -0x14(%rbp), %r8d 0x1014 addl $0x1, %r8d 0x1017 movl %r8d, -0x14(%rbp) 0x3010 movl -0x14(%rbp), %r8d 0x3014 addl $0x1, %r8d 0x3017 movl %r8d, -0x14(%rbp)

How to Run Multiple Processes Time Sharing Static Relocation Base Base+Bounds Segmentation

Base Idea: translate virtual addresses to physical by adding a fixed offset each time. Store offset in a base register. Each process has a different value in the base register when running. This is a “dynamic relocation” technique

(free) code, data heap (free) stack (free) code, data heap (free) stack (free) 0KB 1KB P1 2KB 4KB P2 5KB physical address = virtual address + base P1: load 100, R1 -> load 1124, R1 P2: load 100, R1 -> load 4196, R1 P2: load 1000, R1 -> load 5196, R1 P1: store R1, > store R1, 4096

Base+Bounds Memory Management Unit (MMU) Now with base and bounds registers Will add more into it Who should do translation with base register? (1) process, (2) OS, or (3) HW Who should modify the base register? (1) process, (2) OS, or (3) HW

(free) code, data heap (free) stack (free) code, data heap (free) stack (free) 0KB 1KB P1 2KB 4KB P2 5KB P1: load 100, R1 -> load 1124, R1 P2: load 100, R1 -> load 4196, R1 P2: load 1000, R1 -> load 5196, R1 P1: store R1, > store R1, 4096 interrupt OS! Problems? Internal fragmentation Virtual space size constraint

How to Run Multiple Processes Time Sharing Static Relocation Base Base+Bounds Segmentation

Idea: generalize base+bounds One base+bounds pair for each segment Requires more registers! Resize segments as needed How does this help?

Virtual Address Break virtual addresses into two parts one part indicates segment one part indicates offset within segment If an address has 14 bits, 2 for segment, 12 for offset 0: code+data 1: heap 2: stack

1 // get top 2 bits of 14-bit VA 2 Segment = (VirtualAddress & SEG_MASK) >> SEG_SHIFT 3 // now get offset 4 Offset = VirtualAddress & OFFSET_MASK 5 if (Offset >= Bounds[Segment]) 6 RaiseException(PROTECTION_FAULT) 7 else 8 PhysAddr = Base[Segment] + Offset 9 Register = AccessMemory(PhysAddr)

(free) heap (free) stack (free) 0KB 1KB 2KB 3KB 4KB 5KB Virtual 0x1010 0x1100 0x1400 Physical 1KB+16 1kB+256 Interrupt OS Segment Base Size Code Heap 1KB 1KB Stack

(free) heap (free) stack (free) 0KB 1KB 2KB 3KB 4KB 5KB Virtual 0x2C00 Physical 4KB Segment Base Size Positive? Code 1 Heap 1KB 1KB 1 Stack 5KB 1KB 0

Support for Code Sharing Idea: make base/bounds for the code of several processes point to the same physical mem Careful: need extra protection! Adding protection bits Segment Base Size Positive? Protection Code 1 Read-Execute Heap 1KB 1KB 1 Read-Write Stack 5KB 1KB 0 Read-Write

Space Management Multiple-partition allocation Free chunks are scattered throughout memory Allocate memory from a chunk able to accommodate it Maintains information about allocated and free regions Policies: First-fit: Allocate the first chunk that is big enough Best-fit: Allocate the smallest chunk that is big enough Worst-fit: Allocate the largest chunk; must also search entire list Next-fit: Allocate the second chunk that is big enough Segregated Lists, Buddy Allocation

Fragmentation External Fragmentation – total memory space exists to satisfy a request, but it is not contiguous Internal Fragmentation – allocated memory may be slightly larger than requested memory; this size difference is memory internal to a partition, but not being used Reduce external fragmentation by compaction Shuffle memory contents to place all free memory together in one large block Compaction is possible only if relocation is dynamic, and is done at execution time

Segmentation Pros? supports sparse address space code sharing fine grained protection Cons? external fragmentation Next: paging