18-213: Introduction to Computer Systems April 6, 2015

Slides:



Advertisements
Similar presentations
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.
Advertisements

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.
Welcome to Florida International University Online J.O.B.S. Link Applicant Tutorial.
Creating a Program In today’s lesson we will look at: what programming is different types of programs how we create a program installing an IDE to get.
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.
Welcome to the Brookdale Community College Online Employment System Applicant Tutorial.
1 Optimizing Malloc and Free Professor Jennifer Rexford
Welcome to the Ivy Tech Community College Online Employment System Applicant Tutorial.
1 Welcome to the Colgate University Online Employment System Applicant Tutorial.
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.
Carnegie Mellon 1 Debugging and Version control / : Introduction to Computer Systems 12 th Recitation, Nov. 14, 2011 Slides by: Lin Xiao(lxiao)
Welcome to the Sinclair Community College Online Employment Applicant Tutorial.
Welcome to the University of Florida Online Employment System Applicant Tutorial.
Welcome to And the Rice University Online Job Application Tutorial.
Welcome to the Alaska Statewide System Online Employment System Applicant Tutorial.
Welcome to the Southeastern Louisiana University’s Online Employment Site Applicant Tutorial!
CSE 486/586 CSE 486/586 Distributed Systems PA Best Practices Steve Ko Computer Sciences and Engineering University at Buffalo.
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.
Welcome to the University of West Florida Online Employment System Applicant Tutorial.
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.
1 Advanced Computer Programming Project Management: Methodologies Copyright © Texas Education Agency, 2013.
1 Agenda Administration Background Our first C program Working environment Exercise Memory and Variables.
ICS 145B -- L. Bic1 Project: Main Memory Management Textbook: pages ICS 145B L. Bic.
Forms and Server Side Includes. What are Forms? Forms are used to get user input We’ve all used them before. For example, ever had to sign up for courses.
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
Debugging Computer Networks Sep. 26, 2007 Seunghwan Hong.
CSE 123 Discussion 10/05/2015 Updated from Anup and Narendran’s excellent notes.
Debugging of # P. Hristov 04/03/2013. Introduction Difficult problem – The behavior is “random” and depends on the “history” – The debugger doesn’t.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 11 – gdb and Debugging.
Goal Setting Why Should You Use Goal Setting?. What is a Goal Anyway? Goal is: the end toward which effort is directed. Goals are not dreams and wants.
Debugging 1/6/2016. Debugging 1/6/2016 Debugging  Debugging is a methodical process of finding and reducing the number of bugs, or defects, in a program.
C++ 程序语言设计 Chapter 12: Dynamic Object Creation. Outline  Object creation process  Overloading new & delete.
M1G Introduction to Programming 2 3. Creating Classes: Room and Item.
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.
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.
Carnegie Mellon 1 Malloc Recitation Ben Spinelli Recitation 11: November 9, 2015.
Introduction to Computing Systems and Programming Programming.
Debugging Malloc Lab Detecting Memory-Related Errors.
Text2PTO: Modernizing Patent Application Filing A Proposal for Submitting Text Applications to the USPTO.
Carnegie Mellon Dynamic Memory Allocation : Introduction to Computer Systems Recitation 11: Monday, Nov 3, 2014 SHAILIN DESAI SECTION L 1.
Winter 2009 Tutorial #6 Arrays Part 2, Structures, Debugger
YAHMD - Yet Another Heap Memory Debugger
10.3 Details of Recursion.
Recitation 11: More Malloc Lab
Lab: ssh, scp, gdb, valgrind
Recitation: C Review TA’s 19 Feb 2018.
Recitation 11: More Malloc Lab
Optimizing Malloc and Free
Lab: ssh, scp, gdb, valgrind
Terminos españoles de ingeneria de computacion.
Recitation 11: More Malloc Lab
CSCI 380: Operating Systems Lecture #11 Instructor: William Killian
Optimizing Dynamic Memory Management
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,
CSCI 380: Operating Systems Instructor: William Killian
Malloc Lab CSCI 380: Operating Systems
TUTORIAL 7 CS 137 F18 October 30th.
An Introduction to Debugging
Working with the Compute Block
Makefiles, GDB, Valgrind
Presentation transcript:

18-213: Introduction to Computer Systems April 6, 2015 Malloc Lab Debugging 18-213: Introduction to Computer Systems April 6, 2015 Courtesy: Previous two years’ slides.

News Malloc Lab due Friday, April 10th Not many people have been submitted yet…… If you have not started please do start. If you are stuck somewhere, please spend more time on the problem before you come for office hours. You need to have a basic idea about the problem you are facing, with limited time in office hours it is really difficult to debug an error from scratch.

Errors Some errors are identified by the driver The error message is straightforward in most cases “garbled byte” means part of the allocated payload returned to the user has been overwritten by your allocator, that is you have allocated an already allocated block.

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. “out of memory” occurs when the memory is used very inefficiently, or there are lost blocks.

Segfault To resolve a segfault, it is necessary to identify the initial instructions that might have deviated from the intended behaviour. 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 corrupted. 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.

FOR THE LOVE OF ALL THAT IS HOLY AND SACRED, WRITE A GOOD HEAP CHECKER Heap Checker, cont FOR THE LOVE OF ALL THAT IS HOLY AND SACRED, WRITE A GOOD HEAP CHECKER

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 tortoise 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 not give you full points. If you write a faulty heap checker, it may complain even if your malloc code is correct, so make sure you write a stable and correct heap checker. (out of experience)

Useful Tools Valgrind GDB Illegal accesses, uninitialized values… watch, rwatch, awatch

Asking for help It can be hard for the TAs 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, watchpoints (only use watchpoints if you’re willing to wait several years)…

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 are 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 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 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!