Memory Management in OS: Bare Machine, Resident Monitor & Multiprogramming
A computer cannot execute a program directly from nowhere. The program and the data it needs must be available in main memory while the CPU is working on them. The operating system therefore needs rules for deciding which program stays in memory, where it stays, how much memory it gets, and how one program is protected from another. These tasks are part of Memory Management in OS.
Memory management did not become advanced in one day. Early computers used a simple Bare Machine model. Later, a small control program called the Resident Monitor stayed in memory. After that, Multiprogramming allowed several programs to remain in memory together so that the CPU did not have to remain idle whenever one job waited for input/output.
What Is Memory Management in Operating System?
Memory Management in OS is the operating-system function that controls the use of main memory.
It decides how memory is given to programs and how that memory is taken back after a program finishes.
Memory management is the process of keeping track of main memory, allocating memory to programs, protecting memory areas and freeing memory when it is no longer required.
Why Does an Operating System Need Memory Management?
What Is Main Memory?
Main memory, usually RAM, stores instructions and data that are actively needed by running programs.
The CPU can work much faster with data in main memory than with data stored permanently on secondary storage.
The exact memory layout depends on the operating system and memory-management method, but the basic question remains the same: who owns each part of memory?
Main Functions of Memory Management in OS
Bare Machine in Operating System
In a Bare Machine system, there is little or no operating-system software between the user program and the hardware.
The programmer or program directly controls much of the machine.
How Bare Machine Memory Management Works
In the simplest form, the whole available memory can be used by one program.
The program is loaded into memory and then the CPU begins executing it.
When that program finishes, another program may be loaded.
Advantages and Problems of Bare Machine Systems
Advantages
- very simple memory model
- little operating-system overhead
- program can directly control hardware
Major Problems
- poor convenience
- little or no automatic job management
- weak protection
- CPU may remain idle during manual operations
- one program generally controls memory at a time
- poor support for sharing the computer efficiently
Why Was the Bare Machine Model Not Enough?
Problem
Every job required direct control and repeated loading operations.
Human setup time and program transitions could waste expensive CPU time.
Next Idea
Keep a small control program permanently in memory.
Let that program automatically manage the execution of user jobs.
This small control program became known as a Resident Monitor.
Resident Monitor in Operating System
A Resident Monitor is a small system program that remains permanently in main memory while user jobs are executed.
The monitor controls job sequencing and basic system operations.
Resident Monitor is an early operating-system program that stays in memory and automatically controls the loading and execution of user jobs.
Memory Layout in a Resident Monitor System
How Resident Monitor Works
After one job finishes, the monitor can automatically prepare the next job.
This reduces the amount of manual intervention required between jobs.
Why Does the Resident Monitor Need Memory Protection?
The resident monitor stays in memory while user code is running.
Therefore, user code should not be allowed to overwrite the monitor area.
Early systems could use hardware protection mechanisms such as a boundary or protection register to prevent the user program from writing into the monitor's protected area.
Limitations of Resident Monitor
Improvement Over Bare Machine
- automatic job sequencing
- less manual setup between jobs
- system code remains available in memory
- better control over hardware operations
Remaining Problems
- typically one user job runs at a time
- CPU can still become idle during slow I/O
- large parts of memory may remain unused
- memory utilization is still limited
The Big Problem: CPU Waiting for I/O
Suppose the current job sends a request to a slow input/output device.
The job cannot continue until that I/O operation finishes.
If no other job is available in memory, the CPU may simply wait.
This wasted CPU time motivated the next big idea: keep more than one program in memory.
Multiprogramming in Operating System
Multiprogramming means keeping multiple programs or jobs in main memory at the same time.
When the currently running program has to wait for I/O, the operating system can give the CPU to another ready program.
Multiprogramming is an operating-system technique in which several jobs are kept in memory together so the CPU can switch to another job when one job is waiting.
Memory Layout in Multiprogramming
Now main memory no longer contains only one user job.
Several jobs can occupy different memory areas at the same time.
How Multiprogramming Improves CPU Utilization
Suppose P1 begins an I/O operation.
Instead of leaving the CPU idle, the operating system can run P2.
When P2 later waits, P3 may run.
Memory Management Requirements Created by Multiprogramming
Multiprogramming improves CPU utilization, but it makes memory management much more difficult.
Why Is Relocation Needed in Multiprogramming?
In a bare machine, a program may be written or loaded with the assumption that it begins at a fixed memory location.
In multiprogramming, that location may already be occupied by another process.
Program's View
Program works with its own logical addresses.
Example: address 0, 1, 2, 3...
Physical Memory
The program may actually be loaded starting from a different physical location.
Example: address 5000 onward.
Therefore, some mechanism is needed to translate or relocate program addresses.
Why Is Memory Protection Important in Multiprogramming?
Several processes are now present in memory at the same time.
Without protection, one incorrect program could overwrite:
The operating system therefore needs hardware-assisted memory protection.
Simple Protection Idea: Base and Limit
One basic memory-protection concept is to use a base register and a limit register.
How Can Several Programs Fit Into Memory?
One early approach is to divide available memory into areas or partitions.
Different processes can be loaded into different partitions.
This leads to important later topics such as:
- fixed partitioning,
- variable partitioning,
- internal fragmentation,
- external fragmentation,
- compaction,
- paging,
- and segmentation.
Degree of Multiprogramming
The degree of multiprogramming means how many processes are present in main memory and available for execution at a time.
If P1, P2, P3 and P4 are all loaded into memory, the degree of multiprogramming is 4.
A higher degree can give the CPU more work to choose from, but loading too many processes can also create memory pressure.
Multiprogramming vs Multitasking
| Point | Multiprogramming | Multitasking |
|---|---|---|
| Main Goal | Keep CPU busy by having multiple jobs available | Provide responsive sharing of CPU among active tasks |
| Typical Switch Reason | One job may wait for I/O | Scheduler may switch frequently using time sharing |
| User View | Historically batch-oriented | Interactive multiple applications |
| Memory Requirement | Several programs may be resident in memory | Several active tasks also require managed memory |
Bare Machine vs Resident Monitor vs Multiprogramming
| Point | Bare Machine | Resident Monitor | Multiprogramming |
|---|---|---|---|
| OS Presence | Very little or none | Small monitor remains in memory | Operating system manages multiple resident jobs |
| User Jobs in Memory | Usually one | Usually one active user job | Several jobs |
| Job Switching | Mostly manual or direct | Monitor automatically starts next job | OS can switch between resident jobs |
| CPU Utilization | Poor | Better than bare machine | Much better when jobs have I/O waits |
| Memory Protection Need | Low in simple one-job model | Monitor must be protected from user job | OS and all processes must be protected from each other |
| Memory Complexity | Very low | Low | Much higher |
| Important New Problem | Manual management | CPU idle during I/O | Allocation, relocation, protection and fragmentation |
Why Did Memory Management Evolve?
Bare Machine Problem
The machine required too much direct control and manual job handling.
Resident Monitor Solution
Keep system control software permanently available in memory.
Resident Monitor Problem
CPU could still sit idle when the only user job waited for I/O.
Multiprogramming Solution
Keep multiple jobs in memory so another job can use the CPU.
Important Memory Management Problems Introduced by Multiprogramming
Logical Address and Physical Address: A Small Preview
As memory management becomes more advanced, it becomes useful to separate the address used by the program from the actual RAM location.
This concept becomes extremely important in paging and virtual memory.
Simple Example: Why Multiprogramming Helps
Suppose three programs are available:
P1, P2 and P3.
P1 starts using the CPU. After some time, P1 asks the disk to read a file.
Disk I/O is slow compared with the CPU.
In a one-job system, the CPU may have to wait.
In a multiprogrammed system, the OS can run P2 while P1 waits.
Later, if P2 also waits for I/O, P3 can run.
Important Terms From This Chapter
Common Mistakes Students Make
It also includes tracking, protection, relocation, sharing and deallocation.
It means the machine operates with little or no resident operating-system control.
The monitor occupies one part while the user job uses another part.
Resident-monitor systems can still execute user jobs mainly one at a time, while multiprogramming keeps several jobs ready in memory.
One CPU can still support multiprogramming by switching among several resident jobs.
On one CPU, jobs execute one at a time but the CPU switches when needed.
Multiple resident programs make protection essential.
A program may be loaded at different physical locations in a multiprogrammed system.
Memory Management Evolution in Simple Steps
Memory Management in OS Exam Preparation
For a 2-Mark Question
Answer: Memory management is the operating-system function that keeps track of main memory, allocates memory to programs, protects memory areas and frees memory when it is no longer required.
Bare Machine Short Answer
A Bare Machine system has little or no resident operating-system control. One program generally uses the machine and memory directly at a time.
Resident Monitor Short Answer
Resident Monitor is an early operating-system program that remains permanently in memory and controls the loading and execution of user jobs.
Multiprogramming Short Answer
Multiprogramming keeps several jobs in main memory so that the CPU can execute another job when the current job is waiting for I/O.
For a 5-Mark Question
- define memory management
- explain Bare Machine
- explain Resident Monitor
- explain Multiprogramming
- write why multiprogramming improves CPU utilization
For a 10-Mark Question
- meaning of Memory Management in OS
- functions of memory management
- Bare Machine memory model
- limitations of Bare Machine
- Resident Monitor
- Resident Monitor memory layout
- need for protection
- limitations of single-job batch systems
- Multiprogramming
- CPU utilization improvement
- memory allocation
- relocation
- protection
- comparison of all three stages
Memory Management Practice Questions
Memory Management Quick Revision
Frequently Asked Questions About Memory Management in OS
What is Memory Management in Operating System?
Memory Management in Operating System is the function that keeps track of main memory, allocates memory to programs, protects memory areas and frees memory after programs no longer need it.
What is a Bare Machine in OS?
A Bare Machine is an early or minimal computing environment in which little or no resident operating-system software controls the machine. A program works very directly with hardware and memory.
How is memory used in a Bare Machine system?
In the simplest Bare Machine model, one user program can occupy the available memory and execute until it finishes.
What is Resident Monitor in Operating System?
Resident Monitor is an early system program that remains permanently in main memory and controls the loading and execution of user jobs.
Why is it called Resident Monitor?
It is called resident because the monitor remains resident, or permanently present, in main memory while user jobs are executed.
What is the memory layout of Resident Monitor?
One part of memory is reserved for the Resident Monitor, while the remaining user area is used for the current user job.
What is Multiprogramming in Operating System?
Multiprogramming is a technique in which several programs are kept in main memory together so the CPU can switch to another program when the current program is waiting.
Why does multiprogramming improve CPU utilization?
When one job waits for input/output, the CPU can execute another ready job instead of remaining idle.
Does multiprogramming require multiple CPUs?
No. Multiprogramming can work on a single CPU because the operating system switches the CPU among multiple programs that are already in memory.
What is degree of multiprogramming?
Degree of multiprogramming is the number of processes or jobs currently present in main memory and available for execution.
Why is memory protection needed in multiprogramming?
Memory protection is needed because several processes share main memory. One process should not overwrite the operating system or another process's memory.
Why is relocation needed in memory management?
Relocation is needed because a process may be loaded at different physical memory locations depending on which parts of memory are available.
What is the difference between Bare Machine and Resident Monitor?
A Bare Machine has little or no resident operating-system control, while a Resident Monitor system keeps a small control program permanently in memory to manage jobs automatically.
What is the difference between Resident Monitor and Multiprogramming?
A Resident Monitor mainly manages user jobs one after another, while multiprogramming keeps multiple jobs in memory together so the CPU can switch among them when one job waits.
What is the difference between multiprogramming and multitasking?
Multiprogramming mainly aims to keep the CPU busy by maintaining multiple jobs in memory, while multitasking emphasizes responsive time sharing among active tasks.
What memory-management problems appear with multiprogramming?
Important problems include memory allocation, protection, relocation, free-space tracking, fragmentation and deciding which processes should remain in memory.
Conclusion
Memory Management in OS became more important as computers moved from simple one-program systems to systems that could keep many programs ready at the same time.
In a Bare Machine, one program directly controlled the machine with very little operating-system support.
The Resident Monitor improved this model by keeping a small control program permanently in memory. It could automatically load and execute jobs one after another.
But a single job could still make the CPU wait during slow I/O. Multiprogramming solved this problem by keeping several jobs in memory so another job could use the CPU while one job waited.
This improvement created new memory-management requirements: allocation, relocation, protection, free-space management and controlled sharing.
The easiest way to remember this chapter is: Bare Machine = one program, Resident Monitor = one permanent controller, Multiprogramming = many programs in memory.
