Question
In this assignment, you will implement a Memory Management System(MMS). Using C Programming Language..... MAKE SURE YOU USE C PROGRAMMING Your MMS will handle all
In this assignment, you will implement a Memory Management System(MMS). Using C Programming Language..... MAKE SURE YOU USE C PROGRAMMING
Your MMS will handle all requests of allocation of memory space by different users (one thread per user) . HINT(You will use Pthreads and Semaphores).
Your MMS will provide the user with an interface for making memory requests and also for freeing up memory that is no longer needed by the user. One of the jobs of your memory management system is to service user memory requests by matching the size of the request with a large enough space, from which to satisfy the request. Make sure that the size of memory allocated is in bytes and is in a power of 2.
When your MMS gets the request of size size, it will allocate a space of memory with the size size memory chunk that is requested. Write the code and use two functions, one called memory_malloc to allocate memory and the other memory_free to de-allocate the memory. Make sure the know the size of what is being freed. Every time a block of memory is allocated by memory_malloc, store the size of that block allocated (as an integer) somewhere. Note that memory_malloc returns a pointer to the first byte of the block of memory it just allocated. The size of the block allocated will be used when the user calls memory_free to return the block to the free memory blocks. It is a good idea to merge freed memory blocks together to give a block of a larger size in case some user needs it.
First, use a standard malloc (or equivalent) call to allocate a large amount of memory from the system. The specific amount of memory that your system will be able to handle will be determined by parameter MAX_SIZE. This allocated memory will form free memory blocks and allocated blocks of memory to the user are taken from here when memory_malloc is called.
Your memory_malloc should call one of the three functions First-fit, Best-fit, or Worst-fit. To implement these functions please follow the definition of each one of them as seen and explained in class.
Your program should have one command-line argument which specifies the number N of threads (users). When the program starts, it creates N+1 threads which place themselves in a thread pool. N of these threads will be the users that request memory space from your MMS. The MMS is implemented as a separate thread, that is the remaining of the N+1 threads. Make sure to pay attention to thread synchronization issues, if any.
Work in multithreading concept where each thread will request the MMS for some memory space, print on the screen I am thread # thread-ID going to sleep, than sleep for some random time and then wakes up and prints on the screen I am thread #ID, waking up, and then ask the MMS to release that memory block previously allocated to the thread. Make sure you cover the case where the MMS runs out of memory space. In this case it will choose one or more thread users and treats them as the ones that have the lowest priority and forces them to give up their allocated memory. Make sure that you cover the case where you need to merge freed memory holes together to cover the case where a larger size is needed by some user(s), as described in paragraph-6 above. Make sure that you cover the case where a very large size requested cannot be accommodated by the system. In this case the requesting thread shall be notified with an error notice and the need to request a size no larger than the specified MAX_SIZE that you specify/consider when designing your MMS, and return said thread(s) to the pool of threads, to complete/try again among the other threads in the pool.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started