Project 2. Assigned: 02/20/2015 Due Date: 03/06/2015

Size: px
Start display at page:

Download "Project 2. Assigned: 02/20/2015 Due Date: 03/06/2015"

Transcription

1 CSE 539 Project 2 Assigned: 02/20/2015 Due Date: 03/06/2015 Building a thread-safe memory allocator In this project, you will implement a thread-safe malloc library. The provided codebase includes a simple implementation of a serial malloc library (i.e., NOT thread safe). Your job is to make it thread safe and possibly optimize it so that it has a better performance (in terms of both utilization and speed). Remember that correctness comes first, then performance. Thus, even though this document describes the provided infrastructure on how to test your serial memory allocator first, then parallel memory allocator, it doesn t necessarily mean that you want work on the project in that order; it highly depends on what you plan to do and how you structure your code. Please read through the entire document carefully before you start. The information in this document will help you navigate the codebase. If you organize your code well, you can likely make it thread safe first, and then optimize the baseline malloc implementation without too much disruption to the thread-safe part. Logistics for this project As in project1, you will be obtaining a copy of the base code via your svn repository (if you svn up, you should see a proj2 directory). You are encouraged to work in pairs for this project (though you are not required to). If you decide to work in a group of two, you just need to turn in one copy of the code please designate one person s svn repository for turning in code. You will still have to turn in separate writeups, however. Since this project is due on Friday, you will turn in your writeup by committing the pdf file of your writeup in your own repository (even if you are in a group of two and your repo is not the designated code repo). The due time will be before midnight, at 11 : 59 : 59 pm. Heap memory allocator interface Your dynamic storage allocator will consist of the following four functions, which (among other functions) are declared in allocator interface.h and should be defined in allocator.cpp. The allocator interface.h and allocator.cpp are encapsulated in the namespace called my to prevent name collision with the malloc library in libc. 1

2 int allocator::init(void); Before calling any functions relating to memory allocations, an application we use to evaluate your implementation will call allocator::init. You may use this function to perform any necessary initialization of your library, such as allocating the initial heap area. The return value should be 1 if there was a problem in performing the initialization and 0 if everything went smoothly. void* allocator::malloc(size t size); This call must return a pointer to a contiguous block of newly allocated memory which is at least size bytes long. This entire block must lie within the heap region and must not overlap any other currently allocated chunk. The pointers returned by allocator::malloc must always be aligned to 8-byte boundaries and within the heap boundary (i.e., between values returned by mem heap lo() and mem heap hi() from memlib.c); you ll notice that the libc implementation of malloc does the same. If the requested size is zero or an error occurs and the requested block cannot be allocated, a NULL pointer must be returned. void allocator::free(void* ptr); This call notifies your storage allocator that a currently allocated block of memory should be deallocated. The argument must be a pointer previously returned by allocator::malloc or allocator::realloc, and not previously freed. You are not required to detect or handle either of these error cases. However, you should handle freeing a NULL pointer it is defined to have no effect. void* allocator::realloc(void* ptr, size t size); This call returns a pointer to an allocated region, similarly to how allocator::malloc behaves. There are two special cases you should be aware of. If ptr is NULL, the call is equivalent to allocator::malloc(size);. If size is equal to zero, the call is equivalent to allocator::free(ptr);. Otherwise, ptr must meet the same constraints as the argument to allocator::free; it must point to a previously allocated block and it must have been previously returned by either allocator::malloc or allocator::realloc. You do not need to defend against frees to invalid pointers. The return value of allocator::realloc must meet all of the same constraints as the return value of allocator::malloc; namely, it be 8-byte aligned, must point to a block of memory of at least size bytes, and within the heap boundary. There is one additional constraint on the behavior of allocator::realloc. Any data in the old block must be copied over to the new block. If the new block is smaller, the old values are truncated; if the new block is larger, the value of each of the bytes at the end of the block is undefined. 2

3 A naive implementation of allocator::realloc might consist of nothing more than a call to allocator::malloc, a memory copy, and a call to allocator::free. This is, in fact, how the reference implementation works; leaving this solution in place is probably a good way to get started. Once you ve made progress on allocator::malloc and allocator::free, you will want to consider ways of improving the performance of allocator::realloc. All of this behavior matches the semantics of the corresponding libc routines. Type man malloc at the shell to see additional documentation, if you re curious. The allocator.cpp file we have given you currently simply makes calls to a fairly simple and serial (i.e., NOT thread-safe) malloc library that uses a freelist without binning (code in mm-implicit.c). Each block in the freelist has a header and footer to allow coalescing. (A high level description of the implicit free-list implementation can be found here: cs.cmu.edu/afs/cs/academic/class/15213-f11/www/lectures/18-allocation-basic. pdf). Support routines The code in memlib.c simulates the memory system for your dynamic memory allocator. You can invoke the following functions in memlib.c: void* mem sbrk(int incr); Expands the heap by incr bytes, where incr is a positive non-zero integer and returns a generic pointer to the first byte of the newly allocated heap area. The semantics are identical to the Unix sbrk function, except that mem sbrk accepts only a positive non-zero integer argument. void* mem heap lo(void); Returns a pointer to the first byte in the heap. void* mem heap hi(void); Returns a generic pointer to the last byte in the heap. size t mem heapsize(void); Returns the current size of the heap in bytes. size t mem pagesize(void); Returns the system page size in bytes (4 KB on Linux systems). It is unlikely that you will need this. 3

4 Improving and testing the serial malloc library implementation You are encouraged to improve the serial implementation of the malloc library. The simple implementation in mm-implicit functions correctly, but it is slow, and the utilization could be improved. We have provided infrastructure for you to improve and test the serial malloc library. The serial implementation can be tested by running the trace-based driver program mdriver. The mdriver tests your allocator.cpp package for correctness, space utilization, and throughput. You should be sure to test that your serial implementation works correctly before you try to make it thread safe; otherwise you will be in debugging hell for the rest of the week. The driver program is controlled by a trace file. Each trace file contains a sequence of allocate, reallocate, and free commands that instruct the driver to call your allocator::malloc, allocator::realloc, and allocator::free routines in some sequence. The driver mdriver accepts the following command line arguments: -t <tracedir>: Look for the default trace files in directory <tracedir> instead of the default directory (../traces). -f <tracefile>: Use one particular tracefile for testing instead of the default set of tracefiles. -h: Print a summary of the command line arguments. -l: Run and measure libc malloc in addition to the students allocator::malloc package. Note that there is no utility measure for the libc runs. -v: Verbose output. Print a performance breakdown for each tracefile in a compact table. -V: More verbose output. Prints additional diagnostic information as each trace file is processed. Useful during debugging for determining which trace file is causing your malloc package to fail. -c: Invoke the allocator::check method after each call to the malloc library. This is extremely useful for debugging. Right now it simply calls the mm checkheap function in mm-implicit.c which checks the heap validity based on how mm-implicit.c manages the heap space. As you modify the malloc library, you should customize the allocator::check to check for the validity of your heap space. 4

5 Making the malloc library thread safe Even though the malloc library in mm-implicit is a fine starting point, you need to think about how you want to restructure the library so that you can make it thread safe. In particular, mm-implicit uses static variables liberally, and you probably wouldn t want that. It is best to organize the code so that you can easily encapsulate variables for each thread-local heap, and anything that s not thread-local will need to be protected via some form of synchronization. If you add any new *.c or *.cpp files, be sure to edit your Makefile to reflect that (adding the corresponding *.o files under OBJS or the benchmarks won t compile). For testing the thread-safe version of your malloc library, we will use following additional files: benchmarks/ contains benchmark programs. wrapper.[cpp,h] contains wrapper functions for building benchmark programs. You should not modify these files. validate.py validates the correctness and computes a utilization score of an allocator for multi-threaded programs. You should not modify this file. To build the testing benchmarks, you run make benchmark. This command builds 3 versions for each benchmark program. For example, benchmarks/cache-thrash.cpp generates cache-thrash, cache-thrash-validate and cache-thrash-libc. cache-thrash uses your allocator to allocate memory, while cache-thrash-libc uses a standard allocator. cache-thrash-validate will be used with the script validate.py to test the correctness of your allocator. You should not use it for performance testing. Benchmarks for testing the thread-safe library We are using concurrent benchmarks from the paper Hoard: A Scalable Memory Allocator for Multithreaded Applications. [1] cache-thrash tests resilience against active false sharing. Active false sharing occurs when malloc satisfies memory requests by different threads from the same cache line. Parameters: <threads> <inner-loop> <object-size> <iterations>./cache-thrash P cache-scratch tests resilience against passive false sharing. Passive false sharing occurs when free allows a future malloc to produce false sharing. 5

6 Parameters: <threads> <inner-loop> <object-size> <iterations>./cache-scratch P larson simulates a server: each thread allocates and deallocates objects, and then transfers some objects (randomly selected) to other threads to be freed. This producerconsumer problem might lead to a blowup in the allocator, where some threads keep allocating bigger and bigger heaps. Parameters: <seconds> <min-obj-size> <max-obj-size> <objects> <iterations> <rng seed> <num-threads>./larson RAND P linux-scalability tests allocator throughput. Parameters: <object-size> <iterations> <number-of-threads>./linux-scalability P You can also write your own benchmarks. The program should include../wrapper.cpp, call end thread() at the end of each thread, and call end program() at the end of the program. Then, you can add this new program in Makefile. Although we will not run your benchmarks to evaluate your program, they are useful for your regression testing. Correctness tests You can use validate.py to test the correctness of the allocator:./validate.py./cache-scratch-validate This will print out VALIDATION SUCCESS if there is no error in the program. Note that you need to use a *-validate binary. validate.py runs the program and logs all memory operations to multiple files in tmp/. After that, it reads all logs, verifies that all memory operations are legal, and calculates a space utilization score. There is also a script testbenchmarks.sh already in your directory. It shows a few parameters that you can use for testing your program. During grading, we will run your program with slightly different parameters. Note that right now your program succeeds in some of these runs specified in testbenchmarks.sh, because they are configured to run with single thread or because the thread interleaving behavior doesn t trigger an error. More likely the runs with multiple threads will fail with validation error or segmentation fault. This should not occur once you have a correctly implemented thread-safe library. Hints and tips Use thread for thread-local storage. 6

7 Use volatile keyword when variables can be changed by itself. Note that volatile is not a memory fence; it s a compiler hint telling the compiler that it should always fetch the value from memory instead of keeping it in a register. Since we haven t covered memory fences and hardware memory model, you probably should not write code that requires memory fences, unless you know what you are doing. Your allocator should allocate memory such that programs run fast. You should think about how the programs access the memory, not just how to allocate memory as fast as possible. Keep in mind that TLB miss can also affect the performance of the program. Rules and reminders You should not change any of the sources in the distribution except for the Makefile, allocator.cpp, validator.h, allocator interface.h and bad allocator.cpp. You are free to add new files and update the Makefile appropriately if you wish. All of the other files will be overwritten with fresh copies during grading You should not invoke any memory-management related library calls or system calls. This excludes the use of malloc, calloc, free, realloc, sbrk, brk, mmap or any variants of these calls in your code. Usage of C++ Standard Template Library containers is NOT allowed (since they will use memory on heap internally bypassing our allocator heap interface). All data structures that allocate memory on heap MUST use our allocator heap interface. Hence, all heap memory space used by your data structures will hence be counted under space utilization. The total size of all defined global and static scalar variables and compound data structures should be small, ideally not exceed 256 bytes per thread, but we will not put a strict upper bound on it. The spirit is that you should also consider space overhead, and any space you use for bookkeeping is counted towards the space utilization. Evaluation You will receive zero points if you break any of the rules or your code is buggy / won t compile. Otherwise, your grade will be calculated based on both correctness and performance (utilization and speed). The library should work correctly for both serial and parallel code (as evaluated by invoking mdriver and the parallel benchmarks. 7

8 You will get partial credit if you have a correct working version of a thread-safe malloc library that simply uses the mm-implicit implementation protected by locks. The more efficient (both utilization and throughput) your implementation is, the more credit you will get. That said, since this is a project mainly about thread-safe malloc library, the first goal should be to make the malloc library thread-safe. Once that s done, go back to optimize the baseline malloc library that you use to implement the per-thread heap. Writeup In your write-up, which you will turn in via committing a pdf in your svn repo, please include: 1. a description of your strategy for making the library thread-safe, including a justification on why it correctly synchronizes accesses from multiple threads and that it is deadlock free. 2. a description of any changes you made to the serial basecode to speed it up (or a description of the new memory allocator if you re-implemented the serial version). 3. a description of any optimizations that you did for speeding up the parallel malloc library implementation. 4. a description of how you divide up the work if you worked in a group of two. Note that even if you work in a group of two, you still need to turn your own writeup. References [1] Emery D. Berger, Kathryn S. McKinley, Robert D. Blumofe, Paul R. Wilson, Hoard: a scalable memory allocator for multithreaded applications, ACM SIGPLAN Notices, v.35 n.11, p , Nov

Writing a Dynamic Storage Allocator

Writing a Dynamic Storage Allocator Project 3 Writing a Dynamic Storage Allocator Out: In class on Thursday, 8 Oct 2009 Due: In class on Thursday, 22 Oct 2009 In this project, you will be writing a dynamic storage allocator for C programs,

More information

ECE454, Fall 2014 Homework3: Dynamic Memory Allocation Assigned: Oct 9th, Due: Nov 6th, 11:59PM

ECE454, Fall 2014 Homework3: Dynamic Memory Allocation Assigned: Oct 9th, Due: Nov 6th, 11:59PM ECE454, Fall 2014 Homework3: Dynamic Memory Allocation Assigned: Oct 9th, Due: Nov 6th, 11:59PM The TA for this assignment is Xu Zhao (nuk.zhao@mail.utoronto.ca). 1 Introduction OptsRus is doing really

More information

CS 105 Malloc Lab: Writing a Dynamic Storage Allocator See Web page for due date

CS 105 Malloc Lab: Writing a Dynamic Storage Allocator See Web page for due date CS 105 Malloc Lab: Writing a Dynamic Storage Allocator See Web page for due date 1 Introduction In this lab you will be writing a dynamic storage allocator for C programs, i.e., your own version of the

More information

CSE 361 Fall 2017 Malloc Lab: Writing a Dynamic Storage Allocator Assigned: Monday Nov. 13, Due: Monday Dec. 05, 11:59PM

CSE 361 Fall 2017 Malloc Lab: Writing a Dynamic Storage Allocator Assigned: Monday Nov. 13, Due: Monday Dec. 05, 11:59PM CSE 361 Fall 2017 Malloc Lab: Writing a Dynamic Storage Allocator Assigned: Monday Nov. 13, Due: Monday Dec. 05, 11:59PM 1 Introduction In this lab you will be writing a dynamic storage allocator for C

More information

Spring 2016, Malloc Lab: Writing Dynamic Memory Allocator

Spring 2016, Malloc Lab: Writing Dynamic Memory Allocator 1. Introduction Spring 2016, Malloc Lab: Writing Dynamic Memory Allocator Assigned: Mar. 03 Due: Mar. 17, 15:59 In this lab you will be writing a dynamic memory allocator for C programs, i.e., your own

More information

CSE 351, Spring 2010 Lab 7: Writing a Dynamic Storage Allocator Due: Thursday May 27, 11:59PM

CSE 351, Spring 2010 Lab 7: Writing a Dynamic Storage Allocator Due: Thursday May 27, 11:59PM CSE 351, Spring 2010 Lab 7: Writing a Dynamic Storage Allocator Due: Thursday May 27, 11:59PM 1 Instructions In this lab you will be writing a dynamic storage allocator for C programs, i.e., your own version

More information

CS 213, Fall 2002 Malloc Lab: Writing a Debugging Dynamic Storage Allocator Assigned: Fri Nov. 1, Due: Tuesday Nov. 19, 11:59PM

CS 213, Fall 2002 Malloc Lab: Writing a Debugging Dynamic Storage Allocator Assigned: Fri Nov. 1, Due: Tuesday Nov. 19, 11:59PM CS 213, Fall 2002 Malloc Lab: Writing a Debugging Dynamic Storage Allocator Assigned: Fri Nov. 1, Due: Tuesday Nov. 19, 11:59PM Anubhav Gupta (anubhav@cs.cmu.edu) is the lead person for this assignment.

More information

1 Introduction. 2 Logistics. 3 Hand Out Instructions

1 Introduction. 2 Logistics. 3 Hand Out Instructions CS 153, Winter 2018 Malloc Lab: Writing a Dynamic Storage Allocator Due: Last Friday in final s week. No slack days Graded by Interview on the same Friday or over weekend Nael Abu-Ghazaleh (nael@cs.ucr.edu)

More information

COMP 321: Introduction to Computer Systems

COMP 321: Introduction to Computer Systems Assigned: 3/8/18, Due: 3/29/18 Important: This project may be done individually or in pairs. Be sure to carefully read the course policies for assignments (including the honor code policy) on the assignments

More information

CS 3214, Fall 2015 Malloc Lab: Writing a Dynamic Storage Allocator Due date: November 16, 2014, 11:59pm

CS 3214, Fall 2015 Malloc Lab: Writing a Dynamic Storage Allocator Due date: November 16, 2014, 11:59pm CS 3214, Fall 2015 Malloc Lab: Writing a Dynamic Storage Allocator Due date: November 16, 2014, 11:59pm 1 Introduction In this lab you will be writing a dynamic storage allocator for C programs, i.e.,

More information

CSCI 2021, Fall 2018 Malloc Lab: Writing a Dynamic Storage Allocator Assigned: Monday November 5th Due: Monday November 19th, 11:55PM

CSCI 2021, Fall 2018 Malloc Lab: Writing a Dynamic Storage Allocator Assigned: Monday November 5th Due: Monday November 19th, 11:55PM CSCI 2021, Fall 2018 Malloc Lab: Writing a Dynamic Storage Allocator Assigned: Monday November 5th Due: Monday November 19th, 11:55PM 1 Introduction In this lab you will be writing a dynamic storage allocator

More information

CSE 361S Intro to Systems Software Final Project

CSE 361S Intro to Systems Software Final Project Due: Tuesday, December 9, 2008. CSE 361S Intro to Systems Software Final Project In this project, you will be writing a dynamic storage allocator for C programs (i.e., your own version of malloc, free,

More information

CS 105 Malloc Lab: Writing a Dynamic Storage Allocator See Web page for due date

CS 105 Malloc Lab: Writing a Dynamic Storage Allocator See Web page for due date CS 105 Malloc Lab: Writing a Dynamic Storage Allocator See Web page for due date 1 Introduction In this lab you will be writing a dynamic storage allocator for C programs, i.e., your own version of the

More information

CS201: Lab #4 Writing a Dynamic Storage Allocator

CS201: Lab #4 Writing a Dynamic Storage Allocator CS201: Lab #4 Writing a Dynamic Storage Allocator In this lab you will write a dynamic storage allocator for C programs, i.e., your own version of the malloc, free and realloc routines. You are encouraged

More information

CSCI0330 Intro Computer Systems Doeppner. Project Malloc. Due: 11/28/18. 1 Introduction 1. 2 Assignment Specification Support Routines 4

CSCI0330 Intro Computer Systems Doeppner. Project Malloc. Due: 11/28/18. 1 Introduction 1. 2 Assignment Specification Support Routines 4 Project Malloc Due: 11/28/18 1 Introduction 1 2 Assignment 2 2.1 Specification 2 2.2 Support Routines 4 3 The Trace-driven Driver Program (mdriver) 6 4 Using the REPL 6 5 Programming Rules 7 6 GDB 7 6.1

More information

Project 4: Implementing Malloc Introduction & Problem statement

Project 4: Implementing Malloc Introduction & Problem statement Project 4 (75 points) Assigned: February 14, 2014 Due: March 4, 2014, 11:59 PM CS-3013, Operating Systems C-Term 2014 Project 4: Implementing Malloc Introduction & Problem statement As C programmers, we

More information

HW 3: Malloc CS 162. Due: Monday, March 28, 2016

HW 3: Malloc CS 162. Due: Monday, March 28, 2016 CS 162 Due: Monday, March 28, 2016 1 Introduction Your task in this assignment is to implement your own memory allocator from scratch. This will expose you to POSIX interfaces, force you to reason about

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

Project 3a: Malloc and Free

Project 3a: Malloc and Free Project 3a: Malloc and Free DUE 03/17 at 11:59 PM One late day allowed for submission without any penalty Objectives There are four objectives to this part of the assignment: Note To understand the nuances

More information

Project 2 Overview: Part A: User space memory allocation

Project 2 Overview: Part A: User space memory allocation Project 2 Overview: Once again, this project will have 2 parts. In the first part, you will get to implement your own user space memory allocator. You will learn the complexities and details of memory

More information

Assignment 5. CS/ECE 354 Spring 2016 DUE: April 22nd (Friday) at 9 am

Assignment 5. CS/ECE 354 Spring 2016 DUE: April 22nd (Friday) at 9 am 1. Collaboration Policy Assignment 5 CS/ECE 354 Spring 2016 DUE: April 22nd (Friday) at 9 am For this assignment, you may work in pairs (2 people). All students (whether working in a pair or not) must

More information

My malloc: mylloc and mhysa. Johan Montelius HT2016

My malloc: mylloc and mhysa. Johan Montelius HT2016 1 Introduction My malloc: mylloc and mhysa Johan Montelius HT2016 So this is an experiment where we will implement our own malloc. We will not implement the world s fastest allocator, but it will work

More information

Lab 1: Dynamic Memory: Heap Manager

Lab 1: Dynamic Memory: Heap Manager Lab 1: Dynamic Memory: Heap Manager Introduction to Systems, Duke University 1 Introduction For this lab you implement a basic heap manager. The standard C runtime library provides a standard heap manager

More information

The Art and Science of Memory Allocation

The Art and Science of Memory Allocation Logical Diagram The Art and Science of Memory Allocation Don Porter CSE 506 Binary Formats RCU Memory Management Memory Allocators CPU Scheduler User System Calls Kernel Today s Lecture File System Networking

More information

Recitation #11 Malloc Lab. November 7th, 2017

Recitation #11 Malloc Lab. November 7th, 2017 18-600 Recitation #11 Malloc Lab November 7th, 2017 1 2 Important Notes about Malloc Lab Malloc lab has been updated from previous years Supports a full 64 bit address space rather than 32 bit Encourages

More information

Recitation #12 Malloc Lab - Part 2. November 14th, 2017

Recitation #12 Malloc Lab - Part 2. November 14th, 2017 18-600 Recitation #12 Malloc Lab - Part 2 November 14th, 2017 1 2 REMINDER Malloc Lab checkpoint is due on 11/17 This is Friday (instead of the usual Thursday deadline) No late days available Final submission

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

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

ANITA S SUPER AWESOME RECITATION SLIDES

ANITA S SUPER AWESOME RECITATION SLIDES ANITA S SUPER AWESOME RECITATION SLIDES 15/18-213: Introduction to Computer Systems Dynamic Memory Allocation Anita Zhang, Section M UPDATES Cache Lab style points released Don t fret too much Shell Lab

More information

Advanced Memory Allocation

Advanced Memory Allocation Advanced Memory Allocation Call some useful functions of the GNU C library to save precious memory and to find nasty bugs. by Gianluca Insolvibile Dealing with dynamic memory traditionally has been one

More information

1. Overview This project will help you understand address spaces and virtual memory management.

1. Overview This project will help you understand address spaces and virtual memory management. Project 2--Memory Worth: 12 points Assigned: Due: 1. Overview This project will help you understand address spaces and virtual memory management. In this project, you will implement an external pager,

More information

CSE351 Winter 2016, Final Examination March 16, 2016

CSE351 Winter 2016, Final Examination March 16, 2016 CSE351 Winter 2016, Final Examination March 16, 2016 Please do not turn the page until 2:30. Rules: The exam is closed-book, closed-note, etc. Please stop promptly at 4:20. There are 125 (not 100) points,

More information

Copyright 2013 Thomas W. Doeppner. IX 1

Copyright 2013 Thomas W. Doeppner. IX 1 Copyright 2013 Thomas W. Doeppner. IX 1 If we have only one thread, then, no matter how many processors we have, we can do only one thing at a time. Thus multiple threads allow us to multiplex the handling

More information

Malloc Lab & Midterm Solutions. Recitation 11: Tuesday: 11/08/2016

Malloc Lab & Midterm Solutions. Recitation 11: Tuesday: 11/08/2016 Malloc Lab & Midterm Solutions Recitation 11: Tuesday: 11/08/2016 Malloc 2 Important Notes about Malloc Lab Malloc lab has been updated from previous years Supports a full 64 bit address space rather than

More information

Allocating memory in a lock-free manner

Allocating memory in a lock-free manner Allocating memory in a lock-free manner Anders Gidenstam, Marina Papatriantafilou and Philippas Tsigas Distributed Computing and Systems group, Department of Computer Science and Engineering, Chalmers

More information

Memory Allocation. Copyright : University of Illinois CS 241 Staff 1

Memory Allocation. Copyright : University of Illinois CS 241 Staff 1 Memory Allocation Copyright : University of Illinois CS 241 Staff 1 Memory allocation within a process What happens when you declare a variable? Allocating a page for every variable wouldn t be efficient

More information

C: Pointers. C: Pointers. Department of Computer Science College of Engineering Boise State University. September 11, /21

C: Pointers. C: Pointers. Department of Computer Science College of Engineering Boise State University. September 11, /21 Department of Computer Science College of Engineering Boise State University September 11, 2017 1/21 Pointers A pointer is a variable that stores the address of another variable. Pointers are similar to

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

SmartHeap for Multi-Core

SmartHeap for Multi-Core SmartHeap for Multi-Core Getting Started and Platform Guide for Linux Version 11.2 SmartHeap and HeapAgent are trademarks of Compuware Corporation. All other trademarks are the property of their respective

More information

10.1. CS356 Unit 10. Memory Allocation & Heap Management

10.1. CS356 Unit 10. Memory Allocation & Heap Management 10.1 CS356 Unit 10 Memory Allocation & Heap Management 10.2 BASIC OS CONCEPTS & TERMINOLOGY 10.3 User vs. Kernel Mode Kernel mode is a special mode of the processor for executing trusted (OS) code Certain

More information

Recitation 10: Malloc Lab

Recitation 10: Malloc Lab Recitation 10: Malloc Lab Instructors Nov. 5, 2018 1 Administrivia Malloc checkpoint due Thursday, Nov. 8! wooooooooooo Malloc final due the week after, Nov. 15! wooooooooooo Malloc Bootcamp Sunday, Nov.

More information

Programming Tips for CS758/858

Programming Tips for CS758/858 Programming Tips for CS758/858 January 28, 2016 1 Introduction The programming assignments for CS758/858 will all be done in C. If you are not very familiar with the C programming language we recommend

More information

CS 322 Operating Systems Programming Assignment 4 Writing a memory manager Due: April 5, 11:30 PM

CS 322 Operating Systems Programming Assignment 4 Writing a memory manager Due: April 5, 11:30 PM CS 322 Operating Systems Programming Assignment 4 Writing a memory manager Due: April 5, 11:30 PM Goals To understand the nuances of building a memory allocator. To create a shared library. Background

More information

CS 137 Part 5. Pointers, Arrays, Malloc, Variable Sized Arrays, Vectors. October 25th, 2017

CS 137 Part 5. Pointers, Arrays, Malloc, Variable Sized Arrays, Vectors. October 25th, 2017 CS 137 Part 5 Pointers, Arrays, Malloc, Variable Sized Arrays, Vectors October 25th, 2017 Exam Wrapper Silently answer the following questions on paper (for yourself) Do you think that the problems on

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 Goals of this Lecture Help you learn about: The need for dynamic* memory mgmt (DMM) Implementing

More information

Machine Problem 1: A Simple Memory Allocator

Machine Problem 1: A Simple Memory Allocator Machine Problem 1: A Simple Memory Allocator Introduction In this machine problem, you are to develop a simple memory allocator that implements the functions my malloc() and my free(), very similarly to

More information

Recitation 11: More Malloc Lab

Recitation 11: More Malloc Lab Recitation 11: More Malloc Lab Instructor: TA(s) 1 Understanding Your Code Sketch out the heap Add Instrumentation Use tools 2 Sketch out the Heap Start with a heap, in this case implicit list 0 4 4 4

More information

Carnegie Mellon. Malloc Boot Camp. Stan, Nikhil, Kim

Carnegie Mellon. Malloc Boot Camp. Stan, Nikhil, Kim Malloc Boot Camp Stan, Nikhil, Kim Agenda Carnegie Mellon Conceptual Overview Explicit List Segregated list Splitting, coalescing Hints on hints Advanced debugging with GDB Fun GDB tricks Writing a good

More information

o Code, executable, and process o Main memory vs. virtual memory

o Code, executable, and process o Main memory vs. virtual memory Goals for Today s Lecture Memory Allocation Prof. David August COS 217 Behind the scenes of running a program o Code, executable, and process o Main memory vs. virtual memory Memory layout for UNIX processes,

More information

CS 322 Operating Systems Programming Assignment 4 Writing a memory manager Due: November 16, 11:30 PM

CS 322 Operating Systems Programming Assignment 4 Writing a memory manager Due: November 16, 11:30 PM CS 322 Operating Systems Programming Assignment 4 Writing a memory manager Due: November 16, 11:30 PM Goals To understand the nuances of building a memory allocator. To create a shared library. Background

More information

Today. Dynamic Memory Allocation: Basic Concepts. Dynamic Memory Allocation. Dynamic Memory Allocation. malloc Example. The malloc Package

Today. Dynamic Memory Allocation: Basic Concepts. Dynamic Memory Allocation. Dynamic Memory Allocation. malloc Example. The malloc Package Today Dynamic Memory Allocation: Basic Concepts Basic concepts Performance concerns Approach 1: implicit free lists CSci 01: Machine Architecture and Organization Lecture #9, April th, 016 Your instructor:

More information

CS 429H, Spring 2012 Optimizing the Performance of a Pipelined Processor Assigned: March 26, Due: April 19, 11:59PM

CS 429H, Spring 2012 Optimizing the Performance of a Pipelined Processor Assigned: March 26, Due: April 19, 11:59PM CS 429H, Spring 2012 Optimizing the Performance of a Pipelined Processor Assigned: March 26, Due: April 19, 11:59PM 1 Introduction In this lab, you will learn about the design and implementation of a pipelined

More information

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

CS61C Machine Structures. Lecture 4 C Pointers and Arrays. 1/25/2006 John Wawrzynek. www-inst.eecs.berkeley.edu/~cs61c/

CS61C Machine Structures. Lecture 4 C Pointers and Arrays. 1/25/2006 John Wawrzynek. www-inst.eecs.berkeley.edu/~cs61c/ CS61C Machine Structures Lecture 4 C Pointers and Arrays 1/25/2006 John Wawrzynek (www.cs.berkeley.edu/~johnw) www-inst.eecs.berkeley.edu/~cs61c/ CS 61C L04 C Pointers (1) Common C Error There is a difference

More information

Dynamic Memory Allocation I Nov 5, 2002

Dynamic Memory Allocation I Nov 5, 2002 15-213 The course that gives CMU its Zip! Dynamic Memory Allocation I Nov 5, 2002 Topics Simple explicit allocators Data structures Mechanisms Policies class21.ppt Harsh Reality Memory is not unbounded

More information

Hoard: A Fast, Scalable, and Memory-Efficient Allocator for Shared-Memory Multiprocessors

Hoard: A Fast, Scalable, and Memory-Efficient Allocator for Shared-Memory Multiprocessors Hoard: A Fast, Scalable, and Memory-Efficient Allocator for Shared-Memory Multiprocessors Emery D. Berger Robert D. Blumofe femery,rdbg@cs.utexas.edu Department of Computer Sciences The University of Texas

More information

CS61C : Machine Structures

CS61C : Machine Structures inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture #3 C Strings, Arrays, & Malloc 2007-06-27 Scott Beamer, Instructor Sun announces new supercomputer: Sun Constellation CS61C L3 C Pointers

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

Dynamic Memory Allocation. Gerson Robboy Portland State University. class20.ppt

Dynamic Memory Allocation. Gerson Robboy Portland State University. class20.ppt Dynamic Memory Allocation Gerson Robboy Portland State University class20.ppt Harsh Reality Memory is not unbounded It must be allocated and managed Many applications are memory dominated Especially those

More information

CSE351 Spring 2018, Final Exam June 6, 2018

CSE351 Spring 2018, Final Exam June 6, 2018 CSE351 Spring 2018, Final Exam June 6, 2018 Please do not turn the page until 2:30. Last Name: First Name: Student ID Number: Name of person to your left: Name of person to your right: Signature indicating:

More information

Secure Software Programming and Vulnerability Analysis

Secure Software Programming and Vulnerability Analysis Secure Software Programming and Vulnerability Analysis Christopher Kruegel chris@auto.tuwien.ac.at http://www.auto.tuwien.ac.at/~chris Heap Buffer Overflows and Format String Vulnerabilities Secure Software

More information

Project #1: Tracing, System Calls, and Processes

Project #1: Tracing, System Calls, and Processes Project #1: Tracing, System Calls, and Processes Objectives In this project, you will learn about system calls, process control and several different techniques for tracing and instrumenting process behaviors.

More information

HOT-Compilation: Garbage Collection

HOT-Compilation: Garbage Collection HOT-Compilation: Garbage Collection TA: Akiva Leffert aleffert@andrew.cmu.edu Out: Saturday, December 9th In: Tuesday, December 9th (Before midnight) Introduction It s time to take a step back and congratulate

More information

18-447: Computer Architecture Lecture 16: Virtual Memory

18-447: Computer Architecture Lecture 16: Virtual Memory 18-447: Computer Architecture Lecture 16: Virtual Memory Justin Meza Carnegie Mellon University (with material from Onur Mutlu, Michael Papamichael, and Vivek Seshadri) 1 Notes HW 2 and Lab 2 grades will

More information

Lecture 8 Dynamic Memory Allocation

Lecture 8 Dynamic Memory Allocation Lecture 8 Dynamic Memory Allocation CS240 1 Memory Computer programs manipulate an abstraction of the computer s memory subsystem Memory: on the hardware side 3 @ http://computer.howstuffworks.com/computer-memory.htm/printable

More information

CSCI-UA /2. Computer Systems Organization Lecture 19: Dynamic Memory Allocation: Basics

CSCI-UA /2. Computer Systems Organization Lecture 19: Dynamic Memory Allocation: Basics Slides adapted (and slightly modified) from: Clark Barrett Jinyang Li Randy Bryant Dave O Hallaron CSCI-UA.0201-001/2 Computer Systems Organization Lecture 19: Dynamic Memory Allocation: Basics Mohamed

More information

PROJECT 2 - MEMORY ALLOCATOR Computer Systems Principles. October 1, 2010

PROJECT 2 - MEMORY ALLOCATOR Computer Systems Principles. October 1, 2010 PROJECT 2 - MEMORY ALLOCATOR Computer Systems Principles Emery Berger Mark Corner October 1, 2010 1 Overview The purpose of this project is to acquaint you with how memory allocators provide virtual memory

More information

Directory. File. Chunk. Disk

Directory. File. Chunk. Disk SIFS Phase 1 Due: October 14, 2007 at midnight Phase 2 Due: December 5, 2007 at midnight 1. Overview This semester you will implement a single-instance file system (SIFS) that stores only one copy of data,

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

Reminder: compiling & linking

Reminder: compiling & linking Reminder: compiling & linking source file 1 object file 1 source file 2 compilation object file 2 library object file 1 linking (relocation + linking) load file source file N object file N library object

More information

Introduction to Computer Systems /18 243, fall th Lecture, Oct. 22 th

Introduction to Computer Systems /18 243, fall th Lecture, Oct. 22 th Introduction to Computer Systems 15 213/18 243, fall 2009 16 th Lecture, Oct. 22 th Instructors: Gregory Kesden and Markus Püschel Today Dynamic memory allocation Process Memory Image %esp kernel virtual

More information

CMSC 341 Lecture 2 Dynamic Memory and Pointers

CMSC 341 Lecture 2 Dynamic Memory and Pointers CMSC 341 Lecture 2 Dynamic Memory and Pointers Park Sects. 01 & 02 Based on earlier course slides at UMBC Today s Topics Stack vs Heap Allocating and freeing memory new and delete Memory Leaks Valgrind

More information

Recall: Address Space Map. 13: Memory Management. Let s be reasonable. Processes Address Space. Send it to disk. Freeing up System Memory

Recall: Address Space Map. 13: Memory Management. Let s be reasonable. Processes Address Space. Send it to disk. Freeing up System Memory Recall: Address Space Map 13: Memory Management Biggest Virtual Address Stack (Space for local variables etc. For each nested procedure call) Sometimes Reserved for OS Stack Pointer Last Modified: 6/21/2004

More information

Week 5, continued. This is CS50. Harvard University. Fall Cheng Gong

Week 5, continued. This is CS50. Harvard University. Fall Cheng Gong This is CS50. Harvard University. Fall 2014. Cheng Gong Table of Contents News... 1 Buffer Overflow... 1 Malloc... 6 Linked Lists... 7 Searching... 13 Inserting... 16 Removing... 19 News Good news everyone!

More information

Programming with MPI

Programming with MPI Programming with MPI p. 1/?? Programming with MPI One-sided Communication Nick Maclaren nmm1@cam.ac.uk October 2010 Programming with MPI p. 2/?? What Is It? This corresponds to what is often called RDMA

More information

HW1 due Monday by 9:30am Assignment online, submission details to come

HW1 due Monday by 9:30am Assignment online, submission details to come inst.eecs.berkeley.edu/~cs61c CS61CL : Machine Structures Lecture #2 - C Pointers and Arrays Administrivia Buggy Start Lab schedule, lab machines, HW0 due tomorrow in lab 2009-06-24 HW1 due Monday by 9:30am

More information

SYSTEM CALL IMPLEMENTATION. CS124 Operating Systems Fall , Lecture 14

SYSTEM CALL IMPLEMENTATION. CS124 Operating Systems Fall , Lecture 14 SYSTEM CALL IMPLEMENTATION CS124 Operating Systems Fall 2017-2018, Lecture 14 2 User Processes and System Calls Previously stated that user applications interact with the kernel via system calls Typically

More information

MEMORY MANAGEMENT UNITS

MEMORY MANAGEMENT UNITS Memory Management Units memory management unit (MMU) simply converts a virtual address generated by a CPU into a physical address which is applied to the memory system address space divided into fixed

More information

Segmentation. Multiple Segments. Lecture Notes Week 6

Segmentation. Multiple Segments. Lecture Notes Week 6 At this point, we have the concept of virtual memory. The CPU emits virtual memory addresses instead of physical memory addresses. The MMU translates between virtual and physical addresses. Don't forget,

More information

Heap Management. Heap Allocation

Heap Management. Heap Allocation Heap Management Heap Allocation A very flexible storage allocation mechanism is heap allocation. Any number of data objects can be allocated and freed in a memory pool, called a heap. Heap allocation is

More information

Pointers in C/C++ 1 Memory Addresses 2

Pointers in C/C++ 1 Memory Addresses 2 Pointers in C/C++ Contents 1 Memory Addresses 2 2 Pointers and Indirection 3 2.1 The & and * Operators.............................................. 4 2.2 A Comment on Types - Muy Importante!...................................

More information

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2017 Lecture 7

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2017 Lecture 7 CS24: INTRODUCTION TO COMPUTING SYSTEMS Spring 2017 Lecture 7 LAST TIME Dynamic memory allocation and the heap: A run-time facility that satisfies multiple needs: Programs can use widely varying, possibly

More information

Dynamic Memory Allocation I

Dynamic Memory Allocation I Dynamic Memory Allocation I William J. Taffe Plymouth State University Using the Slides of Randall E. Bryant Carnegie Mellon University Topics Simple explicit allocators Data structures Mechanisms Policies

More information

Pebbles Kernel Specification September 26, 2004

Pebbles Kernel Specification September 26, 2004 15-410, Operating System Design & Implementation Pebbles Kernel Specification September 26, 2004 Contents 1 Introduction 2 1.1 Overview...................................... 2 2 User Execution Environment

More information

Operating Systems, Assignment 2 Threads and Synchronization

Operating Systems, Assignment 2 Threads and Synchronization Operating Systems, Assignment 2 Threads and Synchronization Responsible TA's: Zohar and Matan Assignment overview The assignment consists of the following parts: 1) Kernel-level threads package 2) Synchronization

More information

CSC/ECE 506: Computer Architecture and Multiprocessing Program 3: Simulating DSM Coherence Due: Tuesday, Nov 22, 2016

CSC/ECE 506: Computer Architecture and Multiprocessing Program 3: Simulating DSM Coherence Due: Tuesday, Nov 22, 2016 CSC/ECE 506: Computer Architecture and Multiprocessing Program 3: Simulating DSM Coherence Due: Tuesday, Nov 22, 2016 1. Overall Problem Description In this project, you will add new features to a trace-driven

More information

COMP 321: Introduction to Computer Systems

COMP 321: Introduction to Computer Systems Assigned: 1/18/18, Due: 2/1/18, 11:55 PM Important: This project must be done individually. Be sure to carefully read the course policies for assignments (including the honor code policy) on the assignments

More information

Creating a String Data Type in C

Creating a String Data Type in C C Programming Creating a String Data Type in C For this assignment, you will use the struct mechanism in C to implement a data type that models a character string: struct _String { char data; dynamically-allocated

More information

UW CSE 351, Winter 2013 Final Exam

UW CSE 351, Winter 2013 Final Exam Full Name: Student ID #: UW CSE 351, Winter 2013 Final Exam March 20, 2013 2:30pm - 4:20pm Instructions: Write your full name and UW student ID number on the front of the exam. When the exam begins, make

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

CS Programming In C

CS Programming In C CS 24000 - Programming In C Week 16: Review Zhiyuan Li Department of Computer Science Purdue University, USA This has been quite a journey Congratulation to all students who have worked hard in honest

More information

377 Student Guide to C++

377 Student Guide to C++ 377 Student Guide to C++ c Mark Corner January 21, 2004 1 Introduction In this course you will be using the C++ language to complete several programming assignments. Up to this point we have only provided

More information

Memory Allocation II. CSE 351 Autumn Instructor: Justin Hsia

Memory Allocation II. CSE 351 Autumn Instructor: Justin Hsia Memory Allocation II CSE 351 Autumn 2016 Instructor: Justin Hsia Teaching Assistants: Chris Ma Hunter Zahn John Kaltenbach Kevin Bi Sachin Mehta Suraj Bhat Thomas Neuman Waylon Huang Xi Liu Yufang Sun

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

CS-537: Midterm Exam (Fall 2013) Professor McFlub

CS-537: Midterm Exam (Fall 2013) Professor McFlub CS-537: Midterm Exam (Fall 2013) Professor McFlub Please Read All Questions Carefully! There are fourteen (14) total numbered pages. Please put your NAME (mandatory) on THIS page, and this page only. Name:

More information

Process s Address Space. Dynamic Memory. Backing the Heap. Dynamic memory allocation 3/29/2013. When a process starts the heap is empty

Process s Address Space. Dynamic Memory. Backing the Heap. Dynamic memory allocation 3/29/2013. When a process starts the heap is empty /9/01 Process s Address Space Dynamic Memory 0x7fffffff Stack Data (Heap) Data (Heap) 0 Text (Code) Backing the Heap When a process starts the heap is empty The process is responsible for requesting memory

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

Declaring Pointers. Declaration of pointers <type> *variable <type> *variable = initial-value Examples:

Declaring Pointers. Declaration of pointers <type> *variable <type> *variable = initial-value Examples: 1 Programming in C Pointer Variable A variable that stores a memory address Allows C programs to simulate call-by-reference Allows a programmer to create and manipulate dynamic data structures Must be

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

CS 11 C track: lecture 5

CS 11 C track: lecture 5 CS 11 C track: lecture 5 Last week: pointers This week: Pointer arithmetic Arrays and pointers Dynamic memory allocation The stack and the heap Pointers (from last week) Address: location where data stored

More information