<s>
In	O
computer	B-General_Concept
science	I-General_Concept
,	O
thrashing	B-General_Concept
occurs	O
when	O
a	O
computer	O
's	O
virtual	B-Architecture
memory	I-Architecture
resources	B-General_Concept
are	O
overused	O
,	O
leading	O
to	O
a	O
constant	O
state	O
of	O
paging	B-Architecture
and	O
page	B-General_Concept
faults	I-General_Concept
,	O
inhibiting	O
most	O
application-level	O
processing	O
.	O
</s>
<s>
The	O
situation	O
can	O
continue	O
indefinitely	O
until	O
either	O
the	O
user	O
closes	O
some	O
running	O
applications	O
or	O
the	O
active	O
processes	B-Operating_System
free	O
up	O
additional	O
virtual	B-Architecture
memory	I-Architecture
resources	B-General_Concept
.	O
</s>
<s>
After	O
completing	O
initialization	O
,	O
most	O
programs	O
operate	O
on	O
a	O
small	O
number	O
of	O
code	B-Language
and	O
data	B-General_Concept
pages	O
compared	O
to	O
the	O
total	O
memory	O
the	O
program	O
requires	O
.	O
</s>
<s>
The	O
pages	O
most	O
frequently	O
accessed	O
are	O
called	O
the	O
working	B-General_Concept
set	I-General_Concept
.	O
</s>
<s>
When	O
the	O
working	B-General_Concept
set	I-General_Concept
is	O
a	O
small	O
percentage	O
of	O
the	O
system	O
's	O
total	O
number	O
of	O
pages	O
,	O
virtual	B-Architecture
memory	I-Architecture
systems	O
work	O
most	O
efficiently	O
and	O
an	O
insignificant	O
amount	O
of	O
computing	O
is	O
spent	O
resolving	O
page	B-General_Concept
faults	I-General_Concept
.	O
</s>
<s>
As	O
the	O
working	B-General_Concept
set	I-General_Concept
grows	O
,	O
resolving	O
page	B-General_Concept
faults	I-General_Concept
remains	O
manageable	O
until	O
the	O
growth	O
reaches	O
a	O
critical	O
point	O
.	O
</s>
<s>
This	O
condition	O
is	O
referred	O
to	O
as	O
thrashing	B-General_Concept
.	O
</s>
<s>
Thrashing	B-General_Concept
occurs	O
on	O
a	O
program	O
that	O
works	O
with	O
huge	O
data	B-General_Concept
structures	O
,	O
as	O
its	O
large	O
working	B-General_Concept
set	I-General_Concept
causes	O
continual	O
page	B-General_Concept
faults	I-General_Concept
that	O
drastically	O
slow	O
down	O
the	O
system	O
.	O
</s>
<s>
Satisfying	O
page	B-General_Concept
faults	I-General_Concept
may	O
require	O
freeing	O
pages	O
that	O
will	O
soon	O
have	O
to	O
be	O
re-read	O
from	O
disk	O
.	O
</s>
<s>
The	O
term	O
is	O
also	O
used	O
for	O
various	O
similar	O
phenomena	O
,	O
particularly	O
movement	O
between	O
other	O
levels	O
of	O
the	O
memory	B-General_Concept
hierarchy	I-General_Concept
,	O
where	O
a	O
process	O
progresses	O
slowly	O
because	O
significant	O
time	O
is	O
being	O
spent	O
acquiring	O
resources	B-General_Concept
.	O
</s>
<s>
"	O
Thrashing	B-General_Concept
"	O
is	O
also	O
used	O
in	O
contexts	O
other	O
than	O
virtual	B-Architecture
memory	I-Architecture
systems	O
;	O
for	O
example	O
,	O
to	O
describe	O
cache	B-General_Concept
issues	O
in	O
computing	O
or	O
silly	B-Protocol
window	I-Protocol
syndrome	I-Protocol
in	O
networking	O
.	O
</s>
<s>
Virtual	B-Architecture
memory	I-Architecture
works	O
by	O
treating	O
a	O
portion	O
of	O
secondary	O
storage	O
such	O
as	O
a	O
computer	O
hard	B-Device
disk	I-Device
as	O
an	O
additional	O
layer	O
of	O
the	O
cache	B-General_Concept
hierarchy	I-General_Concept
.	O
</s>
<s>
Virtual	B-Architecture
memory	I-Architecture
is	O
notable	O
for	O
allowing	O
processes	B-Operating_System
to	O
use	O
more	O
memory	O
than	O
is	O
physically	O
present	O
in	O
main	B-Architecture
memory	I-Architecture
and	O
for	O
enabling	O
virtual	B-Architecture
machines	I-Architecture
.	O
</s>
<s>
Operating	B-General_Concept
systems	I-General_Concept
supporting	O
virtual	B-Architecture
memory	I-Architecture
assign	O
processes	B-Operating_System
a	O
virtual	B-General_Concept
address	I-General_Concept
space	I-General_Concept
and	O
each	O
process	O
refers	O
to	O
addresses	B-General_Concept
in	O
its	O
execution	O
context	O
by	O
a	O
so-called	O
virtual	B-General_Concept
address	I-General_Concept
.	O
</s>
<s>
In	O
order	O
to	O
access	O
data	B-General_Concept
such	O
as	O
code	B-Language
or	O
variables	O
at	O
that	O
address	O
,	O
the	O
process	O
must	O
translate	O
the	O
address	O
to	O
a	O
physical	B-General_Concept
address	I-General_Concept
in	O
a	O
process	O
known	O
as	O
virtual	B-Architecture
address	I-Architecture
translation	I-Architecture
.	O
</s>
<s>
In	O
effect	O
,	O
physical	O
main	B-Architecture
memory	I-Architecture
becomes	O
a	O
cache	B-General_Concept
for	O
virtual	B-Architecture
memory	I-Architecture
which	O
is	O
in	O
general	O
stored	O
on	O
disk	O
in	O
memory	B-General_Concept
pages	I-General_Concept
.	O
</s>
<s>
Programs	O
are	O
allocated	O
a	O
certain	O
number	O
of	O
pages	O
as	O
needed	O
by	O
the	O
operating	B-General_Concept
system	I-General_Concept
.	O
</s>
<s>
Active	O
memory	B-General_Concept
pages	I-General_Concept
exist	O
in	O
both	O
RAM	B-Architecture
and	O
on	O
disk	O
.	O
</s>
<s>
Inactive	O
pages	O
are	O
removed	B-General_Concept
from	I-General_Concept
the	I-General_Concept
cache	I-General_Concept
and	O
written	O
to	O
disk	O
when	O
the	O
main	B-Architecture
memory	I-Architecture
becomes	O
full	O
.	O
</s>
<s>
If	O
processes	B-Operating_System
are	O
utilizing	O
all	O
main	B-Architecture
memory	I-Architecture
and	O
need	O
additional	O
memory	B-General_Concept
pages	I-General_Concept
,	O
a	O
cascade	O
of	O
severe	O
cache	B-General_Concept
misses	O
known	O
as	O
page	B-General_Concept
faults	I-General_Concept
will	O
occur	O
,	O
often	O
leading	O
to	O
a	O
noticeable	O
lag	O
in	O
operating	B-General_Concept
system	I-General_Concept
responsiveness	B-Application
.	O
</s>
<s>
This	O
process	O
together	O
with	O
the	O
futile	O
,	O
repetitive	O
page	B-Architecture
swapping	I-Architecture
that	O
occurs	O
are	O
known	O
as	O
"	O
thrashing	B-General_Concept
"	O
.	O
</s>
<s>
In	O
modern	O
computers	O
,	O
thrashing	B-General_Concept
may	O
occur	O
in	O
the	O
paging	B-Architecture
system	O
(	O
if	O
there	O
is	O
not	O
sufficient	O
physical	O
memory	O
or	O
the	O
disk	O
access	O
time	O
is	O
overly	O
long	O
)	O
,	O
or	O
in	O
the	O
I/O	O
communications	O
subsystem	O
(	O
especially	O
in	O
conflicts	B-Architecture
over	I-Architecture
internal	I-Architecture
bus	I-Architecture
access	I-Architecture
)	O
,	O
etc	O
.	O
</s>
<s>
Depending	O
on	O
the	O
configuration	O
and	O
algorithms	O
involved	O
,	O
the	O
throughput	O
and	O
latency	O
of	O
a	O
system	O
may	O
degrade	O
by	O
multiple	O
orders	B-Device
of	I-Device
magnitude	I-Device
.	O
</s>
<s>
Thrashing	B-General_Concept
is	O
a	O
state	O
in	O
which	O
the	O
CPU	O
performs	O
'	O
productive	O
 '	O
work	O
less	O
,	O
and	O
'	O
swapping	O
 '	O
more	O
.	O
</s>
<s>
The	O
overall	O
memory	O
access	O
time	O
may	O
increase	O
since	O
the	O
higher	O
level	O
memory	O
is	O
only	O
as	O
fast	O
as	O
the	O
next	O
lower	O
level	O
in	O
the	O
memory	B-General_Concept
hierarchy	I-General_Concept
.	O
</s>
<s>
Thrashing	B-General_Concept
occurs	O
when	O
there	O
are	O
too	O
many	O
pages	O
in	O
memory	O
,	O
and	O
each	O
page	O
refers	O
to	O
another	O
page	O
.	O
</s>
<s>
The	O
real	O
memory	O
shortens	O
in	O
capacity	O
to	O
have	O
all	O
the	O
pages	O
in	O
it	O
,	O
so	O
it	O
uses	O
'	O
virtual	B-Architecture
memory	I-Architecture
 '	O
.	O
</s>
<s>
When	O
each	O
page	B-Architecture
in	I-Architecture
execution	O
demands	O
that	O
page	O
that	O
is	O
not	O
currently	O
in	O
real	O
memory	O
(	O
RAM	B-Architecture
)	O
it	O
places	O
some	O
pages	O
on	O
virtual	B-Architecture
memory	I-Architecture
and	O
adjusts	O
the	O
required	O
page	O
on	O
RAM	B-Architecture
.	O
</s>
<s>
If	O
the	O
CPU	O
is	O
too	O
busy	O
in	O
doing	O
this	O
task	O
,	O
thrashing	B-General_Concept
occurs	O
.	O
</s>
<s>
In	O
virtual	B-Architecture
memory	I-Architecture
systems	O
,	O
thrashing	B-General_Concept
may	O
be	O
caused	O
by	O
programs	O
or	O
workloads	O
that	O
present	O
insufficient	O
locality	B-General_Concept
of	I-General_Concept
reference	I-General_Concept
:	O
if	O
the	O
working	B-General_Concept
set	I-General_Concept
of	O
a	O
program	O
or	O
a	O
workload	O
cannot	O
be	O
effectively	O
held	O
within	O
physical	O
memory	O
,	O
then	O
constant	O
data	B-General_Concept
swapping	O
,	O
i.e.	O
,	O
thrashing	B-General_Concept
,	O
may	O
occur	O
.	O
</s>
<s>
The	O
term	O
was	O
first	O
used	O
during	O
the	O
tape	O
operating	B-General_Concept
system	I-General_Concept
days	O
to	O
describe	O
the	O
sound	O
the	O
tapes	O
made	O
when	O
data	B-General_Concept
was	O
being	O
rapidly	O
written	O
to	O
and	O
read	O
.	O
</s>
<s>
A	O
worst-case	O
scenario	O
of	O
this	O
sort	O
on	O
the	O
IBM	B-Device
System/370	I-Device
series	O
mainframe	B-Architecture
computer	I-Architecture
could	O
be	O
an	O
execute	B-General_Concept
instruction	I-General_Concept
crossing	O
a	O
page	O
boundary	O
that	O
points	O
to	O
a	O
move	O
instruction	O
itself	O
also	O
crossing	O
a	O
page	O
boundary	O
,	O
itself	O
pointing	O
to	O
a	O
source	O
and	O
a	O
target	O
that	O
each	O
cross	O
page	O
boundaries	O
.	O
</s>
<s>
If	O
any	O
one	O
of	O
the	O
eight	O
pages	O
ca	O
n't	O
be	O
swapped	B-Architecture
in	I-Architecture
(	O
for	O
example	O
to	O
make	O
room	O
for	O
any	O
of	O
the	O
other	O
pages	O
)	O
,	O
the	O
instruction	O
will	O
fault	O
,	O
and	O
every	O
attempt	O
to	O
restart	O
it	O
will	O
fail	O
until	O
all	O
eight	O
pages	O
can	O
be	O
swapped	B-Architecture
in	I-Architecture
.	O
</s>
<s>
A	O
system	O
thrashing	B-General_Concept
is	O
often	O
a	O
result	O
of	O
a	O
sudden	O
spike	O
in	O
page	O
demanding	O
from	O
a	O
small	O
number	O
of	O
running	O
programs	O
.	O
</s>
<s>
Swap-token	O
is	O
a	O
lightweight	O
and	O
dynamic	O
thrashing	B-General_Concept
protection	O
mechanism	O
.	O
</s>
<s>
The	O
basic	O
idea	O
is	O
to	O
set	O
a	O
token	O
in	O
the	O
system	O
,	O
which	O
is	O
randomly	O
given	O
to	O
a	O
process	O
that	O
has	O
page	B-General_Concept
faults	I-General_Concept
when	O
thrashing	B-General_Concept
happens	O
.	O
</s>
<s>
The	O
process	O
that	O
has	O
the	O
token	O
is	O
given	O
a	O
privilege	O
to	O
allocate	O
more	O
physical	O
memory	B-General_Concept
pages	I-General_Concept
to	O
build	O
its	O
working	B-General_Concept
set	I-General_Concept
,	O
which	O
is	O
expected	O
to	O
quickly	O
finish	O
its	O
execution	O
and	O
to	O
release	O
the	O
memory	B-General_Concept
pages	I-General_Concept
to	O
other	O
processes	B-Operating_System
.	O
</s>
<s>
Thrashing	B-General_Concept
is	O
best	O
known	O
in	O
the	O
context	O
of	O
memory	O
and	O
storage	O
,	O
but	O
analogous	O
phenomena	O
occur	O
for	O
other	O
resources	B-General_Concept
,	O
including	O
:	O
</s>
<s>
Where	O
main	B-Architecture
memory	I-Architecture
is	O
accessed	O
in	O
a	O
pattern	O
that	O
leads	O
to	O
multiple	O
main	B-Architecture
memory	I-Architecture
locations	O
competing	O
for	O
the	O
same	O
cache	B-General_Concept
lines	I-General_Concept
,	O
resulting	O
in	O
excessive	O
cache	B-General_Concept
misses	O
.	O
</s>
<s>
This	O
is	O
most	O
problematic	O
for	O
caches	B-General_Concept
that	O
have	O
low	O
associativity	O
.	O
</s>
<s>
Where	O
the	O
translation	B-Architecture
lookaside	I-Architecture
buffer	I-Architecture
(	O
TLB	O
)	O
acting	O
as	O
a	O
cache	B-General_Concept
for	O
the	O
memory	B-General_Concept
management	I-General_Concept
unit	I-General_Concept
(	O
MMU	O
)	O
which	O
translates	O
virtual	O
addresses	B-General_Concept
to	O
physical	O
addresses	B-General_Concept
is	O
too	O
small	O
for	O
the	O
working	B-General_Concept
set	I-General_Concept
of	O
pages	O
.	O
</s>
<s>
TLB	O
thrashing	B-General_Concept
can	O
occur	O
even	O
if	O
instruction	O
cache	B-General_Concept
or	O
data	B-General_Concept
cache	B-General_Concept
thrashing	B-General_Concept
are	O
not	O
occurring	O
,	O
because	O
these	O
are	O
cached	O
in	O
different	O
sizes	O
.	O
</s>
<s>
Instructions	O
and	O
data	B-General_Concept
are	O
cached	O
in	O
small	O
blocks	O
(	O
cache	B-General_Concept
lines	I-General_Concept
)	O
,	O
not	O
entire	O
pages	O
,	O
but	O
address	O
lookup	O
is	O
done	O
at	O
the	O
page	O
level	O
.	O
</s>
<s>
Thus	O
even	O
if	O
the	O
code	B-Language
and	O
data	B-General_Concept
working	B-General_Concept
sets	I-General_Concept
fit	O
into	O
cache	B-General_Concept
,	O
if	O
the	O
working	B-General_Concept
sets	I-General_Concept
are	O
fragmented	B-Architecture
across	O
many	O
pages	O
,	O
the	O
virtual	B-General_Concept
address	I-General_Concept
working	B-General_Concept
set	I-General_Concept
may	O
not	O
fit	O
into	O
TLB	O
,	O
causing	O
TLB	O
thrashing	B-General_Concept
.	O
</s>
<s>
Frequent	O
garbage	B-General_Concept
collection	I-General_Concept
,	O
due	O
to	O
failure	O
to	O
allocate	O
memory	O
for	O
an	O
object	O
,	O
due	O
to	O
insufficient	O
free	O
memory	O
or	O
insufficient	O
contiguous	O
free	O
memory	O
due	O
to	O
memory	B-Architecture
fragmentation	I-Architecture
is	O
referred	O
to	O
as	O
heap	O
thrashing	B-General_Concept
.	O
</s>
<s>
A	O
similar	O
phenomenon	O
occurs	O
for	O
processes	B-Operating_System
:	O
when	O
the	O
process	O
working	B-General_Concept
set	I-General_Concept
cannot	O
be	O
coscheduled	B-Operating_System
–	O
so	O
not	O
all	O
interacting	O
processes	B-Operating_System
are	O
scheduled	O
to	O
run	O
at	O
the	O
same	O
time	O
–	O
they	O
experience	O
"	O
process	O
thrashing	B-General_Concept
"	O
due	O
to	O
being	O
repeatedly	O
scheduled	O
and	O
unscheduled	O
,	O
progressing	O
only	O
slowly	O
.	O
</s>
