Blog Forum Wiki Links Contact Us NetbookUser
RunCore Pro IV SSD Transforms your ASUS EEE PC by increasing 
performance 5-40X. Your satistfaction guaranteed RunCore Pro 70mm SATA Mini PCI-e SSD
RunCore Pro IV 70mm SATA II Mini PCI-e SSD
RunCore Pro IV 2.5 Inch SATA II SSD

You are not logged in.

#1 2007-12-19 5:37:32 am

nickca
Member
Registered: 2007-12-12
Posts: 53

Xubuntu - moving parts of /var to RAM to minimize writes

I'm running the eee distribution of Xubuntu, release 2. I want to minimize writes to the SSD in every way I can, so I moved some directories under /var to tmpfs in RAM. Here's what I changed:

* /var/run and /var/lock are already mounted as tmpfs by default. So far so good.
* I moved /tmp and /var/tmp to tmpfs. I added these lines to /etc/fstab:

Code:

tmp     /tmp            tmpfs   noexec,nosuid,rw,size=1024K     0       0
vartmp  /var/tmp        tmpfs   noexec,nosuid,rw,size=1024K     0       0

Then just rm -rf everything currently in /tmp and /var/tmp, reboot, and the temp directories are now tmpfs filesystems using 1MB of RAM each. That was easy enough. /var/log is a bit more difficult. This isn't a server, so I don't particularly care about extensive logs, but I do want to save the logs from at least one session of use in case something goes wrong. I wrote these scripts:

/etc/init.d/logbkup.sh - back up one session's worth of logs

Code:

#!/bin/sh
if [ -f /var/log_bkup/log_bkup.tar.gz ]; then
  /bin/rm /var/log_bkup/log_bkup.tar.gz
fi

echo "Backing up logs to tar archive..."
/bin/tar czf /var/log_bkup/log_bkup.tar.gz /var/log

Make sure /var/log_bkup (or somewhere to back up the logs to) exists.

/etc/init.d/mklogdir.sh - create a skeleton in /var/log at boot

Code:

echo "Creating directories in /var/log"
/bin/mkdir /var/log/apparmor
/bin/mkdir /var/log/apt
/bin/mkdir /var/log/cups
/bin/mkdir /var/log/dist-upgrade
/bin/mkdir /var/log/fsck
/bin/mkdir /var/log/gdm
/bin/mkdir /var/log/news
/bin/mkdir /var/log/samba
/bin/mkdir /var/log/unattended-upgrades
/bin/mkdir /var/log/installer

I'm not sure if the mklogdir script is really necessary, the directories may be created automatically as needed, but it can't hurt. Then link the scripts so they're called at boot and shutdown. I linked them to /etc/rc2.d/S05mklogdir.sh, /etc/rc0.d/S15logbkup.sh, and /etc/rc6.d/S15logbkup.sh. Then I added this to /etc/fstab:

varlog  /var/log        tmpfs   noexec,nosuid,rw,size=8192K     0       0

8MB should be plenty for logs (remember, it gets recreated at each boot).

Next, I rebooted from my Xubuntu live USB stick (the one I installed from) and mounted my install partition on /media/sda1, then deleted everything from /media/sda1/var/log to make sure it's an empty mount point. Then I rebooted, no problems. Thus, I'm using 10MB worth of RAM for all my temp files and logs, and the logs get written to disk once at shutdown rather than lots of small writes to different files the whole time the machine is on. With 1GB of ram and no swap I still have around 730MB RAM free on average. I could just not back up the logs at all, but you never know when you'll need them. This may be obsessive, but every write to the SSD you can save counts, and it was easy to do (writing this took much longer than it did to actually do it.

Last edited by nickca (2007-12-19 5:43:23 am)


eeePC 4G 7B - 1GB DDR667 RAM - Internal USB hub w/32GB (2x16GB) flash, Bluetooth, spare internal USB connection

Offline

 

#2 2007-12-19 2:11:50 pm

CMYanko
Senior Member
From: Hartford, CT
Registered: 2007-12-10
Posts: 281
Website

Re: Xubuntu - moving parts of /var to RAM to minimize writes

Nice, not clear to me how tmpfs is in ram though. fstab just foes does that?

Like you I can boot from stick, why haven't you installed yet, issues or just want to keep Xandros around?

As alive image, but on a writeable drive, can we install stuff and it will stay? (this one is probably a dumb question but I'm in rarefied air).

Offline

 

#3 2007-12-19 4:05:23 pm

tristan
Member
From: Brisbane, Australia
Registered: 2007-12-05
Posts: 99

Re: Xubuntu - moving parts of /var to RAM to minimize writes

It's probably a good idea to make your browser cache reside in ram too. I made a tmpfs of ~/.opera/cache4, since this is hammered during a browsing session.

Offline

 

#4 2007-12-19 4:34:22 pm

nickca
Member
Registered: 2007-12-12
Posts: 53

Re: Xubuntu - moving parts of /var to RAM to minimize writes

CMYanko wrote:

Nice, not clear to me how tmpfs is in ram though. fstab just foes does that?

fstab tells the OS which filesystems to mount and where to mount them. If you put those entries in /etc/fstab, the OS will create filesystems in RAM automatically mounted in the directory you specify. tmpfs is a special filesystem in Linux that uses RAM rather than disk.

Like you I can boot from stick, why haven't you installed yet, issues or just want to keep Xandros around?

I've got Xubuntu installed to the SSD drive. I booted from the live USB stick to clear out /var/log on the SSD, so it wasn't being actively used by the OS and I could thus ensure that it was an emptied completely. It's possible to mount tmpfs filesystems over directories that aren't empty, but I wanted to mount them in empty directories.

As alive image, but on a writeable drive, can we install stuff and it will stay? (this one is probably a dumb question but I'm in rarefied air).

You can install things, but they won't persist after a reboot unless you modify the actual live image (not easy to do). Live distributions keep any files you add or changes you make in RAM and dispose of them on reboot/shutdown.

It's probably a good idea to make your browser cache reside in ram too. I made a tmpfs of ~/.opera/cache4, since this is hammered during a browsing session.

Great idea. What size did you make it? Anyone have any other suggestions for things to move to RAM storage?


eeePC 4G 7B - 1GB DDR667 RAM - Internal USB hub w/32GB (2x16GB) flash, Bluetooth, spare internal USB connection

Offline

 

#5 2007-12-19 5:42:54 pm

tristan
Member
From: Brisbane, Australia
Registered: 2007-12-05
Posts: 99

Re: Xubuntu - moving parts of /var to RAM to minimize writes

nickca wrote:

It's probably a good idea to make your browser cache reside in ram too. I made a tmpfs of ~/.opera/cache4, since this is hammered during a browsing session.

Great idea. What size did you make it? Anyone have any other suggestions for things to move to RAM storage?

I don't specify a size, I think it's dynamically resizable that way. I also put my ~/.thumbnails in tmpfs, as this can also end up with a lot of little thumbnail files being written.

Offline

 

#6 2007-12-19 7:13:05 pm

beowabbit
Member
From: Boston, MA, USA
Registered: 2007-11-01
Posts: 14

Re: Xubuntu - moving parts of /var to RAM to minimize writes

tristan, I presume Opera supports both RAM cache and disk cache, as Firefox does.  If so, why not just axe the disk cache altogether?  (And make the RAM cache larger if you like.)  If you put the "disk" cache in tmpfs, it ends up in RAM anyway, so the only difference between an 8MB RAM cache plus a 0MB (nonexistent) disk cache and a 4MB RAM cache plus a 4MB disk cache is that in the latter case stuff gets copied back and forth between different areas of RAM.

Offline

 

#7 2007-12-19 7:17:14 pm

tristan
Member
From: Brisbane, Australia
Registered: 2007-12-05
Posts: 99

Re: Xubuntu - moving parts of /var to RAM to minimize writes

I set opera to not use a disk cache but it seems to anyway. Maybe I need to revisit the settings.

Offline

 

#8 2007-12-21 3:37:13 pm

nickca
Member
Registered: 2007-12-12
Posts: 53

Re: Xubuntu - moving parts of /var to RAM to minimize writes

I tried to make a tmpfs under /var/cache/moz for Firefox and symlink it to /home/nickca/.mozilla/firefox/(profile dir)/Cache, but I noticed Firefox just deleted the symlink and recreated the directory, so I decided to not overthink the problem and just disable disk cache as the poster above recommends. Here's how you do that on Firefox if anyone wants to know:

Open a tab, type "about:config" in the address bar

Type "disk" in the search (Filter) field

You should see "browser.disk.cache.capacity" and "browser.disk.cache.enable", set them to "0" and "false" respectively

Now search for "memory", you should see "browser.memory.cache.capacity" and "browser.memory.cache.enable", make sure "enable" is set to "true" and "capacity" is set to some nonzero value, my capacity is set to 8192 or 8MB, which should be more than enough.

Edit: While you're in there, here's some settings you can change to reduce overall memory usage without affecting performance:

browser.sessionhistory.max_total_viewers = 4, this will cache 4 pages in memory at a time
config.trim_on_minimize = true, you will probably have to create this key. This will allow the OS to reclaim some RAM while Firefox is minimized.

If you have 512MB RAM rather than 1GB as I do, you may want to set these values smaller, such as 4096 for browser.memory.cache.capacity and 2 or even 0 (don't cache any pages, reload them every time) for browser.sessionhistory.max_total_viewers.

Last edited by nickca (2007-12-21 3:43:59 pm)


eeePC 4G 7B - 1GB DDR667 RAM - Internal USB hub w/32GB (2x16GB) flash, Bluetooth, spare internal USB connection

Offline

 

#9 2007-12-26 2:17:34 am

nickca
Member
Registered: 2007-12-12
Posts: 53

Re: Xubuntu - moving parts of /var to RAM to minimize writes

One more thing - if you set /tmp to just use 1MB of RAM as I did, Youtube/Google Video/etc. streaming Flash videos will exhibit an annoying behavior of just playing the first second or two of the video and then hanging. I went nuts trying to fix this, disabling extensions, enabling/resizing/disabling the disk/memory cache in Firefox, etc. until I discovered the Flash plugin caches to /tmp instead of your Firefox cache directory. This should also be true for Opera or any other browser that uses the Flash plugin. I upped /tmp to 8MB and that seems to be adequate. It may still hang with longer videos, in which case I'll just up the size again.


eeePC 4G 7B - 1GB DDR667 RAM - Internal USB hub w/32GB (2x16GB) flash, Bluetooth, spare internal USB connection

Offline

 

#10 2008-01-03 8:03:50 pm

mmmsoap
New member
Registered: 2008-01-03
Posts: 1

Re: Xubuntu - moving parts of /var to RAM to minimize writes

nickca wrote:

Then just rm -rf everything currently in /tmp and /var/tmp, reboot, and the temp directories are now tmpfs filesystems using 1MB of RAM each. That was easy enough.

Great idea, but I did run into some trouble. I think 1 MB may be too small....I upped mine to 4MB but still got "not enough room on the device" errors when trying to install xubuntu-restricted-extras. I did get *further* along in the download after I upped from 1MB to 4MB. I'm considering going all out and upping it to 16MB....

(Although my system seems to max out the CPU far more often than it maxes out the 512 MB of RAM, so I should have some room to play. I'm rarely, if ever, above 50% of RAM used, and never touch swap other than for hibernating.)

Last edited by mmmsoap (2008-01-03 8:04:17 pm)

Offline

 

#11 2008-01-29 12:23:02 pm

mordred
Senior Member
From: Puglia, Italy
Registered: 2008-01-27
Posts: 105

Re: Xubuntu - moving parts of /var to RAM to minimize writes

think these are great tips to increase or SSD's life.. what about adding them in the wiki (i can do it if you don't mind)?

Also, I am using eeeXubuntu too and since this is my first time with a non-gentoo distro I am unfamiliar with the package management. My question is: can we move the package manager cache or the temporary packages storage to an SD card or to a tmpfs partition?

Last edited by mordred (2008-01-29 1:06:08 pm)


my small howto on streaming

Offline

 

#12 2008-09-22 5:43:13 pm

groom
New member
Registered: 2008-09-22
Posts: 1

Re: Xubuntu - moving parts of /var to RAM to minimize writes

mordred wrote:

think these are great tips to increase or SSD's life.. what about adding them in the wiki (i can do it if you don't mind)?

i contributed to a french part of the wiki in this direction, you should do it the same (if not already done!) on the english version.

Also, I am using eeeXubuntu too and since this is my first time with a non-gentoo distro I am unfamiliar with the package management. My question is: can we move the package manager cache or the temporary packages storage to an SD card or to a tmpfs partition?

Yes of course:
the APT tools download packages in/var/cache/apt/archives/ by default.
you have 2 solutions:

1:

Code:

$ sudo apt-get clean         #to remove archives
$ sudo nano /etc/fstab      #to add an external device as mount point into /var/cache/apt/archives
$ sudo mount /var/cache/apt/archives

EITHER

2: edit /etc/apt/apt.conf.d/20archive to override the location of Dir::Cache Dir::Cache::archives and Dir::Parts (for partial downloads)

Offline

 

Board footer

Powered by PunBB 1.2.15
© Copyright 2002–2005 Rickard Andersson