Skip to content

3.3 Read Write Disk Operation Reduction

D3vil0p3r edited this page Oct 22, 2022 · 3 revisions

Avoiding unnecessary access to slow storage drives is good for performance and also increasing lifetime of the devices, although on modern hardware the difference in life expectancy is usually negligible.

Sync Browser Profile

A very good impact on the performance is to move some resources directly to the RAM. One of these could be the browser profile. Relocate files, such as the browser profile, to a tmpfs file system, can improve the application response as all the files are now stored in RAM. For this purpose, in Athena profile-sync-daemon has been used. Its configuration, stored in $HOME/.config/psd/psd.conf, is defined in the following manner:

#
# $XDG_CONFIG_HOME/psd/psd.conf
#
# For documentation, refer man 1 psd or to the wiki page
# https://wiki.archlinux.org/index.php/Profile-sync-daemon

## NOTE the following:
## To protect data from corruption, in the event that you do make an edit while
## psd is active, any changes made will be applied the next time you start psd.

# Uncomment and set to "yes" to use overlayfs instead of a full copy to reduce
# the memory costs and to improve sync/unsync operations. Note that your kernel
# MUST have this module available in order to use this mode.
#
USE_OVERLAYFS="yes"

# Uncomment and set to "yes" to resync on suspend to reduce potential data loss.
# Note that your system MUST have gdbus from glib2 installed to use this mode.
#
#USE_SUSPSYNC="no"

# List any browsers in the array below to have managed by psd. Useful if you do
# not wish to have all possible browser profiles managed which is the default if
# this array is left commented.
#
# Possible values:
#  chromium
#  chromium-dev
#  conkeror.mozdev.org
#  epiphany
#  falkon
#  firefox
#  firefox-trunk
#  google-chrome
#  google-chrome-beta
#  google-chrome-unstable
#  heftig-aurora
#  icecat
#  inox
#  luakit
#  midori
#  opera
#  opera-beta
#  opera-developer
#  opera-legacy
#  otter-browser
#  qupzilla
#  qutebrowser
#  palemoon
#  rekonq
#  seamonkey
#  surf
#  vivaldi
#  vivaldi-snapshot
#
BROWSERS=(firefox)

# Uncomment and set to "no" to completely disable the crash recovery feature.
#
# The default is to create crash recovery backups if the system is ungracefully
# powered-down due to a kernel panic, hitting the reset switch, battery going
# dead, etc. Some users keep very diligent backups and don't care to have this
# feature enabled.
#USE_BACKUPS="yes"

# Uncomment and set to an integer that is the maximum number of crash recovery
# snapshots to keep (the oldest ones are deleted first).
#
# The default is to save the most recent 5 crash recovery snapshots.
#BACKUP_LIMIT=5

Then, the PSD service must be enabled: systemctl --user enable --now psd. In Athena, it is run in run-once.sh script.

PSD must be run automatically on the user behalf, so it is needed to create a file /etc/sudoers.d/sudo_nopasswd_psd with the following content:

%wheel ALL=(ALL) NOPASSWD: /usr/bin/psd-overlay-helper

This file is managed in athena-application-config.

In Athena, as browser, Firefox ESR is used. It needs a little extra step for being configured with PSD. It is needed only to create a symbolic link of the firefox-esr folder named as firefox:

ln -s $HOME/.mozilla/firefox-esr $HOME/.mozilla/firefox

then, firefox-esr folder should be set with 700 permissions for privacy reason.

For checking if the Firefox profile is correctly set, run:

systemctl --user restart profile-sync-daemon
psd p

From this output, check for the entry showing the path of Firefox profile. It should be in /dev/shm or /tmp.

Usually, it is possible to store in RAM also other folders or files for being accessible quickly, but it is important to take care of the RAM available space. For checking which directories are referencing RAM, run df -h and check for all tmpfs entries and check for their available space.

Source: https://forums.linuxmint.com/viewtopic.php?t=344286

Improving Compile Times

Parallel compilation

The make build system uses the MAKEFLAGS environment variable to specify additional options for make. The variable can also be set in the makepkg.conf file.

In /etc/makepkg.conf, set MAKEFLAGS as follows:

MAKEFLAGS="-j$(nproc)"

to determine the number of available processors to be used during the compiling. It has been implemented in athena-system-installation package.

Building from files in memory

As compiling requires many I/O operations and handling of small files, moving the working directory to a tmpfs may bring improvements in build times.

The BUILDDIR variable can be temporarily exported to makepkg to set the build directory to an existing tmpfs. For example:

BUILDDIR=/tmp/makepkg

It has been implemented in athena-system-installation package.

Note that:

  • Avoid compiling larger packages in tmpfs to prevent running out of memory.
  • The tmpfs directory must be mounted without the noexec option, otherwise it will prevent built binaries from being executed.
  • Keep in mind that packages compiled in tmpfs will not persist across reboot. Consider setting the PKGDEST option appropriately to move the built package automatically to a persistent directory.