1. Zapho

    Nice post – great info. One point though, be careful with tmpfs. By default, tmpfs allocates half of your RAM for the temporary file system. This block is then unavailable to the OS. In my case, I found that 4GB of my 8GB RAM was being used to hold a handful of temp files that collectively were no bigger than 10mb. Naturally, I was a bit annoyed!

    You should specify a limit in fstab as follows:

  2. agor

    Good point the one Zapho makes, another way to do that is to specify percentage.
    My system has 16G ram, so i decided to go close to 1.5-2G:

    • namhuy

      I set mine at 1G

  3. james

    Nice and concise. However one note. noatime includes nodiratime. So you don’t need to do #2 if you have #1 in place. Won’t hurt anything, just a note. Otherwise thanks

  4. ken

    no comment, but a question. if hibernation and suspend are disabled, why create a swap partition and limit “swapiness”? most seem to “get it”, but to me, a novice (have not run ubuntu at all), it seems like a lot of work when swap could be eliminated if
    enough ddr3 is installed. i am planning on 8gb of ddr3.
    please reply.

    • namhuy

      If you have enough RAM on your system, it’s safe to turn off swap completely. Don’t forget some programs like VM (virtual machines), video editors, LibreOffice uses lots of memory.

      You can turn off swap
      1. If you don’t run any RAM intensive programs
      2. Don’t use hibernation (save contents of RAM to swap partitions)

      Sometimes some bad programs *may* eat your RAM like crazy, swap partition is still like a safety net to prevent your system to crash (not likely to happen though).

      My laptop w/ 8 Gb RAM, I do run VMs sometimes with 2 Gb RAM each VMs, the system never use any swap space (I mount swap partition on RAM to prevent SSD wear/tear), so technically even I do have swap partition it’s on RAM not on my SSD. In your case depends on how you use your system, 8 Gb of RAM is safe to disable swap completely, if you want to.

      • ken

        thanks. i will use your optimization tips. let me just keep it simple and keep a small swap
        because the machine will be for editing photos, though not much else.
        how is swap mounted to ddr3? i assume you have no swap partition on the ssd?

        • namhuy

          I just checked my laptop. I do have swap parition on my SSD, but since I set vm.swappiness = 0, my system won’t write anything swap but use RAM space first. You can use swapon command to see if you have swap parition or not

          This is my swap parition
          Filename Type Size Used Priority
          /dev/sda5 partition 8179708 0 -1


          /dev/sda5: UUID=”ab83ccb7-53af-4ef7-aff5-9157ee85dc30″ TYPE=”swap”

          You can completely disable swap parition by add “#” sign in front of your swap parition in fstab file.

  5. Ejoo

    I used this line on ubuntu 12.04, and my system crashed. It has to be “size=50M” instead of “size=50mb”. Before rebooting, check out the new fstab with ‘sudo mount -a’, and look for errors. BUT nevertheless, great work here on this side.

    Though it’s good, to set the limit, I don’t think that tmpfs “allocates” all the size given by option. You can check this out with ‘df -h’ and then check your free ram. A good german :-/ article: http://wiki.ubuntuusers.de/SSD/Auslagerung

  6. isaac

    @Ejoo Many thanks for the note on the size needing to be “size=50M”

    Following the first commenter’s note also crashed my system (14.04 running Gnome Shell). For anyone else having this problem, here’s what got my system back up:

    1. Log into the terminal via safe mode
    2. Run the following command to be able to edit the /etc/fstab file: “mount -o remount /” (see this ask ubuntu discussion http://askubuntu.com/questions/197459/how-to-fix-sudo-unable-to-open-read-only-file-system)
    3. Change “50mb” to “50M”
    4. Reload (reloading may take a minute or two… be patient)

  7. Hi,
    interesting topic. Thanks for the infos.

    If you’re interested on using Linux on servers with huge partitions, consider rather using XFS than ext4. It performs better on large partitions, even better on large files (videodata), has no issue on RAID configs, has all the features you need, including TRIM support for SSD.

    And last but not least its invented by SGI ;).

    If you want to use XFS for intensive read/write work there are a lot of tweaks around for XFS, beginning from the creation of partitions to parameters on fstab.

    Creating proper optimized XFS partitions: http://www.mythtv.org/wiki/Optimizing_Performance or http://brian.lanierfamily.net/xfs-file-system-tweaks-for-performance/

    Great fstab parameters for XFS: http://everything2.com/title/Filesystem+performance+tweaking+with+XFS+on+Linux

    At the end you land on “noatime,nodiratime,logbufs=8,discard” for an SSD optimized XFS partition. Blazingly fast initialized, reliable & fast. Never forget that booting however can’t be done through XFS.

    So you need a 500mb /boot partition as extX. At least. Don’t know if this changed in the newer Kernels. Correct me if I’m wrong.

    Don’t forget to increase “blockdev” parameters in your rc.local file for SSD (Depending on you CPU)
    “blockdev –setra 32768 (or) 65536 /dev/sdX”

    (begin tuning with “8192” and measure write/read performance & increase it to the best value for your system).

    • namhuy

      thanks for the tips. I head about XFS but never try. I will try on virtualbox later and maybe write another tutorial for XFS. Again, thanks :)

  8. Alsan Wong

    I’m having a problem of can’t startup the session caused by the line:

    tmpfs /var/tmp tmpfs defaults,noatime,mode=1777 0 0

    by removing this line, everythings works fine. thanks for the tips anyway.

  9. With SSD, JFS and deadline scheduler is unofficially recommended by some people. JFS supports TRIM. there are some strong words like… ext4 kills SSD etc. Here’s a link:
    Phoronix did some FS reviews also:

  10. Cy D. Fect

    You should not add /var/spool to the ramdisk (tmpfs). It can seriously mess things up!

  11. Narendran Gopalakrishnan

    SELinux wasn’t happy with /etc/fstab changes, so had to set the rootcontext as well, as below:
    # This is absolutely safe:
    tmpfs /tmp tmpfs defaults,mode=1777,size=10%,relatime,nodiratime 0 0

    # These are non-standard (these dirs are *intended* to be persistent) – The
    # rootcontext’s for keeping SELinux happy, were determined by first looking at
    # the output of: ls -d –scontext /var/tmp /var/log /var/spool
    tmpfs /var/tmp tmpfs defaults,mode=1777,size=10%,relatime,nodiratime,rootcontext=system_u:object_r:tmp_t:s0 0 0
    tmpfs /var/log tmpfs defaults,mode=0755,size=10%,relatime,nodiratime,rootcontext=system_u:object_r:var_log_t:s0 0 0
    tmpfs /var/spool tmpfs defaults,mode=0755,size=10%,relatime,nodiratime,rootcontext=system_u:object_r:var_spool_t:s0 0 0

  12. justcomment

    Thx a lot. I’m not the heavy linux user, but have some experience with some distros and html :). I like those c&p instuctions very much, really. But you made a little mistake.

    In section:

    To change swappiness setting:
    $ su – nano /etc/sysctl.conf

    I have no idea, maybe you too, where the h1-Tag came from :). But it’s, as you for sure know a html command, that confuses the ubuntu terminal. So, if somebody without html-knowledge tries those instructions with copy and paste, he would earn an error and would’t know why.

    Hope I could help you and you will correct this instruction problem.

    Greets from Germany

    • namhuy

      Hi there, thanks for letting me know, I had problem with “FancyBox for WordPress” plugin in the past, It broke some of my posts format with was a mess a for me to clean up. I had fixed most of them but I guess i missed this one. By the way, this article has been updated, H1 tag was removed. Thanks again :)

Leave a Reply