From 0280edf9f4564acbfc7595e3aacdaeee74949cb7 Mon Sep 17 00:00:00 2001 From: Thomas Kaiser Date: Mon, 15 May 2017 17:45:34 +0200 Subject: [PATCH] Try to implement persistent XDG_CACHE behaviour --- config/chromium.conf | 4 ++-- desktop.sh | 2 +- distributions.sh | 2 +- makeboarddeb.sh | 13 ++++++++++++- scripts/armhwinfo | 12 ++++++------ scripts/log2ram/log2ram | 20 +++++++++++--------- scripts/log2ram/xdgcache2ram.default | 13 +++++++++++++ scripts/log2ram/xdgcache2ram.service | 18 ++++++++++++++++++ 8 files changed, 64 insertions(+), 20 deletions(-) create mode 100644 scripts/log2ram/xdgcache2ram.default create mode 100644 scripts/log2ram/xdgcache2ram.service diff --git a/config/chromium.conf b/config/chromium.conf index 4c472be35..3b0a49947 100644 --- a/config/chromium.conf +++ b/config/chromium.conf @@ -6,7 +6,7 @@ CHROMIUM_FLAGS="\ --disable-smooth-scrolling \ --disable-low-res-tiling \ --enable-low-end-device-mode \ ---num-raster-threads=4 \ +--num-raster-threads=2 \ --profiler-timing=0 \ --disable-composited-antialiasing \ ---disk-cache-size=300000000 \ No newline at end of file +--disk-cache-size=100000000" diff --git a/desktop.sh b/desktop.sh index 3af19cdbe..a4cbab616 100644 --- a/desktop.sh +++ b/desktop.sh @@ -25,7 +25,7 @@ install_desktop () # install optimized chromium configuration cp $SRC/lib/config/chromium.conf $CACHEDIR/$SDCARD/etc/chromium-browser/default - echo "export XDG_CACHE_HOME=\"/var/log/.cache\"" > $CACHEDIR/$SDCARD/etc/chromium-browser/customizations/10-cachedir + echo "export XDG_CACHE_HOME=\"/var/xdgcache\"" > $CACHEDIR/$SDCARD/etc/chromium-browser/customizations/10-cachedir fi # install dedicated startup icons cp $SRC/lib/bin/icons/${RELEASE}.png $CACHEDIR/$SDCARD/usr/share/pixmaps diff --git a/distributions.sh b/distributions.sh index 790ab5188..6d4648177 100644 --- a/distributions.sh +++ b/distributions.sh @@ -138,7 +138,7 @@ install_common() install -m 644 $SRC/lib/scripts/firstrun.service $CACHEDIR/$SDCARD/etc/systemd/system/ # enable additional services - chroot $CACHEDIR/$SDCARD /bin/bash -c "systemctl --no-reload enable firstrun.service resize2fs.service armhwinfo.service log2ram.service >/dev/null 2>&1" + chroot $CACHEDIR/$SDCARD /bin/bash -c "systemctl --no-reload enable firstrun.service resize2fs.service armhwinfo.service log2ram.service xdgcache2ram.service >/dev/null 2>&1" # copy "first run automated config, optional user configured" cp $SRC/lib/config/armbian_first_run.txt $CACHEDIR/$SDCARD/boot/armbian_first_run.txt diff --git a/makeboarddeb.sh b/makeboarddeb.sh index 9a5e99b98..d6efbe920 100644 --- a/makeboarddeb.sh +++ b/makeboarddeb.sh @@ -67,7 +67,7 @@ create_board_package() #!/bin/sh [ remove = "\$1" ] || [ abort-install = "\$1" ] && dpkg-divert --package linux-${RELEASE}-root-${DEB_BRANCH}${BOARD} --remove --rename \ --divert /etc/mpv/mpv-dist.conf /etc/mpv/mpv.conf - systemctl disable log2ram.service armhwinfo.service >/dev/null 2>&1 + systemctl disable log2ram.service xdgcache2ram.service armhwinfo.service >/dev/null 2>&1 exit 0 EOF @@ -88,6 +88,12 @@ create_board_package() if [ -f "/etc/systemd/system/log2ram.service" ]; then mv /etc/systemd/system/log2ram.service /etc/systemd/system/log2ram-service.dpkg-old fi + if [ ! -f "/etc/default/xdgcache2ram" ]; then + cp /etc/default/xdgcache2ram.dpkg-dist /etc/default/xdgcache2ram + fi + if [ -f "/etc/systemd/system/xdgcache2ram.service" ]; then + mv /etc/systemd/system/xdgcache2ram.service /etc/systemd/system/xdgcache2ram-service.dpkg-old + fi exit 0 EOF @@ -286,6 +292,11 @@ create_board_package() install -m 755 $SRC/lib/scripts/log2ram/log2ram.hourly $destination/etc/cron.daily/log2ram cp $SRC/lib/scripts/log2ram/log2ram.default $destination/etc/default/log2ram.dpkg-dist + # xdgcache2ram - persistent xdgcache based on log2ram + cp $SRC/lib/scripts/log2ram/xdgcache2ram.service $destination/lib/systemd/system/xdgcache2ram.service + ln -s /usr/sbin/log2ram $destination/usr/sbin/xdgcache2ram + cp $SRC/lib/scripts/log2ram/xdgcache2ram.default $destination/etc/default/xdgcache2ram.dpkg-dist + if [[ $LINUXFAMILY == sun*i ]]; then install -m 755 $SRC/lib/scripts/armbian-add-overlay $destination/usr/sbin if [[ $BRANCH == default ]]; then diff --git a/scripts/armhwinfo b/scripts/armhwinfo index ee41af039..ed76ba1ad 100644 --- a/scripts/armhwinfo +++ b/scripts/armhwinfo @@ -316,7 +316,7 @@ adjust_chromium_settings() { if [ -f /etc/chromium-browser/default ]; then # create chromium cache directory - [[ ! -d /var/log/.cache ]] && mkdir /var/log/.cache && chgrp netdev /var/log/.cache && chmod g+w /var/log/.cache + [[ ! -d /var/xdgcache ]] && mkdir -m775 /var/xdgcache && chgrp netdev /var/xdgcache && chmod g+w /var/xdgcache # Desktop image. Let's adjust chromium cache size depending on available DRAM (15%) # and count of render threads based on number of CPU cores @@ -324,13 +324,13 @@ adjust_chromium_settings() { memory_total=$(awk '{printf("%d",$2/1024)}' <<<${mem_info}) cpu_cores=$(grep -c processor /proc/cpuinfo) chromium_disk_cache=$(( ${memory_total} * 158000 )) - log2ram_size=$(( 50 + $(( ${memory_total} / 1000 * 150 )) )) + xdgcache_size=$(( ${memory_total} / 1000 * 150 )) - # adjust log2ram config if necessary (switching between devices with different amount + # adjust xdgcache config if necessary (switching between devices with different amount # of DRAM but same OS image) - grep -q "^SIZE=${log2ram_size}M" /etc/default/log2ram || \ - sed -i "s/^SIZE=.*/SIZE=${log2ram_size}M/" /etc/default/log2ram && \ - systemctl restart log2ram + grep -q "^SIZE=${xdgcache_size}M" /etc/default/log2ram || \ + sed -i -e "s/^SIZE=.*/SIZE=${xdgcache_size}M/" -e "s/^ENABLED=.*/ENABLED=true/" \ + /etc/default/xdgcache2ram && systemctl restart xdgcache2ram # adjust chromium settings sed -i -e "s/disk-cache-size=.*/disk-cache-size=${chromium_disk_cache}/" \ diff --git a/scripts/log2ram/log2ram b/scripts/log2ram/log2ram index 2f41a8fd3..db3f536cd 100644 --- a/scripts/log2ram/log2ram +++ b/scripts/log2ram/log2ram @@ -1,22 +1,24 @@ #!/bin/sh -# Source: https://github.com/azlux/log2ram +# Source based on: https://github.com/azlux/log2ram # License: MIT # License file: /usr/share/log2ram/LICENSE SIZE=40M USE_RSYNC=false ENABLED=false +ME="${0##*/}" +DIRNAME="$(sed 's/2ram$//' <<<"${ME}")" -[ -f /etc/default/log2ram ] && . /etc/default/log2ram +[ -f /etc/default/${ME} ] && . /etc/default/${ME} [ "$ENABLED" != true ] && exit 0 # don't touch anything below here. -HDD_LOG=/var/log.hdd/ -RAM_LOG=/var/log/ -LOG2RAM_LOG="${HDD_LOG}log2ram.log" +HDD_LOG=/var/${DIRNAME}.hdd/ +RAM_LOG=/var/${DIRNAME}/ +LOG2RAM_LOG="${HDD_LOG}${ME}.log" LOG_OUTPUT="tee -a $LOG2RAM_LOG" isSafe () { @@ -28,7 +30,7 @@ syncToDisk () { isSafe if [ "$USE_RSYNC" = true ]; then - rsync -aXWv --delete --exclude log2ram.log --links $RAM_LOG $HDD_LOG 2>&1 | $LOG_OUTPUT + rsync -aXWv --delete --exclude ${ME}.log --links $RAM_LOG $HDD_LOG 2>&1 | $LOG_OUTPUT else cp -rfup $RAM_LOG -T $HDD_LOG 2>&1 | $LOG_OUTPUT fi @@ -38,7 +40,7 @@ syncFromDisk () { isSafe if [ "$USE_RSYNC" = true ]; then - rsync -aXWv --delete --exclude log2ram.log --links $HDD_LOG $RAM_LOG 2>&1 | $LOG_OUTPUT + rsync -aXWv --delete --exclude ${ME}.log --links $HDD_LOG $RAM_LOG 2>&1 | $LOG_OUTPUT else cp -rfup $HDD_LOG -T $RAM_LOG 2>&1 | $LOG_OUTPUT fi @@ -51,7 +53,7 @@ case "$1" in rm -f $LOG2RAM_LOG mount --bind $RAM_LOG $HDD_LOG mount --make-private $HDD_LOG - mount -t tmpfs -o nosuid,noexec,nodev,mode=0755,size=$SIZE log2ram $RAM_LOG + mount -t tmpfs -o nosuid,noexec,nodev,mode=0755,size=$SIZE ${ME} $RAM_LOG syncFromDisk ;; @@ -65,7 +67,7 @@ case "$1" in syncToDisk ;; *) - echo "Usage: log2ram {start|stop|write}" >&2 + echo "Usage: ${ME} {start|stop|write}" >&2 exit 1 ;; esac diff --git a/scripts/log2ram/xdgcache2ram.default b/scripts/log2ram/xdgcache2ram.default new file mode 100644 index 000000000..0a385f4a8 --- /dev/null +++ b/scripts/log2ram/xdgcache2ram.default @@ -0,0 +1,13 @@ +# configuration values for the log2ram service +# +# enable the log2ram service? +ENABLED=false +# +# size of the tmpfs mount +SIZE=1M +# +# use rsync instead of cp -r +# requires rsync installed, may provide better performance +# due to copying only new and changed files +USE_RSYNC=true +# diff --git a/scripts/log2ram/xdgcache2ram.service b/scripts/log2ram/xdgcache2ram.service new file mode 100644 index 000000000..cb0ba3543 --- /dev/null +++ b/scripts/log2ram/xdgcache2ram.service @@ -0,0 +1,18 @@ +[Unit] +Description=Armbian enhanced xdgcache based on Log2Ram +DefaultDependencies=no +Before=rsyslog.service syslog.target systemd-journald.service sysinit.target shutdown.target +After=local-fs.target +Conflicts=shutdown.target +RequiresMountsFor=/var/xdgcache /var/xdgcache.hdd +IgnoreOnIsolate=yes + +[Service] +Type=oneshot +ExecStart=/usr/sbin/xdgcache2ram start +ExecStop=/usr/sbin/xdgcache2ram stop +ExecReload=/usr/sbin/xdgcache2ram write +RemainAfterExit=yes + +[Install] +WantedBy=sysinit.target