<s>
A	O
journaling	B-Application
file	I-Application
system	I-Application
is	O
a	O
file	B-Application
system	I-Application
that	O
keeps	O
track	O
of	O
changes	O
not	O
yet	O
committed	O
to	O
the	O
file	B-Application
system	I-Application
's	O
main	O
part	O
by	O
recording	O
the	O
goal	O
of	O
such	O
changes	O
in	O
a	O
data	O
structure	O
known	O
as	O
a	O
"	O
journal	B-General_Concept
"	O
,	O
which	O
is	O
usually	O
a	O
circular	B-Data_Structure
log	I-Data_Structure
.	O
</s>
<s>
In	O
the	O
event	O
of	O
a	O
system	B-General_Concept
crash	I-General_Concept
or	O
power	O
failure	O
,	O
such	O
file	B-Application
systems	I-Application
can	O
be	O
brought	O
back	O
online	O
more	O
quickly	O
with	O
a	O
lower	O
likelihood	O
of	O
becoming	O
corrupted	O
.	O
</s>
<s>
Depending	O
on	O
the	O
actual	O
implementation	O
,	O
a	O
journaling	B-Application
file	I-Application
system	I-Application
may	O
only	O
keep	O
track	O
of	O
stored	O
metadata	O
,	O
resulting	O
in	O
improved	O
performance	O
at	O
the	O
expense	O
of	O
increased	O
possibility	O
for	O
data	O
corruption	O
.	O
</s>
<s>
Alternatively	O
,	O
a	O
journaling	B-Application
file	I-Application
system	I-Application
may	O
track	O
both	O
stored	O
data	O
and	O
related	O
metadata	O
,	O
while	O
some	O
implementations	O
allow	O
selectable	O
behavior	O
in	O
this	O
regard	O
.	O
</s>
<s>
In	O
1990	O
IBM	O
introduced	O
JFS	B-Application
in	O
AIX	B-Application
3.1	O
as	O
one	O
of	O
the	O
first	O
UNIX	O
commercial	O
filesystems	B-Application
that	O
implemented	O
journaling	O
.	O
</s>
<s>
The	O
next	O
year	O
the	O
idea	O
was	O
popularized	O
in	O
a	O
widely	O
cited	O
paper	O
on	O
log-structured	B-Application
file	I-Application
systems	I-Application
.	O
</s>
<s>
This	O
was	O
subsequently	O
implemented	O
in	O
Microsoft	O
's	O
Windows	B-Device
NT	I-Device
's	O
NTFS	B-Application
filesystem	B-Application
in	O
1993	O
,	O
in	O
Apple	O
's	O
HFS	B-Application
Plus	I-Application
filesystem	B-Application
in	O
1998	O
,	O
and	O
in	O
Linux	B-Application
's	O
ext3	B-Application
filesystem	I-Application
in	O
2001	O
.	O
</s>
<s>
Updating	O
file	B-Application
systems	I-Application
to	O
reflect	O
changes	O
to	O
files	O
and	O
directories	O
usually	O
requires	O
many	O
separate	O
write	O
operations	O
.	O
</s>
<s>
This	O
makes	O
it	O
possible	O
for	O
an	O
interruption	O
(	O
like	O
a	O
power	O
failure	O
or	O
system	B-General_Concept
crash	I-General_Concept
)	O
between	O
writes	O
to	O
leave	O
data	O
structures	O
in	O
an	O
invalid	O
intermediate	O
state	O
.	O
</s>
<s>
For	O
example	O
,	O
deleting	O
a	O
file	O
on	O
a	O
Unix	B-Operating_System
file	I-Operating_System
system	I-Operating_System
involves	O
three	O
steps	O
:	O
</s>
<s>
Releasing	O
the	O
inode	B-Application
to	O
the	O
pool	O
of	O
free	O
inodes	B-Application
.	O
</s>
<s>
If	O
a	O
crash	B-General_Concept
occurs	O
after	O
step	O
1	O
and	O
before	O
step	O
2	O
,	O
there	O
will	O
be	O
an	O
orphaned	O
inode	B-Application
and	O
hence	O
a	O
storage	B-Error_Name
leak	I-Error_Name
;	O
if	O
a	O
crash	B-General_Concept
occurs	O
between	O
steps	O
2	O
and	O
3	O
,	O
then	O
the	O
blocks	O
previously	O
used	O
by	O
the	O
file	O
cannot	O
be	O
used	O
for	O
new	O
files	O
,	O
effectively	O
decreasing	O
the	O
storage	O
capacity	O
of	O
the	O
file	B-Application
system	I-Application
.	O
</s>
<s>
If	O
step	O
3	O
preceded	O
step	O
1	O
,	O
a	O
crash	B-General_Concept
between	O
them	O
could	O
allow	O
the	O
file	O
's	O
blocks	O
to	O
be	O
reused	O
for	O
a	O
new	O
file	O
,	O
meaning	O
the	O
partially	O
deleted	O
file	O
would	O
contain	O
part	O
of	O
the	O
contents	O
of	O
another	O
file	O
,	O
and	O
modifications	O
to	O
either	O
file	O
would	O
show	O
up	O
in	O
both	O
.	O
</s>
<s>
On	O
the	O
other	O
hand	O
,	O
if	O
step	O
2	O
preceded	O
step	O
1	O
,	O
a	O
crash	B-General_Concept
between	O
them	O
would	O
cause	O
the	O
file	O
to	O
be	O
inaccessible	O
,	O
despite	O
appearing	O
to	O
exist	O
.	O
</s>
<s>
Detecting	O
and	O
recovering	O
from	O
such	O
inconsistencies	O
normally	O
requires	O
a	O
complete	O
walk	O
of	O
its	O
data	O
structures	O
,	O
for	O
example	O
by	O
a	O
tool	O
such	O
as	O
fsck	B-Device
(	O
the	O
file	B-Application
system	I-Application
checker	O
)	O
.	O
</s>
<s>
This	O
must	O
typically	O
be	O
done	O
before	O
the	O
file	B-Application
system	I-Application
is	O
next	O
mounted	O
for	O
read-write	O
access	O
.	O
</s>
<s>
If	O
the	O
file	B-Application
system	I-Application
is	O
large	O
and	O
if	O
there	O
is	O
relatively	O
little	O
I/O	O
bandwidth	O
,	O
this	O
can	O
take	O
a	O
long	O
time	O
and	O
result	O
in	O
longer	O
downtimes	O
if	O
it	O
blocks	O
the	O
rest	O
of	O
the	O
system	O
from	O
coming	O
back	O
online	O
.	O
</s>
<s>
To	O
prevent	O
this	O
,	O
a	O
journaled	B-Application
file	I-Application
system	I-Application
allocates	O
a	O
special	O
area	O
—	O
the	O
journal	B-General_Concept
—	O
in	O
which	O
it	O
records	O
the	O
changes	O
it	O
will	O
make	O
ahead	O
of	O
time	O
.	O
</s>
<s>
After	O
a	O
crash	B-General_Concept
,	O
recovery	O
simply	O
involves	O
reading	O
the	O
journal	B-General_Concept
from	O
the	O
file	B-Application
system	I-Application
and	O
replaying	O
changes	O
from	O
this	O
journal	B-General_Concept
until	O
the	O
file	B-Application
system	I-Application
is	O
consistent	O
again	O
.	O
</s>
<s>
The	O
changes	O
are	O
thus	O
said	O
to	O
be	O
atomic	B-General_Concept
(	O
not	O
divisible	O
)	O
in	O
that	O
they	O
either	O
succeed	O
(	O
succeeded	O
originally	O
or	O
are	O
replayed	O
completely	O
during	O
recovery	O
)	O
,	O
or	O
are	O
not	O
replayed	O
at	O
all	O
(	O
are	O
skipped	O
because	O
they	O
had	O
not	O
yet	O
been	O
completely	O
written	O
to	O
the	O
journal	B-General_Concept
before	O
the	O
crash	B-General_Concept
occurred	O
)	O
.	O
</s>
<s>
Some	O
file	B-Application
systems	I-Application
allow	O
the	O
journal	B-General_Concept
to	O
grow	O
,	O
shrink	O
and	O
be	O
re-allocated	O
just	O
as	O
a	O
regular	O
file	O
,	O
while	O
others	O
put	O
the	O
journal	B-General_Concept
in	O
a	O
contiguous	O
area	O
or	O
a	O
hidden	O
file	O
that	O
is	O
guaranteed	O
not	O
to	O
move	O
or	O
change	O
size	O
while	O
the	O
file	B-Application
system	I-Application
is	O
mounted	O
.	O
</s>
<s>
Some	O
file	B-Application
systems	I-Application
may	O
also	O
allow	O
external	O
journals	O
on	O
a	O
separate	O
device	O
,	O
such	O
as	O
a	O
solid-state	B-Device
drive	I-Device
or	O
battery-backed	O
non-volatile	O
RAM	O
.	O
</s>
<s>
Changes	O
to	O
the	O
journal	B-General_Concept
may	O
themselves	O
be	O
journaled	O
for	O
additional	O
redundancy	O
,	O
or	O
the	O
journal	B-General_Concept
may	O
be	O
distributed	O
across	O
multiple	O
physical	O
volumes	O
to	O
protect	O
against	O
device	O
failure	O
.	O
</s>
<s>
The	O
internal	O
format	O
of	O
the	O
journal	B-General_Concept
must	O
guard	O
against	O
crashes	B-General_Concept
while	O
the	O
journal	B-General_Concept
itself	O
is	O
being	O
written	O
to	O
.	O
</s>
<s>
Many	O
journal	B-General_Concept
implementations	O
(	O
such	O
as	O
the	O
JBD2	O
layer	O
in	O
ext4	B-Application
)	O
bracket	O
every	O
change	O
logged	O
with	O
a	O
checksum	O
,	O
on	O
the	O
understanding	O
that	O
a	O
crash	B-General_Concept
would	O
leave	O
a	O
partially	O
written	O
change	O
with	O
a	O
missing	O
(	O
or	O
mismatched	O
)	O
checksum	O
that	O
can	O
simply	O
be	O
ignored	O
when	O
replaying	O
the	O
journal	B-General_Concept
at	O
next	O
remount	O
.	O
</s>
<s>
A	O
physical	O
journal	B-General_Concept
logs	O
an	O
advance	O
copy	O
of	O
every	O
block	O
that	O
will	O
later	O
be	O
written	O
to	O
the	O
main	O
file	B-Application
system	I-Application
.	O
</s>
<s>
If	O
there	O
is	O
a	O
crash	B-General_Concept
when	O
the	O
main	O
file	B-Application
system	I-Application
is	O
being	O
written	O
to	O
,	O
the	O
write	O
can	O
simply	O
be	O
replayed	O
to	O
completion	O
when	O
the	O
file	B-Application
system	I-Application
is	O
next	O
mounted	O
.	O
</s>
<s>
If	O
there	O
is	O
a	O
crash	B-General_Concept
when	O
the	O
write	O
is	O
being	O
logged	O
to	O
the	O
journal	B-General_Concept
,	O
the	O
partial	O
write	O
will	O
have	O
a	O
missing	O
or	O
mismatched	O
checksum	O
and	O
can	O
be	O
ignored	O
at	O
next	O
mount	O
.	O
</s>
<s>
A	O
logical	O
journal	B-General_Concept
stores	O
only	O
changes	O
to	O
file	O
metadata	O
in	O
the	O
journal	B-General_Concept
,	O
and	O
trades	O
fault	O
tolerance	O
for	O
substantially	O
better	O
write	O
performance	O
.	O
</s>
<s>
A	O
file	B-Application
system	I-Application
with	O
a	O
logical	O
journal	B-General_Concept
still	O
recovers	O
quickly	O
after	O
a	O
crash	B-General_Concept
,	O
but	O
may	O
allow	O
unjournaled	O
file	O
data	O
and	O
journaled	O
metadata	O
to	O
fall	O
out	O
of	O
sync	O
with	O
each	O
other	O
,	O
causing	O
data	O
corruption	O
.	O
</s>
<s>
The	O
file	O
's	O
inode	B-Application
,	O
to	O
note	O
in	O
the	O
file	O
's	O
metadata	O
that	O
its	O
size	O
has	O
increased	O
.	O
</s>
<s>
In	O
a	O
metadata-only	O
journal	B-General_Concept
,	O
step	O
3	O
would	O
not	O
be	O
logged	O
.	O
</s>
<s>
The	O
write	O
cache	O
in	O
most	O
operating	O
systems	O
sorts	O
its	O
writes	O
(	O
using	O
the	O
elevator	B-Algorithm
algorithm	I-Algorithm
or	O
some	O
similar	O
scheme	O
)	O
to	O
maximize	O
throughput	O
.	O
</s>
<s>
To	O
avoid	O
an	O
out-of-order	O
write	O
hazard	O
with	O
a	O
metadata-only	O
journal	B-General_Concept
,	O
writes	O
for	O
file	O
data	O
must	O
be	O
sorted	O
so	O
that	O
they	O
are	O
committed	O
to	O
storage	O
before	O
their	O
associated	O
metadata	O
.	O
</s>
<s>
This	O
can	O
be	O
tricky	O
to	O
implement	O
because	O
it	O
requires	O
coordination	O
within	O
the	O
operating	O
system	O
kernel	O
between	O
the	O
file	B-Application
system	I-Application
driver	O
and	O
write	O
cache	O
.	O
</s>
<s>
Some	O
journaling	B-Application
file	I-Application
systems	I-Application
conservatively	O
assume	O
such	O
write-reordering	O
always	O
takes	O
place	O
,	O
and	O
sacrifice	O
performance	O
for	O
correctness	O
by	O
forcing	O
the	O
device	O
to	O
flush	O
its	O
cache	O
at	O
certain	O
points	O
in	O
the	O
journal	B-General_Concept
(	O
called	O
barriers	O
in	O
ext3	B-Application
and	O
ext4	B-Application
)	O
.	O
</s>
<s>
Some	O
UFS	B-Operating_System
implementations	O
avoid	O
journaling	O
and	O
instead	O
implement	O
soft	B-Application
updates	I-Application
:	O
they	O
order	O
their	O
writes	O
in	O
such	O
a	O
way	O
that	O
the	O
on-disk	O
file	O
system	O
is	O
never	O
inconsistent	O
,	O
or	O
that	O
the	O
only	O
inconsistency	O
that	O
can	O
be	O
created	O
in	O
the	O
event	O
of	O
a	O
crash	B-General_Concept
is	O
a	O
storage	B-Error_Name
leak	I-Error_Name
.	O
</s>
<s>
To	O
recover	O
from	O
these	O
leaks	O
,	O
the	O
free	O
space	O
map	O
is	O
reconciled	O
against	O
a	O
full	O
walk	O
of	O
the	O
file	B-Application
system	I-Application
at	O
next	O
mount	O
.	O
</s>
<s>
This	O
garbage	B-General_Concept
collection	I-General_Concept
is	O
usually	O
done	O
in	O
the	O
background	O
.	O
</s>
<s>
In	O
log-structured	B-Application
file	I-Application
systems	I-Application
,	O
the	O
write-twice	O
penalty	O
does	O
not	O
apply	O
because	O
the	O
journal	B-General_Concept
itself	O
is	O
the	O
file	B-Application
system	I-Application
:	O
it	O
occupies	O
the	O
entire	O
storage	O
device	O
and	O
is	O
structured	O
so	O
that	O
it	O
can	O
be	O
traversed	O
as	O
would	O
a	O
normal	O
file	B-Application
system	I-Application
.	O
</s>
<s>
Full	O
copy-on-write	B-Language
file	B-Application
systems	I-Application
(	O
such	O
as	O
ZFS	B-Application
and	O
Btrfs	B-Operating_System
)	O
avoid	O
in-place	O
changes	O
to	O
file	O
data	O
by	O
writing	O
out	O
the	O
data	O
in	O
newly	O
allocated	O
blocks	O
,	O
followed	O
by	O
updated	O
metadata	O
that	O
would	O
point	O
to	O
the	O
new	O
data	O
and	O
disown	O
the	O
old	O
,	O
followed	O
by	O
metadata	O
pointing	O
to	O
that	O
,	O
and	O
so	O
on	O
up	O
to	O
the	O
superblock	O
,	O
or	O
the	O
root	O
of	O
the	O
file	B-Application
system	I-Application
hierarchy	O
.	O
</s>
<s>
This	O
has	O
the	O
same	O
correctness-preserving	O
properties	O
as	O
a	O
journal	B-General_Concept
,	O
without	O
the	O
write-twice	O
overhead	O
.	O
</s>
