logo Use CA10RAM to get 10%* Discount.
Order Nowlogo
(5/5)

Implement your own memory manager using the Buddy Algorithm. You should use the mmap() system call to initially allocate a large block of memory. 

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

Buddy System Memory Management

Implement your own memory manager using the Buddy Algorithm. You should use the mmap() system call to initially allocate a large block of memory.  A good initial amount is 512MB. From there on, manage the chunk of memory returned by mmap using your own memory management functions.

 

Note that you will have to store the data structures used to represent the buddy system somewhere in memory. You may statically declare these pointers in your code (in the data segment). For this purpose you may assume that the maximum amount of memory that you will ever manage is limited to 32GB. 

 

The beginning of each block should contain a block_header (defined in buddy.c) that maintains the “metadata” for the current block of memory.  This structure includes the TAG field described in the “Buddy System” algorithm by Knuth.

 

Your library should be initialized in a function named buddy_init.  If the user doesn't call this function, then it is transparently called whenever the user calls the buddy_malloc buddy_calloc for the first time. You can test for that using a static variable.

 

Note that if a 0 is passed as an argument to buddy_init, then it initializes the memory pool to be of the default size (512MB, as specified above).  If the caller specifies an unreasonably small size, then the buddy system may not be able to satisfy any requests.

 

If the memory cannot be allocated, then your buddy_calloc or buddy_malloc functions should set errno to ENOMEM (which is defined in errno.h header file) and return NULL.

 

The starter files include a buddy.h header file that contains all the declarations and prototypes. They also include a skeleton buddy.c that has the declaration for the pool and the table of lists for the buddy system.

 

  • Implement buddy_init() as described in buddy.h. The return codes of any library or system calls made in your library related to this method must be checked and validated to prevent segmentation faults.

  • Implement buddy_malloc() as described in buddy.h. See the testing hints below for several use cases your write method should be able to handle without segfaults. The return codes of any library or system calls  made in your library related to this method must be checked and validated to prevent segmentation faults. 

  • Implement buddy_calloc() as described in buddy.h. The return codes of any library or system calls made in your library related to this method must be checked and validated to prevent segmentation faults.

  • Implement buddy_realloc() as described in buddy.h. The return codes of any library or system calls made in your library related to this method must be checked and validated to prevent segmentation faults.

  • Implement buddy_free() as described in buddy.h. The return codes of any library or system calls made in your library related to this method must be checked and validated to prevent segmentation faults.

  • Fully test your buddy implementation using the provided unit tests. This will require implementation of the print_buddy_lists(), get_max_kval() and get_min_kval() functions provided in buddy.h

Testing

Library Tests

We have provided a set of unit tests in buddy-unit-test.c that checks a number of boundary cases in the buddy memory manager. The buddy-unit-test tool includes tests that are not on the “safe path”, meaning that it tries to do things that it expects to fail. Don’t be too disheartened if not all the tests pass on the first pass. The bulk of the work on this project begins once you start testing.

(5/5)
Attachments:

Related Questions

. Introgramming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma

. The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

. Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th

. SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

. Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Um e HaniScience

919 Answers

Hire Me
expert
Muhammad Ali HaiderFinance

532 Answers

Hire Me
expert
Husnain SaeedComputer science

568 Answers

Hire Me
expert
Atharva PatilComputer science

520 Answers

Hire Me