An Efficient Heap Management Technique with Minimum Fragmentation and Auto Compaction

Size: px
Start display at page:

Download "An Efficient Heap Management Technique with Minimum Fragmentation and Auto Compaction"

Transcription

1 An Efficient Heap Management Technique with Minimum Fragmentation and Auto Compaction Krishna Lal. Baishnab, Soumyabrata Dev, Ziaul Haque Choudhury, Amlan Nag National Institute of Technology, Silchar Assam Abstract- Heap management is responsible for the allocation of heap segments to a running application. When the logic of the heap management is left to the application programmer, as it is the case with programming languages like C and C++, a number of problems may arise. One kind of problems related to imperfect heap management is that of memory fragmentation. Hence compaction of data is required to increase the efficient data storage capacity of the memory. Depending on whether active blocks within the heap may be shifted in position, one of the two approaches to compaction is possible: partial compaction and full compaction. But both these methods are too expensive and hence they are generally not used in large program modules. In this paper a new heap management technique MFAC (Minimum Fragmentation and Auto Compaction) is proposed which has an inherent auto compaction technique in its algorithm leading to minimum fragmentation of memory space. Simulation results show that in most scenarios, MFAC outperforms the 1 st fit and best fit technique by a considerable margin. I. INTRODUCTION The capability to dynamically allocate memory to a running application is an essential need for a wide range of software systems, and it is supported by most programming languages. The management of the dynamically allocated memory consists of two parts: the language primitives that allow the allocation and deallocation of heap segments, and the logic that controls these primitives. Some programming languages control tightly the heap management and come with runtime support that implements the logic for the heap management. Other programming languages provide only the heap allocation primitives but leave the development of the heap management logic to the programmer. An example of such a case is C, where the programmer can use calls like malloc() and free() to allocate and deallocate heap segments, and it is his/her own responsibility to correctly use these primitives in order to keep the heap in a consistent state. This case of heap management is more error-prone, and flaws in the logic of heap management are the source of some of the most persistent and difficult to correct software problems. Embedded software suffers a lot from memory leaks and double-frees, because often all the applications in the system run in a single process space. This implies that the heap space wasted or corrupted by one application does not only endanger its own execution, but it endangers also the execution of all other applications in the system, since all applications share the same heap. Another characteristic of embedded software is that it often has to run on very limited resources and with real-time constraints. The combination of these two factors results in a prohibitive cost for the use of run time support for heap management. This is one of the reasons why embedded software relies mostly on the debugging of the heap management logic during the software test phase in order to remove memory leak and double-free errors.. One of the serious problems is the fragmentation error in memory. The system may give a memory full message even if the total free space is more than the requested memory slot. This is because there may be lack of contiguous memory space for its allocation. To this direction our proposed algorithm helps. It has an auto compaction technique which causes minimum fragmentation in the system. The rest of the paper is organized in the following manner. Section II summarizes previous work on dynamic memory management. Section III presents our proposed algorithm MFAC. The simulation results are shown in Section IV which has a comparative analysis with the first-fit and the best-fit technique of memory management. Section V concludes the paper. II: PREVIOUS WORKS In recent research, studies have shown that object-oriented applications written in C++ can run upto 10 times slower than comparable C programs. This execution time overhead can largely be contributed to inefficient heap management algorithms. Since object-oriented applications tend to be more memory intensive than procedural ones, the ability to effectively manage heap memory is crucial to the performance of such systems. In software approaches, the DMM execution time is linearly proportional to the number of objects existing in the system. For example, as the calls to malloc intersperse with the calls to delete, the heap becomes increasingly fragmented and the occupied list and the free list become longer as well. In first fit approach, the list is searched from the beginning. The free block that is large enough to satisfy the request is then selected. If the block is larger than necessary, it is split and the remainder is put back on the free-list. The major problem with first fit is that the larger blocks at the beginning of the list are often split first. Since these blocks are often larger than the requested size, the remaining /10/$ IEEE 266

2 portions are put back on the list. If the splitting occurs frequently, the beginning of the list may have many small unusable blocks. Therefore, the search time may increase since the search must go past them each time a larger block is requested. In best fit, the list is searched to find the smallest free block large enough to satisfy a request. The basic rational for this approach is to minimize the amount of fragmented space (caused by splitting). However, the problem may still occur if the selected block is not a perfect fit to the requested size. In such situation, splitting may put small memory blocks back to the list. These small blocks may be unusable. Additionally, the search in best fit is very exhaustive. Thus, this scheme may not scale well to large heaps with many free blocks. III: OUR PROPOSED ALGORITHM At the very outset, several terminologies must be defined that we have used in the various parts of the algorithm. Free-list: This denotes the list of free nodes where memory can be allocated using the malloc() function. The generalized manner of expressing a free node is given as [ab] where a denotes the starting memory address location and b denotes the number of contiguous available memory location. Whenever a number of free nodes become available after the application of free() function; they automatically get sorted with the existing nodes of the free list. For instance, the free list contains the node [a,b] and the nodes that have been de allocated are [c,d] and [e,f], then the sorted free list consist of [e,f]-[a,b]-[c,d] under the condition f<=b<=d i.e. according to increasing free memory size. Hash map is a virtual mapping between the starting memory address and the list of nodes attached with it. In the same manner, a node is denoted as [x,y] where x denotes the starting memory address and y the set of contiguous memory location. Simulations results are done in C language with the in-built graphics library graphics.h. A comparative study is done between our proposed technique MFAC with the already existing 1 st fit and best fit technique. The algorithm is presented in a step by step manner taking suitable examples. Let us assume that the total memory available is 32 bytes (though in reality it can range to thousands of bytes). When a request for memory allocation comes, the algorithm searches for the requisite available space and allocates memory space to it. As mentioned before, the algorithm also maintains a free list and a hash map. At the beginning of operation, let us assume that there is a request to allocate 2 bytes of memory space. The whole 32 bytes are empty and hence it allocates the 1 st 2 bytes to it. The free list will look like [3,30] i.e. it has 30 bytes of available memory space and the next starting memory address location is loc. 3. and the hash map would look like: Fig 1: Hash map- I After that, let there be a continual request to allocate 5 bytes, 3 bytes and 4 bytes of memory space respectively. After allocating 5 bytes Free list: [8,25] After allocating 3 bytes Free list: [11,22] Fig 2 : Hash Map-II Fig 3: Hash Map-III After allocating 4 bytes Free list: [15,18] 267

3 minimum and data is compacted automatically. It is worthwhile to mention out here that in MFAC, it is not assumed that the allocated data is stored in contiguous memory location; it may get scattered over the entire empty memory space. In general cases, the starting memory address describes the whole chunk of data. The additional overhead in MFAC is a pointer that traverses through different memory locations as directed by the hash table. Continuing with the above case study, let us assume that the following operations take place in order: free the memory location at 11, then allocation of 7 bytes and 6 bytes respectively. The final hash map is given below for easy reference. Fig 4: Hash Map-IV Now, let there be a request then to free memory space at the location number 3 of the memory map. The node [3,5] attached to the memory loc 3 gets detached and gets sorted according to increasing memory space with the other nodes of the free list. The free list would look like [3,5]-[15,18] and the hash map as follows: Fig 7: Hash Map-VII IV. SIMULATION RESULTS Fig 5: Hash Map-V Next, assume that there is a request to allocate 6 bytes of memory space. In such scenarios, the proposed algorithm comes into play. Out of 6 bytes requested, it allocates 5 bytes starting from location number 3 and the remaining 1 byte from location number from loc no. 15. The free list becomes [16-17] and the hash map as follows: Fig 6: Hash Map-VI In the above step it is observed that the MFAC algorithm allocates the data in such a manner that the fragmentation is The proposed algorithm MFAC is simulated in C with the graphics library of Turbo C compiler graphics.h. A comparative analysis is made between MFAC, 1 st fit and best fit algorithm and the memory map generated from the C code clearly indicates that MFAC outperforms the other technique by a considerable margin. MFAC causes the data to be compacted automatically causing to minimum fragmentation. The same sequence of events (as given in the case study of Section III) is observed in the simulator and the results generated are given below. The memory map clearly indicates that MFAC outperforms the other techniques by a considerable margin. As in the example when the last request to allocate 6 bytes of memory comes, MFAC could easily allocate free space to it. But on the other hand, 1 st or best fit could not do so. It shows a message Memory Full. The complete pseudo code of the algorithm for the implementation of MFAC algorithm is given below. The flow chart has used a record type having two fields: address location (indicating the starting allocation point) and size (number of memory locations allocated). Algorithm: PSEUDOCODE OF ALGO Subroutine dealloc (int_addr) If hash_map[-addr]!=null then 268

4 Selection sort on the addr field of hash map Wrap-compact (hash_tabel[-addr] Else Write (invalid address ) Print (Memory ) Exit (0); Subroutine Wrap_component(node*addr) While (compact()!=0) Update_bit_mao(hash_map[-addr] return-to-freelist(hash_map[-addr] hash_map[-addr]= NULL return; Subroutine alloc( int size) 1 Void *g 2 G=freelist 3 If g!=null 4 Size=size-g->size 5 If size<0 6 Add_to_hash_map(freelist->addr,g->size-abs(size)) 7 Update_bit_map(hash_map[-addr] 8 Else 9 If size>0 10 Add_to_hash_map(g-addr,g->size) 11 Delete_from_beg(free_list) 12 go to 3 13 else 14 add_to_hash_map(g-> addr,g->size) 15 deletefrom_beg(freelist) 16 end if 17 end if 18 endif Fig 8: Memory Map in MFAC Fig 9: Memory map in 1 st and best fit algorithm 269

5 V. ANALYSIS OF MFAC & FUTURE EXTENSIONS MFAC has an auto compaction technique and hence it leads to minimum fragmentation (as shown above). But it is assumed that the data are not always stored in contiguous memory location. In general cases, it stores in contiguous memory location but in worst case scenarios, it is distributed over different part of empty memory space. The additional overhead is such scenario is a memory pointer that traverses through different parts of the memory in accordance to the linked list (as shown is hash table). The main challenge that MFAC model will face is the allocation of the trivial data structures like the arrays and the structures. Basically our model doesn t support contiguous memory allocation and that may create problems in referring to the allocated trivial data structures. The hash map will come in handy in such scenarios. A deep analysis of the hash map reveals that the hash map is actually an image of the current state of the memory. The array elements are actually accessed by our original base+offset formula. In the hash map the base can be the pointer field in the first element of the list. Once we get the base pointer we can then add the offset to get the desired address. Suppose the offset is 12 and the hash map has the contents [1,4]-[2,5]-[5,10]. At the very outset, we need to find in which block of the hash map the offset belong. Adding 4 and 5 we get 4+5 = 9, as it is less than 12 and hence the desired block is somewhere in the block starting at the address 5. Since we are left with only (12-9) = 3 units and the number of contiguous free memory location at the location no. 5 is 10, so we calculate the desired value as 5+(12-9) = 5+3 = 8. Hence we get the desired value at memory location 8. The hash table that has been generated during the entire operation can be stored in virtual memory. In such cases, the program s run-time requirement decreases considerably. Another modification that can be incorporated in MFAC is that a wilderness chunk from the virtual memory can be appended to the end of heap area when it shows a memory full message. The virtual memory would then map memory pages from the main memory into the access memory. This will provide an infinite memory space to the heap. MFAC is still in its initial stages and several other modifications can be incorporated into it to increase its efficiency. REFRENCES [1] Terrence W. Pratt, Marvin V. Zelkowitz, Programming languages- design and implementation, Prentice Hall India [2] H. Verta, T. Saridakis, detection of Heap management flaws in component based software [3] T.Austin,S.Breach, and G.Sohi,Efficient Detection of All Pointer and Array Access Errors. In Proceedings of the ACM SIGPLAN1994 Conference on Programming Language Design and Implementation (PLDI 94), pages 290 to 301,June [4] W.Bush, J.Pincus, and D.Sielaff. A Static Analyzer for Finding Dynamic Programming Errors. Software: Practice and Experience, 30(7): ,June2000. [5] C. Dan Lo, W. Srisa-an, J. M Chang, The design and analysis of a quantitative simulator for dyanamic memory management, the Journal of Systems and softwares. [6] Chang, J.M.,Srisaan, W.,Lo, C.D.,1999. Introduction to DMMX (Dynamic Memory Management Extension).In: Proceeding of ICCD Workshop on Hardware Support for Objects and Microarchitectures for Java, 10 October 1999, Austin, TX, pp [7] Jhonstone, M.S., Wilson, P.R., The memory fragmentation problem: solved? In International Symposium on Memory Management, October Vancouver, British Columbia, Canada, pp [8] Larson, P.A.,Krishnam, M.,1998. Memory allocation for long-running server applications. In Proceedings of 1988 International Symposium on Memory Management, 1998, pp

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

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 Heap Management The heap is the portion of the store that is used for data that lives indefinitely, or until the program explicitly deletes it. While local variables typically become inaccessible when

More information

Run-time Environments - 3

Run-time Environments - 3 Run-time Environments - 3 Y.N. Srikant Computer Science and Automation Indian Institute of Science Bangalore 560 012 NPTEL Course on Principles of Compiler Design Outline of the Lecture n What is run-time

More information

Optimizing Dynamic Memory Management

Optimizing Dynamic Memory Management Optimizing Dynamic Memory Management 1 Goals of this Lecture Help you learn about: Details of K&R heap mgr Heap mgr optimizations related to Assignment #5 Faster free() via doubly-linked list, redundant

More information

Run-time Environments -Part 3

Run-time Environments -Part 3 Run-time Environments -Part 3 Y.N. Srikant Computer Science and Automation Indian Institute of Science Bangalore 560 012 NPTEL Course on Compiler Design Outline of the Lecture Part 3 What is run-time support?

More information

Run-Time Environments/Garbage Collection

Run-Time Environments/Garbage Collection Run-Time Environments/Garbage Collection Department of Computer Science, Faculty of ICT January 5, 2014 Introduction Compilers need to be aware of the run-time environment in which their compiled programs

More information

CS399 New Beginnings. Jonathan Walpole

CS399 New Beginnings. Jonathan Walpole CS399 New Beginnings Jonathan Walpole Memory Management Memory Management Memory a linear array of bytes - Holds O.S. and programs (processes) - Each cell (byte) is named by a unique memory address Recall,

More information

CS61C : Machine Structures

CS61C : Machine Structures inst.eecs.berkeley.edu/~cs61c/su06 CS61C : Machine Structures Lecture #6: Memory Management CS 61C L06 Memory Management (1) 2006-07-05 Andy Carle Memory Management (1/2) Variable declaration allocates

More information

ECE 2035 A Programming HW/SW Systems Spring problems, 5 pages Exam Three 13 April Your Name (please print clearly)

ECE 2035 A Programming HW/SW Systems Spring problems, 5 pages Exam Three 13 April Your Name (please print clearly) Instructions: This is a closed book, closed note exam. Calculators are not permitted. If you have a question, raise your hand; do not leave your seat. Please work the exam in pencil and do not separate

More information

Lecture 7. Memory Management

Lecture 7. Memory Management Lecture 7 Memory Management 1 Lecture Contents 1. Memory Management Requirements 2. Memory Partitioning 3. Paging 4. Segmentation 2 Memory Memory is an array of words or bytes, each with its own address.

More information

Memory Management. Memory Management

Memory Management. Memory Management Memory Management Chapter 7 1 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated efficiently to pack as many processes into memory as possible 2 1 Memory

More information

e-pg Pathshala Subject: Computer Science Paper: Operating Systems Module 35: File Allocation Methods Module No: CS/OS/35 Quadrant 1 e-text

e-pg Pathshala Subject: Computer Science Paper: Operating Systems Module 35: File Allocation Methods Module No: CS/OS/35 Quadrant 1 e-text e-pg Pathshala Subject: Computer Science Paper: Operating Systems Module 35: File Allocation Methods Module No: CS/OS/35 Quadrant 1 e-text 35.1 Introduction File system is the most visible part of the

More information

Binding and Storage. COMP 524: Programming Language Concepts Björn B. Brandenburg. The University of North Carolina at Chapel Hill

Binding and Storage. COMP 524: Programming Language Concepts Björn B. Brandenburg. The University of North Carolina at Chapel Hill Binding and Storage Björn B. Brandenburg The University of North Carolina at Chapel Hill Based in part on slides and notes by S. Olivier, A. Block, N. Fisher, F. Hernandez-Campos, and D. Stotts. What s

More information

DOWNLOAD PDF LINKED LIST PROGRAMS IN DATA STRUCTURE

DOWNLOAD PDF LINKED LIST PROGRAMS IN DATA STRUCTURE Chapter 1 : What is an application of linear linked list data structures? - Quora A linked list is a linear data structure, in which the elements are not stored at contiguous memory locations. The elements

More information

CS61C : Machine Structures

CS61C : Machine Structures inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 7 More Memory Management CS 61C L07 More Memory Management (1) 2004-09-15 Lecturer PSOE Dan Garcia www.cs.berkeley.edu/~ddgarcia Star Wars

More information

UNIT III MEMORY MANAGEMENT

UNIT III MEMORY MANAGEMENT UNIT III MEMORY MANAGEMENT TOPICS TO BE COVERED 3.1 Memory management 3.2 Contiguous allocation i Partitioned memory allocation ii Fixed & variable partitioning iii Swapping iv Relocation v Protection

More information

Lecture Notes on Garbage Collection

Lecture Notes on Garbage Collection Lecture Notes on Garbage Collection 15-411: Compiler Design Frank Pfenning Lecture 21 November 4, 2014 These brief notes only contain a short overview, a few pointers to the literature with detailed descriptions,

More information

Data Structure for Language Processing. Bhargavi H. Goswami Assistant Professor Sunshine Group of Institutions

Data Structure for Language Processing. Bhargavi H. Goswami Assistant Professor Sunshine Group of Institutions Data Structure for Language Processing Bhargavi H. Goswami Assistant Professor Sunshine Group of Institutions INTRODUCTION: Which operation is frequently used by a Language Processor? Ans: Search. This

More information

Last week. Data on the stack is allocated automatically when we do a function call, and removed when we return

Last week. Data on the stack is allocated automatically when we do a function call, and removed when we return Last week Data can be allocated on the stack or on the heap (aka dynamic memory) Data on the stack is allocated automatically when we do a function call, and removed when we return f() {... int table[len];...

More information

A Comprehensive Complexity Analysis of User-level Memory Allocator Algorithms

A Comprehensive Complexity Analysis of User-level Memory Allocator Algorithms 2012 Brazilian Symposium on Computing System Engineering A Comprehensive Complexity Analysis of User-level Memory Allocator Algorithms Taís Borges Ferreira, Márcia Aparecida Fernandes, Rivalino Matias

More information

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

In multiprogramming systems, processes share a common store. Processes need space for: Memory Management In multiprogramming systems, processes share a common store. Processes need space for: code (instructions) static data (compiler initialized variables, strings, etc.) global data (global

More information

CS 536 Introduction to Programming Languages and Compilers Charles N. Fischer Lecture 11

CS 536 Introduction to Programming Languages and Compilers Charles N. Fischer Lecture 11 CS 536 Introduction to Programming Languages and Compilers Charles N. Fischer Lecture 11 CS 536 Spring 2015 1 Handling Overloaded Declarations Two approaches are popular: 1. Create a single symbol table

More information

ECE 2035 Programming HW/SW Systems Fall problems, 5 pages Exam Three 28 November 2012

ECE 2035 Programming HW/SW Systems Fall problems, 5 pages Exam Three 28 November 2012 Instructions: This is a closed book, closed note exam. Calculators are not permitted. If you have a question, raise your hand and I will come to you. Please work the exam in pencil and do not separate

More information

Memory Management william stallings, maurizio pizzonia - sistemi operativi

Memory Management william stallings, maurizio pizzonia - sistemi operativi 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

More information

File Management By : Kaushik Vaghani

File Management By : Kaushik Vaghani File Management By : Kaushik Vaghani File Concept Access Methods File Types File Operations Directory Structure File-System Structure File Management Directory Implementation (Linear List, Hash Table)

More information

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

Memory Management. Reading: Silberschatz chapter 9 Reading: Stallings. chapter 7 EEL 358 Memory Management Reading: Silberschatz chapter 9 Reading: Stallings chapter 7 1 Outline Background Issues in Memory Management Logical Vs Physical address, MMU Dynamic Loading Memory Partitioning Placement

More information

CS61C : Machine Structures

CS61C : Machine Structures inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 7 C Memory Management 2007-02-06 Hello to Said S. from Columbus, OH CS61C L07 More Memory Management (1) Lecturer SOE Dan Garcia www.cs.berkeley.edu/~ddgarcia

More information

Memory Allocation. Static Allocation. Dynamic Allocation. Dynamic Storage Allocation. CS 414: Operating Systems Spring 2008

Memory Allocation. Static Allocation. Dynamic Allocation. Dynamic Storage Allocation. CS 414: Operating Systems Spring 2008 Dynamic Storage Allocation CS 44: Operating Systems Spring 2 Memory Allocation Static Allocation (fixed in size) Sometimes we create data structures that are fixed and don t need to grow or shrink. Dynamic

More information

File System Interface and Implementation

File System Interface and Implementation Unit 8 Structure 8.1 Introduction Objectives 8.2 Concept of a File Attributes of a File Operations on Files Types of Files Structure of File 8.3 File Access Methods Sequential Access Direct Access Indexed

More information

CS61C : Machine Structures

CS61C : Machine Structures inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 7 C Memory Management!!Lecturer SOE Dan Garcia!!!www.cs.berkeley.edu/~ddgarcia CS61C L07 More Memory Management (1)! 2010-02-03! Flexible

More information

File system internals Tanenbaum, Chapter 4. COMP3231 Operating Systems

File system internals Tanenbaum, Chapter 4. COMP3231 Operating Systems File system internals Tanenbaum, Chapter 4 COMP3231 Operating Systems Architecture of the OS storage stack Application File system: Hides physical location of data on the disk Exposes: directory hierarchy,

More information

Memory Management (Chaper 4, Tanenbaum)

Memory Management (Chaper 4, Tanenbaum) Memory Management (Chaper 4, Tanenbaum) Copyright 1996 25 Eskicioglu and Marsland (and Prentice-Hall and Paul Lu) Memory Mgmt Introduction The CPU fetches instructions and data of a program from memory;

More information

Project 0: Implementing a Hash Table

Project 0: Implementing a Hash Table Project : Implementing a Hash Table CS, Big Data Systems, Spring Goal and Motivation. The goal of Project is to help you refresh basic skills at designing and implementing data structures and algorithms.

More information

Chapter 17. Disk Storage, Basic File Structures, and Hashing. Records. Blocking

Chapter 17. Disk Storage, Basic File Structures, and Hashing. Records. Blocking Chapter 17 Disk Storage, Basic File Structures, and Hashing Records Fixed and variable length records Records contain fields which have values of a particular type (e.g., amount, date, time, age) Fields

More information

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

File Systems. OS Overview I/O. Swap. Management. Operations CPU. Hard Drive. Management. Memory. Hard Drive. CSI3131 Topics. Structure. File Systems I/O Management Hard Drive Management Virtual Memory Swap Memory Management Storage and I/O Introduction CSI3131 Topics Process Management Computing Systems Memory CPU Peripherals Processes

More information

Lecture 7 More Memory Management Slab Allocator. Slab Allocator

Lecture 7 More Memory Management Slab Allocator. Slab Allocator CS61C L07 More Memory Management (1) inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 7 More Memory Management 2006-09-13 Lecturer SOE Dan Garcia www.cs.berkeley.edu/~ddgarcia Unbox problems

More information

File Directories Associated with any file management system and collection of files is a file directories The directory contains information about

File Directories Associated with any file management system and collection of files is a file directories The directory contains information about 1 File Management 2 File Directories Associated with any file management system and collection of files is a file directories The directory contains information about the files, including attributes, location

More information

Dynamic Memory Allocation

Dynamic Memory Allocation Dynamic Memory Allocation CS61, Lecture 10 Prof. Stephen Chong October 4, 2011 Announcements 1/2 Assignment 4: Malloc Will be released today May work in groups of one or two Please go to website and enter

More information

A Dynamic Memory Management Unit for Embedded Real-Time System-on-a-Chip

A Dynamic Memory Management Unit for Embedded Real-Time System-on-a-Chip A Dynamic Memory Management Unit for Embedded Real-Time System-on-a-Chip Mohamed Shalan Georgia Institute of Technology School of Electrical and Computer Engineering 801 Atlantic Drive Atlanta, GA 30332-0250

More information

Limitations of the stack

Limitations of the stack The heap hic 1 Limitations of the stack int *table_of(int num, int len) { int table[len+1]; for (int i=0; i

More information

DYNAMIC MEMORY ALLOCATOR ALGORITHMS SIMULATION AND PERFORMANCE ANALYSIS

DYNAMIC MEMORY ALLOCATOR ALGORITHMS SIMULATION AND PERFORMANCE ANALYSIS ISTANBUL UNIVERSITY JOURNAL OF ELECTRICAL & ELECTRONICS ENGINEERING YEAR VOLUME NUMBER : 25 : 5 : 2 (1435-1441) DYNAMIC MEMORY ALLOCATOR ALGORITHMS SIMULATION AND PERFORMANCE ANALYSIS 1 Fethullah Karabiber

More information

Requirements, Partitioning, paging, and segmentation

Requirements, Partitioning, paging, and segmentation 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)

More information

PROCESS VIRTUAL MEMORY. CS124 Operating Systems Winter , Lecture 18

PROCESS VIRTUAL MEMORY. CS124 Operating Systems Winter , Lecture 18 PROCESS VIRTUAL MEMORY CS124 Operating Systems Winter 2015-2016, Lecture 18 2 Programs and Memory Programs perform many interactions with memory Accessing variables stored at specific memory locations

More information

Dynamic Storage Allocation

Dynamic Storage Allocation 6.172 Performance Engineering of Software Systems LECTURE 10 Dynamic Storage Allocation Charles E. Leiserson October 12, 2010 2010 Charles E. Leiserson 1 Stack Allocation Array and pointer A un Allocate

More information

A program execution is memory safe so long as memory access errors never occur:

A program execution is memory safe so long as memory access errors never occur: A program execution is memory safe so long as memory access errors never occur: Buffer overflows, null pointer dereference, use after free, use of uninitialized memory, illegal free Memory safety categories

More information

Algorithm Design and Analysis. What is an Algorithm? Do Algorithms Matter?

Algorithm Design and Analysis. What is an Algorithm? Do Algorithms Matter? Algorithm Design and Analysis shereen@pacificu.edu 1 What is an Algorithm? A sequence of computational steps that transforms the input into the desired output." To be interesting, an algorithm has to solve

More information

Garbage Collection (1)

Garbage Collection (1) Garbage Collection (1) Advanced Operating Systems Lecture 7 This work is licensed under the Creative Commons Attribution-NoDerivatives 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nd/4.0/

More information

Q1. What is Deadlock? Explain essential conditions for deadlock to occur?

Q1. What is Deadlock? Explain essential conditions for deadlock to occur? II nd Midterm session 2017-18 Subject: Operating System ( V CSE-B ) Q1. What is Deadlock? Explain essential conditions for deadlock to occur? In a multiprogramming environment, several processes may compete

More information

Today: Segmentation. Last Class: Paging. Costs of Using The TLB. The Translation Look-aside Buffer (TLB)

Today: Segmentation. Last Class: Paging. Costs of Using The TLB. The Translation Look-aside Buffer (TLB) Last Class: Paging Process generates virtual addresses from 0 to Max. OS divides the process onto pages; manages a page table for every process; and manages the pages in memory Hardware maps from virtual

More information

Memory Management (Chaper 4, Tanenbaum)

Memory Management (Chaper 4, Tanenbaum) Memory Management (Chaper 4, Tanenbaum) Memory Mgmt Introduction The CPU fetches instructions and data of a program from memory; therefore, both the program and its data must reside in the main (RAM and

More information

CS 241 Honors Memory

CS 241 Honors Memory CS 241 Honors Memory Ben Kurtovic Atul Sandur Bhuvan Venkatesh Brian Zhou Kevin Hong University of Illinois Urbana Champaign February 20, 2018 CS 241 Course Staff (UIUC) Memory February 20, 2018 1 / 35

More information

ECE 598 Advanced Operating Systems Lecture 10

ECE 598 Advanced Operating Systems Lecture 10 ECE 598 Advanced Operating Systems Lecture 10 Vince Weaver http://www.eece.maine.edu/~vweaver vincent.weaver@maine.edu 17 February 2015 Announcements Homework #1 and #2 grades, HW#3 Coming soon 1 Various

More information

Frequently asked questions from the previous class survey

Frequently asked questions from the previous class survey CS 370: OPERATING SYSTEMS [MEMORY MANAGEMENT] Shrideep Pallickara Computer Science Colorado State University L20.1 Frequently asked questions from the previous class survey Virtual addresses L20.2 SLIDES

More information

CS 390 Chapter 8 Homework Solutions

CS 390 Chapter 8 Homework Solutions CS 390 Chapter 8 Homework Solutions 8.3 Why are page sizes always... Page sizes that are a power of two make it computationally fast for the kernel to determine the page number and offset of a logical

More information

Data Structure Series

Data Structure Series Data Structure Series This series is actually something I started back when I was part of the Sweet.Oblivion staff, but then some things happened and I was no longer able to complete it. So now, after

More information

Introduction to Linked List: Review. Source:

Introduction to Linked List: Review. Source: Introduction to Linked List: Review Source: http://www.geeksforgeeks.org/data-structures/linked-list/ Linked List Fundamental data structures in C Like arrays, linked list is a linear data structure Unlike

More information

Princeton University. Computer Science 217: Introduction to Programming Systems. Dynamic Memory Management

Princeton University. Computer Science 217: Introduction to Programming Systems. Dynamic Memory Management Princeton University Computer Science 217: Introduction to Programming Systems Dynamic Memory Management 1 Agenda The need for DMM DMM using the heap section DMMgr 1: Minimal implementation DMMgr 2: Pad

More information

11.1 Segmentation: Generalized Base/Bounds

11.1 Segmentation: Generalized Base/Bounds 11 Segmentation So far we have been putting the entire address space of each process in memory. With the base and bounds registers, the OS can easily relocate processes to different parts of physical memory.

More information

6.172 Performance Engineering of Software Systems Spring Lecture 9. P after. Figure 1: A diagram of the stack (Image by MIT OpenCourseWare.

6.172 Performance Engineering of Software Systems Spring Lecture 9. P after. Figure 1: A diagram of the stack (Image by MIT OpenCourseWare. 6.172 Performance Engineering of Software Systems Spring 2009 Lecture 9 MIT OpenCourseWare Dynamic Storage Allocation Stack allocation: LIFO (last-in-first-out) Array and pointer A used unused P before

More information

TABLES AND HASHING. Chapter 13

TABLES AND HASHING. Chapter 13 Data Structures Dr Ahmed Rafat Abas Computer Science Dept, Faculty of Computer and Information, Zagazig University arabas@zu.edu.eg http://www.arsaliem.faculty.zu.edu.eg/ TABLES AND HASHING Chapter 13

More information

ECE 2035 Programming HW/SW Systems Fall problems, 5 pages Exam Three 20 November 2013

ECE 2035 Programming HW/SW Systems Fall problems, 5 pages Exam Three 20 November 2013 Instructions: This is a closed book, closed note exam. Calculators are not permitted. If you have a question, raise your hand and I will come to you. Please work the exam in pencil and do not separate

More information

Jump Tables A jump table is essentially a list of places in the code to jump to. This can be thought of in C as an array of function pointers. In Asse

Jump Tables A jump table is essentially a list of places in the code to jump to. This can be thought of in C as an array of function pointers. In Asse : Some very useful data structures commonly used in embedded systems programming (Jump tables, Circular buffers, Linked lists, Stacks and queues, Memory pools) Spring 2016 : Some very useful data structures

More information

Memory Management. Dr. Yingwu Zhu

Memory Management. Dr. Yingwu Zhu Memory Management Dr. Yingwu Zhu Big picture Main memory is a resource A process/thread is being executing, the instructions & data must be in memory Assumption: Main memory is infinite Allocation of memory

More information

A Feasibility Study for Methods of Effective Memoization Optimization

A Feasibility Study for Methods of Effective Memoization Optimization A Feasibility Study for Methods of Effective Memoization Optimization Daniel Mock October 2018 Abstract Traditionally, memoization is a compiler optimization that is applied to regions of code with few

More information

In Java we have the keyword null, which is the value of an uninitialized reference type

In Java we have the keyword null, which is the value of an uninitialized reference type + More on Pointers + Null pointers In Java we have the keyword null, which is the value of an uninitialized reference type In C we sometimes use NULL, but its just a macro for the integer 0 Pointers are

More information

Chapter 12: File System Implementation

Chapter 12: File System Implementation Chapter 12: File System Implementation Virtual File Systems. Allocation Methods. Folder Implementation. Free-Space Management. Directory Block Placement. Recovery. Virtual File Systems An object-oriented

More information

Question Bank Subject: Advanced Data Structures Class: SE Computer

Question Bank Subject: Advanced Data Structures Class: SE Computer Question Bank Subject: Advanced Data Structures Class: SE Computer Question1: Write a non recursive pseudo code for post order traversal of binary tree Answer: Pseudo Code: 1. Push root into Stack_One.

More information

Algorithms and Data Structures

Algorithms and Data Structures Algorithms and Data Structures Open Hashing Ulf Leser Open Hashing Open Hashing: Store all values inside hash table A General framework No collision: Business as usual Collision: Chose another index and

More information

Acknowledgements These slides are based on Kathryn McKinley s slides on garbage collection as well as E Christopher Lewis s slides

Acknowledgements These slides are based on Kathryn McKinley s slides on garbage collection as well as E Christopher Lewis s slides Garbage Collection Last time Compiling Object-Oriented Languages Today Motivation behind garbage collection Garbage collection basics Garbage collection performance Specific example of using GC in C++

More information

Lecture 7: Binding Time and Storage

Lecture 7: Binding Time and Storage Lecture 7: Binding Time and Storage COMP 524 Programming Language Concepts Stephen Olivier February 5, 2009 Based on notes by A. Block, N. Fisher, F. Hernandez-Campos, and D. Stotts Goal of Lecture The

More information

Memory Management. Memory Management Requirements

Memory Management. Memory Management Requirements Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable supply of ready processes to consume available processor time 1 Memory Management

More information

Memory Allocation with Lazy Fits

Memory Allocation with Lazy Fits Memory Allocation with Lazy Fits Yoo C. Chung Soo-Mook Moon School of Electrical Engineering Seoul National University Kwanak PO Box 34, Seoul 151-742, Korea {chungyc,smoon}@altair.snu.ac.kr ABSTRACT Dynamic

More information

Memory Allocation in VxWorks 6.0 White Paper

Memory Allocation in VxWorks 6.0 White Paper Memory Allocation in VxWorks 6.0 White Paper Zoltan Laszlo Wind River Systems, Inc. Copyright 2005 Wind River Systems, Inc 1 Introduction Memory allocation is a typical software engineering problem for

More information

Preview. Memory Management

Preview. Memory Management Preview Memory Management With Mono-Process With Multi-Processes Multi-process with Fixed Partitions Modeling Multiprogramming Swapping Memory Management with Bitmaps Memory Management with Free-List Virtual

More information

Requirements, Partitioning, paging, and segmentation

Requirements, Partitioning, paging, and segmentation Requirements, Partitioning, paging, and segmentation Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated efficiently to pack as many processes into memory

More information

Chapter 11: File System Implementation. Objectives

Chapter 11: File System Implementation. Objectives Chapter 11: File System Implementation Objectives To describe the details of implementing local file systems and directory structures To describe the implementation of remote file systems To discuss block

More information

Parallel storage allocator

Parallel storage allocator CSE 539 02/7/205 Parallel storage allocator Lecture 9 Scribe: Jing Li Outline of this lecture:. Criteria and definitions 2. Serial storage allocators 3. Parallel storage allocators Criteria and definitions

More information

CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages CMSC 330: Organization of Programming Languages Memory Management and Garbage Collection CMSC 330 Spring 2017 1 Memory Attributes Memory to store data in programming languages has the following lifecycle

More information

VMem. By Stewart Lynch.

VMem. By Stewart Lynch. VMem By Stewart Lynch. 1 Contents Introduction... 3 Overview... 4 Getting started... 6 Fragmentation... 7 Virtual Regions... 8 The FSA... 9 Biasing... 10 The Coalesce allocator... 11 Skewing indices...

More information

Name, Scope, and Binding. Outline [1]

Name, Scope, and Binding. Outline [1] Name, Scope, and Binding In Text: Chapter 3 Outline [1] Variable Binding Storage bindings and lifetime Type bindings Type Checking Scope Lifetime vs. Scope Referencing Environments N. Meng, S. Arthur 2

More information

Memory management. Johan Montelius KTH

Memory management. Johan Montelius KTH Memory management Johan Montelius KTH 2017 1 / 22 C program # include int global = 42; int main ( int argc, char * argv []) { if( argc < 2) return -1; int n = atoi ( argv [1]); int on_stack

More information

Dynamic Memory Management

Dynamic Memory Management Dynamic Memory Management Professor Jennifer Rexford http://www.cs.princeton.edu/~jrex 1 Goals of Today s Lecture Dynamic memory management o Garbage collection by the run-time system (Java) o Manual deallocation

More information

Compiler Construction D7011E

Compiler Construction D7011E Compiler Construction D7011E Lecture 14: Memory Management Viktor Leijon Slides largely by Johan Nordlander with material generously provided by Mark P. Jones. 1 First: Run-time Systems 2 The Final Component:

More information

Memory Management Basics

Memory Management Basics Memory Management Basics 1 Basic Memory Management Concepts Address spaces! Physical address space The address space supported by the hardware Ø Starting at address 0, going to address MAX sys! MAX sys!!

More information

A.Arpaci-Dusseau. Mapping from logical address space to physical address space. CS 537:Operating Systems lecture12.fm.2

A.Arpaci-Dusseau. Mapping from logical address space to physical address space. CS 537:Operating Systems lecture12.fm.2 UNIVERSITY of WISCONSIN-MADISON Computer Sciences Department CS 537 A. Arpaci-Dusseau Intro to Operating Systems Spring 2000 Dynamic Memory Allocation Questions answered in these notes When is a stack

More information

User created Heap Management in C on AIX

User created Heap Management in C on AIX Nitin.Bagoria User Created Heap Management in C on AIX Page 1 of 9 User created Heap Management in C on AIX Introduction The term heap, or memory heap, generally means a free memory pool, from which a

More information

CSC369 Lecture 5. Larry Zhang, October 19,2015

CSC369 Lecture 5. Larry Zhang, October 19,2015 CSC369 Lecture 5 Larry Zhang, October 19,2015 1 Describe your A1 experience using the feedback form 2 Announcements Assignment 2 out later this week, due November 11 Midterm next week in lecture: 9:10AM

More information

Engine Support System. asyrani.com

Engine Support System. asyrani.com Engine Support System asyrani.com A game engine is a complex piece of software consisting of many interacting subsystems. When the engine first starts up, each subsystem must be configured and initialized

More information

BBM 201 DATA STRUCTURES

BBM 201 DATA STRUCTURES BBM 201 DATA STRUCTURES Lecture 8: Dynamically Allocated Linked Lists 2017-2018 Fall int x; x = 8; int A[4]; An array is stored as one contiguous block of memory. How can we add a fifth element to the

More information

Class Information ANNOUCEMENTS

Class Information ANNOUCEMENTS Class Information ANNOUCEMENTS Third homework due TODAY at 11:59pm. Extension? First project has been posted, due Monday October 23, 11:59pm. Midterm exam: Friday, October 27, in class. Don t forget to

More information

Memory Management. Kevin Webb Swarthmore College February 27, 2018

Memory Management. Kevin Webb Swarthmore College February 27, 2018 Memory Management Kevin Webb Swarthmore College February 27, 2018 Today s Goals Shifting topics: different process resource memory Motivate virtual memory, including what it might look like without it

More information

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

Addresses in the source program are generally symbolic. A compiler will typically bind these symbolic addresses to re-locatable addresses. 1 Memory Management Address Binding The normal procedures is to select one of the processes in the input queue and to load that process into memory. As the process executed, it accesses instructions and

More information

Memory Management. Memory Management... Memory Management... Interface to Dynamic allocation

Memory Management. Memory Management... Memory Management... Interface to Dynamic allocation CSc 453 Compilers and Systems Software 24 : Garbage Collection Introduction Department of Computer Science University of Arizona collberg@gmail.com Copyright c 2009 Christian Collberg Dynamic Memory Management

More information

FILE SYSTEMS. CS124 Operating Systems Winter , Lecture 23

FILE SYSTEMS. CS124 Operating Systems Winter , Lecture 23 FILE SYSTEMS CS124 Operating Systems Winter 2015-2016, Lecture 23 2 Persistent Storage All programs require some form of persistent storage that lasts beyond the lifetime of an individual process Most

More information

Operating Systems. Memory Management. Lecture 9 Michael O Boyle

Operating Systems. Memory Management. Lecture 9 Michael O Boyle Operating Systems Memory Management Lecture 9 Michael O Boyle 1 Memory Management Background Logical/Virtual Address Space vs Physical Address Space Swapping Contiguous Memory Allocation Segmentation Goals

More information

Events, Memory Management

Events, Memory Management Events, Memory Management Events, Memory Management 1. Call back, message pumps 2. Call backs vs messages 3. Memory management Callback Program registers and event handler program that is called whenever

More information

Programs in memory. The layout of memory is roughly:

Programs in memory. The layout of memory is roughly: Memory 1 Programs in memory 2 The layout of memory is roughly: Virtual memory means that memory is allocated in pages or segments, accessed as if adjacent - the platform looks after this, so your program

More information

DATA STRUCTURES/UNIT 3

DATA STRUCTURES/UNIT 3 UNIT III SORTING AND SEARCHING 9 General Background Exchange sorts Selection and Tree Sorting Insertion Sorts Merge and Radix Sorts Basic Search Techniques Tree Searching General Search Trees- Hashing.

More information

CSCI 4500 / 8506 Sample Questions for Quiz 5

CSCI 4500 / 8506 Sample Questions for Quiz 5 CSCI 4500 / 8506 Sample Questions for Quiz 5 1. Why might a system treat memory allocation requests from the operating system itself differently from those generated by an application? a. The OS typically

More information

G Programming Languages - Fall 2012

G Programming Languages - Fall 2012 G22.2110-003 Programming Languages - Fall 2012 Lecture 2 Thomas Wies New York University Review Last week Programming Languages Overview Syntax and Semantics Grammars and Regular Expressions High-level

More information

Lectures 13 & 14. memory management

Lectures 13 & 14. memory management Lectures 13 & 14 Linked lists and memory management Courtesy of Prof. Garcia (UCB) CS61C L05 Introduction to C (pt 3) (1) Review Pointers and arrays are virtually same C knows how to increment pointers

More information