You are on page 1of 33

Chapter-3

Memory management

1
Outline
• Overview
• Logical vs physical address space
• Fixed partitioning
• Dynamic partitioning
• Paging
• Segmentation
• Swamping
• Caching

2
Overview
• In a uni-programming system, main memory is
divided into two parts:

one part for the operating system (resident


monitor, kernel) and

 one part for the program currently being


executed.

3
Cont’d
• In a multiprogramming system, the “user” part
of memory must be further subdivided to
accommodate multiple processes
• The task of subdivision is carried out
dynamically by the operating system and is
known as memory management

4
Cont’d
• Memory management is intended to satisfy the
following requirements:
Relocation
Protection
Sharing
Logical organization
Physical organization

5
Relocation
• In a multiprogramming system, the available main memory is generally

shared among a number of processes.

• Active processes need to be able to be swapped in and out of main memory

in order to maximize processor utilization

• Once a program has been swapped out to disk, it would be quite limiting to

declare that when it is next swapped back in, it must be placed in the same

main memory region as before

6
Protection

• Each process should be protected against unwanted

interference by other processes, whether accidental or

intentional.

• Thus, programs in other processes should not be able to

reference memory locations in a process for reading or writing

purposes without permission.

7
Cont’d
• In one sense, satisfaction of the relocation requirement
increases the difficulty of satisfying the protection
requirement.

• Because the location of a program in main memory is


unpredictable, it is impossible to check absolute
addresses at compile time to assure protection

8
Sharing
• Processes that are cooperating on some task may need to share
access to the same data structure.
• Any protection mechanism must have the flexibility to allow several
processes to access the same portion of main memory.
• Advantageous to allow each process access to the same copy of the
program rather than have their own separate copy
• Memory management must allow controlled access to shared areas
of memory without compromising protection
• Mechanisms used to support relocation support sharing capabilities

9
Logical Organization
• Main memory in a computer system is organized as a linear, or one-
dimensional, address space, consisting of a sequence of bytes or words.
• Most programs are organized into modules, some of which are unmodifiable
and some of which contain data that may be modified.
– modules can be written and compiled independently
– different degrees of protection given to modules (read-only, execute-
only)
• sharing on a module level corresponds to the user’s way of viewing the
problem

10
Physical Organization
• Computer memory is organized into at least two levels, referred to as main memory
and secondary memory.

• Main memory provides fast access at relatively high cost.


– In addition, main memory is volatile; that is, it does not provide permanent storage.

• Secondary memory is slower and cheaper than main memory and is usually not
volatile.
– Thus secondary memory of large capacity can be provided for long-term storage of programs
and data, while a smaller main memory holds programs and data currently in use.

• In this two-level scheme, the organization of the flow of information between main
and secondary memory is a major system concern.

11
Binding of instructions and data to
memory
Address binding of instructions and data to memory
addresses can happen at three different stages.
Compile time:
– If memory location is known apriori, absolute code can be
generated; must recompile code if starting location changes.
Load time:
– Must generate relocatable code if memory location is not
known at compile time.
Execution time:
– Binding delayed until runtime if the process can be moved
during its execution from one memory segment to another.
Need hardware support for address maps

12
Logical vs. Physical Address Space
• The concept of a logical address space that is
bound to a separate physical address space is
central to proper memory management.
• Logical Address: or virtual address - generated by
CPU
– reference to a memory location independent of the
current assignment of data to memory

13
Cont’d
• Physical Address: address seen by memory unit.
– the physical address refers to a location in the memory
unit

• Logical and physical addresses are the same in


compile time and load-time binding schemes
• Logical and physical addresses differ in
execution-time address-binding scheme.

14
Memory Management Unit (MMU)
• Hardware device that maps virtual 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 address.

15
Swapping
• Swapping is a mechanism in which a process can be
swapped temporarily out of main memory to
secondary storage (disk) and make that memory
available to other processes.

• the system swaps back the process from the


secondary storage to main memory

16
Fixed sized partition
• In the fixed sized partition the system divides
memory into fixed size partition (may or may
not be of the same size)
• Main memory is divided in to number of
Static partition at system generated time
• A process may be loaded in to partition of
equal or greater size .

17
Cont’d
Disadvantage
• A program may be too big to fit in a partition
• program needs to be designed with the use of overlays
• internal fragmentation
– wasted space due to the block of data loaded being
smaller than the partition

18
Dynamic Partitioning
• Partition are created dynamically, so that each
process loaded into partition of exactly the
same size as that process
• Partitions are of variable length and number
• Process is allocated exactly as much memory
as it requires
• This technique was used by IBM’s mainframe
operating system

19
Cont’d
Disadvantage
External Fragmentation
• memory becomes more and more fragmented
•memory utilization decline
• time consuming and wastes CPU time
• OS shifts processes so that they are contiguous

20
PAGING
• Suppose, that main memory is partitioned into equal fixed-
size chunks that are relatively small, and that each process is
also divided into small fixed-size chunks of the same size.
• Then the chunks of a process, known as pages, could be
assigned to available chunks of memory, known as frames, or
page frames.
• Each process is divided into frame-size pages;
• smaller processes require fewer pages, larger processes require
more
• When a process is brought in, all of its pages are loaded into
available frames, and a page table is set up

21
Page Table
• Maintained by operating system for each
process
• Contains the frame location for each page in
the process
• Processor must know how to access for the
current process used by processor to produce a
physical address

22
Cont’d
• Address generated by CPU is divided into
– Page number(p): Number of bits required to
represent the pages in Logical Address Space or
Page number
– Page offset(d): Number of bits required to
represent particular word in a page or page size
of Logical Address Space or word number of a
page or page offset.

23
Cont’d
• Physical Address is divided into
• Frame number(f): Number of bits required to
represent the frame of Physical Address Space
or Frame number.
• Frame offset: Number of bits required to
represent particular word in a frame or frame
size of Physical Address Space or word number
of a frame or frame offset.

24
SEGMENTATION
• A user program can be subdivided using segmentation, in
which the program and its associated data are divided into a
number of segments.

• a process is divided into a number of segments that need not


be of equal size.

• When a process is brought in, all of its segments are loaded


into available regions of memory, and a segment table is set
up.

25
Cont’d
• a logical address using segmentation consists of two
parts, in this case a
– segment number :It is the base address of the
segment
– an offset : It is the length of the segment.
• Because of the use of unequal-size segments,
segmentation is similar to dynamic partitioning.
• Each segment contain same type of functions such as
main function can be included in one segment and the
library functions can be included in the other
segment,
26
Cont’d
Disadvantages

 It can have external fragmentation.

 it is difficult to allocate contiguous memory


to variable sized partition.

 Costly memory management algorithms

27
Thrashing
• Thrashing is a condition or a situation when the
system is spending a major portion of its time in
servicing the page faults, but the actual processing
done is very negligible.
• If a process is allocated too few frames, then there
will be too many and too frequent page faults
• If a process does not have enough pages, the page-
fault rate is very high.

28
Causes of Thrashing
• High degree of multiprogramming : If the number of
processes keeps on increasing in the memory than number
of frames allocated to each process will be decreased.

• Lacks of Frames: If a process has less number of frames


then less pages of that process will be able to reside in
memory and hence more frequent swapping in and out
will be required. This may lead to thrashin

29
Cache Memory
• A small amount of fast memory that sits between normal main
memory and CPU

• When processor attempts to read a word from memory, cache is


checked first

• It is used to hold those parts of data and program which are most
frequently used by the CPU.

• The parts of data and programs are transferred from the disk to
cache memory by the operating system, from where the CPU can
access them

30
Cont’d
Advantages
• The advantages of cache memory are as
follows −
– Cache memory is faster than main memory.
– It consumes less access time as compared to main
memory.
– It stores the program that can be executed within a
short period of time.
– It stores data for temporary use.

31
Cont’d
Disadvantages

• The disadvantages of cache memory are as follows −


– Cache memory has limited capacity.

– It is very expensive.

32
Cont’d

33

You might also like