LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Trying to use ramdisks/tmpfs to speed things up (https://www.linuxquestions.org/questions/linux-newbie-8/trying-to-use-ramdisks-tmpfs-to-speed-things-up-4175438494/)

Rookie1337 11-23-2012 07:50 PM

Trying to use ramdisks/tmpfs to speed things up
 
I'm trying to speed Linux up as much as possible and found this post from a long time again (2009) talking about using unionfs to merge some dirs like /lib /bin into dirs stored in RAM for crazy speed increases.

http://ubuntuforums.org/showpost.php...27&postcount=1

Unfortunately, unionfs is dead and buried as far as I know and I can't figure out if I can get overlayfs to reproduce this method. Does someone know if there's a way to have overlayfs work the same way?

I had another idea which just used mount -B to link /lib /bin /share dirs to /run/shm but again don't know if it would work.

Any help is appreciated and thanks in advance.

[EDITED] The solution is my last post. There's no real way apparently to do what I thought could be done so this thread is solved/over. Thanks.

Elv13 11-24-2012 02:41 PM

Hi, welcome to LQ.

Linux will automagically cache a lot of files in memory by default so you don't have to do this. If you have a lot of ram, a very common technique, sometime used by distributions by default is read-ahead or preloading.

The principles are simple, during or quickly after booting. You cat "/path/to/files > /dev/null" all files you read often, including libraries and applications. Doing, that, you add them to the in-memory file cache. So it will basically be ready when you need them, just as your solution. You can then gather statistics using a daemon watching file descriptors to know which file to load first and so on. This do give some crazy speed too. There is already some daemon like ureadahead to do this.

An other solution, more closely related to the original one is to use LZO compressed ramdisks. That way you can store more information into less memory. I am not sure if this would be faster, I don't think so. Ramdisks are amazing, but to store something as big as /usr/lib, no so sure. I guess you could also do one huge initramfs image with most of the system already loaded and keep it as root. I guess this could work, but it would take 10 minutes to boot your computer.

Rookie1337 11-24-2012 04:25 PM

I'm on Kubuntu 12.10 and I'm sure it has either/both ureadahead and readahead but the problem is their defaults never seem to do anything as I'm still hitting the HDDs hard on the first load of a program and the load times aren't that great after that (they're not like the ramdisk setup I have in Windows please don't hurt me for mentioning that). I've tried preload and prelink in the past and they both didn't seem to really do much. I think time showed a whole 1second improvement in xbmc which went from something like 5 seconds to 4...which still doesn't match my other OS's speed(and I hate that I've made it faster then Linux).

Hmm...that's the second time someone has mentioned cat "src" > /dev/null and I'm wondering why. I thought /dev/null was the "black hole" of Linux systems in which once things went there then they were gone. But then comes the big problem...how can I hold the things that I want in the cache so the kernel doesn't dump them?

I wrote up a script that seemed to work until the first line of free dropped to 500 in the readout (the part the system claims is free not the "actual" free amount). Then my overlayfs system seemed to slow down.

Here's my attempt...tell me if it's stupid or pointless. I couldn't decide between binding and overlayfs. I've only tried overlayfs with this script so far so IDK if binding would be any better. I'm going to try out your method.

Quote:

#!/bin/bash
#Must chmod +x first
#Binding dirs to Rapiddisk
#You need to have made the Rapiddisk modules which required the kernel source

sudo rm -rf /mnt/Rapiddisk
sudo modprobe rxdsk
sudo rxadm --attach 4096
#creates 4GB ramdisk at /dev/rxd0
sudo mke2fs -F /dev/rxd0
sudo mkdir /mnt/Rapiddisk
sudo mount /dev/rxd0 /mnt/Rapiddisk

#First is to make dirs
sudo mkdir /mnt/Rapiddisk/google
sudo mkdir /mnt/Rapiddisk/usrlib
sudo mkdir /mnt/Rapiddisk/lib
sudo mkdir /mnt/Rapiddisk/bin
sudo mkdir /mnt/Rapiddisk/share

#Next is to sync dirs
sudo rsync -aEvz /usr/bin /mnt/Rapiddisk/bin
sudo rsync -aEvz /opt/google/chrome /mnt/Rapiddisk/google
sudo rsync -aEvz /usr/lib /mnt/Rapiddisk/usrlib
sudo rsync -aEvz /usr/share /mnt/Rapiddisk/share
sudo rsync -aEvz /lib /mnt/Rapiddisk/lib

#Finally binding
#sudo mount -B /opt/google/chrome /mnt/Rapiddisk/google
#sudo mount -B /usr/lib /mnt/Rapiddisk/usrlib
#sudo mount -B /usr/share /mnt/Rapiddisk/share
#sudo mount -B /usr/bin /mnt/Rapiddisk/bin
#sudo mount -B /lib /mnt/Rapiddisk/lib

#Finally Mount overlayfs
sudo mount -t overlayfs overlayfs -olowerdir=/opt/google/chrome,upperdir=/mnt/Rapiddisk/google /mnt/Rapiddisk/google
sudo mount -t overlayfs overlayfs -olowerdir=/usr/lib,upperdir=/mnt/Rapiddisk/usrlib /mnt/Rapiddisk/usrlib
sudo mount -t overlayfs overlayfs -olowerdir=/usr/bin,upperdir=/mnt/Rapiddisk/bin /mnt/Rapiddisk/bin
sudo mount -t overlayfs overlayfs -olowerdir=/usr/share,upperdir=/mnt/Rapiddisk/share /mnt/Rapiddisk/share
sudo mount -t overlayfs overlayfs -olowerdir=/lib,upperdir=/mnt/Rapiddisk/lib /mnt/Rapiddisk/lib

Elv13 11-24-2012 04:39 PM

The kernel wont dump things unless it need the memory. If it need the memory, then you are in trouble with your ramdisks. It will move them to the swap, making things slower. ureadahead have a static filelist. You need to update this list of you want other binaries preloaded. You can also get an SSD.

Rookie1337 11-24-2012 05:13 PM

I am getting an SSD soon. I guess until then I have to settle with Windows being faster than Linux? I find it depressing that I've made it so Windows on a HDD is faster than Linux on the same HDD. I really wanted to find a way to fix that problem.

But anyway...say I wanted to move /usr/lib into the fs cache how could I do that since cat won't let me? Also...my readahead/ureadahead have empty .confs and I'm not sure how to use them for my intentions of pulling certain dirs into cache as they don't offer much direction in the manpages and seem focused on only being for speeding up booting.

Elv13 11-25-2012 02:34 AM

Windows do preload most used DLLs the same way Linux does, but Linux list is static while Windows one is dynamic. Make the Linux list dynamic and it will be as fast. Just as with Windows, boot time will slow down over time (yes, this is why Windows boot is always slower).

Rookie1337 11-25-2012 09:50 AM

Umm...you lost me there...how could I go about doing what you just said? Is that in readahead/ureadahead or preload?

jefro 11-25-2012 11:20 AM

If you boot to a pre os then copy your filesystem to a ramdrive or such then boot to it, you will get the so called crazy speeds. Many of the minimal type live cd's still do such a trick. They tend to use a squashfs file to copy to ram. They also use aufs or union or whatever is current.

Rookie1337 11-25-2012 12:13 PM

Yeah I'm familiar with that distro type as SLAX was my first foray into Linux back in 2010. And I am hoping that SLAX7 will be as easy as 6 was because I might just end up using it as the primary.

But the methods of trying to do such a thing with other distros are either extremely complicated and/or outdated. And in my first post someone showed how you could use unionfs to basically have everything you put into the unionfs read from ram. But since unionfs and aufs are dead/purged from the mainline kernel I was originally looking to see if there is a way to use overlayfs to replicate that method. As far as I have tried nothing really works. I think (if I understand Linux's fs_cache) I finally realized that the reason I was seeing speed improvements was not because the overlayfs or bind setup I had like in the script were actually doing what I wanted them too; but rather because I had invoked a copy command (rsync) and that it was filling the cache. Hence, eventually things would slow down as the cache began to change as I continued using the computer.

I had another (likely bad/impossible) idea as to how to get the things I wanted stored in ram but I figured it wouldn't work as it would involve copying the desired dirs to some temporary location (to store the info until it can be moved) and then mounting their original location into a Rapiddisk/ramfs/tmpfs and then copying their contents to the original locations that have now be mounted as a ram location. Example copy the contents of /usr/lib to some location; mount /usr/lib into a ram location; move the copied contents back to /usr/lib; enjoy the speed of instant loading programs. Sadly, I'm pretty sure this wouldn't work but maybe someone can tell me with certainty?

TobiSGD 11-25-2012 12:53 PM

Quote:

Originally Posted by Rookie1337 (Post 4836693)
But the methods of trying to do such a thing with other distros are either extremely complicated and/or outdated.

I have done that with Slackware and AUFS and actually it was pretty easy. I was using AUFS at that time, but I see no reason why that shouldn't work with overlayfs. I gave up on this approach for simple reasons:
1. Using a fast SSD gave me a good performance enhancement already.
2. I switched to using mostly very lightweight applications that are started automatically when the system boots.
3. With nowadays RAM sizes it is not likely that you really suffer from a to small cache.

The effort you have to make outweighs the benefits, at least for me.

Rookie1337 11-25-2012 02:42 PM

Well, I thought aufs and unionfs were dead or removed from the mainline kernels and most of the methods for changing say slackware or buntu are beyond me as I'm just a simple general user and the level of detail I can handle is basically demonstrated by the (I guess useless) script I posted earlier(AKA note much). But your point #3 is something that has me confused...on first boot my cache from free -m is tiny and it only ever grows after I've started programs. What I want is that speed on the second start for the first start...so I want the cache filled and retaining what I want all the time. But so far I've found nothing that seems to be able to do that. That's what led me to seek out the ramfs/tmpfs/ramdisk/overlayfs ideas.

So basically, there isn't any way besides getting an SSD or using some premade toram distros like SLAX or Porteus to really make things faster for a general user or someone with limited time?

TobiSGD 11-25-2012 02:51 PM

Quote:

Originally Posted by Rookie1337 (Post 4836781)
Well, I thought aufs and unionfs were dead or removed from the mainline kernels

There are patches at least for AUFS, I think I will have a look at overlayfs and see if that is easier.

Quote:

What I want is that speed on the second start for the first start...so I want the cache filled and retaining what I want all the time.
Just use preload for that, it will keep track of the most used programs and load the needed libraries when the computer is idling/at boot. This comes with the downside of longer boot times, since at one time the libraries/programs have to be loaded into RAM.
Or just do it like I do, if you have plenty of RAM (I have 16GB on my main machine) just autostart your applications at boot.

Rookie1337 11-25-2012 03:18 PM

Alright. I'll retry preload but how can I tell if it is actually doing anything? The last time I had it installed it didn't change any of the cache or free values so was it not running?

And how do you have it set to start up your programs on boot? Just have them running when you shutdown? Or do you have something else going on? It doesn't help me with a program like XBMC unless there's another method besides just leaving programs open...man there's so much I really don't understand about how Linux works. :(

Elv13 11-25-2012 04:58 PM

In theory, if you have enough RAM, the second start should always be preloaded unless you flush the cache. Firefox and LibreOffice are just slow to start, there is nothing you can do about it. Some apps are faster on Windows because they enable PGO. Most Linux distribution don't do any PGO at all, so it is not fair comparison. If you want to enable profile guided optimization, startup time optimization and reducing startup time dependencies mesh, then the you need Gentoo. Even then, you need Gentoo and a lot of time to perform tens of 1-2% optimizations.

Rookie1337 11-25-2012 09:36 PM

Quote:

Originally Posted by Elv13 (Post 4836844)
In theory, if you have enough RAM, the second start should always be preloaded unless you flush the cache. Firefox and LibreOffice are just slow to start, there is nothing you can do about it. Some apps are faster on Windows because they enable PGO. Most Linux distribution don't do any PGO at all, so it is not fair comparison. If you want to enable profile guided optimization, startup time optimization and reducing startup time dependencies mesh, then the you need Gentoo. Even then, you need Gentoo and a lot of time to perform tens of 1-2% optimizations.

Hmm...I never knew/heard about PGO but it didn't seem to help windows that much. My problem is that in Windows I have the option to install programs to a savable ramdisk and as such they all start as fast as ram speeds allow. I find it ironic that the "backwards" compartmentalized way of windows actually turned into something useful.

Alright, so in your opinion are preload and even prelink worth while? Do they even work?


All times are GMT -5. The time now is 11:35 PM.