OS Unit 4 Notes
OS Unit 4 Notes
regster
16900
pteca
233pss
memoy
CPU 14345
346
Fragmentation
External Fragmentation: External fragmentation exists when there is enough total menmory
space to satisfy a request but the available spaces are not contiguous; storage is fragmented into a ge
umher of small hole This frnntatic. Droblem can be severe In toe worst c3
in one big free bloc. slead, we might be able o run several more processes.
Internal Fragmentation: The memory allocated to 4process may be slightly larger than the
requested memory. The difference between these two numbers is internal memory that is inter al to a
partition.
Compaction: One solution to the problem of external fragmentation is Compaction. The goal is to
shuftle the memory contents so as to place allfree memory together in one large block. Compaction is not
always possible. The simplest compaction algorithm is to move allprocesses toward one end of memory:
all holes move in the other direction, producing one large hole of available memory but this scheme can
be expensive. Another possible solution to the extenal-fragmentation problem is to permit the logical
address space of the processes to be noncontiguous.
allocation
Memory Protection in contiguous memory
space, we need the ability to determine the
To nake sure thateach process has a separate memory the process can access
and to ensure that
range of legal addresses that the process may access
by using two registers, usually a base
only these legal addresses. We can provide this protection
and a limit or relocation.
memory address. The limit register specifies
* The base register holds the smallest legal physical and the limit register is 100, then
holds 300
the size of the range. For example, if the base register
from 300through 400.
the program can legally access alladdresses
Protection of memory space is accomplished by having the
CPU hardware compare every address
program executing in user mode to
generated in user mode with the registers. Any attempt by a
results in a trap to the operating system.
access operating-system memory or other users' memory
Eirit reocation
rogister registcr
physical
logica addresS
andresS
memory
CPU
stuceeu
Paging
address space a process to be
* Paging is a memory-management scheme that permits the physical
non-contiguous.
* Paging avoids external fragmentation but not internal fragmentation.
iogca pysical
addess address f0000 . . 0000
CPU
f1111.. 1111
ohysta
page tabe
Pagng hardware
* 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
their source
Every address generated the CPU(Logical address) 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.
The size of apage 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 apage size makes the
translation of a logical address into a page number and page offset particularly easy.
Downioaded by Swe
Example:
frarne
page 0
page 1 1 page 0
page 2 23 2
37
page 3 page tabie 3 page 2
log ca 4 Dage 1
memony
7 page 3
phrysical
memory
Page Table
Page table is a data structure maintained by OS.
In paging OS creates page table for every process separately.
Page table contains frame number, corresponding to Page number.
Page table resides in physical memory; it wastes large space in physical memory because
generally its size is large.
Paging with TLB
table.
memory access, TLB is used with page
* To increase thespeed of hardwarecache. called atranslation
look aside buffer.
small. fast, lookup
TLB is a special,
following way.
The TLB is usedwith page tables in the address is generated
contains only a few of the page-table entries. When a logical
V The TLB (known as
number is presented to the TLB. If the page number is found
by the CPU, its page memory.
immediately available and is used to access
a TLB Hit). its frame number is reference to the page
number is not in the TLB (known as a TLB Miss), a memory
V If the page access memory.
be made. When the frame number is obtained. we can use it to
table must
iogcal
attress
CPU pd
page trame
Nurter tubet
prysicel
addess
TLB
TIB SS
pysical
fremony
fage tatie
2 paçe 0
OC000 rare nutrber
page 0 3 page1
page 1 4 page 2
2
page 2
37
pago 3 48
Dage 4 7 page3
10 468 70 i
page 5 8 pace 4
12 287 page tatie
9 paçe5
page n
Imit ASe
Segment
tabe
CPU
Ves
Each entry in the segment table has a segment base and a segment limit. The segment base
contains the starting physical address where the segment resides in memory, and the segment
limit specifies the length of the segment.
In segmentation logical address consists of two parts: a segment number, s, and an offset into that
segment, d. the segment number are used as an index to the segment table. The offset
d of the
logical address must be between 0 and the segment limit. If it is not, we trap to the operating
system (logical addressing attempt beyond end of segment). When an offset is legal, it is added to
the segment base to produce the address in physical memory of the desired byte. The segment
table is thus essentially an array of base-limitregister pairs.
Example: segment 2 is 400 bytes long and begins at location 4300. Thus, a reference to byte 53
of segment 2is mapped onto location 4300 +53- 4353. Areference to segment 3, byte 852, is
mapned to 3200 (the base of segment 3) + 852 = 4052 Areference to byte 1222 of segment 0
would result in a trap to the operating system, as this segment is only 1,000 bytes long.
Sgrrait
1000
tegmet abie
6egert
479
Begierit
tyic mencity
Virtual memory
processes that are not completely in
3 Virtual memory is a technique that allows the execution of
programs can be larger than physical
memory. One major advantage of this scheme is that
memory.
and to implement shared memory.
* Virtual memory also allows processes to share files easily performance
easy to implement, however, and may substantially decrease
Virtual memory is not
if it is used carelessly.
Demand Paging
loaded when they are demanded during
$ Indemand-paged virtual memory, pages are only
never loaded into physical memory.
program execution. Pages that are never accessed are thus
This technique is commonly used in virtual memory systems.
Indemand paging lazy swapper is used. It never swaps a
page into memory unless that page will
*
be needed.
Objective of Demand paging is to increase degree of multi-programming.
studoeu
13
vca mei
measured by
Paging: Performance of demand paging is generally
Performance of Demand (0<p<1). We would expect pto
be close to
probability of apage fault
effective access time. Let pbe the page faults. The effective access time
is then
have only a few
zero-that is, we would expect to
Effectiveaccess time= (1 - p) *
ma tp* page fault time.
Example:
reterence string
701 2 0 3 0 4 2 30 3 2 1 2
77
7 7
3
page rames
string.
Example:
refterence string 0
017
7 0 1 2 0 3 0 A 2 3 03 2 1 2
77 z
4
pagetrames
3. LRUPage Replacement: renlace the nage that has not been used for the
longest
we can
* In least recently algorithm
period of time. page-replacement
how to implement LRU replacement. An LRU
is
** The major problem substantial hardware assistance.
algorithm may require
Example:
reference string
2 1 2 O 701
Þ 4 2 3 0 3
2 0 3
1
4
page frames
Thrashing
swap-in andswap-out than executing. Thrashing occurs
if it spending more time in
Aprocess is thrashing muliprogramming
much. too
when we increase degree of
studee
thrasthig
cegreo of mu'tiprogramminig
Thrashing
As the degree of multiprogramming increases, CPU utilization also increases, although more slowly, until
a maximum
is reached,. If the increased even further. thrashing sets in, and
CPU utilization drops sharply. degree of point,
At this to increase isCPU utilization and stop thrashing. we must
multiprogramming
decrease the degree of
multiprogramm1ng.
Locality of Reference
Locanty ot Reference refers to the tendency of the computer program to access instructions whose
addresses are near one another. The property of locality of 1eference is mainly shown by loops and
subroutine calls in a program.
"In case of loops in program control procegsing unit repeatedly refers to the set of instructions that
constitutethe loop.
" In case of subroutine calls, every time the set of instructions are fetched from memory.
" References to data items also get localized that means same data item is referenced again and
again.
Temporal Locality- Temporal locality means current data or instruction that is being fetched may be
needed soon. So we should store that data or instruction in the cache memory so that we can avoid again
searching in main memory for the same data.
Spatial Locality - Spatial locality means instruction or data near to the current memory location that is
being fetched, may be needed soon inthe near future. This is slihtly different from the temporal locality.
Here we are talking about nearly located memory locations while in temporal locality we were talking
about the actual memory location that was being fetched.
Bare Machine
In computer science, bare machine refers to a computer executing instructions directly on logic hardware
without an intervening operating system. prior to the development of operating systems, sequential
instructions were executed on the computer hardware directly using machine language without any