### Lab 9, Problem 2 Completed

parent 83a936af
 # Name: Son Pham # Class: CSCI 315 # Prof: Luiz Felipe Perrone # answers.txt [1.1] Since my memory allocator doesn't use page, and the process specify the amount of memory it needds case by case, and only just enough amount of memory is allocated, the only type of fragmentation possible is EXTERNAL. [1.2] Some of the performance metrics we could use: - Average fragmentation (Sum of allocated memory over - Standard deviation of fractions. - Fraction variance. - Confidence interval. [1.3] double average_frag() 123 -> 456 -> 789 Pseudo-code: // int numBlobs = 0; int totalSize = 0; dnode temp = head of the freeList; // while (blob != NULL) { numBlobs += 1; totalSize += blobSize; blob = blob -> next; } return (double) totalSize / numBlobs; Since totalSize is always the amount allocated. I only need to take that allocated amount and divided by the numBlobs. Since numBlobs will increase by one everytime an allocation is succeeded, I can just make an int that keep tracks of this number and I don't have to count the number of blobs everytime. [2.1] Think critically about the pseudo-code given. The way the algorithm is currently structued is not typical of programs because: 1. You don't allocate and deallocate like crazy like that, you usually allocate all at once and deallocate all at once. 2. This is not representative of a program fragmentation because when the number of requests are high, you basically chop the program up until everything pieces of very small byte. Usually, a program ALLOCATE ALL MEMORY first and DEALLOCATE ALL MEMORY later. In order to have a representative amount of fragmentation, it is very important to allocate all the memory first and then deallocate later. The pseudo-code for the algorithm would look like. srandom(seed); int r = 0; void *p[num_requests]; int i = 0; while (r < requests): p[r] allocate(random number between 100 and 1000); while (r< requests): if (p[r] != NULL) deallocate(p[r]); average_frag(); \ No newline at end of file
This diff is collapsed.
 CC = gcc -I ./include CFLAGS = -std=gnu99 -Wall -g #-DDEBUG INC = ./include SRC = ./src OBJ = ./obj DOC = ./doc BIN = ./bin vpath %.h ./include vpath %.c ./src EXECS = dlisttest frag-eval all: \$(EXECS) doc: doxygen \$(OBJ)/allocator.o: dlist.h dnode.h allocator.h allocator.c \$(CC) \$(CFLAGS) -c \$(SRC)/allocator.c -o \$(OBJ)/allocator.o \$(OBJ)/dnode.o: dnode.h dnode.c \$(CC) \$(CFLAGS) -c \$(SRC)/dnode.c -o \$(OBJ)/dnode.o \$(OBJ)/dlist.o: dlist.h dlist.c dnode.h \$(CC) \$(CFLAGS) -c \$(SRC)/dlist.c -o \$(OBJ)/dlist.o dlisttest: \$(SRC)/dlisttest.c \$(OBJ)/dnode.o \$(OBJ)/dlist.o \$(CC) \$(CFLAGS) \$(OBJ)/dnode.o \$(OBJ)/dlist.o \$(SRC)/dlisttest.c -o \$(BIN)/dlisttest frag-eval: \$(SRC)/frag-eval.c \$(OBJ)/allocator.o \$(OBJ)/dnode.o \$(OBJ)/dlist.o \$(CC) \$(CFLAGS) \$(OBJ)/allocator.o \$(OBJ)/dnode.o \$(OBJ)/dlist.o \$(SRC)/frag-eval.c -o \$(BIN)/frag-eval .PHONY: clean clean: /bin/rm -rf \$(BIN)/* \$(OBJ)/* core* *~
 CC = gcc -I ./include CFLAGS = -std=gnu99 -Wall -g #-DDEBUG INC = ./include SRC = ./src OBJ = ./obj DOC = ./doc BIN = ./bin vpath %.h ./include vpath %.c ./src EXECS = dlisttest frag-eval all: \$(EXECS) doc: doxygen \$(OBJ)/allocator.o: dlist.h dnode.h allocator.h allocator.c \$(CC) \$(CFLAGS) -c \$(SRC)/allocator.c -o \$(OBJ)/allocator.o \$(OBJ)/dnode.o: dnode.h dnode.c \$(CC) \$(CFLAGS) -c \$(SRC)/dnode.c -o \$(OBJ)/dnode.o \$(OBJ)/dlist.o: dlist.h dlist.c dnode.h \$(CC) \$(CFLAGS) -c \$(SRC)/dlist.c -o \$(OBJ)/dlist.o dlisttest: \$(SRC)/dlisttest.c \$(OBJ)/dnode.o \$(OBJ)/dlist.o \$(CC) \$(CFLAGS) \$(OBJ)/dnode.o \$(OBJ)/dlist.o \$(SRC)/dlisttest.c -o \$(BIN)/dlisttest frag-eval: \$(SRC)/frag-eval.c \$(OBJ)/allocator.o \$(OBJ)/dnode.o \$(OBJ)/dlist.o \$(CC) \$(CFLAGS) \$(OBJ)/allocator.o \$(OBJ)/dnode.o \$(OBJ)/dlist.o \$(SRC) frag-eval.c -o \$(BIN)/frag-eval .PHONY: clean clean: /bin/rm -rf \$(BIN)/* \$(OBJ)/* core* *~
 # Name: Son Pham # Class: CSCI 315 # Prof: Luiz Felipe Perrone # answers.txt [1.1] Since my memory allocator doesn't use page, and the process specify the amount of memory it needds case by case, and only just enough amount of memory is allocated, the only type of fragmentation possible is EXTERNAL. [1.2] Some of the performance metrics we could use: - Average fragmentation (Sum of allocated memory over - Standard deviation of fractions. - Fraction variance. - Confidence interval. [1.3] double average_frag() 123 -> 456 -> 789 Pseudo-code: // int numBlobs = 0; int totalSize = 0; dnode temp = head of the freeList; // while (blob != NULL) { numBlobs += 1; totalSize += blobSize; blob = blob -> next; } return (double) totalSize / numBlobs; Since totalSize is always the amount allocated. I only need to take that allocated amount and divided by the numBlobs. Since numBlobs will increase by one everytime an allocation is succeeded, I can just make an int that keep tracks of this number and I don't have to count the number of blobs everytime.
 # Name: Son Pham # Class: CSCI 315 # Prof: Luiz Felipe Perrone # answers.txt [1.1] Since my memory allocator doesn't use page, and the process specify the amount of memory it needds case by case, and only just enough amount of memory is allocated, the only type of fragmentation possible is EXTERNAL. [1.2] Some of the performance metrics we could use: - Average fragmentation (Sum of allocated memory over - Standard deviation of fractions. - Fraction variance. - Confidence interval. [1.3] double average_frag() 123 -> 456 -> 789 Pseudo-code: // int numBlobs = 0; int totalSize = 0; dnode temp = head of the freeList; // while (blob != NULL) { numBlobs += 1; totalSize += blobSize; blob = blob -> next; } return (double) totalSize / blobSize;
 # Name: Son Pham # Class: CSCI 315 # Prof: Luiz Felipe Perrone # designAPI.txt Testing: -------- My four test files are: memory-test.c worst-fit-test.c best-fit-test.c first-fit-test.c dlist.c: -------- I add function dlist_find_node so that I can find the node that corresponds to the memory. I feel that it is a lot easier to deal with the node than the memory of the node. This becomes important when I have to grab the size of the node that I want to deallocate I also add two functions: dlist_get_front_node and dlist_get_back_node to get the address of the two nodes at the two ends of the list. I add the dlist_print function to print the list in a convenient and tractable manner. dnode.h: -------- I add the size of the memory chunk as one of the piece of information of the node to make it easier to deal with. First-fit policy: ----------------- I simply traverse the entire list and find the first node that is available and has enough capacity to carry the whole size Best-fit policy: ---------------- I traverse the list and find the smallest chunk of memory that still has enough capacity to carry the allocated size Worst-fit policy: ----------------- I traverse the list and find the largest chunk of memory that still has enough capacity to carry the allocated size.
 # Name: Son Pham # Class: CSCI 315 # Prof: Luiz Felipe Perrone # designAPI.txt dlist.c: -------- I add function dlist_find_node so that I can find the node that corresponds to the memory. I feel that it is a lot easier to deal with the node than the memory of the node. I also add two functions: dlist_get_front_node and dlist_get_back_node to get the address of the two nodes at the two ends of the list. I add the dlist_print function to print the list in a convenient and tractable manner. dnode.h: -------- I add the size of the memory chunk as one of the piece of information of the node to make it easier to deal with. First-fit policy: ----------------- I simply traverse the entire list and find the first node that is available and has enough capacity to carry the whole size Best-fit policy: ---------------- I traverse the list and find the smallest chunk of memory that still has enough capacity to carry the allocated size Worst-fit policy: ----------------- I traverse the list and find the largest chunk of memory that still has enough capacity to carry the allocated size.
This diff is collapsed.
 CC = gcc -I ./include CFLAGS = -std=gnu99 -Wall -g #-DDEBUG INC = ./include SRC = ./src OBJ = ./obj DOC = ./doc BIN = ./bin vpath %.h ./include vpath %.c ./src EXECS = dlisttest extra-credit-test all: \$(EXECS) doc: doxygen \$(OBJ)/allocator.o: dlist.h dnode.h allocator.h allocator.c \$(CC) \$(CFLAGS) -c \$(SRC)/allocator.c -o \$(OBJ)/allocator.o \$(OBJ)/dnode.o: dnode.h dnode.c \$(CC) \$(CFLAGS) -c \$(SRC)/dnode.c -o \$(OBJ)/dnode.o \$(OBJ)/dlist.o: dlist.h dlist.c dnode.h \$(CC) \$(CFLAGS) -c \$(SRC)/dlist.c -o \$(OBJ)/dlist.o dlisttest: \$(SRC)/dlisttest.c \$(OBJ)/dnode.o \$(OBJ)/dlist.o \$(CC) \$(CFLAGS) \$(OBJ)/dnode.o \$(OBJ)/dlist.o \$(SRC)/dlisttest.c -o \$(BIN)/dlisttest extra-credit-test: \$(SRC)/extra-credit-test.c \$(OBJ)/allocator.o \$(OBJ)/dnode.o \$(OBJ)/dlist.o \$(CC) \$(CFLAGS) \$(OBJ)/allocator.o \$(OBJ)/dnode.o \$(OBJ)/dlist.o \$(SRC)/extra-credit-test.c -o \$(BIN)/extra-credit-test .PHONY: clean clean: /bin/rm -rf \$(BIN)/* \$(OBJ)/* core* *~
 CC = gcc -I ./include CFLAGS = -std=gnu99 -Wall -g #-DDEBUG INC = ./include SRC = ./src OBJ = ./obj DOC = ./doc BIN = ./bin vpath %.h ./include vpath %.c ./src EXECS = dlisttest memory-test all: \$(EXECS) doc: doxygen \$(OBJ)/allocator.o: dlist.h dnode.h allocator.h allocator.c \$(CC) \$(CFLAGS) -c \$(SRC)/allocator.c -o \$(OBJ)/allocator.o \$(OBJ)/dnode.o: dnode.h dnode.c \$(CC) \$(CFLAGS) -c \$(SRC)/dnode.c -o \$(OBJ)/dnode.o \$(OBJ)/dlist.o: dlist.h dlist.c dnode.h \$(CC) \$(CFLAGS) -c \$(SRC)/dlist.c -o \$(OBJ)/dlist.o dlisttest: \$(SRC)/dlisttest.c \$(OBJ)/dnode.o \$(OBJ)/dlist.o \$(CC) \$(CFLAGS) \$(OBJ)/dnode.o \$(OBJ)/dlist.o \$(SRC)/dlisttest.c -o \$(BIN)/dlisttest extra-credit-test: \$(SRC)/extra-credit-test.c \$(OBJ)/allocator.o \$(OBJ)/dnode.o \$(OBJ)/dlist.o \$(CC) \$(CFLAGS) \$(OBJ)/allocator.o \$(OBJ)/dnode.o \$(OBJ)/dlist.o \$(SRC)/extra-credit-test.c -o \$(BIN)/extra-credit-test .PHONY: clean clean: /bin/rm -rf \$(BIN)/* \$(OBJ)/* \$(DOC)/* core* *~