Operating System Memory Management
Operating System Memory Management
Management
Memory management is the functionality of an operating system which
handles or manages primary memory and moves processes back and forth
between main memory and disk during execution. Memory management
keeps track of each memory location, regardless of either it is allocated to
some process or it is free. It checks how much memory is to be allocated to
processes. It decides which process will get memory at what time. It tracks
whenever some memory gets freed or unallocated and correspondingly it
updates the status.
1 Symbolic addresses
The addresses used in a source code. The variable names, constants, and
instruction labels are the basic elements of the symbolic address space.
2
Relative addresses
3 Physical addresses
Virtual and physical addresses are the same in compile-time and load-time
address-binding schemes. Virtual and physical addresses differ in
execution-time address-binding scheme.
The value in the base register is added to every address generated by a user
process, which is treated as offset at the time it is sent to memory. For
example, if the base register value is 10000, then an attempt by the user to use
address location 100 will be dynamically reallocated to location 10100.
The user program deals with virtual addresses; it never sees the real physical
addresses.
Address Binding
Now coming back to address binding, the logical address generated by CPU
is divided into two parts:
Page number is used to index into the page table, to get the corresponding
physical frame/page number. The physical page number is them combined
with the offset to get the complete physical address.
All these segments together form the physical address space of the
process. Logical to physical address mapping is done through a segment
table. Each segment in memory has a segment number assigned by the
loader. A segment table is used to keep the following information about
each segment.
Segment number.
Offset or displacement within the segment.
Segment number is used to index into the segment table to get the values of
segment limit and base. First, we check that offset is within the range
[0, limit]. If so, value of segment base is added to the offset to get the real
physical memory address within the segment.
I hope the above explains the execution-time address binding in the context
of different memory management schemes.
Apart from execution-time, address binding can be further classified into two
different types:
If you are writing a Dynamically loaded program, then your compiler will
compile the program and for all the modules which you want to include
dynamically, only references will be provided and rest of the work will be
done at the time of execution.
At the time of loading, with static loading, the absolute program (and
data) is loaded into memory for execution to start.
If you are using dynamic loading, dynamic routines of the library are
stored on a disk in relocatable form and are loaded into memory only when
they are needed by the program.
When dynamic linking is used, it is not required to link the actual module or
library with the program, rather a reference to the dynamic module is
provided at the time of compilation and linking. Dynamic Link Libraries
(DLL) in Windows and Shared Objects in Unix are good examples of
dynamic libraries.
Swapping
Swapping is a mechanism in which a process can be swapped temporarily
out of main memory (or move) to secondary storage (disk) and make that
memory available to other processes. At some later time, the system swaps
back the process from the secondary storage to main memory.
Let us assume that the user process is of size 2048KB and on a standard
hard disk where swapping will take place has a data transfer rate around 1
MB per second. The actual transfer of the 1000K process to or from
memory will take
Now considering in and out time, it will take complete 4000 milliseconds
plus other overhead where the process competes to regain main memory.
Memory Allocation
Main memory usually has two partitions −
1
Single-partition allocation
2 Multiple-partition allocation
Fragmentation
As processes are loaded and removed from memory, the free memory
space is broken into little pieces. It happens after sometimes that processes
cannot be allocated to memory blocks considering their small size and
memory blocks remains unused. This problem is known as Fragmentation.
1 External fragmentation
2
Internal fragmentation
Paging
A computer can address more memory than the amount physically installed
on the system. This extra memory is called virtual memory and it is a
section of a hard that's set up to emulate the computer's RAM. Paging
technique plays an important role in implementing virtual memory.
A data structure called page map table is used to keep track of the
relation between a page of a process to a frame in physical memory.
When the system allocates a frame to any page, it translates this logical
address into a physical address and create entry into the page table to be
used throughout execution of the program.
This process continues during the whole execution of the program where
the OS keeps removing idle pages from the main memory and write them
onto the secondary memory and bring them back when required by the
program.
Due to equal size of the pages and frames, swapping becomes very easy.
Page table requires extra memory space, so may not be good for a system
having small RAM.
References:
https://www.tutorialspoint.com/operating_system/os_memory_management.htm
https://www.quora.com/What-is-address-binding-in-memory-management