Chapter Three Memory Management (Main Memory)
Chapter Three Memory Management (Main Memory)
• Program must be brought into memory and placed within a process for it to be run.
• Input queue or job queue :- collection of processes on the disk(storage) that are
waiting to be brought into memory to run the program.
Processes are always uses virtual address space and they do not see physical
address.
The logical address is a virtual address and can be viewed by the user.
The logical address is used like a reference, to access the physical address.
Physical Address Space
The physical address is address that seen by memory unit and used to access
memory units.
The logical and physical address generated while run-time address binding
method differs from each other.
The logical address is generated by the CPU while program is running whereas,
the physical addres is computed by the MMU (Memory Management Unit).
Cont..
Memory-Management Unit (MMU)
Hardware device that maps virtual(Logical) to physical address.
In MMU scheme, the value in the relocation register is added to every address
generated by a user process at the time it is sent to memory.
The user program deals with logical addresses; it never sees the real physical
addresses.
Swapping
• For execution, each process must be placed in the main memory.
• This technique uses Address binding which is the process of mapping the
program's logical addresses to corresponding physical or main memory
addresses.
Cont..
• Due to address binding methods, the process that is swapped out of main
memory occupies same address space.
• When it is swapped back to the main memory ,the binding is done at the
assembly or load time.
Advantage of swaps
Swap is generally cheaper. There is no upfront premium and it reduces transactions costs.
Swap can be used to border risk, and long time period border is possible.
It has longer term than futures or options. Swaps will run for years, however forwards and
futures are for the relatively short term.
Using swaps can give companies a better match between their liabilities and revenues.
Disadvantages of swaps
Early termination of swap before maturity may acquire a breakage cost.
Lack of liquidity.
• The logical memory of a process is broken into the same fixed-sized blocks
called pages.
• So, when a process is to be executed, the pages of the process from the source
i.e. back store are loaded into any available frames in main memory.
• CPU generates the logical address for a process which consists of two parts that
are page number and the page offset.
• This base address is combined with page offset to generate the address of the
page in main memory.
Advantages
•Allocating memory is easy and cheap
•Eliminates external fragmentation
•Data (page frames) can be scattered all over PM
•Pages are mapped appropriately anyway
•Allows demand paging and prepaging
•More efficient swapping
•No need for considerations about fragmentation
•Just swap out page least likely to be used
Disadvantages
•Longer memory access times (page table lookup)
•Defended page tables
•Inverted page tables
•Memory requirements (one entry per VM page)
•Internal fragmentation
Paging Vs Swapping
• Paging allows the memory address space of a process to be noncontiguous.
• Swapping is less flexible as it moves entire process back and forth between
main memory and back store.
• Because internal fragmentation of pages takes place, the user’s view of memory
is lost.
• Segments or sections are also used in object files of compiled programs when
they are linked together into a program image and when the image is loaded into
memory.
Cont..
Advantages of segmentation
• Allow the use of separate memory areas for the program code and data
• Permit a program to be placed into different areas of memory whenever the program
is end.
• Multitasking becomes easy
• The advantage of having separate code and data segments is that one program can
work on different sets of data.
• The reference logical addressed can be loaded into the instruction pointer (IP) and
run the program anywhere in the segment memory
• Programs are re-locatable so that programs can be run at any location in the memory
Disadvantages of segmentation
•External fragmentation is present
•Costly memory management algorithms.
•Segmentation finds free memory area big enough. .
•Segments of unequal size not suited as well for swapping
Paging Vs. Segmentation
Segmentation Paging
Program is divided into variable size segments Program is divided into fixed size pages
User or compiler is responsible for dividing the program into Division into pages is performed by the Operating System
segments
Processor uses segment number, offset to calculate absolute Processor uses page number, offset to calculate absolute
address address
Operating System maintains a list of free holes in main Operating System maintains a free frame list
DMA
• Stands for "Direct Memory Access."
• DMA is a method of transferring data from the computer's RAM to another part
of the computer without processing or using the CPU.
• While most data that is input or output from your computer is processed by the
CPU, some data does not require processing, or can be processed by another
device.
• In these situations, DMA can save processing time and is a more efficient way
to move data from the computer's memory to other devices
Cont..
• DMA channels are used by high speed devices and they allow them to
communicate directly with the main memory (RAM) on our system.
• When DMA channels are used, CPU is not involved in the communication.
Contiguous Memory Allocation
• The main memory must accommodate both the operating system and the various user
processes.
• Therefore need to allocate different parts of the main memory in the most efficient
way possible.
• The memory is usually divided into two partitions: one for the resident operating
system, and one for the user processes.
• We may place the operating system in either low memory or high memory.
• With this approach each process is contained in a single contiguous section of
memory.
Cont..
• One of the simplest methods for memory allocation is to divide memory into
several fixed-sized partitions.
• When the process terminates, the partition becomes available for another
process.
Cont..
• The contiguous memory allocation scheme can be implemented in operating
systems with the help of two registers, known as the base and limit registers.
Cont..
• The operating system keeps a table indicating which parts of memory are
available and which are occupied.
• Finally, when a process arrives and needs memory, a memory section large
enough for this process is delivered.