Welcome back, and our next port of call is going to be mount options.
We can certainly improve performance with mount options,
especially if we are just using the defaults.
And so much we have got used to, in recent years especially,
of just using the defaults as our mount options.
Very often, those defaults are designed to work well,
but, in general, we're going to be able to disable some features,
and that's likely to give us better performance,
but also we're likely to lose a little bit of data protection.
For example, we can disable the journal on an ext4 file system,
and we can go through and change the sync speed,
how often we flush our data to disk after write.
But that's going to increase our performance,
but increases the likelihood or the possibility of data loss.
As we go through and take a look at our mount options in ext4,
by remounting our file systems with barrier=0,
really disabling our journal,
the journal keeps the transaction log of open files that are
being written to so in case our system crashes,
it's very easily they can go through and look at the files that were
open and make sure that they are in good condition.
With a commit =0, that defaults to 5 seconds, and it's our flush interval,
how often we sync data from memory through to disk.
Increasing it to 60 seconds, then again,
is going to improve our write performance,
but the difficulty is that if we have a failure of our system,
then chances are we might be able to lose a little bit more data.
But they're not too dangerous to implement, but they are considerations.
We can always go back and set it to the default, so barrier=1 and commit=5.
If we want help on our mount options, we can go through man 5 and ext4.
Remember, man 5, the section 5, is looking at configuration options.
So we're going to dive out through to our command line
now, and I emphasize the term we,
because I'd really love you to be able to follow through with me.
We're going to be investigating the mount options on our Ubuntu 20.04
system and setting mount options in ext4. So come on,
let's find that command line.
And here we are on the glorious command line of our Ubuntu 20.04 system.
If we go back and take a look at our mount command, looking for the type
of ext4. Now we saw this before, but we probably didn't pay too much
attention to it. As I go through and hit the Enter key, we can not only
see the device, where it's mounted to, the type of file system, but we can
also see the mount options. And these are probably coming from the fstab
file and default.
If we want to change some of our mount options very often, we are able to start
tuning our performance, but generally, when we're tuning performance, we have
data security that is probably losing a little bit.
So as we go through and take a look at maybe sudo and mount ‑o, for our
options, and we can have, first of all, the remount option as it's currently
mounted, and we can have barrier=0 to turn it off.
We can also put barrier=nobarrier, and that's an older ext3 system that
can still be used. And we can go through and set on then our commit, and
we can have this =60. With this, we're looking at how often we write our
data from the cache through to disk.
So when we're writing to data, we're defaulting to write every 5
seconds. By changing it to 60 seconds, hopefully, we have larger
amounts of data that we can be writing, but less often. We need to do
this for our root file system, so just space and / at the end and
then hit the big Enter key.
We go back up and look at our mount command,
we can see now the additional options that have been configured. Now
the reality is we're probably not doing enough writes to be able to
really see any of the benefits here.
The barrier=0, or the no barrier option as we're reading it, is really
disabling our transaction tracking system. With that, we're really writing
to our transaction logs in the file system. They then end up writing the
data to disk, so we're doubling up on the data that is being written, but
that gives me protection. In the case of a file system crash, then we've got
our transaction logs that are open, and we know then which files were open
when the file system crashed. By increasing our commit time out, then again,
if we have a file system crash, there's likely that we might have more data in
cache that is lost than was actually flushed through to disk.
So it's a consideration. Of course, if we want to go back and set these
back to the default, then we can go through and set our commit time to
5, and then we can have our barrier=1.
Now when we go through and take a look, we can see that we're back
to just the two original options, rw, obviously read/write, the
relatime was introduced in the 2.6 Kernel.
The idea being rather than updating our last access time when the
file was last read, with the relative access time, we only update
the access time if it's 24‑hours old or if the access time is older
than the current ctime or mtime.
So it's just making sure that we need to do less writes to our disk.
If we want to look more at some of these options, we can go into man 5 ext4.
Remember, the man page section 5 is looking at configuration files,
but it allows us to see the mount options.
We first see all of the features, such as the extent that we looked at.
But then we get through to our MOUNT OPTIONS, and we see mount
options that have come through from ext2 and ext3 before
getting into our ext4 mount options.
But this gives you an idea that the documentation is there for our benefit,
and we can read a little bit more about what options are available and how we can improve our system.