Please enable JavaScript.
Coggle requires JavaScript to display documents.
Chapter 2: Memory and Process Management - Coggle Diagram
Chapter 2: Memory and Process Management
INTRODUCTION
Main memory and the registers built into the processor itself are the only storage that the CPU can access directly.
Any instructions in execution, and any data being used by the instructions, must be in one of these direct-access storage devices
If the data are not in memory, they must be moved there before the CPU can operate on them.
Registers that are built into the CPU are generally accessible within one cycle of the CPU clock.
Most CPUs can decode instructions and perform simple operations on register contents at the rate of one (or more operations per clock tick.)
Unlike registers, main memory is accessed via a transaction on the memory bus.
Memory access may take many cycles of the CPU clock to complete, (in which case the processor normally needs to stall, since it does not have the data required to complete the instruction that it is executing.)
This situation is intolerable because of the frequency of memory accesses: the remedy is to add fast memory between the CPU and main memory.
A memory buffer used to accommodate a speed differential, called a cache.
Define the function of memory manager.
Keeping track of which parts of memory are currently being used and by whom
Deciding which processes (or parts thereof) and data to move into and out of memory
Allocating and de-allocating memory space as needed
Describe the characteristics of the different levels in the hierarchy of memory organization
Four Level of Memory Hierarchy Characteristics
The memory technology and storage organization at each level are characterized by five parameters:
access time
-the round-trip time from the CPU to the memory
memory size
-the number of bytes or words
cost per byte
-cost of the memory estimated by the product
transfer bandwidth
-rate at which information is transferred between adjacent levels
unit of transfer
-size for data transfer
1) Registers and Caches
The register and the cache are parts of the processor complex, built either on the processor chip or on the processor board.
The cache is controlled by the Memory Management Unit (MMU) and is programmer-transparent.
2) Main Memory
The main memory is sometimes called the primary memory of a computer system.
It is usually much larger than the cache and often implemented by the most cost-effective RAM chips
The main memory is managed by a MMU in cooperation with the operating system
3&4) Disk Drives and Tape Units
Disk drives and tape units are handled by the OS with limited user intervention.
The disk storage is considered the highest level of on-line memory. It holds the system programs such as the OS and compilers and some user programs and their data sets.
The magnetic tape units are off-line memory for use as backup storage. They hold copies of present and past user programs and processed results and files.
Memory devices at a lower level are:
faster to access
smaller in size, and
more expensive per byte
having a higher bandwidth and
using a smaller unit of transfer as compared with those at a higher level.
Describe memory management strategies:
Fetch, Placement (Best-Fit, First-Fit And Worst-Fit), Replacement.
Placement
Memory allocation is the process of assigning blocks of memory on request.
Typically the allocator receives memory from the operating system in a small number of large blocks that it must divide up to satisfy the requests for smaller blocks.
It must also make any returned blocks available for reuse.
There are many common ways to perform this, with different strengths and weaknesses.
Best-Fit
The memory manager places a process in the smallest memory in which it will fit.
This strategy produces the smallest leftover hole.
Entire list of holes is to be searched
Search of entire list can be avoided by keeping the list of holes sorted by size.
First-Fit
Allocate the first hole that is big enough.
Searching may start either at the beginning of the set of holes or where the previous first-fit search ended.
Stop searching as soon as first hole large enough to hold the process is found.
The first fit approach tends to fragment the blocks near the beginning of the list without considering blocks further down the list.
Worst-Fit
Allocate the largest hole.
In contrast, this strategy aims to produce the largest leftover hole, which may be big enough to hold another process.
Replacement
When a process generates a page fault, the memory manager must locate referenced page in secondary storage, load it into page frame in main memory and update corresponding page table entry.
If no frame is free, we find one that is not currently being used and free it.
We can free a frame by writing its contents to swap space and changing the page table (and all other tables) to indicate that the page is no longer in memory.
Fetch
Routines
A section of a program that performs a particular task.
Programs consist of modules, each of which contains one or more routines.
The term routine is synonymous with procedure, function, and subroutine.
The operating system is a collection of software routines.
Resident routine
Permanent in memory.
Normally, a computer does not have enough memory to hold all the programs you use.
When you want to run a program, therefore, the operating system is obliged to “ free some memory by copying data or programs from main memory to a disk.” (This process is known as swapping.)
Swapping
A process can be swapped temporarily out of memory to a backing store, and then brought back into memory for continued execution.
Major part of swap time is transfer time; total transfer time is directly proportional to the amount of memory swapped.
Modified versions of swapping are found on many systems, i.e., UNIX, Linux, and Windows.
Certain programs, however, can be marked as being memory resident, which means that the operating system is not permitted to swap them out to a storage device; they will always remain in memory.
The programs and data used most frequently are the ones that should be memory resident. This includes central portions of the operating system and special programs, such as calendars and calculators, that you want to be able to access immediately.
Another term for memory resident is RAM resident.
In DOS systems, memory-resident programs are called pop-up utilities or TSRs (terminate and stay resident).
Transient routine
Transient refers to a module that, once loaded into main memory, is expected to remain in memory for a short time.
The term overlay is commonly used instead, and refer to a program module that is brought to memory when it is needed by the running program and then replaced with another when it is no longer needed, so a program had lower memory requirements.
Program modules were written to allow different modules to share the same memory region and the main program itself was responsible of exchanging modules between disk and memory as necessary
Comparison Between Resident And Transient Routines
Resident Routines
A routines that stays in memory
Routines that directly support application programs as they run
Example : routine that control physical I/O
Transient Routines
A routines that is loaded as needed
stored on disk and read into memory only when needed
Example : routines that formats disks
Fixed-Partition
Most simple memory management scheme for multiprogrammed systems.
Divide memory into fixed size partitions, possibly of different size.
Partitions fixed at system initialization time and may not be changed during system operation.
Divide the memory into a number of separate fixed areas, each of which can hold one process.
A technique used in early multiprogramming operating systems involved partitioning the available primary memory into a number of regions.
Each region having a fixed size, different regions potentially having different sizes.
The sum of the sizes of all regions equals the size of the primary memory.
Fixed partitions have fixed size and usually cannot be easily expanded or shrunk.
Advantage :
Simplicity.
Easy to implement
Multiprogramming
Dynamic Partition
In contrast to fixed partition, is the dynamic partition.
Dynamic partitions can change size by themselves when they need it
Allow the partitions to be variable in size at load time.
Allocate to the process the exact amount of memory it requires.
Processes are loaded into consecutive areas until the memory is filled, or, more likely, the remaining space is too small to accommodate another process
Under dynamic memory management, the transient area is treated as a pool of unstructured free space.
When the system decides to load a particular program, a region of memory just sufficient to hold the program is allocated from the pool
Because a program gets only the space it needs, relatively little is wasted.
Advantages :
Jobs are given only as much memory as they request. Still, contiguous blocks are needed. Internal fragmentation problem is solved.
Disadvantage :
Suffer external fragmentation.
Virtual Memory
Technique that allows the execution of processes that are not completely in memory.
Virtual memory is used by the operating system in order to enhance the storage capacity of the working memory, without requiring the installation of additional Random Access Memory modules.
Virtual memory combines your computer’s RAM with temporary space on your hard disk.
When RAM runs low, virtual memory moves data from RAM to a space called a paging file.
Moving data to and from the paging file frees up RAM to complete its work.
The more RAM your computer has, the faster your programs will generally run.
If a lack of RAM is slowing your computer, you might be tempted to increase virtual memory to compensate.
However, your computer can read data from RAM much more quickly than from a hard disk, so adding RAM is a better solution.
Segmentation
Another memory management approach, segmentation, is similar to dynamic partitioning.
With segmentation, a program is divided into several segments, each similar to a partition of varied size.
Segmentation, is usually visible, which is actually based on the programmers’ logical view of programs
With segmentation, programs are divided into variable size segments, instead of fixed size pages.
Every logical address is formed of a segment name and an offset within that segment.
In practice, segments are numbered.
Programs are segmented automatically by compiler or assembler.
Dynamic address translation.
To dynamically translate a segment address to an absolute address:
1) Break the address into segment and displacement portions
2) Use the segment number to find the segment’s absolute entry point address in a program segment table
3) Add the displacement to the entry point address.
Paging
The ways in which the operating system can store and retrieve data
From secondary storage for use in main memory.
Break the main memory into fixed-sized blocks called frames.
And break the program or process image into blocks of the same size called pages.
The program is bought into memory for execution as pages.
The program takes the pages from main memory during execution.
When the page required is not in main memory, the operating system fetches the required page from hard disk into main memory and moves the other page from main memory back to hard disk.
This process is referred as Paging.
When a process is to be executed, its pages are loaded into any available frames, as illustrated in Figure 8
Paging leads to problem of Internal Fragmentation.
When a page of smaller size than the size of frame is placed in a larger size frame, it leads to unused memory space within a frame.
For example, when a page of 5 MB is placed in a frame of 7 MB, 2 MB of memory in the frame is wasted.
This wastage of unused memory is called Internal Fragmentation.
Advantage :
It allows the physical address space of a process to be noncontiguous.
Disadvantage:
Internal fragmentation occur.
Segmentation and Paging
1.With segmentation and paging, addresses are divided into a segment number, a page number within that segment, and a displacement within that page.
2.After the instruction control unit expands the relative address, dynamic address translation begins.
3.First, the program’s segment table is searched for the segment number, which yields the address of the segment’s page table.
4.The page table is then searched for the page’s base address, which is added to the displacement to get an absolute address.