Requirements, Partitioning, paging, and segmentation

Similar documents
Requirements, Partitioning, paging, and segmentation

Memory Management. Memory Management

Memory Management. Memory Management Requirements

Paging, and segmentation

Memory Management william stallings, maurizio pizzonia - sistemi operativi

Lecture 7. Memory Management

Memory Management. Reading: Silberschatz chapter 9 Reading: Stallings. chapter 7 EEL 358

Chapter 7 Memory Management

3. Memory Management

Memory Management. Memory Management

CIS Operating Systems Contiguous Memory Allocation. Professor Qiang Zeng Spring 2018

6. Which of the following operating systems was the predecessor of Microsoft MS-DOS? a. Dynix b. Minix c. CP/M

Process. Memory Management

Process. One or more threads of execution Resources required for execution. Memory (RAM) Others

12: Memory Management

CIS Operating Systems Memory Management. Professor Qiang Zeng Fall 2017

Process. One or more threads of execution Resources required for execution. Memory (RAM) Others

Chapter 9 Real Memory Organization and Management

Chapter 9 Real Memory Organization and Management

Process. One or more threads of execution Resources required for execution

File Systems. OS Overview I/O. Swap. Management. Operations CPU. Hard Drive. Management. Memory. Hard Drive. CSI3131 Topics. Structure.

Memory: Overview. CS439: Principles of Computer Systems February 26, 2018

Performance of Various Levels of Storage. Movement between levels of storage hierarchy can be explicit or implicit

CSCI 4500 / 8506 Sample Questions for Quiz 5

Preview. Memory Management

Operating Systems: Internals and Design Principles. Chapter 7 Memory Management Seventh Edition William Stallings

COMPUTER SCIENCE 4500 OPERATING SYSTEMS

UNIT III MEMORY MANAGEMENT

Memory management. Knut Omang Ifi/Oracle 10 Oct, 2012

CS Operating Systems

CS Operating Systems

Memory Management. Dr. Yingwu Zhu

General Objective:To understand the basic memory management of operating system. Specific Objectives: At the end of the unit you should be able to:

Administrivia. Deadlock Prevention Techniques. Handling Deadlock. Deadlock Avoidance

ECE 598 Advanced Operating Systems Lecture 10

MEMORY MANAGEMENT/1 CS 409, FALL 2013

Main Memory. Electrical and Computer Engineering Stephen Kim ECE/IUPUI RTOS & APPS 1

Main Memory (Part I)

Operating Systems Memory Management. Mathieu Delalandre University of Tours, Tours city, France

Memory Management Basics

Chapter 8: Memory Management. Operating System Concepts with Java 8 th Edition

CS420: Operating Systems

CS399 New Beginnings. Jonathan Walpole

Background. Contiguous Memory Allocation

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

Part II: Memory Management. Chapter 7: Physical Memory Chapter 8: Virtual Memory Chapter 9: Sharing Data and Code in Main Memory

Operating systems. Part 1. Module 11 Main memory introduction. Tami Sorgente 1

Memory Management. q Basic memory management q Swapping q Kernel memory allocation q Next Time: Virtual memory

Chapter 8: Memory Management. Background Swapping Contiguous Allocation Paging Segmentation Segmentation with Paging

Operating Systems. Memory Management. Lecture 9 Michael O Boyle

Operating Systems and Computer Networks. Memory Management. Dr.-Ing. Pascal A. Klein

CSE325 Principles of Operating Systems. Memory. David P. Duggan. March 6, 2010

Operating Systems (2INC0) 2017/18

Memory management. Requirements. Relocation: program loading. Terms. Relocation. Protection. Sharing. Logical organization. Physical organization

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

Chapter 8: Memory- Management Strategies. Operating System Concepts 9 th Edition

Last Class: Deadlocks. Where we are in the course

Module 8: Memory Management

Module 9: Memory Management. Background. Binding of Instructions and Data to Memory

Memory Management. Dr. Yingwu Zhu

Memory Management. To do. q Basic memory management q Swapping q Kernel memory allocation q Next Time: Virtual memory

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

CS370 Operating Systems

The Memory Management Unit. Operating Systems. Autumn CS4023

Chapter 8: Memory Management

Memory and multiprogramming

Chapter 9 Memory Management

Memory Management. CSE 2431: Introduction to Operating Systems Reading: , [OSC]

Basic Memory Management

Memory management: outline

Memory management: outline

8: Memory Management

Chapter 9: Memory Management. Background

CIS Operating Systems Non-contiguous Memory Allocation. Professor Qiang Zeng Spring 2018

! What is main memory? ! What is static and dynamic allocation? ! What is segmentation? Maria Hybinette, UGA. High Address (0x7fffffff) !

Memory Management. Today. Next Time. Basic memory management Swapping Kernel memory allocation. Virtual memory

In multiprogramming systems, processes share a common store. Processes need space for:

8.1 Background. Part Four - Memory Management. Chapter 8: Memory-Management Management Strategies. Chapter 8: Memory Management

Operating Systems Unit 6. Memory Management

Module 8: Memory Management

Part Three - Memory Management. Chapter 8: Memory-Management Strategies

Memory Management. Memory Management

Logical versus Physical Address Space

OPERATING SYSTEMS. After A.S.Tanenbaum, Modern Operating Systems 3rd edition Uses content with permission from Assoc. Prof. Florin Fortis, PhD

Chapters 9 & 10: Memory Management and Virtual Memory

Chapter 9 Memory Management Main Memory Operating system concepts. Sixth Edition. Silberschatz, Galvin, and Gagne 8.1

Roadmap. Tevfik Koşar. CSC Operating Systems Spring Lecture - XII Main Memory - II. Louisiana State University

I.-C. Lin, Assistant Professor. Textbook: Operating System Principles 7ed CHAPTER 8: MEMORY

CS 31: Intro to Systems Virtual Memory. Kevin Webb Swarthmore College November 15, 2018

MEMORY MANAGEMENT: Real Storage. Unit IV

Chapter 8: Memory- Management Strategies. Operating System Concepts 9 th Edition

Chapter 8: Memory- Management Strategies

I.-C. Lin, Assistant Professor. Textbook: Operating System Concepts 8ed CHAPTER 8: MEMORY

Chapter 8: Main Memory

Classifying Information Stored in Memory! Memory Management in a Uniprogrammed System! Segments of a Process! Processing a User Program!

Memory management. Last modified: Adaptation of Silberschatz, Galvin, Gagne slides for the textbook Applied Operating Systems Concepts

Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation

Outlook. Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation Example: The Intel Pentium

CS6401- Operating System UNIT-III STORAGE MANAGEMENT

Chapter 8 & Chapter 9 Main Memory & Virtual Memory

Transcription:

Requirements, Partitioning, paging, and segmentation

Main Memory: The Big Picture kernel memory proc struct kernel stack/u area Stack kernel stack/u area Stack kernel stack/u area Stack Data Text (shared) Data Text (shared) Data Text (shared) 2

Memory Management Main memory holds The kernel Processes that are running, ready, or blocked Memory management Efficient and effective allocation of main memory to processes Performed by the operating system with support from the hardware 3

Requirements Relocation Protection Sharing Logical organization Physical organization 4

Relocation Why/What: Programmer does not know where the program will be placed in memory when it is executed While the program is executing, it may be swapped to disk and returned to main memory at a different location Consequences/Constraints: Memory references must be translated in the code to actual physical memory address 5

Protection Why/What: Protect process from interference by other processes Processes require permission to access memory in another processes address space. Consequences/Constraints: Impossible to check addresses at compile/link time since the program could be relocated Must be checked at run time 6

Sharing Allow several processes to access the same data Allow multiple process to share the same program text rather than have their own separate copy 7

Logical Organization Programs organized into modules stack, text, uninitialized data, or logical modules such as libraries, objects, etc. Code modules may be compiled independently Different degrees of protection given to modules read-only, execute-only Share modules 8

Unix Process Memory Layout Low Address Text Initialized Data Uninitialized Data (BSS) Heap Read from program file by exec Zeroed by exec High Address Stack argv[ ], env[ ] 9

Physical Organization Memory organized into two levels: main and secondary memory. Memory available for a program plus its data may be insufficient Overlaying allows various modules to be assigned the same region of memory Main memory relatively fast, expensive and volatile Secondary memory relatively slow, cheaper, larger capacity, and non-volatile 10

Hardware Support How to partition memory How to keep track of which partition belongs to which process How to prevent a process from accessing a partition that has not been allocated to it 11

Section 7.1 Assumptions Processes are never partially in memory Processes are stored contiguously 12

Memory Partitioning Virtual Memory Segmentation and/or Paging Non-Virtual memory approaches Partitioning - Fixed and Dynamic simple Paging simple Segmentation 13

Fixed Partitioning Partition available memory into regions with fixed boundaries Equal-size partitions Process size <= partition size can be loaded into available partition If all partitions are full, the operating system can swap a process out of a partition If program size > partition size, then programmer must use overlays 14

Fixed Partitioning - Equal Size Main memory use is inefficient Internal Fragmentation - Part of partition unused Operating System 8 M 8 M process 1 Unused 8 M 8 M 3 M 8 M 15

Fixed partitioning - unequal sizes Lessens the problem of Internal Fragmentation Operating System 8 M 2 M process 1 6 M 8 M 3 M 8 M 12 M 16

Fixed partition: placement algorithm Equal-size partitions because all partitions are of equal size, it does not matter which partition is used Unequal-size partitions can assign each process to the smallest partition within which it will fit queue for each partition processes are assigned in such a way as to minimize wasted memory within a partition 17

One Process Queue per partition Operating System New Processes 18

One Process Queue for all partitions Operating System New Processes 19

Pros and cons of fixed partitioning Pros: Fixed partitioning is simple and very little OS support is required. Cons: Since number of partitions is fixed, it limits the degree of multi-programming It is inefficient with small processes. If the sizes of processes is known beforehand then a reasonable size can be decided on. 20

Dynamic Partitioning Partitions are created dynamically Partitions are of variable size and number Partition sizes are determined based on requests Disadvantages: External Fragmentation - small holes in memory between allocated partitions Placement is more complicated - Must use compaction to shift processes so they are contiguous and all free memory is in one block 21

Example Dynamic Partitioning 22

Dynamic partition: placement alg. Operating system must decide which free block to allocate to a process Best-fit algorithm Chooses block that is closest in size to the request Results in minimally sized fragments requiring compaction Worst performer overall 23

Dynamic partition: placement alg. First-fit algorithm Starts scanning from beginning and choose first available block that is large enough. May have many process loaded in the front end of memory Fastest Best 24

Dynamic partition: placement alg. Next-fit Scan memory from the location of the last allocation and chooses the next available block that is large enough More often allocate a block of memory at the end of memory where the largest block is found Compaction is required to obtain a large block at the end of memory Compaction is more frequent 25

8K alloc 16K block 8K 12K First Fit 12K Last allocated block (14K) 22K 18K Best Fit 6K 2K 8K 6K 8K 6K Allocated block 14K Free block Next Fit 14K 36K Before 20K After 26

Buddy System Fixed and dynamic partitioning have their drawbacks Fixed partitioning Limits number of active processes Uses space inefficiently if the sizes of the processes don t match with that of the partitions Dynamic partitioning More complex to maintain Includes overhead of compaction 27

Buddy System Entire space available is treated as a single block of size 2 U If a request for a block of size s such that 2 U-1 < s <= 2 U Allocated entire block Otherwise Split block into two equal buddies Continues until smallest block greater than or equal to s becomes available requests rounded to power of two 28

Buddy System Advantages: coalesces adjacent buffers Disadvantage: performance (recursive coalescing is expensive) poor api 29

Buddy System Allocation Begin with one large block Suppose we want a block of size 16 256 128 64 32 16 8 4 2 1 30

Buddy System Allocation Begin with one large block Recursively subdivide 256 128 64 32 16 8 4 2 1 31

Buddy System Allocation Begin with one large block Recursively subdivide 256 128 64 32 16 8 4 2 1 32

Buddy System Allocation Begin with one large block Recursively subdivide 256 128 64 32 16 8 4 2 1 33

Buddy System Allocation Begin with one large block Yield 2 blocks size 16 256 128 64 32 16 8 4 2 1 34

Buddy System Allocation Begin with one large block Yield 2 blocks size 16 One of those blocks can be given to the program 256 128 64 32 16 8 4 2 1 35

Deallocation and Coalescing 256 128 64 32 16 8 4 2 1 36

Deallocation and Coalescing When a block becomes free, it tries to rejoin its buddy A bit in its buddy tells whether the buddy is free If so, they can glue together and make a block twice as big 256 128 64 32 16 8 4 2 1 37

Deallocation and Coalescing 256 128 64 32 16 8 4 2 1 38

Deallocation and Coalescing 256 128 64 32 16 8 4 2 1 39

Deallocation and Coalescing 256 128 64 32 16 8 4 2 1 40

Deallocation and Coalescing Coalescing strategies: Prompt at the point of deallocation (right away) Delayed wait until it s necessary (at allocation) Thorough coalesce the entire heap Demand coalesce only to satisfy an allocation request 256 128 64 32 16 8 4 2 1 41

Relocation Absolute or physical memory addresses are Based on the partitions into which the process is loaded Determined when A process is first loaded A process is reloaded after being swapped out Compaction occurs Not knowable at compile or link time Executable files use logical or relocatable addresses Relative addresses are one example of logical addresses Logical addresses must be translated to physical addresses at run time 42

Hardware Support for Relocation Relative address Base Register Process Control Block Adder Program Bounds Register Comparator Absolute address Interrupt to operating system Data Stack Process image in main memory 43

Registers Used during Execution Assigned when a process enters the running state Base register starting address for the process Bounds register ending location of the process (where do the values come from?) Translate from relative addresses to physical addresses Base register is added to each relative address to produce absolute address If absolute address exceeds bounds register, an interrupt is generated to the operating system 44

Assumptions Sections 7.3 and 7.4 Processes are (still) never partially in memory Processes are not necessarily stored contiguously 45

Simple Paging Partition memory into equally sized pieces Pieces of memory are called frames Partition each process into frame-sized pieces Pieces of a process are called pages Pages are loaded in frames when process is loaded Not necessarily contiguous! No external fragmentation Internal fragmentation limited to last page Operating system maintains a page table for each process Contains an entry for each process page specifying the frame into which the page is loaded (when and how is the page table created?) Physical address = frame number * frame size + offset 46

47 0 1 2 3 4 5 6 7 A.0 A.1 B.0 B.1 A.0 A.1 C.0 B.0 B.1 A.0 A.1 C.0 A.0 A.1 C.0 A.0 A.1 D.0 D.1 D.2 D.3 0 1 2 3 2 3 5 6 Process D Page Table 7 Free Frame List 0 1 2 3 4 5 6 7 Memory frames

Address Translation in Paging To make it efficient, the page (frame) size is a power of 2 Given a (page #, offset), find (frame #, offset) 2 n > number of pages => n bits to hold the page number 2 k > number of frames => k bits to hold the frame number 2 m = number of bytes in a page => m bits to determine the offset within a page Logical address is concatenation nm Physical address is concatenation km where k is the frame corresponding to page n (obtained from the page table) 48

Address Translation in Paging Page # (n bits) Offset (m bit) 0 0 0 0 0 1 0 1 1 1 0 1 1 1 1 0 Process Page Table: 0 1 2 0 1 0 0 1 0 0 1 0 0 1 1 0 1 0 1 0 1... Frame # (k bits) 0 1 0 0 1 1 0 1 1 1 0 1 1 1 1 0 Physical Address 49

Address translation e.g. Main memory Frame # Physical address Value 0 0 E 0 1 F Page # Logical Address Value 0 2 G 0 3 H 0 0 A 0 1 B 0 2 C 0 3 D 1 4 E 1 5 F 1 6 G Page # Frame # 0 2 1 0 2 5 3 4 Page table 1 4? 1 5? 1 6? 1 7? 2 8 A 2 9 B 2 10 C 2 11 D 3 12? 1 7 H 3 13? 2 8 I 2 9 J 3 14? 3 15? 4 16 M 2 10 K 4 17 N 2 11 L 4 18 O 3 12 M 3 13 N 4 19 P 5 20 I 5 21 J 3 14 O 3 15 P Process 5 22 K 5 23 L 50

Segmentation Partition each process logical parts Pieces of a process are called segments For example, text segment, data segment, stack segment Segments are loaded in memory when process is loaded Not necessarily contiguous No internal fragmentation External fragmentation is a concern OS maintains a segment table for each process Contains an entry for each segment specifying the starting and ending addresses (when and how is the segment table created?) Physical address = starting address + offset 51

Address translation in segmentation Segment # Offset 0 0 0 1 0 0 1 0 1 1 1 1 0 0 0 0 Process Segment Table: 0 001011101110 0000010000000000 1 011110011110 0010000000100000 + Length Base Address 0 0 1 0 0 0 1 1 0 0 0 1 0 0 0 0 Physical Address 52