Memory management in operating systems involves allocating memory to processes efficiently and securely.
One way to manage memory is by swapping, where the OS moves processes between main memory and a storage area (usually the hard disk or SSD) to free up space and manage limited resources.
→ In a swapping system, bitmaps and linked lists are two common data structures used to track memory allocation.
Swapping in Memory Management
Swapping is a memory management technique where entire processes are swapped in and out of main memory to and from a secondary storage (like a disk). This allows the system to manage memory dynamically and make room for active processes by moving inactive ones out of memory temporarily.
- It helps to utilize memory more efficiently by dynamically managing limited memory resources, especially when multiple processes are competing for space.
Note:
- When a process is inactive or less frequently used, it is “swapped out” of the main memory to secondary storage.
- When a swapped-out process is needed again, it is “swapped in” from secondary storage back to main memory.
1.) Memory Management with Bitmaps:
Memory management using bitmaps involves representing the memory as a sequence of bits, where each bit corresponds to a fixed-sized block of memory.
- A bit value of 1 indicates that the block is allocated, and a bit value of 0 indicates that the block is free.
How It Works:
- Memory is divided into fixed-size blocks or allocation units.
- A bitmap is created, with one bit representing each block.
- When allocating memory, the system searches the bitmap for contiguous 0s (free blocks) of the required size.
- When freeing memory, the corresponding bits are set back to 0.
2.) Memory Management with Linked List
In memory management with linked lists, memory is managed using a dynamic list of blocks, where each node in the list represents a block of memory.
- Each node contains information about the size, status (allocated or free), and a pointer to the next block.