Results 1 to 10 of 10

Thread: speed tweak: Use ramdisks for /lib and /usr/lib without partitions or even rebooting!

Threaded View

  1. #1
    Join Date
    Dec 2007
    Ubuntu Karmic Koala (testing)

    speed tweak: Use ramdisks for /lib and /usr/lib without partitions or even rebooting!

    Currently, Firefox 3.5 and oowriter are both taking less than a second to start up to a full usable state. Gedit takes less than half a second. Even Emacs (X11 mode) takes only 0.416 seconds to start! (Measurements taken by running the command "time <program>," closing the program as soon as it has come up, and then noting the "user" measurement.)

    This is the best performance I've had from ANY operating system on ANY computer.

    Some background: /usr/lib and /lib are the two most commonly-accessed directories. Their primary function is to contain dynamically-linkable libraries (*.so files) for use by other applications. However, a few programs (notably Firefox) will install themselves entirely in /usr/lib. Improving access times for either or both of these directories will result in major performance gains.

    This wasn't lost on whoever posted this thread on the Gentoo forums. However, his/her solution involved creating dedicated partitions for pretty much every directory in "/".

    I looked at the thread, and I wondered if there was a better way.

    Turns out there is. I did it without repartitioning or even rebooting. This is how I did it.

    (WARNING: This guide involves messing with the "guts" of your system, and trying it out is discouraged unless you know what you're doing.)

    First, a few considerations.

    Nearly every program you're likely to run will use libraries from /lib. /lib contains the libraries which are absolutely essential to even a basic system, the same way /bin and /sbin contain binaries which are entirely mandatory. If you make a ramdisk of /lib, basically every single program you'll use will have at least a slight performance benefit. /usr/bin has many more contents, so if you make a ramdisk of it, slightly fewer programs will benefit, but you'll see larger benefits overall. In addition, as mentioned before, some programs are contained entirely in this directory. On the other hand, if you make a ramdisk of it, you'll use up a *lot* more memory. If you can, you should make ramdisks of both, but if you only have enough memory for one of them, pick /lib.

    You'll also want to choose what kind of filesystems to use for your ramdisks. There are two choices available, "Ramfs" and "Tmpfs." Both will initially start at zero bytes in size. "Ramfs" will never use swap, and it will grow dynamically until you run out of memory and the kernel starts randomly killing off processes. "Tmpfs" filesystems are pegged at maximum sizes to which they can grow, and they will use swap if they have to. Keep in mind that if your ramdisks are swapping, you're loosing the performance benefit of having a ramdisk anyway. However, if only a few percent of a ramdisk is swapping, it's still an improvement.

    On my system, /lib is about 660 Mb, /usr/lib is about 1.6 Gb, and I have 4 gigs of RAM. Based on this, I decided to make ramdisks of both /lib and /usr/lib, and to use ramfs for both of them. Your decision should be influenced by the situation on your computer.

    First, create mountpoints for our ramdisks:
    cd /mnt
    sudo mkdir newlib
    sudo mkdir newusrlib
    Then, mount the ramdisks using your chosen filesystem.
    for ramfs:
    sudo mount -t ramfs ramfs /mnt/newlib
    sudo mount -t ramfs ramfs /mnt/newusrlib
    for tmpfs:
    #remember to change the size values to match your system! I suggest adding some extra leeway, just in case.
    sudo mount -t tmpfs -o size=700m tmpfs /mnt/newlib 
    sudo mount -t tmpfs -o size=1700m ramfs /mnt/newusrlib
    Then, copy the files into the ramdisks. This can take a very long time, depending on the amount of data being transferred.
    sudo cp -r /lib/* /mnt/newlib/
    sudo cp -r /usr/lib/* /mnt/newusrlib/
    Be sure you do this right! On my first attempt, I did this:
    sudo cp -r /lib /mnt/newlib/ #WRONG
    sudo cp -r /usr/lib /mnt/newusrlib/ #WRONG
    That results in all the files being copied to /mnt/newlib/lib instead of /mnt/newlib, and /mnt/newusrlib/lib instead of /mnt/newusrlib. I wound up needing to reboot, because not even "mv" would work! A reboot fixed it though.

    Finally, mount the ramdisks over the directories on your hard drive.
    sudo mount -t unionfs -o dirs=/mnt/newlib:/lib=ro none /lib
    sudo mount -t unionfs -o dirs=/mnt/newusrlib:/usr/lib=ro none /usr/lib
    And you're done!

    More considerations:

    If any changes get made to /lib or /usr/lib, those changes are going to be applied only to the ramdisks!

    If this happens, here are the steps to applying those changes to your hard disk:

    sudo umount /lib  # /lib is now a directory on the hard drive once again.
    sudo cp -r /mnt/newlib/* /lib  # copy the new version of /lib onto your hardrive to make the changes permanent
    If you are going to be doing this on a regular basis, you may wish to create some new ramdisks specifically for changes:
    sudo mkdir /mnt/newlib_changes #these directories will be empty
    sudo mkdir /mnt/newusrlib_changes
    Then, when creating your unionfs filesystems:
    sudo mount -t unionfs -o dirs=/mnt/newlib_changes=rw:/mnt/newlib=ro:/lib=ro none /lib #all filesystems besides newlib_changes are now read-only
    sudo mount -t unionfs -o dirs=/mnt/newusrlib_changes=rw:/mnt/newusrlib=ro:/usr/lib=ro none /usr/lib
    After that, you will only need to copy files from newlib_changes and newusrlib_changes, saving you time.

    Finally, you can choose to only copy some files into your ramdisks, and since the ramdisks are in unionfs with the hard drive directories, the non-copied files will come from your hard drive as normal. New files and modified files will still go in the ramdisks, though.
    Last edited by MaxIBoy; July 20th, 2009 at 01:48 AM.
    He that would make his own liberty secure must guard even his enemy from oppression; for if he violates this duty he establishes a precedent that will reach to himself.
    -Thomas Paine


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts