CSCI 380: Operating Systems Instructor: William Killian

Slides:



Advertisements
Similar presentations
11-Jun-14 The assert statement. 2 About the assert statement The purpose of the assert statement is to give you a way to catch program errors early The.
Advertisements

Lectures on File Management
Module R2 CS450. Next Week R1 is due next Friday ▫Bring manuals in a binder - make sure to have a cover page with group number, module, and date. You.
Programming Types of Testing.
1 Optimizing Malloc and Free Professor Jennifer Rexford COS 217 Reading: Section 8.7 in K&R book
Malloc Recitation Section K (Kevin Su) November 5 th, 2012.
Carnegie Mellon 1 Debugging : Introduction to Computer Systems Recitation 12: Monday, Nov. 9 th, 2013 Yixun Xu Section K.
DEBUGGING IN THE REAL WORLD : Recitation 4.
18-213: Introduction to Computer Systems April 6, 2015
Chapter 15 : Attacking Compiled Applications Alexis Kirat - International Student.
Lab 3: Malloc Lab. “What do we need to do?”  Due 11/26  One more assignment after this one  Partnering  Non-Honors students may work with one other.
1 Optimizing Malloc and Free Professor Jennifer Rexford
Bug Session Two. Session description In this session the use of algorithms is reinforced to help pupils plan out what they will need to program on their.
CSE 486/586 CSE 486/586 Distributed Systems PA Best Practices Steve Ko Computer Sciences and Engineering University at Buffalo.
1 Using Classes Object-Oriented Programming Using C++ Second Edition 5.
Using Classes Object-Oriented Programming Using C++ Second Edition 5.
L6: Malloc Lab Writing a Dynamic Storage Allocator October 30, 2006
Chocolate Bar! luqili. Milestone 3 Speed 11% of final mark 7%: path quality and speed –Some cleverness required for full marks –Implement some A* techniques.
CIS*2450 Seminar I Makefiles Debugging/Design Approaches Exception Handling Library Revision Control Designed by: Terry Moreland Updated by: Tom Crabtree.
Carnegie Mellon 1 Debugging Malloc Lab : Introduction to Computer Systems Recitation 12: Monday, Nov. 11 th, 2013 Marjorie Carlson Section A.
Stack and Heap Memory Stack resident variables include:
Building a Real Workflow Thursday morning, 9:00 am Lauren Michael Research Computing Facilitator University of Wisconsin - Madison.
Agenda Attack Lab C Exercises C Conventions C Debugging
CSE 123 Discussion 10/05/2015 Updated from Anup and Narendran’s excellent notes.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 11 – gdb and Debugging.
Hank Childs, University of Oregon April 15th, 2015 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __ / / / /
C++ 程序语言设计 Chapter 12: Dynamic Object Creation. Outline  Object creation process  Overloading new & delete.
Carnegie Mellon Dynamic Memory Allocation : Introduction to Computer Systems Monday March 30th,
More about Java Classes Writing your own Java Classes More about constructors and creating objects.
1 Debugging (Part 2). “Programming in the Large” Steps Design & Implement Program & programming style (done) Common data structures and algorithms Modularity.
Engineering Classes. Objectives At the conclusion of this lesson, students should be able to: Explain why it is important to correctly manage dynamically.
Malloc Lab : Introduction to Computer Systems Recitation 11: Nov. 4, 2013 Marjorie Carlson Recitation A.
CSE 351 Dynamic Memory Allocation 1. Dynamic Memory Dynamic memory is memory that is “requested” at run- time Solves two fundamental dilemmas: How can.
Carnegie Mellon 1 Malloc Lab : Introduction to Computer Systems Friday, July 10, 2015 Shen Chen Xu.
AVCE ICT – Unit 7 - Programming Session 12 - Debugging.
Carnegie Mellon 1 Malloc Recitation Ben Spinelli Recitation 11: November 9, 2015.
Functions in C++ Top Down Design with Functions. Top-down Design Big picture first broken down into smaller pieces.
Debugging Malloc Lab Detecting Memory-Related Errors.
Carnegie Mellon Dynamic Memory Allocation : Introduction to Computer Systems Recitation 11: Monday, Nov 3, 2014 SHAILIN DESAI SECTION L 1.
Memory Management.
Object Lifetime and Pointers
Winter 2009 Tutorial #6 Arrays Part 2, Structures, Debugger
YAHMD - Yet Another Heap Memory Debugger
Quiz: How Are Your Meetings
CSE 374 Programming Concepts & Tools
10.3 Details of Recursion.
Testing and Debugging.
Recitation 11: More Malloc Lab
Constructive Computer Architecture Tutorial 6: Discussion for lab6
Lab: ssh, scp, gdb, valgrind
CS 240 – Lecture 11 Pseudocode.
Recitation 11: More Malloc Lab
Recitation 10: Malloc Lab
Optimizing Malloc and Free
Lab: ssh, scp, gdb, valgrind
Terminos españoles de ingeneria de computacion.
Recitation 10: Malloc Lab
Recitation 11: More Malloc Lab
Coding Concepts (Standards and Testing)
Virtual Memory CSCI 380: Operating Systems Lecture #7 -- Review and Lab Suggestions William Killian.
CSCI 380: Operating Systems Lecture #11 Instructor: William Killian
Optimizing Dynamic Memory Management
Handling Arrays Completion of ideas needed for a general and complete program Final concepts needed for Final.
Fall 2018 CISC124 2/24/2019 CISC124 Quiz 1 marking is complete. Quiz average was about 40/60 or 67%. TAs are still grading assn 1. Assn 2 due this Friday,
Malloc Lab CSCI 380: Operating Systems
CSCI 380: Operating Systems William Killian
Arrays.
Working with the Compute Block
Makefiles, GDB, Valgrind
Recitation 10: Malloc Lab
Presentation transcript:

CSCI 380: Operating Systems Instructor: William Killian (Malloc) Debugging CSCI 380: Operating Systems Instructor: William Killian

Errors Some errors are identified by the driver The error message is straightforward in most cases “garbled byte” means part of the payload returned to the user has been overwritten by your allocator “out of memory” occurs when the memory is used very inefficiently, or there are lost blocks

Errors But most of the times… Do “gdb mdriver” and “run” to find out which line segfaults Note that a segfault occurring at line 200 could actually be caused by a bug on line 70

Segfault To resolve a segfault, it is necessary to find the earliest time things went wrong. One way to do this is to print the whole heap before/after relevant functions Scroll up from the point of segfault and find the earliest operation that makes the heap look wrong Sometimes this gives too much information, not all of which are useful The heap checker can make this easier Checks violation of invariants (corruption of the heap)

Heap Checker Once you’ve settled on a design, write the heap checker that checks all the invariants of the particular design The checking should be detailed enough that the heap check passes if and only if the heap is truly well-formed Call the heap checker before/after the major operations whenever the heap should be well-formed Define macros to enable/disable it conveniently e.g.

Invariants (non-exhaustive) Block level: Header and footer match Payload area is aligned List level: Next/prev pointers in consecutive free blocks are consistent Free list contains no allocated blocks All free blocks are in the free list No contiguous free blocks in memory (unless you defer coalescing) No cycles in the list (unless you use circular lists) Segregated list contains only blocks that belong to the size class Heap level: Prologue/Epilogue blocks are at specific locations (e.g. heap boundaries) and have special size/alloc fields All blocks stay in between the heap boundaries And your own invariants (e.g. address order)

Hare and Tortoise Algorithm Detects cycles in linked lists Set two pointers “hare” and “tortoise” to the beginning of the list During each iteration, move the hare pointer forward two nodes and move the tortoise forward one node. If they are pointing to the same node after this, the list has a cycle. If the hare reaches the end of the list, there are no cycles.

Other things to watch for Uninitialized pointers and/or memory Make sure mm_init() initializes everything It is called by the driver between each iteration of every trace If something is overlooked, you might be able to pass every single trace file, but the complete driver test will fail

Valgrind To check for Illegal accesses, uninitialized values…

Asking for help It can be hard for me to debug your allocator, because this is a more open-ended lab Before asking for help, ask yourself some questions: What part of which trace file triggers the error? Around the point of the error, what sequence of events do you expect? What part of the sequence already happened? If you can’t answer, it’s a good idea to gather more information… How can you measure which step worked OK? printf, breakpoints, heap checker…

Asking for help Bring to us a detailed story, not just a “plot summary” “Allocations of size blah corrupt my heap after coalescing the previous block at this line number...” is detailed “It segfaults” is not Most importantly: don’t hesitate to come to office hours if you really need help

Beyond Debugging: Error prevention It is hard to write code that is completely correct the first time, but certain practices can make your code less error-prone Plan what each function does before writing code Draw pictures when linked list is involved Consider edge cases when the block is at start/end of list Write pseudocode first Document your code as you write it

Beyond Debugging: Version control “I had 60 util points just 5 minutes ago!” Save the allocator after each major progress Most basic: copy files around using the cp command Alternatively: keep different versions in separate c files, and use “ln –s mm-version-x.c mm.c” to start using a particular version Or use git/svn/cvs… Make sure your repository is private if you use remote repos

Optimization To achieve better performance, sometimes you would want to tweak certain parameters. Number of size classes, the separation of size classes, the amount by which the heap is extended (CHUNKSIZE)… It is better to write modular and encapsulated code so that changing the parameters only requires changing a few lines of code Use inline functions and macros wisely

Optimization When you hit a bottleneck, find which part is limiting your performance A profiler is good for this kind of job To use gprof: Change the Makefile to add “-pg” to the compilation flag Run the driver. This will generate a file called gmon.out Run “gprof ./mdriver” to see the result Don’t forget to change the Makefile back

Final Words Start now, if not already Come to office hours early Write the heap checker well Be prepared to start over several times Though this shouldn’t be necessary since we have a path: Explicit Implicit Segmented Before handing in, check: Does the header comment contain a detailed description of your approach? Is the indentation correct? Any line over 80 chars? (go to autolab to verify these)

Questions? Good luck!