Memory Management william stallings, maurizio pizzonia - sistemi operativi

Similar documents
Memory Management. Memory Management

Memory Management. Memory Management Requirements

Lecture 7. Memory Management

Chapter 7 Memory Management

3. Memory Management

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

Requirements, Partitioning, paging, and segmentation

Requirements, Partitioning, paging, and segmentation

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

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

Paging, and segmentation

Memory Management. Memory Management

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

The Memory Management Unit. Operating Systems. Autumn CS4023

Administrivia. Deadlock Prevention Techniques. Handling Deadlock. Deadlock Avoidance

Last class: Today: Deadlocks. Memory Management

MEMORY MANAGEMENT/1 CS 409, FALL 2013

CIS Operating Systems Memory Management. Professor Qiang Zeng Fall 2017

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

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

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

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

Process. Memory Management

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

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

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

Background. Contiguous Memory Allocation

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

Heap Management portion of the store lives indefinitely until the program explicitly deletes it C++ and Java new Such objects are stored on a heap

Chapter 9 Real Memory Organization and Management

Chapter 9 Real Memory Organization and Management

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

UNIT III MEMORY MANAGEMENT

Preview. Memory Management

ECE 598 Advanced Operating Systems Lecture 10

CS399 New Beginnings. Jonathan Walpole

Chapter 8: Memory Management

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

CS420: Operating Systems

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

Main Memory (Part I)

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

Operating Systems Unit 6. Memory Management

6 - Main Memory EECE 315 (101) ECE UBC 2013 W2

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

Memory Management. Memory Management

Memory Management (1) Memory Management

Memory Management (1) Memory Management. CPU vs. memory. No.8. Prof. Hui Jiang Dept of Electrical Engineering and Computer Science, York University

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

Chapters 9 & 10: Memory Management and Virtual Memory

Operating Systems. Memory Management. Lecture 9 Michael O Boyle

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

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

Memory Management. Contents: Memory Management. How to generate code? Background

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

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

Chapter 9 Memory Management

Chapter 7: Main Memory. Operating System Concepts Essentials 8 th Edition

Virtual Memory. Chapter 8

12: Memory Management

Goals of Memory Management

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

CS307: Operating Systems

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

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

Chapter 8: Main Memory

Chapter 9: Memory Management. Background

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

Module 8: Memory Management

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

Chapter 8: Main Memory

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

Memory Management. Jo, Heeseung

Main Memory. CISC3595, Spring 2015 X. Zhang Fordham University

MEMORY MANAGEMENT. Jo, Heeseung

Memory Management. Dr. Yingwu Zhu

Memory Management. COMP755 Advanced Operating Systems

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

CSCI 4500 / 8506 Sample Questions for Quiz 5

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

CSE 421/521 - Operating Systems Fall Lecture - XII Main Memory Management. Tevfik Koşar. University at Buffalo. October 18 th, 2012.

CS6401- Operating System UNIT-III STORAGE MANAGEMENT

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

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

CS307 Operating Systems Main Memory

Memory Management. Frédéric Haziza Spring Department of Computer Systems Uppsala University

CS370 Operating Systems

Operating Systems, Fall

Operating Systems, Fall

Chapter 8 & Chapter 9 Main Memory & Virtual Memory

Computer Systems II. Memory Management" Subdividing memory to accommodate many processes. A program is loaded in main memory to be executed

Module 8: Memory Management

Operating Systems 2230

Main Memory Yi Shi Fall 2017 Xi an Jiaotong University

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

Memory Management. Dr. Yingwu Zhu

Chapter 8: Main Memory

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

Outlook. File-System Interface Allocation-Methods Free Space Management

Chapter 8: Memory Management Strategies

Transcription:

Memory Management 1

summary goals and requirements techniques that do not involve virtual memory 2

memory management tracking used and free memory primitives allocation of a certain amount of memory de-allocation of what allocated or garbage collectors, permit reuse of de-allocated memory memory used for... data structures (e.g. array, objects, ecc.) kernel data structures (allocator implemented in the kernel) process data structures (allocator implemented by language runtime libraries, e.g. C/C++ malloc) processes (within an O.S.) 3

memory management within the o.s. subdividing memory to accommodate multiple processes memory needs to be allocated to ensure a reasonable supply of ready processes to consume available processor time needs for memory is hardly know before running usually dynamically allocated to processes upon request (requires a complex management system) 4

summary and applicability many techniques and concepts in memory management equally apply to memory allocation for processes and for data fixed partitioning, dynamic compaction, fragmentation, placement algorithms, buddy system we talk about a process but it may be any kind of data hardware supported techinques apply only to processes virtual memory, paging, segmentation 5

memory management techniques that do not involves virtual memory 6

Fixed Partitioning Equal-size partitions Any process or data whose size is less than or equal to the partition size can be loaded into an available partition If all partitions are full, the operating system can swap a process out of a partition A process/data may not fit in a partition. For processes, the programmer must design the program with overlays still used in hard disk partitioning LVM overcome such limitation (linux) 7

Fixed Partitioning Main memory use is inefficient. Any program, no matter how small, occupies an entire partition. This is called internal fragmentation. 8

partitions size 9

Placement Algorithm with Equal-size partitions 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 it will fit into Queue for each partition Processes/data are assigned in such a way as to minimize wasted memory within a partition 10

Placement Algorithm with Partitions 11

dynamic partitioning and compaction Partitions are of variable length and number Process/data is allocated exactly as much memory as required Eventually get holes in the memory. This is called external fragmentation Must use compaction to shift processes so they are contiguous and all free memory is in one block in the general case compaction may be unfeasible (e.g. for C/C++ memory allocators) 12

external fragmentation 13

external fragmentation 14

Dynamic Partitioning Placement Algorithm Operating system must decide which free block to allocate to a process Best-fit algorithm Chooses the block that is closest in size to the request Worst performer overall since smallest block is found for process, the smallest amount of fragmentation is left Memory compaction must be done more often 15

Dynamic Partitioning Placement First-fit algorithm Algorithm Scans memory form the beginning and chooses the first available block that is large enough Fastest May have many process loaded in the front end of memory that must be searched over when trying to find a free block 16

Dynamic Partitioning Placement Algorithm Next-fit Scans memory from the location of the last placement More often allocate a block of memory at the end of memory where the largest block is found The largest block of memory is broken up into smaller blocks Compaction is required to obtain a large block at the end of memory 17

examples allocation of a block of 16MB 18

Buddy System simple but powerful allocator widely used in O.S. to allocate large chunks of fixed size e.g. 4KB pages in today architectures (x86_32) no fragmentation in this case it can be used as a base for a more fine grainded allocator which is called slab allocator in Linux and Sun Solaris and is used for kernel data structures 19

Buddy System entire space available is treated as a single block of 2 U a request of s bytes returns a block of ceil(log 2 s) bytes if a request of size s such that 2 i-1 < s <= 2 i, a block of length 2 i is allocated a 2 i block can be split into two equal buddies of 2 i-1 bytes for each request a big block is found and split until the smallest block greater than or equal to s is generated 20

Buddy System it maintains a lists L i (i=1..u) of unallocated blocks (holes) of size 2 i splitting: remove a hole from L i+1 split it, and put the two buddies it into L i coalescing: remove two unallocated buddies from L i and put it into L i+1 21

buddy system: example 22

procedure get_hole input: i (precondition: i U) output: a block c of size 2 i (postcondition: L i does not contain c) if ( L i is empty ) b= get_hole(i+1); < split b into two buddies b 1 and b 2 > < put b 1 and b 2 into L i > c= < first hole in L i > Buddy System <remove c form L i > return c 23

buddy system: tree representation 24

memory management requirements for processes relocation pointers to functions linked data structures 25

memory management requirements for processes relocation for processes 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 (relocated) memory references in the code must be translated to actual physical memory address relocation for data is hard data created by process, relocation performed by OS, need for a standard, never done 26

memory management requirements for processes protection processes should not be able to reference memory locations in another process without permission references must be checked at run time impossible to check memory references at compile time (may directly depend on the input) exercise: given a generic input and program prove that reference check is not computable! (reduce stopping problem to it) memory protection requirement must be satisfied by the processor (hardware) rather than the operating system (software) Operating system cannot anticipate all of the memory references a process will perform 27

memory management sharing requirements for processes allow several processes to access the same portion of memory better to allow each process access to the same copy of the program rather than have their own separate copy 28

memory management requirements for processes logical organization programs are written in modules sw engineering reasons: divide the responsibility for development, maintenance, testing, ecc modules can be written and compiled independently different degrees of protection given to modules (read-only, execute-only) share modules among processes 29

memory management requirements for processes physical organization memory available for a program plus its data may be insufficient overlaying allows various modules to be assigned the same region of memory programmer does not know how much memory will be available 30

relocation a process may occupy different partitions, which means different absolute memory locations when a program is loaded into memory the absolute memory locations are determined different execution may lead to different locations on-the-fly relocation during execution swap out and swap in compaction of allocated partitions 31

addresses in the program Physical The absolute address or actual location in main memory Logical Reference to a location in a logical memory independent of the current assignment of data to memory Translation must be made to the physical address by the hardware (MMU) Relative (logical or physical) Address expressed as a location relative to some known point 32

hardware support for relocation Base register Starting address for the process Bounds register Ending location of the process These values are set when the process is loaded or when the process is swapped in 33

hardware support for relocation The value of the base register is added to a relative address to produce an absolute address The resulting address is compared with the value in the bounds register If the address is not within bounds, an interrupt is generated to the operating system If the address is ok it is used to access memory relocation is performed by setting appropriate value in the registers 34

hardware support for relocation 35

Paging Partition memory into small equal fixed-size chunks and divide each process into the same size chunks The chunks of a process are called pages and chunks of memory are called frames Operating system maintains a page table for each process Contains the frame location for each page in the process Memory address consist of a page number and offset within the page 36

Assignment of Process Pages to Free Frames 37

Assignment of Process Pages to Free Frames 38

Page Tables 39

Segmentation All segments of all programs do not have to be of the same length There is a maximum segment length Addressing consist of two parts - a segment number and an offset Since segments are not equal, segmentation is similar to dynamic partitioning 40

paging vs. segmentation 41

logical to physical translation paging 42

logical to physical translation segmentation 43