
Originally Posted by
DBelton
yes, you set the noatime in the options in fstab.
like so:
LABEL=Drive\040K /media/Drive_K ext4 defaults,noatime 0 0
However, I have heard of some having problems trying to set data=writeback in /etc/fstab if it's not the default for the drive. It seems that on boot, the filesystem gets mounted read only, then it's remounted read/write. I've heard of some problem with it not being about to change that option on a remount. It may be fixed now, though.
You will probably want to set the journalling options as stevea has shown above.
Edit: I should have said that the problem above would only occur if you were trying to set journalling options on your / (root) filesystem since it is the only one that gets mounted read only at boot time and hence the only one that would try and be remounted read/write
The root file system "/" is initially mounted "ro" and then remounted according to fstab; has been for many many years. This does not preclude using any of the options shown. I think there is some confusion on this complex issue. The journal mode of an ext3/4 rootfs cannot be changed after the mount. See the "rootflags=data=writeback" description in post #1.
The ext3/ext4 journal allows the file system to be repaired readily in case of a crash or unexpected power loss. ext3 and ext4 file systems can be created without any journal or modified to not have a journal as described in post 1. These can also be mounted with journalling disabled using the "noload" option, which might be the most flexible approach.
Obviously without journalling there are fewer disk writes. The ext3/4 file system mount takes several journal options including a "data=writeback" option which allows for optimal throughput, unordered journal writes, but recent writes may be lost, though FS integrity preserved.
If you wish to keep the journal, and wish to have optimal throughput, and can accept losing some of the last writes in case of a crash, then then the "data=writeback" is a reasonable choice. Otherwise the default "data=ordered" does a better job preserving late writes after a crash.
The decision to use avoid journalling is sadly an important means of reducing writes, but also the journal creates a very important means of recovering from crashes. For modern disks and the modern Linux kernel thankfully the need for a fsck is quite rare, but without a journal the result can be costly and could result in a complete loss of the file system.
DO NOT run without a journal until you clearly understand the potential loss of the entire FS and have a good practical plan for that eventuality.

Originally Posted by
jpollard
5 C/ Get rid of /tmp
No complaints over the basics.
But I've never seen the X server write short files to /tmp other than the
creation (one time only) of the directory .X11-unix, .X0-lock.
These (and other .X?-lock) files are created only if needed, and if they
already exist, they are not created again. The files in /tmp/.X11-unix
are domain socket references only (no data). the files /tmp/.X?lock
are used for locking references to the socket files. Again, no data.
JP you are correct. X is writing regularly to the AF_LOCAL socket handle at /tmp/.X11-unix/X* but this does not cause on-disk changes, so my statement above is incorrect. What X does is create and modify inode entries in tmpfs (/dev/shm) and often at a high rate. Fortunately tmpfs is also a memory based file system to is avoids wearing the SSD drive.
One can easily see all the block writes on a system using this command (as root):
echo 1 > /proc/sys/vm/block_dump
and then looking through the "dmesg" command output. [[This mechanism creates a large dmesg file in a hurry, so it should be turned off with "echo 0 > ..." after a few minutes.]]
We can regularly see patterns like ....
Code:
[105484.780246] X(1618): dirtied inode 1453894 (?) on tmpfs
[105484.796435] X(1618): dirtied inode 1453907 (?) on tmpfs
[105484.808977] X(1618): dirtied inode 1453912 (?) on tmpfs
[105487.770635] X(1618): dirtied inode 1453944 (?) on tmpfs
[105488.213089] X(1618): dirtied inode 1453946 (?) on tmpfs
[105488.213250] X(1618): dirtied inode 1453945 (?) on tmpfs
[105488.213861] X(1618): dirtied inode 1453949 (?) on tmpfs
[105488.213898] X(1618): dirtied inode 1453952 (?) on tmpfs
[105488.214032] X(1618): dirtied inode 1453955 (?) on tmpfs
[105488.214109] X(1618): dirtied inode 1453959 (?) on tmpfs
[105488.214163] X(1618): dirtied inode 1453958 (?) on tmpfs
[105488.214317] X(1618): dirtied inode 1453964 (?) on tmpfs
[105488.215022] X(1618): dirtied inode 1453967 (?) on tmpfs
[105488.215216] X(1618): dirtied inode 1453970 (?) on tmpfs
[105488.218509] X(1618): dirtied inode 1454002 (?) on tmpfs
[105488.238657] X(1618): dirtied inode 1454012 (?) on tmpfs
[105488.239632] X(1618): dirtied inode 1454017 (?) on tmpfs
[105488.240157] X(1618): dirtied inode 1454022 (?) on tmpfs
18 inodes modified in a few seconds, but on tmpfs. A dirtied inode is not automatically a disk write, but the recently revised kernel flush daemons circumvent a lot of "lazy update" policies that were possible in the past.
Sadly we still see long streams of firefox I/O even after the changes in post#1.
Code:
[105063.153633] firefox(2399): WRITE block 15548872 on sda3
[105063.153654] firefox(2399): WRITE block 15548880 on sda3
[105063.153825] firefox(2399): WRITE block 8389248 on sda3
[105063.153969] firefox(2399): WRITE block 15548872 on sda3
[105063.154132] firefox(2399): WRITE block 5556920 on sda3
[105063.154516] firefox(2399): WRITE block 15552672 on sda3
[105063.154527] firefox(2399): WRITE block 15552680 on sda3
[105063.154534] firefox(2399): WRITE block 15552688 on sda3
[105063.154647] firefox(2399): WRITE block 8389248 on sda3
[105063.154778] firefox(2399): WRITE block 15552672 on sda3
{~ 20 omitted)
Of course we want firefox to store recent history and new bookmarks to SSD, but it seems to be using disk beyond these.
Also the recently implemented changes to the kernel flush daemon cause frequent flushing of blocks to disk, so we see sequences like ...
Code:
[104361.279609] flush-8:0(1624): WRITE block 8 on sda3
[104361.279628] flush-8:0(1624): WRITE block 8388736 on sda3
[104361.279637] flush-8:0(1624): WRITE block 8389144 on sda3
[104361.279644] flush-8:0(1624): WRITE block 8389192 on sda3
[104361.279684] flush-8:0(1624): WRITE block 8389248 on sda3
[104361.279692] flush-8:0(1624): WRITE block 8389864 on sda3
[104361.279699] flush-8:0(1624): WRITE block 8391984 on sda3
[104361.279705] flush-8:0(1624): WRITE block 8455736 on sda3
[104361.279727] flush-8:0(1624): WRITE block 12583000 on sda3
[104361.279734] flush-8:0(1624): WRITE block 12583008 on sda3
at irregular intervals.
Still the steps indicated do cause a substantial reduction in disk writes.
The problem with /tmp is different than I had stated. There are a large number of files opened. For example, at this moment I have a fairly spartan gnome desktop running (firefox and two gnome-terminals) and yet ...
lsof | grep /tmp/ | wc -l
reports 135 files currently opened in /tmp. 109 of these are AF_LOCAL sockets handles for desktop gui apps and the other 26 regular files are for gnome-terminal, cupsd, and a handful of panel applets. Of course these files are created and deleted with the associated processes. The total space used by these is modest, even including the directory space used.
A more troubling use of /tmp is that browsers and similar apps write large temporary files to /tmp and writing these to SSD is undesirable.
Now moving /tmp to ramdisk is fine - but you better have enough
swap space somewhere (or lots of free memory) because you can get
into a deadlock/random application aborts because of of it. Web browsers
need to put work files somewhere (pdf files are nasty about that), and
a number of gnome/kde utilities/user daemons will put their workfiles
there too (though these are fairly small - on my system most of these
are 4 bytes long). It may be these files you are referring to.
To be clear, Linux has a tmpfs block device and also a ramdisk block device(see "man ram"). The example in post #1 uses the tmpfs block device to implement /tmp.
The tmpfs block device is more flexible than ramdisk with respect to memory use. tmpfs only uses the amount of DRAM needed (not a fixed allocation). tmpfs has a lot of maximum size options and defaults to half of DRAM size as the maximum. In case memory pressure exists, then tmpfs pages can be moved to swap. Any swap use is undesirable, but if moving some dowloaded pdf file from /tmp to swap means the system can continue that's a reasonable compromise, and it certainly creates fewer SSD writes then downloading to SSD based /tmp.
JP notes a glaring flaw in modern /tmp usage. Most browsers will drop .pdf files, image files, spreadsheets, .doc files and so on into /tmp for temporary usage, for example to bring up a helper application or plugin. So it's not uncommon to have a few hundred MB of "cruft" files in /tmp. Since disk based /tmp is never cleaned these large downloaded files occupy disk space for months or even years.
Mitigating the problem of using tmpfs for /tmp, and it becoming filled are:
A tmpfs based /tmp is cleaned on every shutdown so the "cruft" can't accumulate longer than "uptime".
Any reasonable person investing in a (currently expensive) SSD drive should already have addressed DRAM limitations of their system.
I don't think that filling /tmp on tmpfs is a more likely issue than filling /tmp on disk for anyone who has 1GB or more and can avoid regular use of swap.