Memory Management (1)
Memory Management (1)
Memory,File concepts
Smt B.Soujanya
Assistant Professor
Department of Computer Science and Technology
GITAM Institute of Technology (GIT)
Visakhapatnam – 530045
Email: [email protected]
UNIT-4
assigning portions known as blocks to various running programs to optimize the overall
● It is the most important function of an operating system that manages primary memory.
● It helps processes to move back and forward between the main memory and execution
disk.
● Program must be brought (from disk) into memory and placed within a process for it to
be run
● Main memory and registers are only storage CPU can access directly
● Memory unit only sees a stream of addresses + read requests, or address + data and
write requests
Logical and physical addresses are the same in compile-time and load-time address-binding
schemes; logical (virtual) and physical addresses differ in execution-time address-binding
scheme.
Logical address space is the set of all logical addresses generated by a program
Physical address space is the set of all physical addresses generated by a program
Base and Limit Registers
● A pair of base and limit registers define the logical address space
● CPU must check every memory access generated in user mode to be sure it is between
base and limit for that user
Hardware Address Protection
Swapping
● Swapping is a method in which the process should be swapped temporarily from the
● It will be later brought back into the memory for continue execution.
● Backing store is a hard disk or some other secondary storage device that should be big
enough in order to accommodate copies of all memory images for all users.
■ Backing store – fast disk large enough to accommodate copies of all memory images for all
users; must provide direct access to these memory images
■ Roll out, roll in – swapping variant used for priority-based scheduling algorithms;
lower-priority process is swapped out so higher-priority process can be loaded and executed
■ 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)
Swapping
Benefits of Swapping
Benefits of Swapping
Here, are major benefits/pros of swapping:
We can place the operating system in either low memory or high memory.
In this contiguous memory allocation, each process is contained in a single contiguous section of
memory.
Contiguous Memory Allocation
Three components
2. Memory Allocation
3. Fragmentation
1.Memory Mapping and Protection
● The relocation register contains the value of the smallest physical address;
● the limit register contains the range of logical addresses (for example, relocation =
100040 and limit = 74600).
● With relocation and limit registers, each logical address must be less than the limit
register;the MMU maps the logical address dynamically by adding the value in the
relocation register.
● This mapped address is sent to memory .
● When the CPU scheduler selects a process for execution, the dispatcher loads the
relocation and limit registers with the correct values as part of the context switch.
● The relocation-register scheme provides an effective way to allow the operating-system
size to change dynamically. This flexibility is desirable in many situations.
1.Memory Mapping and Protection
Hardware Support for relocation and limit registers.
2. Memory Allocation
One of the simplest methods for allocating memory is to divide memory into several
fixed-sized partitions.
● In this multiple partition method, when a partition is free, a process is selected from
● When the process terminates, the partition becomes available for another process.
2. Memory Allocation
This procedure is a particular instance of the general dynamic storage allocation problem, which
concerns how to satisfy a request of size n from a list of free holes. There are many solutions to
this problem. The first-fit, best-fit, and worst-fit strategies are the ones most commonly used to
1. First fit. Allocate the first hole that is big enough. Searching can start either at the beginning
of the set of holes or where the previous first-fit search ended. We can stop searching as
soon as we find a free hole that is large enough.
2. Best fit. Allocate the smallest hole that is big enough. We must search the entire list, unless
the list is ordered by size. This strategy produces the smallest leftover hole.
3. Worst fit. Allocate the largest hole. Again, we must search the entire list, unless it is sorted
by size. This strategy produces the largest leftover hole, which may be more useful than the
smaller leftover hole from a best-fit approach.
3.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.Internal fragmentation
Memory block assigned to process is bigger. Some portion of memory is left unused, as it cannot be
2.External fragmentation
Total memory space is enough to satisfy a request or to reside a process in it, but it is not contiguous,
so it cannot be used.
3.Fragmentation
The following diagram shows how fragmentation can cause waste of memory and a compaction
technique can be used to create more free memory out of fragmented memory −
External fragmentation can be reduced by compaction or shuffle memory contents to place all free
memory together in one large block. To make compaction feasible, relocation should be dynamic.
The internal fragmentation can be reduced by effectively assigning the smallest partition but large
enough for the process.
3.Fragmentation
Logical Versus Physical Address Space
The address generated by the CPU is a logical address, whereas the address actually
seen by the memory hardware is a physical address.
Addresses bound at compile time or load time have identical logical and physical
addresses.
Addresses created at execution time, however, have different logical and physical
addresses.
In this case the logical address is also known as a virtual address, and the two
terms are used interchangeably by our text.
The set of all logical addresses used by a program composes the logical
address space, and the set of all corresponding physical addresses composes
the physical address space.
The MMU can take on many forms. One of the simplest is a modification of the
base-register scheme described earlier.
The base register is now termed a relocation register, whose value is added to
every memory request at the hardware level.
Paging
● Paging is a memory-management scheme that permits the physical address space
of a process to be noncontiguous.
● Paging avoids the considerable problem of fitting memory chunks of varying sizes
onto the backing store; most memory-management schemes used before the
● The problem arises because, when some code fragments or data residing in main
memory need to be swapped out, space must be found on the backing store.
Paging
Basic Method:-
The basic method for implementing paging involves breaking physical memory into fixed-sized
blocks called frames and breaking logical memory into blocks of the same size called pages.
When a process is to be executed, its pages are loaded into any available memory frames
from the backing store.
The backing store is divided into fixed-sized blocks that are of the same size as the memory
frames.
Every address generated by the CPU is divided into two parts: a page number (p) and
a page offset (d).
The page number is used as an index into a page table. The page table contains the
base address of each page in physical memory.
This base address is combined with the page offset to define the physical memory
address that is sent to the memory unit.
Paging-Hardware
Paging
The page size (like the frame size) is defined by the hardware.
The size of a page is typically a power of 2, varying between 512 bytes and 16 MB per page,
depending on the computer architecture.
The selection of a power of 2 as a page size makes the translation of a logical address into a page
number and page offset particularly easy.
If the size of logical address space is 2'"* and a page size is 2" addressing units (bytes or words), then
the high-order m - n bits of a logical address designate the page number, and the n low-order bits
designate the page offset.
where p is an index into the page table and d is the displacement within the page.
Paging
Address Translation
Page address is called logical address and represented by page number and the offset.
Frame address is called physical address and represented by a frame number and the
offset.
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.
Paging model of logical and physical memory
Paging-Example
The solution to this problem is to use a very special high-speed memory device called the
translation look-aside buffer, TLB.
The TLB is associative, high-speed memory. Each entry in the TLB consists of two parts: a key
(or tag) and a value. When the associative memory is presented with an item, the item is
compared with all keys simultaneously.
The TLB contains only a few of the page-table entries. When a logical address is generated by
the CPU, its page number is presented to the TLB. If the page number is found, its frame
number is immediately available and is used to access memory.
Paging -Hardware Support
Paging-Protection
● Memory protection in a paged environment is accomplished by protection bits
associated with each frame. Normally, these bits are kept in the page table. One bit can
define a page to be read-write or read-only.
● One additional bit is generally attached to each entry in the page table: a valid-invalid
bit. When this bit is set to "valid," the associated page is in the process's logical
address space and is thus a legal (or valid) page.
● When the bit is set to"invalid,'" the page is not in the process's logical address space.
Illegal addresses are trapped by use of the valid-invalid bit.
● The operating system sets this bit for each page to allow or disallow access to the page.
Paging -Protection
Structure of Page Table
Structure of page table simply defines, in how many ways a page table can be structured. Well, the
paging is a memory management technique where a large process is divided into pages and is
placed in physical memory which is also divided into frames.
Frame and page size is equivalent. The operating system uses a page table to map the logical
address of the page generated by CPU to its physical address in the main memory.
So, six processes will have some or the other of their page in
the main memory which would compel their page tables also to
be in the main memory consuming a lot of space. This is the
drawback of the paging concept.