Function of Memory
Memory is the electronic holding place for the instructions and data a computer needs to reach quickly. It’s where information is stored for immediate use. Memory is one of the basic functions of a computer because, without it, a computer would not be able to function properly. Memory is also used by a computer’s operating system, hardware, and software.
Memory has 3 basic functions.
- Encoding Information
- Storing Information
- Retrieving Information
- Memory Management is the functionality of an operating system that handles or manages primary memory and switches processes between the main memory and disk during execution.
- Memory management keeps track of each and every memory location, regardless of whether it is allocated to some process or is free. It checks how much memory is to be allocated to processes. It decides which process will get memory at what time.
- Separates computer storage into a hierarchy based on response time
- The processor can move from one level to another based on their requirements
- The first three hierarchies are volatile memories which mean when there is no power, and then automatically they lose their stored data.
- Whereas the last hierarchy is not volatile which means they store the data permanently.
- Memory management determines how several processes are managed for their space in memory to increase performance.
- In a uni-programming system, the main memory is divided into two parts
- one used by the operating system and
- the second entirely by the running program.
- In a multiprogramming system, this second part is further subdivided into a number of partitions so that a number of processes get allocated in those partitions.
- This task of the subdivision is carried out by the operating system and the part of an operating system that is responsible for those tasks is known as the memory manager. This complete mechanism that is specified here is called memory management.
Memory manager
- The part of an operating system that performs memory management functionality.
- The various job of memory managers are
- To keep track of which parts of memory are in use and which are free.
- To allocate required memory to processes when they did it and to deallocate when finished.
- To manage swapping of processes between main memory and disk when there is not enough space in memory to hold all the requesting processes.
- A Register is for holding the temporary results and variables. Accessing data from these registers is the fastest way of accessing memory.
- A cache is used for the CPU for memory which is being accessed over and over again. Instead of pulling it every time from the main memory, it is put in the cache for fast access. It is also a smaller memory, however, larger than the register
- Main memory(RAM) is a type of computer memory and it can be increased provided the operating system can handle it.
- Secondary Memory (Hard disk) is a hardware component in a computer. Data is kept permanently in this memory. The memory from the hard disk is not directly accessed by the CPU, hence it is slower. As compared with RAM, hard disk is cheaper per bit.
- Magnetic tape is usually used for backing up large data. When the system needs to access a tape, it is first mounted to access the data. When the data is accessed, it is then unmounted. The memory access time is slower in magnetic tape and it usually takes a few minutes to access a tape.
Swapping
- Swapping is exchanging data between the hard disk and the RAM. Moving the process from main memory to disk and back is called swapping. whenever a new process is ready to be loaded in memory, and if no partition is free, then swapping of process between main memory and secondary storage is done.
- The goal of the virtual memory technique is to make an application think that it has more memory than actually exists.
- 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 the main memory.
- Though performance is usually affected by the swapping process but it helps in running multiple and big processes in parallel and that’s the reason Swapping is also known as a technique for memory compaction.
- Swapping is done when a new ready process is of high priority. The memory manager performs this task by swapping out low-priority processes, suspended for a comparatively long time in order to load and execute the high-priority process.
- When high priority process is terminated, the low-priority process can then be swapped back into the memory and continued.