Memory Management Last Update: July 31, 2014 Memory Management1.

Slides:



Advertisements
Similar presentations
File Systems.
Advertisements

Memory Management Chapter 7.
0 Course Outline n Introduction and Algorithm Analysis (Ch. 2) n Hash Tables: dictionary data structure (Ch. 5) n Heaps: priority queue data structures.
Fixed/Variable Partitioning
Memory Management Chapter 7. Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated efficiently to pack as.
Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable supply of ready processes to.
Allocating Memory.
Chapter 7 Memory Management Operating Systems: Internals and Design Principles, 6/E William Stallings Dave Bremer Otago Polytechnic, N.Z. ©2009, Prentice.
Chapter 101 Virtual Memory Chapter 10 Sections and plus (Skip:10.3.2, 10.7, rest of 10.8)
1 CSE 380 Computer Operating Systems Instructor: Insup Lee University of Pennsylvania, Fall 2002 Lecture Note: Memory Management.
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.
CSCI2413 Lecture 5 Operating Systems Memory Management 1 phones off (please)
Virtual Memory Chapter 8. Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
Memory Management Chapter 7 B.Ramamurthy. Memory Management Subdividing memory to accommodate multiple processes Memory needs to allocated efficiently.
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 A memory manager should take care of allocating memory when needed by programs release memory that is no longer used to the heap. Memory.
Memory Management Chapter 5.
B + -Trees (Part 1). Motivation AVL tree with N nodes is an excellent data structure for searching, indexing, etc. –The Big-Oh analysis shows most operations.
B + -Trees (Part 1) COMP171. Slide 2 Main and secondary memories  Secondary storage device is much, much slower than the main RAM  Pages and blocks.
CSE 326: Data Structures B-Trees Ben Lerner Summer 2007.
Computer Organization and Architecture
Virtual Memory BY JEMINI ISLAM. What is Virtual Memory Virtual memory is a memory management system that gives a computer the appearance of having more.
 2004 Deitel & Associates, Inc. All rights reserved. Chapter 9 – Real Memory Organization and Management Outline 9.1 Introduction 9.2Memory Organization.
1 Lecture 8: Memory Mangement Operating System I Spring 2008.
Tree-Structured Indexes. Range Searches ``Find all students with gpa > 3.0’’ –If data is in sorted file, do binary search to find first such student,
Memory Allocation CS Introduction to Operating Systems.
Maninder Kaur VIRTUAL MEMORY 24-Nov
Real-Time Concepts for Embedded Systems Author: Qing Li with Caroline Yao ISBN: CMPBooks.
ICS 220 – Data Structures and Algorithms Week 7 Dr. Ken Cosh.
ALGORITHMS FOR ISNE DR. KENNETH COSH WEEK 6.
1 B Trees - Motivation Recall our discussion on AVL-trees –The maximum height of an AVL-tree with n-nodes is log 2 (n) since the branching factor (degree,
Dynamic Memory Allocation Questions answered in this lecture: When is a stack appropriate? When is a heap? What are best-fit, first-fit, worst-fit, and.
Memory Management Chapter 7.
MEMORY MANAGEMENT Presented By:- Lect. Puneet Gupta G.P.C.G. Patiala.
CGS 3763 Operating Systems Concepts Spring 2013 Dan C. Marinescu Office: HEC 304 Office hours: M-Wd 11: :30 AM.
Chapter 4 Memory Management.
July 30, 2001Systems Architecture II1 Systems Architecture II (CS ) Lecture 8: Exploiting Memory Hierarchy: Virtual Memory * Jeremy R. Johnson Monday.
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.
CSC 213 – Large Scale Programming Lecture 37: External Caching & (a,b)-Trees.
Memory Management. Roadmap Basic requirements of Memory Management Memory Partitioning Basic blocks of memory management –Paging –Segmentation.
Subject: Operating System.
© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of CHAPTER 12: Multi-way Search Trees Java Software Structures: Designing.
1 Memory Management Chapter 7. 2 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 10: Virtual Memory Background Demand Paging Page Replacement Allocation of.
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming.  To allocate scarce memory.
Storage Structures. Memory Hierarchies Primary Storage –Registers –Cache memory –RAM Secondary Storage –Magnetic disks –Magnetic tape –CDROM (read-only.
CS 241 Section Week #9 (11/05/09). Topics MP6 Overview Memory Management Virtual Memory Page Tables.
1 Memory Management Chapter 7. 2 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable.
Basic Memory Management 1. Readings r Silbershatz et al: chapters
Informationsteknologi Wednesday, October 3, 2007Computer Systems/Operating Systems - Class 121 Today’s class Memory management Virtual memory.
Copyright ©: Nahrstedt, Angrave, Abdelzaher, Caccamo 1 Memory management & paging.
Memory Management OS Fazal Rehman Shamil. swapping Swapping concept comes in terms of process scheduling. Swapping is basically implemented by Medium.
Virtual Memory Pranav Shah CS147 - Sin Min Lee. Concept of Virtual Memory Purpose of Virtual Memory - to use hard disk as an extension of RAM. Personal.
2010INT Operating Systems, School of Information Technology, Griffith University – Gold Coast Copyright © William Stallings /2 Memory Management.
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.
Chapter 8: Memory Management. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 8: Memory Management Background Swapping Contiguous.
Computer Organization
Virtual memory.
Memory Management.
Memory Management 5/11/2018 9:49 PM
Chapter 2 Memory and process management
Memory Management 6/20/ :27 PM
B-Trees 7/5/2018 4:26 AM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and.
Main Memory Management
Computer Architecture
CSE 373 Data Structures and Algorithms
Operating Systems: Internals and Design Principles, 6/E
Presentation transcript:

Memory Management Last Update: July 31, 2014 Memory Management1

Slides copied directly from Andy (And not covered by Jeff)

Computer Memory Last Update: July 31, 2014 Memory Management3 In order to implement any data structure on an actual computer, we need to use computer memory. Computer memory is organized into a sequence of words, each of which typically consists of 4, 8, or 16 bytes (depending on the computer). These memory words are numbered from 0 to N − 1, where N is the number of memory words available to the computer. The number associated with each memory word is known as its memory address.

Object Creation With Java, all objects are stored in a pool of memory, known as the memory heap or Java heap (should not be confused with the “heap” data structure). Consider what happens when we execute a command such as: w = Widget() A new instance of the class is created and stored somewhere within the memory heap. Last Update: July 31, 2014 Memory Management 4

Free List The storage available in the memory heap is divided into blocks, which are contiguous array-like “chunks” of memory that may be of variable or fixed sizes. The system must be implemented so that it can quickly allocate memory for new objects. One popular method is to keep contiguous “holes” of available free memory in a linked list, called the free list. Deciding how to allocate blocks of memory from the free list when a request is made is known as memory management. Last Update: July 31, 2014 Memory Management5

Several heuristics have been suggested for allocating memory from the heap so as to minimize fragmentation. – The best-fit algorithm searches the entire free list to find the hole whose size is closest to the amount of memory being requested. – The first-fit algorithm searches from the beginning of the free list for the first hole that is large enough. – The next-fit algorithm is similar, in that it also searches the free list for the first hole that is large enough, but it begins its search from where it left off previously, viewing the free list as a circularly linked list. – The worst-fit algorithm searches the free list to find the largest hole of available memory. Last Update: July 31, 2014 Memory Management6

Garbage Collection The process of detecting “stale” objects, de-allocating the space devoted to those objects, and returning the reclaimed space to the free list is known as garbage collection. In order for a program to access an object, it must have a direct or indirect reference to that object. – Such objects are live objects. We refer to all live objects with direct reference (that is a variable pointing to them) as root objects. An indirect reference to a live object is a reference that occurs within the state of some other live object, such as a cell of a live array or field of some live object. Last Update: July 31, 2014 Memory Management7

Mark-Sweep Algorithm In the mark-sweep garbage collection algorithm, we associate a “mark” bit with each object that identifies whether that object is live. When we determine at some point that garbage collection is needed, we suspend all other activity and clear the mark bits of all the objects currently allocated in the memory heap. We then trace through the active namespaces and we mark all the root objects as “live.” We must then determine all the other live objects—the ones that are reachable from the root objects. To do this efficiently, we can perform a depth-first search on the directed graph that is defined by objects reference other objects. Last Update: July 31, 2014 Memory Management8

Memory Hierarchies Computers have a hierarchy of different kinds of memories, which vary in terms of their size and distance from the CPU. Closest to the CPU are the internal registers. Access to such locations is very fast, but there are relatively few such locations. At the second level in the hierarchy are the memory caches. At the third level in the hierarchy is the internal memory, which is also known as main memory or core memory. Another level in the hierarchy is the external memory, which usually consists of disks. Last Update: July 31, 2014 Memory Management9

Virtual Memory Virtual memory consists of providing an address space as large as the capacity of the external memory, and of transferring data in the secondary level into the primary level when they are addressed. – Virtual memory does not limit the programmer to the constraint of the internal memory size. The concept of bringing data into primary memory is called caching, and it is motivated by temporal locality. By bringing data into primary memory, we are hoping that it will be accessed again soon, and we will be able to respond quickly to all the requests for this data that come in the near future. Last Update: July 31, 2014 Memory Management10

Page Replacement Strategies When a new block is referenced and the space for blocks from external memory is full, we must evict an existing block. There are several such page replacement strategies, including: – FIFO – LIFO – Random Last Update: July 31, 2014 Memory Management11

The Random Strategy Last Update: July 31, 2014 Memory Management12 Choose a page at random to evict from the cache. – The overhead involved in implementing this policy is an O(1) additional amount of work per page replacement. – Still, this policy makes no attempt to take advantage of any temporal locality exhibited by a user’s browsing.

The FIFO Strategy Last Update: July 31, 2014 Memory Management13 FIFO is quite simple to implement, as it only requires a queue Q to store references to the pages in the cache. – Pages are enqueued in Q when they are referenced, and then are brought into the cache. – When a page needs to be evicted, the computer simply performs a dequeue operation on Q to determine which page to evict. Thus, this policy also requires O(1) additional work per page replacement. – Moreover, it tries to take some advantage of temporal locality.

The LRU Strategy Last Update: July 31, 2014 Memory Management14 LRU evicts the page that was least-recently used. – From a policy point of view, this is an excellent approach, but it is costly from an implementation point of view. – Implementing the LRU strategy requires the use of an adaptable priority queue Q that supports updating the priority of existing pages. If Q is implemented with a sorted sequence based on a linked list, then the overhead for each page request and page replacement is O(1).

B-Trees Last Update: July 31, 2014 Memory Management15

Computer Memory Last Update: July 31, 2014 Memory Management16 In order to implement any data structure on an actual computer, we need to use computer memory. Computer memory is organized into a sequence of words, each of which typically consists of 4, 8, or 16 bytes (depending on the computer). These memory words are numbered from 0 to N − 1, where N is the number of memory words available to the computer. The number associated with each memory word is known as its memory address.

Disk Blocks Consider the problem of maintaining a large collection of items that does not fit in main memory, such as a typical database. In this context, we refer to the external memory as divided into blocks, which we call disk blocks. The transfer of a block between external memory and primary memory is a disk transfer or I/O. There is a great time difference that exists between main memory accesses and disk accesses Thus, we want to minimize the number of disk transfers needed to perform a query or update. We refer to this count as the I/O complexity of the algorithm involved. Last Update: July 31, 2014 Memory Management 17

(a,b) Trees To reduce the number of external-memory accesses when searching, we can represent a map using a multiway search tree. This approach gives rise to a generalization of the (2,4) tree data structure known as the (a,b) tree. An (a,b) tree is a multiway search tree such that each node has between a and b children and stores between a − 1 and b − 1 entries. By setting the parameters a and b appropriately with respect to the size of disk blocks, we can derive a data structure that achieves good external-memory performance. Last Update: July 31, 2014 Memory Management18

Definition An (a,b) tree, where parameters a and b are integers such that 2 ≤ a ≤ (b+1)/2, is a multiway search tree T with the following additional restrictions: Size Property: Each internal node has at least a children, unless it is the root, and has at most b children. Depth Property: All external nodes have the same depth. Last Update: July 31, 2014 Memory Management19

Height of an (a,b) Tree Last Update: July 31, 2014 Memory Management20

Searches and Updates The search algorithm in an (a,b) tree is exactly like the one for multiway search trees. The insertion algorithm for an (a,b) tree is similar to that for a (2,4) tree. – An overflow occurs when an entry is inserted into a b-node w, which becomes an illegal (b+1)-node. – To remedy an overflow, we split node w by moving the median entry of w into the parent of w and replacing w with a (b+1)/2-node w and a (b+1)/2- node w. Removing an entry from an (a,b) tree is similar to what was done for (2,4) trees. – An underflow occurs when a key is removed from an a-node w, distinct from the root, which causes w to become an (a−1)-node. – To remedy an underflow, we perform a transfer with a sibling of w that is not an a-node or we perform a fusion of w with a sibling that is an a-node. Last Update: July 31, 2014 Memory Management21

B-Trees Last Update: July 31, 2014 Memory Management22 A version of the (a,b) tree data structure, which is the best-known method for maintaining a map in external memory, is a “B-tree.” A B-tree of order d is an (a,b) tree with a = d/2 and b = d.

I/O Complexity Proof: – Each time we access a node to perform a search or an update operation, we need only perform a single disk transfer. – Each search or update requires that we examine at most O(1) nodes for each level of the tree. Last Update: July 31, 2014 Memory Management23

Summary Memory Management  Object creation  Garbage collection  Mark-Sweep algorithm Memory hierarchies  Virtual memory  Page replacement strategies: o FIFO, LRU, Random B-Trees  (a, b) Trees Last Update: July 31, 2014 Memory Management 24

Last Update: July 31, 2014 Memory Management 25