📜 ⬆️ ⬇️

Migrate Google Chrome to RAM Disk on Linux

I will describe a simple way to transfer the cache, settings, and other local Google Chrome data to a RAM disk in Linux. This will speed up browser speed and eliminate disk abuse (which is especially critical if you have an SSD).

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 tools to ensure that our task is solved in 10 minutes, head on 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 required. Linux supports kernel-level RAM disks. This thing is called tmpfs . All we need is to mount tmpfs at any convenient place. Create a .chrome/ramdisk directory in 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 with the name of your user, uid and gid with his identifiers (you can find them out with the id command), size with the desired disk size. If you have a RAM at least eat a spoon, then the size can be taken and more. 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 write data into the RAM disk. With the df -h command you can always see how full this and other mounted disks are.

2. We send local Chrome data to our RAM disk



No fiddling with the settings and chrome keys do not need. All unix file systems support symbolic links. Therefore, we stupidly redirect ~/.config/google-chrome and ~/.cache/google-chrome to our disk:

 cd ~/.chrome/ramdisk mkdir cache config ln -s ~/.config/google-chrome config ln -s ~/.cache/google-chrome cache 


3. We limit the size of the cache in Google Chrome



We will not play with keys again, but use policies . To do this, create a file /etc/opt/chrome/policies/managed/cache-size.json with the following content:

 { "DiskCacheSize": 40000000, "MediaCacheSize": 30000000 } 

where tsiferki - this is the size of the total cache and media cache, respectively. You can change it to your taste, but make sure that the size of ~/.config/google-chrome + specified sizes fill the disc by 80 percent. For the size of the first directory is not regulated at all, and DiskCacheSize and MediaCacheSize are not at all rigid boundaries: Chrome can be few exceed if very necessary. At the time of this writing, the RAM disk is used by 83%:

 $ df -h ~/.chrome/ramdisk Filesystem Size Used Avail Use% Mounted on tmpfs 300M 249M 52M 83% /home/cc/.chrome/ramdisk 


4. Maintain the state of the RAM disk between computer reboots



As soon as you pressed the “power off” button, all the data from the RAM went to the paradise for bits. We do not want to start every day with a new sheet - we need to save the RAM disk to a hard disk or solid state disk when leaving the system and restore it at boot. There are roughly a million ways to do this. If you have systemd, you can create the /etc/systemd/system/chrome-ramdisk.service 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-ramdisk is a simple script that saves a RAM disk to a tar archive or, on the contrary, extracts this archive into 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 have been taught to hate Lennart P., then a similar effect can be obtained in good old init-scripts using rc.local, rc.local_shutdown or similar scripts.



PS Google Chrome and Chromium are not exactly the same thing. In particular, they have different paths to the settings directories, cache and policies. Article written for Google Chrome. A minute of googling will provide you with the right paths for chromium.

Truncated

Source: https://habr.com/ru/post/205158/


All Articles