
Develop and demonstrate a custom Linux heap memory manager in C that allocates and frees memory, analyzes usage, and addresses fragmentation, with built-in statistics and demonstrations.
Demonstrate proficiency in C and master iterating, inserting, and deleting nodes in a doubly linked list, apply heap memory management theory with virtual memory to implement heap manager in C.
Access the course code by installing git, forking and cloning the repository on GitHub, and navigating to the Linux Memory Manager/course/Linux memory manager directory to view the source code.
Navigate a ten-phase project to develop a heap memory manager in C, advancing from phase one to phase nine, with phase ten adding extra problems and appendices a-c for theory.
Explore phase one of the virtual memory page allocator by requesting and releasing a complete page with mmap and unmap on Linux. Understand page size and allocation granularity.
Explore how mmap allocates and deallocates virtual memory pages between a user-space Linux memory manager and the kernel via the system call interface, highlighting noncontiguous pages and heap memory.
Explore two API signatures for virtual memory: allocate contiguous pages from the kernel to userspace and release them back, using units and the bottom address, returning the start address.
Implement Linux memory manager APIs to allocate and release virtual memory pages using mmap and munmap, with initialization via m_init and system page size detection.
Register page families by sending each structure's name and size from the user space application to the Linux memory manager during initialization, using kernel-allocated virtual memory pages to store data.
Shows how the Linux memory manager registers page families by requesting memory pages with mmap, stores each family's name and size, and links pages for iteration.
Implement the page family instantiation algorithm in m.c to register a page family by name and size, manage the global VM page pointer, and allocate or extend pages as needed.
Integrate the Linux memory manager with external applications by exposing a user API header that defines registration macros and structures, enabling apps to initialize and register data types (employee, student).
Design data structures for meta and data blocks in a heap memory manager, where each data block has a preceding meta block and meta blocks manage metadata and free/allocated chains.
Define four-field meta block data structure for heap memory manager, including is_free, block_size, next/previous pointers, and offset, to map blocks to linux memory page and enable constant-time malloc/free.
Learn to define five header macros for meta block management: compute field offsets, fetch hosting pages, move to next or previous blocks, and use block size for address calculation.
update the memcache file by redefining the block metadata structure, adding macros to manipulate metadata, and defining a boolean data type for false and true to enable compilation and testing.
When a memory page is allocated, treat it as a free data block guarded by a meta block. Malloc splits it into an allocated block and a remaining free block.
Explore how splitting a free data block during malloc adjusts previous and next pointers of related meta blocks, including penultimate and anti penultimate blocks, in a virtual memory page.
Block merging begins when the memory manager frees a data block, merging consecutive free blocks in the virtual memory page into a bigger free block to prevent fragmentation.
The api that performs block merge merges two consecutive free blocks in a virtual memory page by updating block size, next and previous pointers, creating a single larger free block.
Explore how the Linux memory manager handles virtual memory page management, including page families, first pages, a doubly linked list, and the meta and free data blocks.
Let us Write APIs which are used for VM Page Mgmt.
Explore vm page deletion API in Linux memory manager, deleting a virtual memory page from the page family, handling head or middle list positions, and returning it to kernel space.
Apply the worst fit memory allocation strategy by selecting virtual memory page with the largest free data block to satisfy malloc requests and outline needed data structures and APIs.
gl threads, a glue-based doubly linked list, and reorder a priority queue of free data blocks to implement best fit and first fit in the Linux memory manager.
Implement the mm_split_free_data_block_for_allocation API to split a free data block, update meta blocks, manage no/partial/full splits, handle soft and hard internal fragmentation, update priority queue, and prepare x malloc testing.
Begin phase eight by testing and validating the heap memory manager, writing printing functions to dump the Linux memory manager's state and a demo app to claim memory, then verify.
Demonstrates testing a Linux memory manager by claiming five objects (three employees and two students) and printing its internal state and memory usage, including page families and meta blocks.
Explore optional CLI integration for a C-based Linux memory manager, enabling command-line control to dump memory statistics without hooking printers, and learn to integrate a CLI library into C/C++ projects.
Implement the x3 free call to return memory to memory manager, handle block merging and fragmentation, and finalize the m3 blocks api to free blocks and return pages to kernel.
Explore two scenarios for handling hard internal fragmentation when freeing blocks in a virtual memory page: non-uppermost blocks absorb interior fragmentation, while page-boundary blocks absorb boundary fragmentation, via xfree implementation.
Demonstrate end-to-end testing of a Linux memory manager in C by allocating and freeing blocks across three scenarios, printing memory state, and validating block merging and statistics.
This course attempts to answer the following INTERVIEW QUESTIONS :
1. How will you design your own heap Memory Manager?
2. What is the data structure employed for Heap Memory Management?
3. What is the time complexity to allocate memory to a process?
4. How free( ) knows how much memory to free?
5. How to get rid of Memory Fragmentation?
This course is about - "Design and Implement your own Memory Allocation Scheme to address the problem of Memory Fragmentation, see Memory Usage and statistics and Catch Memory Leaks. Talk to your prof and ask to do this project as your Operating Seminar Project".
Do this yet another System Project and Impress the interviewer with your knowledge of System Memory Management.
In this course, we shall design and implement a scheme in the form of a Library that takes the responsibility to allocate & de-allocate memory to your userspace process while taking care of the problems of Heap internal and external fragmentation behind the scenes. We already are familiar with the problem of Heap internal and external fragmentation which grows and magnifies over a period of time when a process is in execution and make much of the part of Heap memory unusable.
Many companies implement this scheme in the industry in userspace itself to get rid of Fragmentation problems and also speed up the mechanism of Memory (de)allocation to a process.
This is a pure coding based course and at every stage of the course, you need to write a code to implement the project.