Commit 937e2689 authored by nileshjk98's avatar nileshjk98

Memory allocator

parent c51db13d
References :
1. https://www.codesdope.com/course/data-structures-avl-trees/
AVL Tree Psuedocode and Implementation - Iterative implementation of AVL tree
I first worked with recursive implementation which is fairly intuitive and easy to code, but
couldn't get deletion to work. I switched to the iterative implementation present on the above link
and after some modifications, was able to get both insertion and deletion to work.
I am not sure whether this is allowed as per plagiarism rules, but due to time constraints, I wasn't
able to implement AVL tree from scratch. If this violates plagiarism rules, please ignore my
submission for mm2.c .
2. http://www.cs.cmu.edu/afs/cs/academic/class/15213-s12/www/lectures/19-allocation-advanced-1up.pdf
For understanding of explicit lists with boundary tag method for coalescing.
The design
mm1.c - Best Fit + Explicit, doubly linked free list + Boundary tag on both sides for coalescing
mm2.c - First Fit + Height balanced AVL Tree + Boundary tag on both sides for coalescing
Results for mm1.c | Results for mm2.c
trace valid util ops secs Kops | trace valid util ops secs Kops
0 yes 89% 6648 0.001024 6492 | 0 yes 89% 6648 0.000929 7152
1 yes 95% 4800 0.005089 943 | 1 yes 92% 4800 0.000807 5946
2 yes 51% 12000 0.074161 162 | 2 yes 51% 12000 0.000505 23739
3 yes 61% 12 0.000000 40000 | 3 yes 61% 12 0.000000 40000
4 yes 94% 12 0.000000 40000 | 4 yes 94% 12 0.000000 60000
5 yes 80% 10 0.000000 50000 | 5 yes 80% 10 0.000000 50000
6 yes 24% 14401 0.099950 144 | 6 yes 34% 14401 0.000957 15053
Total 71% 37883 0.180225 210 | Total 72% 37883 0.003200 11840
|
Perf index = 42 (util) + 14 (thru) = 56/100 | Perf index = 43 (util) + 40 (thru) = 83/100
Time complexity per operation
mm1.c mm2.c
mm_malloc O(n) O(log n)
mm_free O(1) O(log n)
mm_realloc O(n) O(log n)
where n is number of blocks in free_list
Overhead
mm1.c mm2.c
Header 32 bytes 40 bytes
Footer 8 bytes 8 bytes
Total 40 bytes 48 bytes
Reasons for better results with mm2.c compared to mm1.c
1. With height balanced tree, there is improvement in throughput as all operations are of logarithmic
time complexity compared to linked list based implementation.
2. Due to increased overhead(two additional fields in node structure for storing height
and parent of the tree), utilisation decreases compared to linked list implementation for some trace
files.
3. Both the above mentioned designs show lower throughput compared to mm-naive.c implementation, but
they are more efficient in terms of memory.
4. Using first fit decreases search time(O(log n)) for AVL tree based implementation compared to using
best fit search with linked list(O(n)).
\ No newline at end of file
#include <stdio.h>
extern int mm_init (void);
extern void *mm_malloc (size_t size);
extern void mm_free (void *ptr);
extern void *mm_realloc(void *ptr, size_t size);
/*
* Students work in teams of one or two. Teams enter their team name,
* personal names and login IDs in a struct of this
* type in their bits.c file.
*/
typedef struct {
char *teamname; /* ID1+ID2 or ID1 */
char *name1; /* full name of first member */
char *id1; /* login ID of first member */
char *name2; /* full name of second member (if any) */
char *id2; /* login ID of second member */
} team_t;
extern team_t team;
typedef struct btag {
int size;
char tag;
} btag;
typedef struct node {
btag start_tag;
void* address;
struct node *prev;
struct node *next;
} node;
// An AVL tree node
typedef struct tnode {
btag start_tag;
struct tnode *left;
struct tnode *right;
struct tnode *parent;
int height;
} tnode;
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment