Tmpfs Tools Profile Sync Daemon (PSD)

From WikiMLT

Pro­file-sync-dae­mon (psd) is a tiny pseu­do-dae­mon de­signed to man­age your browser's pro­file in tmpfs and to pe­ri­od­i­cal­ly sync it back to your phys­i­cal disc (HDD/SSD). This is ac­com­plished via a sym­link­ing step and an in­no­v­a­tive use of rsync to main­tain back-up and syn­chro­niza­tion be­tween the two. One of the ma­jor de­sign goals of psd is a com­plete­ly trans­par­ent user ex­pe­ri­ence.

It is de­signed to work on desk­top sys­tems, but by cre­at­ing cus­tom fake pro­files it could be used for non pro­duc­tion servers :) Cur­rent­ly I'm us­ing it to min­i­mize Brave brows­er disk writ­ings. More in­for­ma­tion about the PSD's Brave pro­file could be foun in the ref­er­ences sec­tion be­low.

Iden­ti­fy the Prob­lem

#Prepa­ra­tion de­tails
Iden­ti­fy which di­rec­to­ries has high I/O rate by the fol­low­ing com­mand.
sudo watch -d -n 1 "find ~/.cache ~/.config -type f -size +80k -mmin -10 -printf '%-30s \t %t %p\n'"
Check the cur­rent size of the iden­ti­fied di­rec­to­ries.
du -hs ~/.cache ~/.config
Take a sta­tis­tic for the av­er­age disk write per minute be­fore the set­up.
iostat -h /dev/nvme0n1 -d 60 -t

In­stall PSD

The PSD tool is avail­able as pack­age for many Lin­ux dis­tri­b­u­tions. Here is how to in­stall on Debian/​​​Kali.

sudo apt install profile-sync-daemon

How­ev­er the Debian's pack­age is lit­tle bit old­er but works sta­ble. If you want the lat­est ver­sion in­stall it from its GitHub repos­i­to­ry by per­form­ing the fol­low­ing steps.

cd ~/Git # or ~/Downloads or where you prefer
git clone https://github.com/graysky2/profile-sync-daemon.git
cd profile-sync-daemon
make
sudo make install

Set­up PSD

With­in the lat­est ver­sion on GitHub is avail­able a pro­file for Brave brows­er al­so there is a dis­cus­sion about it. How­ev­er I pre­fer to cre­ate two cus­tom pro­files: 1) the first will han­dle ~/.config/BraveSoftware/Brave-Browser, and 2) the sec­ond will han­dle ~/.cache/BraveSoftware/Brave-Browser.

echo -e 'DIRArr[0]="$XDG_CONFIG_HOME/BraveSoftware/Brave-Browser"\nPSNAME="brave"' | \
sudo tee /usr/share/psd/browsers/brave
echo -e 'DIRArr[0]="'"$HOME"'/.cache/BraveSoftware/Brave-Browser"\nPSNAME="brave-cache"' | \
sudo tee /usr/share/psd/browsers/brave-cache

The next step is to add brave and brave-cache to the PSD user's con­fig­u­ra­tion file – psd.conf.

echo -e '\nBROWSERS="brave brave-cache"' >> ~/.config/psd/psd.conf

I pre­fer al­so to en­able the use of over­layfs mode to im­prove sync speed and to use a small­er mem­o­ry foot­print. The first thing ac­cord­ing to that is to add en­try in the psd.conf file, and al­so an en­try in­to the sudoers.d di­rec­to­ry, be­cause this fea­ture re­quires more per­mis­sions.

echo -e '\nUSE_OVERLAYFS="yes"' >> ~/.config/psd/psd.conf
echo "$USER ALL=(ALL) NOPASSWD: /usr/bin/psd-overlay-helper" | \
sudo tee -a /etc/sudoers.d/psd-overlay-helper
  • Note it is bet­ter and save to use just echo "$USER ALL=(ALL) NOPASS­WD: /us­r/bin/psd-over­lay-helper" to gen­er­ate the line and the use su­do vi­su­do /etc/sudoers.d/psd-overlay-helper.

In ad­di­tion you can en­able the sus­pend-sync fea­ture.

echo -e '\nUSE_SUSPSYNC="yes"' >> ~/.config/psd/psd.conf

This fea­ture re­quires glib2 li­brary, it could be in­stalled on nowa­days Debian/​​​Ubuntu/​​​Kali/​​​etc. via the fol­low­ing com­mand.

sudo apt install libglib2.0-dev

Us­age

You can use man psd to get de­tailed in­for­ma­tion. How­ev­er here are few es­sen­tial com­mands.

PRE­VIEW MODE. The pre­view op­tion can be called to show users ex­act­ly what psd will do/​​​is do­ing based on the en­tries in the con­fig file. It will al­so pro­vide use­ful in­for­ma­tion such as pro­file size, paths, and if any re­cov­ery snap­shots have been cre­at­ed.

psd p
Profile-sync-daemon v6.45

 systemd service: active
 resync-timer:    active
 sync on sleep:   disabled
 use overlayfs:   enabled

Psd will manage the following per /home/<user>/.config/psd/.psd.conf:

 browser/psname:  brave/brave
 owner/group id:  <user>/1000
 sync target:     /home/<user>/.config/BraveSoftware/Brave-Browser
 tmpfs dir:       /run/user/1000/psd/<user>-brave
 profile size:    420M
 overlayfs size:  85M
 recovery dirs:   none

 browser/psname:  brave-cache/brave-cache
 owner/group id:  <user>/1000
 sync target:     /home/<user>/.cache/BraveSoftware/Brave-Browser
 tmpfs dir:       /run/user/1000/psd/<user>-brave-cache
 profile size:    277M
 overlayfs size:  21M
 recovery dirs:   none

START AND STOP PSD. Psd  ships  with a sys­temd user ser­vice to start or stop it (psd.service). Ad­di­tion­al­ly, a pro­vid­ed re­sync-timer will run an hourly re­sync from tmpfs back to the disk. The re­sync-timer is start­ed au­to­mat­i­cal­ly with psd.service so there is no need to start the timer; on­ly start psd.service.

systemctl --user status psd.service
systemctl --user start psd.service
systemctl --user stop psd.service
systemctl --user enable psd.service
systemctl --user disable psd.service

Tweak the rsync-timer.

systemctl --user cat psd-resync.timer
systemctl --user edit psd-resync.timer

CLEAN MODE. The clean mode will delete ALL re­cov­ery snap­shots that have ac­cu­mu­lat­ed. On­ly run it when sure these are no longer need­ed.

psd c

Ref­er­ences