Class Note for CMPSCI 377 at UMass(40)
Class Note for CMPSCI 377 at UMass(40)
Popular in Course
Popular in Department
This 4 page Class Notes was uploaded by an elite notetaker on Friday February 6, 2015. The Class Notes belongs to a course at University of Massachusetts taught by a professor in Fall. Since its upload, it has received 12 views.
Reviews for Class Note for CMPSCI 377 at UMass(40)
Report this Material
What is Karma?
Karma is the currency of StudySoup.
You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!
Date Created: 02/06/15
CMPSCI 377 Operating Systems Fall 2005 Lecture 14 November 10 Lecturer Emery Berger Scribe Eric Hodge Eric Patrick Today 0 Memory Management 141 Memory Management 1411 Introduction Not memory management in kernel but memory management between app and OS the 77run time system77 Java runs in virtual machine in run time system CC runs in libraries libcso libcso Explicit memory management c c Garbage collection Java Python Perl 1412 Explicit Memory Management One of the oldest elds in computer science Must say explicitly What you want to do With memory ask for it Malloc size returns a pointer to space big enough for size bytes Calloc size times multiplies size times also lls memory With zeros Realloc old obj size reallocates old object to a chunk of memory of size realloc null sz mallocsz Realloc p 0 freep Min size returned by malloc 8 bytes sizeof double 8 bytes Freeptr dispose of object Takes object at ptr and gives it back to runtime system If you don7t free your objects you get a memory leak Things slow down due to paging reallocNULL size mallocsize reallocp0 freep 1413 Errors Involved in Memory Management Dangling Pointer Error P malloc xP 14 1 142 Lecture 14 November 10 Freep Z malloc z x z may have overwritten X you had a pointer to some space but now you7ve freed it and now it can be overwritten you can still try to reference it without no guarantees Buffer over ow allocating too small a space and overwriting the end of memory blocki Used by h4XORzi Professor Berger is lSSti Some other errors free objects that you didnlt allocate free objects twice 1414 Memory Allocation What malloc actually does Process is instantiated Loader ldiso in linux loads program to memory7 and points program counter to right place and begins runningi Memory Structure Stack grows downi Heap grows up Code text segment beneath heapi In between stack and heap is a protected page to prevent collision between stack and pointer7 is xed One way of managing heap size is to use a breakpoint sbrkint to set pointeri mmap mmap often maps a le to memory Most UNle have a le called devzeroi Anonymous ler When calling mmap7 allocates memory in swap le for mmap calli Munmapptr7 sz deallocatesi Lecture 14 November 10 143 1415 Issues in Memory Management Should not use an sbrk and mmap approach7 only use mmap Sbrk only allows you to move breakpoint for heap Mmap allows you to remap all the heap to decrease heap size 1416 How memory manager actually manages memory Mmap a big chunk of memory Start and end pointers are at beginning Call malloc87 move end pointer to 8 bytes Moving pointer is referred to as pointer bumping 1417 Freeing Objects Find a way to deallocate x in xyz Cannot move objects around Deallocate x7 marked as being free Header Boundary Tag small amount of space at each section of memory to store object size and status free or allocated FirstFit algorithm On new malloc7 look for FIRST block that has not been allocated that object ts in Runs in worst case On Expected case On2 Best t algorithm go through all of memory using linear search to nd smallest chunk available with greater than required size Runs in On Splitting breaks free area of memory into smaller chunks to allow other smaller chunks of free memory to maximize utilization Coalescing joining adjacent chunks of memory together to t larger objects Linux allocator has a pointer to prevoius memory chunk and pointer to next Steals a bit for 0free7 lallocated Since On is bad7 must manage memory differently 1418 Free Lists Organize array into sizes of chunks Since there are many sizes7 use size classes7 which generalize some sizes into one array spot When freeing an object7 put object into free list under its size class and mark it as free lf requesting an object allocation7 go to its size class and check for available chunk If not available7 take next largest if available OR advance to next object Internal fragmentation extra space allocated that will not be used because your object is smaller than allocated section External fragmentation space lost in between objects that is unusable as it is broken between objects When calling malloc7 put lock around malloc 14 4 Lecture 14 November 10 This prevents race condition from accessing same place in memory To avoid having threads slow down program7 have multiple free listsi 1419 Garbage Collection No such thing as free methodi Find all unused objects and deallocate themi Garbage collection tests for reachabilityi Roots Globals7 stack7 and registers Use roots to nd pointers7 then nd more pointersetci Build reachability tree If there is no pointer to an object7 it is unreachable and is garbage Use marksweep Everything is initially garbagei For every object in tree7 set mark bit to 1 When it is reachable When done searching tree7 sweep through heap7 and deallocate all garbagei Garbage collector is called complete if it is guaranteed to reclaim all memory Stopthe W0rld garbage collector stops program during garbage collection 14110 Semispace collector Known as copying garbage collector Divide heap in two Once 1st heap is lled7 run garbage collection Look at roots and see What gets pointing to from rootsi If it IS pointed to7 copy to 2nd heapi Deallocate rst heapi Then 2nd heap becomes from space Generations allocate to nursuryi 1f object survives7 copy out If not7 reset nurseryi
Are you sure you want to buy this material for
You're already Subscribed!
Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'