- Configure
/tmp
as perfstab
, adjustsize
if needed - Copy
xdg-cache.service
to/etc/systemd/user/xdg-cache.service
- Copy
xdg-cache.sh
to/usr/local/bin/xdg-cache.sh
and thenchmod +x /usr/local/bin/xdg-cache.sh
- Run
systemctl --user enable xdg-cache.service
as the user that needs this service
Created
January 28, 2020 04:02
-
-
Save Frederick888/caa65717541dab3bb7f827d9f281f1ca to your computer and use it in GitHub Desktop.
Offloading XDG cache home to tmpfs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tmpfs /tmp tmpfs defaults,noatime,nosuid,nodev,mode=1777,size=24G 0 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=Synchronises XDG cache between disk and tmpfs for %u | |
Before=default.target | |
[Service] | |
Type=oneshot | |
RemainAfterExit=true | |
ExecStart=/usr/local/bin/xdg-cache.sh ram | |
ExecStop=/usr/local/bin/xdg-cache.sh | |
StandardOutput=journal | |
StandardError=journal | |
TimeoutStopSec=1m | |
[Install] | |
WantedBy=default.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
PERSIST_DIR="$HOME/.cache" | |
TMP_DIR="/tmp/$USER/.cache" | |
if [[ "$1" == "ram" ]]; then | |
# to ram | |
if [ -d "$PERSIST_DIR" ]; then | |
#TIME='%C %Us user %Ss system %es total' time rsync -aq "$PERSIST_DIR/" "$TMP_DIR" | |
mkdir -p "$TMP_DIR" "$TMP_DIR-upper" | |
TIME='%C %Us user %Ss system %es total' time unionfs \ | |
-o rw,async,exec,suid,dev,nonempty,default_permissions,allow_other \ | |
-o use_ino,cow,statfs_omit_ro,hide_meta_files,max_files=65536 \ | |
"$TMP_DIR-upper=RW:$PERSIST_DIR=RO" "$TMP_DIR" | |
fi | |
elif [ -d "$TMP_DIR" ]; then | |
# to disk | |
TIME='%C %Us user %Ss system %es total' time rsync -ai --delete --delete-excluded --ignore-missing-args \ | |
--exclude='/google-chrome' \ | |
--exclude='/yay/*/' \ | |
--exclude='/pip' \ | |
--exclude='/kioexec' \ | |
--exclude='/wine' \ | |
--exclude='/go-build' \ | |
--exclude='/rclone' \ | |
--exclude='/spotify' \ | |
--exclude='/.nv' \ | |
"$TMP_DIR/" "$PERSIST_DIR" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment