MeMS is a custom memory management system implemented in C, designed to manage memory using the mmap and munmap system calls. It provides memory allocation and deallocation functionalities while adhering to specific constraints and requirements.
MeMS (Memory Management System) is a memory management solution that utilizes mmap and munmap system calls for memory allocation and deallocation, with the following key features:
- Memory allocation in multiples of the system's PAGE_SIZE (typically 4096 bytes, but can be changed if need so).
- Use of a free list data structure to keep track of allocated and deallocated memory segments.
- Support for allocating and deallocating memory within the MeMS virtual address space.
The code for MeMS consists of the following components:
struct sub_nodeandstruct main_node: Data structures used for managing memory segments, including holes and processes.initializing_main_node(): Initializes a main_node struct.mems_init(): Initializes the MeMS system, creating the initial main node.mems_finish(): Deallocates all memory allocated by the MeMS system.search_free_list(size_t size): Searches for available memory segments in the free list.mems_malloc(size_t size): Allocates memory of the specified size.mems_print_stats(): Prints statistics on the MeMS system, including main nodes and sub nodes.print_sub_node(struct sub_node* node): Prints information about a sub node.mems_get(void*v_ptr): Retrieves information about a given MeMS virtual address.merge_holes(struct main_node* node): Merges adjacent holes in a main node.mems_free(void *v_ptr): Frees memory associated with a MeMS virtual address.
-
Initialization: Call
mems_init()at the beginning of your program to initialize the MeMS system. -
Memory Allocation: Use
void* mems_malloc(size_t size)to allocate memory dynamically. It returns a MeMS virtual address. -
Memory Deallocation: Use
void mems_free(void *v_ptr)to free the memory allocated at the specified MeMS virtual address. -
Get Physical Address: Use
void* mems_get(void *v_ptr)to get the MeMS physical address mapped to the given virtual address. -
Print Statistics: Call
mems_print_stats()to print detailed statistics about the MeMS system. -
Cleanup: At the end of your program, call
mems_finish()to free all allocated memory and clean up MeMS resources.
- Download and unzip the folder.
- Open
mainfolder interminal - Run
$ make
Then,
$ make run
And finally,
$ make clean




