What is Memory Management in OS ?
- Memory management is the process of controlling and coordinating computer memory, assigning portions called blocks to various running programs to optimize overall system performance.
- Memory management resides in hardware, in the OS (operating system), and in applications.
- In hardware, memory management involves components that physically store data, such as RAM chips, memory caches,etc.,.
- In the OS, memory management involves the allocation (and constant reallocation) of specific memory blocks to individual programs as user demands change.
- At the application level, memory management ensures the availability of adequate memory for the objects and data structures of each running program at all times.Application memory management combines two related tasks, known as allocation and recycling.
- Allocation : When the program requests a block of memory, a part of the memory manager called the allocator assigns that block to the program.
- Recycling : When a program no longer needs the data in previously allocated memory blocks, those blocks become available for reassignment. This task can be done manually (by the programmer) or automatically (by the memory manager).
![What is Memory Management in OS](https://cdn.wikitechy.com/interview-questions/operating-system/what-is-memory-management-in-os.png)
Fragmentation
- As processes are loaded and removed from memory, the free memory space has broken into small pieces.
- That processes cannot be allocated to memory blocks considering their small size and memory blocks remains unused.
- This problem is known as Fragmentation.There are two types of fragmentation,
- Internal fragmentation
- External fragmentation
![internal and external fragmentation in os](https://cdn.wikitechy.com/interview-questions/operating-system/internal-and-external-fragmentation-in-os.png)
Internal and External fragmentation in os
Internal fragmentation
- Memory block assigned to process is lager. Memory is left unused in some portion as it cannot be used by another process.
External fragmentation
- Total memory space is enough to satisfy a request or to reside a process in it, but it is not contiguous, so it cannot be used.