Lecture 7 Page 1 CS 111 Summer 2013 Another Option Fixed partition allocations result in internal fragmentation – Processes don’t use all of the fixed.

Slides:



Advertisements
Similar presentations
Memory.
Advertisements

Part IV: Memory Management
Chapter 6: Memory Management
Memory Management Chapter 7.
Memory Management Chapter 7. Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated efficiently to pack as.
Chapter 7 Memory Management
Chapter 7 Memory Management Operating Systems: Internals and Design Principles, 6/E William Stallings Dave Bremer Otago Polytechnic, N.Z. ©2009, Prentice.
CS 311 – Lecture 21 Outline Memory management in UNIX
Operating System Support Focus on Architecture
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 2010.
Chapter 8 Operating System Support
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.
Chapter 3.7 Memory and I/O Systems. 2 Memory Management Only applies to languages with explicit memory management (C or C++) Memory problems are one of.
Computer Organization and Architecture
1 Lecture 8: Memory Mangement Operating System I Spring 2008.
CS364 CH08 Operating System Support TECH Computer Science Operating System Overview Scheduling Memory Management Pentium II and PowerPC Memory Management.
Layers and Views of a Computer System Operating System Services Program creation Program execution Access to I/O devices Controlled access to files System.
Operating System Chapter 7. Memory Management Lynn Choi School of Electrical Engineering.
Review of Memory Management, Virtual Memory CS448.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-7 Memory Management (1) Department of Computer Science and Software.
Chapter 7 Memory Management
Lecture 7 Page 1 CS 111 Summer 2015 Memory Management CS 111 Operating System Principles Peter Reiher.
Chapter 3.5 Memory and I/O Systems. 2 Memory Management Memory problems are one of the leading causes of bugs in programs (60-80%) MUCH worse in languages.
Cosc 2150: Computer Organization Chapter 6, Part 2 Virtual Memory.
Operating Systems Memory management. Memory Management List of Topics 1. Memory Management 2. Memory In Systems Design 3. Binding Times 4. Introduction.
Memory Management – Page 1 of 49CSCI 4717 – Computer Architecture Memory Management Uni-program – memory split into two parts –One for Operating System.
Memory Management. Roadmap Basic requirements of Memory Management Memory Partitioning Basic blocks of memory management –Paging –Segmentation.
Lecture 11 Page 1 CS 111 Online Memory Management: Paging and Virtual Memory CS 111 On-Line MS Program Operating Systems Peter Reiher.
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.
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.
1 Memory Management Chapter 7. 2 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable.
Lecture 10 Page 1 CS 111 Online Another Option Fixed partition allocations result in internal fragmentation – Processes don’t use all of the fixed partition.
Lecture 10 Page 1 CS 111 Summer 2013 File Systems Control Structures A file is a named collection of information Primary roles of file system: – To store.
CS6502 Operating Systems - Dr. J. Garrido Memory Management – Part 1 Class Will Start Momentarily… Lecture 8b CS6502 Operating Systems Dr. Jose M. Garrido.
Lecture 10 Page 1 CS 111 Spring 2015 Memory Management CS 111 Operating Systems Peter Reiher.
Lecture 10 Page 1 CS 111 Fall 2015 Memory Management CS 111 Operating Systems Peter Reiher.
Lecture 7 Page 1 CS 111 Summer 2013 Dynamic Domain Allocation A concept covered in a previous lecture We’ll just review it here Domains are regions of.
COMP091 – Operating Systems 1 Memory Management. Memory Management Terms Physical address –Actual address as seen by memory unit Logical address –Address.
Chapter 7 Memory Management Eighth Edition William Stallings Operating Systems: Internals and Design Principles.
Memory Management Chapter 5 Advanced Operating System.
Lecture 10 Page 1 CS 111 Online Memory Management CS 111 On-Line MS Program Operating Systems Peter Reiher.
Lecture 12 Page 1 CS 111 Winter 2014 Memory Management CS 111 Operating Systems Peter Reiher.
Memory Management Chapter 7.
Chapter 7 Memory Management
Outline What is memory management about? Memory management strategies:
Memory Management Chapter 7.
Memory Management.
Outline Paging Swapping and demand paging Virtual memory.
Dynamic Domain Allocation
William Stallings Computer Organization and Architecture
CSI 400/500 Operating Systems Spring 2009
Chapter 8: Main Memory.
Operating System Concepts
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.
Main Memory Background Swapping Contiguous Allocation Paging
Lecture 3: Main Memory.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 4/5/2019.
Lecture 35 Syed Mansoor Sarwar
COMP755 Advanced Operating Systems
Presentation transcript:

Lecture 7 Page 1 CS 111 Summer 2013 Another Option Fixed partition allocations result in internal fragmentation – Processes don’t use all of the fixed partition Dynamic domain allocations result in external fragmentation – The elements on the memory free list get smaller and less useful Can we strike a balance in between?

Lecture 7 Page 2 CS 111 Summer 2013 A Special Case for Fixed Allocations frequency 4K K Internal fragmentation results from mismatches between chunk sizes and request sizes (which we have assumed to be randomly distributed). But if we look at what actually happens, it turns out that memory allocation requests aren’t random at all.

Lecture 7 Page 3 CS 111 Summer 2013 Why Aren’t Memory Request Sizes Randomly Distributed? In real systems, some sizes are requested much more often than others Many key services use fixed-size buffers – File systems (for disk I/O) – Network protocols (for packet assembly) – Standard request descriptors These account for much transient use – They are continuously allocated and freed OS might want to handle them specially

Lecture 7 Page 4 CS 111 Summer 2013 Buffer Pools If there are popular sizes, – Reserve special pools of fixed size buffers – Satisfy matching requests from those pools Benefit: improved efficiency – Much simpler than variable domain allocation Eliminates searching, carving, coalescing – Reduces (or eliminates) external fragmentation But we must know how much to reserve – Too little, and the buffer pool will become a bottleneck – Too much, and we will have a lot of unused buffer space Only satisfy perfectly matching requests – Otherwise, back to internal fragmentation

Lecture 7 Page 5 CS 111 Summer 2013 How Are Buffer Pools Used? Process requests a piece of memory for a special purpose – E.g., to send a message System supplies one element from buffer pool Process uses it, completes, frees memory – Maybe explicitly – Maybe implicitly, based on how such buffers are used E.g., sending the message will free the buffer “behind the process’ back” once the message is gone

Lecture 7 Page 6 CS 111 Summer 2013 Dynamically Sizing Buffer Pools If we run low on fixed sized buffers – Get more memory from the free list – Carve it up into more fixed sized buffers If our free buffer list gets too large – Return some buffers to the free list If the free list gets dangerously low – Ask each major service with a buffer pool to return space This can be tuned by a few parameters: – Low space (need more) threshold – High space (have too much) threshold – Nominal allocation (what we free down to) Resulting system is highly adaptive to changing loads

Lecture 7 Page 7 CS 111 Summer 2013 Lost Memory One problem with buffer pools is memory leaks – The process is done with the memory – But doesn’t free it Also a problem when a process manages its own memory space – E.g., it allocates a big area and maintains its own free list Long running processes with memory leaks can waste huge amounts of memory

Lecture 7 Page 8 CS 111 Summer 2013 Garbage Collection One solution to memory leaks Don’t count on processes to release memory Monitor how much free memory we’ve got When we run low, start garbage collection – Search data space finding every object pointer – Note address/size of all accessible objects – Compute the compliment (what is inaccessible) – Add all inaccessible memory to the free list

Lecture 7 Page 9 CS 111 Summer 2013 How Do We Find All Accessible Memory? Object oriented languages often enable this – All object references are tagged – All object descriptors include size information It is often possible for system resources – Where all possible references are known (E.g., we know who has which files open) How about for the general case?

Lecture 7 Page 10 CS 111 Summer 2013 General Garbage Collection Well, what would you need to do? Find all the pointers in allocated memory Determine “how much” each points to Determine what was and was not still pointed to Free what isn’t pointed to Why might that be difficult?

Lecture 7 Page 11 CS 111 Summer 2013 Problems With General Garbage Collection A location in the data or stack segments might seem to contain addresses, but... – Are they truly pointers, or might they be other data types whose values happen to resemble addresses? – Even if they are truly pointers, are they themselves still accessible? – We might be able to infer this (recursively) for pointers in dynamically allocated structures … – But what about pointers in statically allocated (potentially global) areas? And how much is “pointed to,” one word or a million? –

Lecture 7 Page 12 CS 111 Summer 2013 Compaction and Relocation Garbage collection is just another way to free memory – Doesn’t greatly help or hurt fragmentation Ongoing activity can starve coalescing – Chunks reallocated before neighbors become free We could stop accepting new allocations – But resulting convoy on memory manager would trash throughput We need a way to rearrange active memory – Re-pack all processes in one end of memory – Create one big chunk of free space at other end

Lecture 7 Page 13 CS 111 Summer 2013 Memory Compaction swap device PCPC PEPE PFPF PDPD Largest free block Now let’s compact! Largest free block An obvious improvement!

Lecture 7 Page 14 CS 111 Summer 2013 All This Requires Is Relocation... The ability to move a process – From region where it was initially loaded – Into a new and different region of memory What’s so hard about that? All addresses in the program will be wrong – References in the code segment Calls and branches to other parts of the code References to variables in the data segment – Plus new pointers created during execution That point into data and stack segments

Lecture 7 Page 15 CS 111 Summer 2013 The Relocation Problem It is not generally feasible to re-relocate a process – Maybe we could relocate references to code If we kept the relocation information around – But how can we relocate references to data? Pointer values may have been changed New pointers may have been created We could never find/fix all address references – Like the general case of garbage collection Can we make processes location independent?

Lecture 7 Page 16 CS 111 Summer 2013 Virtual Address Spaces 0x xFFFFFFFF shared codeprivate data private stackDLL 1DLL 2DLL 3 Virtual address space (as seen by process) Physical address space (as on CPU/memory bus) address translation unit (magical)

Lecture 7 Page 17 CS 111 Summer 2013 Memory Segment Relocation A natural model – Process address space is made up of multiple segments – Use the segment as the unit of relocation – Long tradition, from the IBM system 360 to Intel x86 architecture Computer has special relocation registers – They are called segment base registers – They point to the start (in physical memory) of each segment – CPU automatically adds base register to every address OS uses these to perform virtual address translation – Set base register to start of region where program is loaded – If program is moved, reset base registers to new location – Program works no matter where its segments are loaded

Lecture 7 Page 18 CS 111 Summer 2013 How Does Segment Relocation Work? 0x xFFFFFFFF shared code private data private stackDLL 1DLL 2DLL 3 Virtual address space Physical memory codedata stack DLL code base registerdata base register stack base registeraux base register physical = virtual + base seg

Lecture 7 Page 19 CS 111 Summer 2013 Relocating a Segment 0x xFFFFFFFF shared code private data private stackDLL 1DLL 2DLL 3 Physical memory codedata stack DLL code base registerdata base register stack base registeraux base register physical = virtual + base seg Let’s say we need to move the stack in physical memory The virtual address of the stack doesn’t change stack base register We just change the value in the stack base register

Lecture 7 Page 20 CS 111 Summer 2013 Relocation and Safety A relocation mechanism (like base registers) is good – It solves the relocation problem – Enables us to move process segments in physical memory – Such relocation turns out to be insufficient We also need protection – Prevent process from reaching outside its allocated memory E.g., by overrunning the end of a mapped segment Segments also need a length (or limit) register – Specifies maximum legal offset (from start of segment) – Any address greater than this is illegal (in the hole) – CPU should report it via a segmentation exception (trap)

Lecture 7 Page 21 CS 111 Summer 2013 How Much of Our Problem Does Relocation Solve? We can use variable sized domains – Cutting down on internal fragmentation We can move domains around – Which helps coalescing be more effective – But still requires contiguous chunks of data for segments – So external fragmentation is still a problem We need to get rid of the requirement of contiguous segments