Migrating Google Chrome to RAM on Linux
- Tutorial
The article does not contain anything interesting for more or less advanced users of Unix-like systems. Nothing at all.
Linux provides us with all the means to ensure that our task is solved in 10 minutes, forehead and correctly, no matter how hard we try to do everything through the ass. I will intentionally write in detail.
1. Create a RAM disk
No third-party applications are required. Linux supports kernel-level RAM disks. This thing is called tmpfs . All we need is to mount tmpfs in any place convenient for us. Create a directory
.chrome/ramdiskin your home directory and add the following line to /etc/fstab:tmpfs /home/сс/.chrome/ramdisk tmpfs noatime,nodiratime,nodev,nosuid,uid=1000,gid=100,mode=0700,size=300M 0 0
replacing it
ссwith the name of your user, uidand gid- with its identifiers (you can find them out with the command id), size- with the desired disk size. If you have at least a spoonful of RAM, then you can take a larger size. A feature of tmpfs is that the specified size will not be backed up in memory - memory will not be wasted at all until you actually cram data into the RAM disk. With the command, df -hyou can always see how full this and other mounted drives are.2. Send the local Chrome data to our RAM disk
No fraud with the settings and chrome keys do not need. All Unix file systems support symbolic links. Therefore stupidly redirect
~/.config/google-chromeand ~/.cache/google-chromein our CD:cd ~/.chrome/ramdisk
mkdir cache config
ln -s ~/.config/google-chrome config
ln -s ~/.cache/google-chrome cache
3. Limit cache sizes in Google Chrome
We will not play with the keys again, but use the policies . To do this, create a file
/etc/opt/chrome/policies/managed/cache-size.jsonwith the following contents:{
"DiskCacheSize": 40000000,
"MediaCacheSize": 30000000
}
where digits are the sizes of the shared cache and media cache, respectively. You can change it to your taste, but making sure that the size
~/.config/google-chrome+ the indicated sizes fill the disk by 80 percent. For the size of the first directory is not regulated in any way, DiskCacheSizeand MediaCacheSizeare not at all tight boundaries: Chrome can slightly exceed them if it is really needed. At the time of this writing, my RAM disk is used at 83%:$ df -h ~/.chrome/ramdisk
Filesystem Size Used Avail Use% Mounted on
tmpfs 300M 249M 52M 83% /home/cc/.chrome/ramdisk
4. We maintain the state of the RAM disk between reboots of the computer
As soon as you clicked the “power off” button, all the data from the RAM flew to paradise for bits. We don’t want to start every day with a new sheet - we need to save the RAM-disk to a hard or solid-state drive when leaving the system and restore it at boot. There are approximately a million ways to do this. If you have systemd, you can create a service
/etc/systemd/system/chrome-ramdisk.service:[Unit]
Description=Keep Chrome's RAM disk between power-offs
[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/home/сс/bin/chrome-ramdisk restore
ExecStop=/home/сс/bin/chrome-ramdisk save
[Install]
WantedBy=multi-user.target
where
~/bin/chrome-ramdiskis a simple script that saves a RAM disk to a tar archive or, on the contrary, extracts this archive to an empty RAM disk:#!/bin/bash
shopt -s dotglob
cd /home/cc/.chrome
if [[ "$1" == "save" ]]; then
rm ramdisk.tar
tar cpf ramdisk.tar ramdisk/*
elif [[ "$1" == "restore" ]]; then
rm -rf ramdisk/*
tar xf ramdisk.tar
fi
Service is enabled by the team
$ sudo systemctl enable chrome-ramdisk.service
If you were taught to hate Lennart P., then a similar effect can be obtained in the good old init-scripts, using
rc.local, rc.local_shutdownor similar scripts.PS Google Chrome and Chromium are not exactly the same thing. In particular, they have different paths to the configuration directories, cache and policies. Article written for Google Chrome. A minute of googling will provide you with the necessary paths for chromium.
A mustache.