Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Run chromium in a RAMDISK, avoid excessive disk (SSD) writes
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
devsk
Advocate
Advocate


Joined: 24 Oct 2003
Posts: 2734
Location: Bay Area, CA

PostPosted: Sat Jan 02, 2010 9:52 am    Post subject: Run chromium in a RAMDISK, avoid excessive disk (SSD) writes Reply with quote

I just wrote this script for myself and thought I would share it with you folks if you want to run chrome in a ramdisk, just like some folks did with firefox.

Chrome is fast. Loads my 3 windows full of 36 tabs in under two seconds. The rsync used by the script is really fast too. You need to install xdialog. I have made the browser a loop because I was seeing a lot of memory leaks, so I was just thinking about recycling the browser once in a while. It syncs with disk on exit or crash or a kill. Fairly small and straightforward. Have a look! And Enjoy!
Code:
#!/bin/sh
#
# Following one time activities need to happen:

# 1. To be able to use this script, you need to add the following line in /etc/fstab

# chromium /home/memyself/.config/chromium tmpfs size=192M,noauto,user,exec,uid=1001,gid=100 0 0
#
# 2. touch /home/memyself/.config/chromium/.unpacked
#
# 3. mv /home/memyself/.config/chromium /home/memyself/.config/chromium.ondisk && mkdir /home/memyself/.config/chromium
#
# Do the above ONLY the first time.

function got_hup()
{
        grep -q /home/memyself/.config/chromium /etc/mtab
        if [ $? -eq 0 ]
        then
                # it was mounted and unpacked
                if [ -f /home/memyself/.config/chromium/.unpacked ]
                then
                        echo "Mounted and used data, syncing it back..."
                        rsync --delete-excluded --delete  -H -av -x \
                                --exclude=/home/memyself/.config/chromium/rsync.log \
                                --exclude=/home/memyself/.config/chromium.ondisk/rsync.log \
                                /home/memyself/.config/chromium/ \
                                /home/memyself/.config/chromium.ondisk/ \
                        > /home/memyself/.config/chromium.ondisk/rsync.log 2>&1
                fi
        fi
        exit 0
}

# trap these and rsync back to disk
trap got_hup 1 2 3 6 15

# mount and unpack
grep -q /home/memyself/.config/chromium /etc/mtab
if [ $? -ne 0 ]
then
        echo "Not mounted, mounting now..."
        mount /home/memyself/.config/chromium
fi

# unpack the stuff if not already there
if [ ! -f /home/memyself/.config/chromium/.unpacked ]
then
        echo "Not unpacked, unpacking from ondisk now..."
        rsync --delete-excluded --delete  -H -av -x \
                --exclude=/home/memyself/.config/chromium/rsync.log \
                --exclude=/home/memyself/.config/chromium.ondisk/rsync.log \
                /home/memyself/.config/chromium.ondisk/ \
                /home/memyself/.config/chromium/ \
        > /home/memyself/.config/chromium/rsync.log 2>&1
fi

# go into a loop
while true
do

        #chromium-bin --single-process "$@" &
        #chromium-bin --process-per-tab "$@" &
        echo "Starting the browser..."
        chromium-bin --process-per-site "$@"
        Xdialog --yesno "Exit the browser?" 8 40
        if [ $? -eq 0 ]
        then
                got_hup
        fi
done


Last edited by devsk on Sat Jan 02, 2010 7:21 pm; edited 1 time in total
Back to top
View user's profile Send private message
shazow
Apprentice
Apprentice


Joined: 11 Dec 2003
Posts: 176
Location: Canada, Ontario

PostPosted: Sat Jan 02, 2010 2:32 pm    Post subject: Reply with quote

Quote:
# 2. touch /home/memyself/.config/.unpacked


Shouldn't this be /home/memyself/.config/chromium/.unpacked or somesuch?

Also, I already run /tmp on tmpfs, would it make sense to do something like this to use /tmp and sync back to ~/.config, without messing up my existing ~/.config?

- shazow
Back to top
View user's profile Send private message
devsk
Advocate
Advocate


Joined: 24 Oct 2003
Posts: 2734
Location: Bay Area, CA

PostPosted: Sat Jan 02, 2010 7:25 pm    Post subject: Reply with quote

shazow wrote:
Quote:
# 2. touch /home/memyself/.config/.unpacked


Shouldn't this be /home/memyself/.config/chromium/.unpacked or somesuch?

Also, I already run /tmp on tmpfs, would it make sense to do something like this to use /tmp and sync back to ~/.config, without messing up my existing ~/.config?

- shazow
Corrected. Sorry, for missing chromium in the path.

Actually, I never meant to mess up ~/.config. I wanted to affect only ~/.config/chromium. The script did the right thing but the comments which instructed the three manual steps were wrong as you pointed out.

As for putting stuff in /tmp and syncing it from there, you can definitely do that, it will only require minor modifications to the script. I don't use /tmp on tmpfs, so I created a separate one for chromium. Its actually better and cleaner if its separate from /tmp. You can unmount it without bothering the rest of the system e.g.

Thanks for catching the bug.
Back to top
View user's profile Send private message
shazow
Apprentice
Apprentice


Joined: 11 Dec 2003
Posts: 176
Location: Canada, Ontario

PostPosted: Sat Jan 02, 2010 8:05 pm    Post subject: Reply with quote

Chrome aside, I would recommend using tmpfs for /tmp. Pretty ideal, especially if you're worried about needless SSD thrashing.

My fstab entry:
Code:
none  /tmp  tmpfs  size=256m  0 0


I imagine it's more elegant to re-use /tmp just because every other app already does, and this way I don't need to mount a separate partition for each app I want to load into RAM. I could see unifying this script to work with pretty much any app.

Anyways, I'm working on a mod of the script to use /tmp, where it symlinks it into /tmp instead of mounting. I'll post it here once I rid all the bugs. :-)

- shazow
Back to top
View user's profile Send private message
shgadwa
Guru
Guru


Joined: 12 Mar 2009
Posts: 326

PostPosted: Wed Jan 06, 2010 11:37 pm    Post subject: Reply with quote

Where does this script go? In what folder?
Back to top
View user's profile Send private message
devsk
Advocate
Advocate


Joined: 24 Oct 2003
Posts: 2734
Location: Bay Area, CA

PostPosted: Wed Jan 06, 2010 11:49 pm    Post subject: Reply with quote

belikeyeshua wrote:
Where does this script go? In what folder?
I named mychromium and put it in ~/bin after chmod +x on it. Note that you need the path where you put it in PATH env var. You can just copy it in /usr/bin.
Back to top
View user's profile Send private message
shgadwa
Guru
Guru


Joined: 12 Mar 2009
Posts: 326

PostPosted: Wed Jan 06, 2010 11:59 pm    Post subject: Reply with quote

devsk wrote:
belikeyeshua wrote:
Where does this script go? In what folder?
I named mychromium and put it in ~/bin after chmod +x on it. Note that you need the path where you put it in PATH env var. You can just copy it in /usr/bin.


Ok, thanks that sounds easy enough. One thing that I'm unsure about is... what do you mean by PATH env var? I thought you were talking about the script here, but that can't be it because there is no env var in your script.
Back to top
View user's profile Send private message
devsk
Advocate
Advocate


Joined: 24 Oct 2003
Posts: 2734
Location: Bay Area, CA

PostPosted: Thu Jan 07, 2010 12:28 am    Post subject: Reply with quote

belikeyeshua wrote:
devsk wrote:
belikeyeshua wrote:
Where does this script go? In what folder?
I named mychromium and put it in ~/bin after chmod +x on it. Note that you need the path where you put it in PATH env var. You can just copy it in /usr/bin.


Ok, thanks that sounds easy enough. One thing that I'm unsure about is... what do you mean by PATH env var? I thought you were talking about the script here, but that can't be it because there is no env var in your script.
You have some work to do to get familiar with how Unix works. PATH is the environment variable which determines how to find the program you are trying to run. It usually has /usr/bin and /bin in it, so any program you put in the directory /usr/bin will be directly callable, without full path. You do "echo $PATH" in a shell to see what the path value is.
Back to top
View user's profile Send private message
shgadwa
Guru
Guru


Joined: 12 Mar 2009
Posts: 326

PostPosted: Thu Jan 07, 2010 12:53 am    Post subject: Reply with quote

Well, I replaced all the memyself's with my user name and I did chmod +x on the file and moved it to /usr/bin. I did everything that the script said to do.

But, when I try to start it, I get this:
Code:
shawn@atlantis ~ $ chromium-bin
[3018:3018:122915575:FATAL:/b/slave/chromium-rel-linux/build/src/chrome/browser/browser_main.cc(655)] Check failed: profile. Cannot get default profile.
Trace/breakpoint trap


Thank you for the help.

EDIT: It looks like I have a problem with the PATH. Funny, I've been using Linux for about 3 years now, and gentoo for over a year... and I don't really know about $PATH and things like that.

I did execute the script by clicking on it, and that opens up chromium. Its a lot faster! ;)

Also, I'm thinking... this has improved the speed of our satellite internet so much that I would like to set this up in our windows XP computers and our Mac OS X computers. Is that possible?
Back to top
View user's profile Send private message
desultory
Administrator
Administrator


Joined: 04 Nov 2005
Posts: 7956

PostPosted: Thu Jan 07, 2010 11:07 am    Post subject: Reply with quote

devsk wrote:
You can just copy it in /usr/bin.
Better yet, /usr/local/bin/.
Back to top
View user's profile Send private message
V10lator
Apprentice
Apprentice


Joined: 11 Jul 2004
Posts: 170

PostPosted: Fri Feb 12, 2010 1:04 pm    Post subject: Reply with quote

shazow wrote:
Anyways, I'm working on a mod of the script to use /tmp, where it symlinks it into /tmp instead of mounting. I'll post it here once I rid all the bugs. :-)

Why symlinking? Why don't you simple change

chromium /home/memyself/.config/chromium tmpfs size=192M,noauto,user,exec,uid=1001,gid=100 0 0

to

/tmp/chrom-speedup /home/memyself/.config/chromium tmpfs user,exec,bind 0 0

or something like that? Of course the dir /tmp/chrom-speedup has to exist. The mount commands in the script should work with that, too ;)
Back to top
View user's profile Send private message
mrmarcdee
n00b
n00b


Joined: 18 Jan 2010
Posts: 67

PostPosted: Thu Feb 25, 2010 1:51 am    Post subject: Reply with quote

When I set this up all of my configuration seems to be lost. So I reconfigured it, and then the next time I rebooted and restarted chromium the configuration was gone again. Whats going on? Does it not save configuration to the harddrive because it is running in RAM or what? Can this be fixed?

Thanks.
Back to top
View user's profile Send private message
equilibrium
Apprentice
Apprentice


Joined: 29 Jun 2003
Posts: 213
Location: UK

PostPosted: Tue Oct 12, 2010 9:29 am    Post subject: Reply with quote

what about using /tmp (if you already have it) ?
Code:
#!/bin/bash
STATIC=chrome
LINK=chromium
PROFILE=/tmp/$USER/chromium

cd ~/.config/

[[ -r $PROFILE ]] || install -dm700 $PROFILE

if [[ `readlink $LINK` != $PROFILE ]]; then
  mv $LINK $STATIC
  ln -s $PROFILE $LINK
fi

if [[ -e $LINK/.unpacked ]]; then
  rsync -av --delete --exclude .unpacked ./$LINK/ ./$STATIC/
else
  rsync -av ./$STATIC/ ./$LINK/
  touch $LINK/.unpacked
fi

then just setup this script in crontab or on bash_login/logout
Code:
echo '/location/of/script' | tee -a ~/.bash_logout ~/.bash_login >/dev/null

crontab -e
Code:
# sync google chromium profile to ramdisk on /tmp
0 */1 * * * /usr/local/bin/chrome-sync &> /tmp/chrome-sync.log

_________________
kernel 3.14.4-2-ck | i3wm | github
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum