Repository navigation
system_configuration.md
This section includes efficient package management, optimization of the makepkg build process, automated cache maintenance, deployment of RAM-compressed block devices using zram for enhanced memory management, installation of alternative kernels, and advanced shell and prompt customization. Each section is designed to maximize system efficiency, minimize maintenance overhead, and ensure optimal performance across a variety of hardware profiles.
- AUR helper and makepkg configuration
- Package manager configuration
- Cache hooks
- Compressed RAM block device configuration
- Additional kernel installation
- Shell and prompt configuration
The initial installation of Yay can be done by cloning the PKGBUILD and building with makepkg:
We make sure we have the base-devel package group installed.
# pacman -S --needed git base-devel
# git clone https://aur.archlinux.org/yay.git
# cd yay
# makepkg -si
The makepkg build system allows configuration for faster and leaner package builds. These optimizations are particularly beneficial on personal systems where build-time performance is prioritized over extensive debugging or maximum binary optimization.
The make build system uses the MAKEFLAGS environment variable to specify additional options for make. The variable can also be set in the /etc/makepkg.conf file.
Users with multi-core/multi-processor systems can specify the number of jobs to run simultaneously. This can be accomplished with the use of nproc(1) to determine the number of available processors. To automatically set the number of parallel jobs according to the number of available processors, add to /etc/makepkg.conf:
MAKEFLAGS="--jobs=$(nproc)"Commit 90bf367e included in pacman 6.0.2-9 from Feburary 2024 enabled the debug and lto options by default.
Building debug packages enables the official repositories to provide more tools to troubleshoot issues for users, but it is not required when building packages on your own and slows down the build process.
Link-time optimization produces more optimized binaries but greatly lengthens the build process, which might not be a desired tradeoff.
To disable those options, add a ! character directly in front of them in the OPTIONS=() array in /etc/makepkg.conf:
OPTIONS=(...!debug !lto...).The pacman-contrib package provides a collection of supplementary tools and scripts that enhance the functionality of pacman, Arch Linux's package manager. These utilities assist in tasks such as cache management, configuration file handling, repository analysis, and more.
The downgradeAUR package is a bash script to downgrade one (or multiple) packages by using the pacman cache or the Arch Linux Archive.
Since pacman 7.0.0.r6.gc685ae6-2 the number of packages being downloaded in parallel (at the same time) is set with ParallelDownloads under [options] in /etc/pacman.conf to default value 5. If the option is unset, packages will be downloaded sequentially.
[options]
ParallelDownloads = 5The multilib repository provides 32-bit libraries, which are necessary for running certain applications like Steam and Wine on a 64-bit Arch Linux system. By default, this repository is disabled. To enable the multilib repository uncomment the following lines in /etc/pacman.conf:
[multilib]
Include = /etc/pacman.d/mirrorlistPacman stores its downloaded packages in /var/cache/pacman/pkg/ and does not remove the old or uninstalled versions automatically. This has some advantages:
It allows to downgrade a package without the need to retrieve the previous version through other means, such as the Arch Linux Archive. A package that has been uninstalled can easily be reinstalled directly from the cache directory, not requiring a new download from the repository. However, it is necessary to deliberately clean up the cache periodically to prevent the directory to grow indefinitely in size.
The paccache(8) script, provided within the pacman-contrib package, deletes all cached versions of installed and uninstalled packages, except for the most recent three, by default:
# paccache -r
You can also define how many recent versions you want to keep. To retain only one past version use:
# paccache -rk1
Add the -u/--uninstalled switch to limit the action of paccache to uninstalled packages. For example to remove all cached versions of uninstalled packages, use the following:
# paccache -ruk0
See paccache -h for more options.
Tip: You can create a hook to run this automatically after every pacman transaction, alternatively, install
paccache-hookAUR andyaycache-hookAUR.
The paccache-hookAUR package provides a configurable pacman hook that automatically cleans the package cache after transactions. It utilizes the paccache utility from pacman-contrib to remove old package versions, helping to conserve disk space.
The configuration is stored in /etc/paccache-hook.conf.
For users of the yay AUR helper, yaycache-hookAUR offers similar functionality, automatically cleaning the yay cache post-transactions.
The configuration is stored in /etc/yaycache-hook.conf.
zram, formerly called compcache, is a Linux kernel module for creating a compressed block device in RAM, i.e. a RAM disk with on-the-fly disk compression. The block device created with zram can then be used for swap or as a general-purpose RAM disk. The two most common uses for zram are for the storage of temporary files (/tmp) and as a swap device. Initially, zram had only the latter function, hence the original name "compcache" ("compressed cache").
Initially the created zram block device does not reserve or use any RAM. Only as files need or want to be swapped out, they will be compressed and moved into the zram block device. The zram block device will then dynamically grow or shrink as required.
Tip: When configuring zram, the size of the zram device controls the maximum uncompressed amount of data it can store, not the maximum compressed size. You can configure the zram's size to be equal to or even greater than your system's physical RAM capacity, as long as the compressed size on physical RAM will not exceed your system's physical RAM capacity.
Tip: If the related zswap kernel feature remains enabled, it will prevent zram from being used effectively. This is because zswap functions as a swap cache in front of zram, intercepting and compressing evicted memory pages before they can reach zram. Despite the output of zramctl(8), most of zswap is unused in this circumstance. Therefore, it's recommended to permanently disable zswap using the kernel parameter or sysfs setting before starting.
Tip: Hibernating to swap on zram is not supported, even when zram is configured with a backing device on permanent storage. logind will protect against trying to hibernate to a swap space on zram.
Contemporary kernels allocate one compression stream per CPU core within a single zram device, so multiple devices per core are not needed kernel.org. The old practice of “one zram per CPU core” applied only to kernels before ~3.15 wiki.gentoo.org.
zram-generator provides systemd-zram-setup@zramN.service units to automatically initialize zram devices without users needing to enable/start the template or its instances. See zram-generator(8).
To use it, install zram-generator, and create /etc/systemd/zram-generator.conf with the following:
[zram0]
zram-size = min(ram / 2, 16384)
compression-algorithm = lz4
swap-priority = 1000-
zram-sizeis the size (inMiB) of zram device, you can useramto represent the total memory. -
compression-algorithmspecifies the algorithm used to compress in zram device.cat /sys/block/zram0/comp_algorithmgives the available compression algorithm (as well as the current one included in brackets). See zram-generator.conf(5). The selected algorithm for zram islz4, which offers very fast (de)compression with moderate ratio, and it yields low CPU overhead and latency. By contrast,zstdgives a higher compression ratio (saves more memory) but is much slower, so it’s best on low-memory systems or for cold data. Benchmarks show thatzstdachieves ~3.8–4× compression whilelz4yields ~2.6–2.7×, butlz4’s throughput is several times higher.
| Compression Algorithm | System RAM & GPU Type |
|---|---|
zstd |
for systems <16GB |
zstd |
for <24GB systems with an iGPU (since that will 'steal' system memory) |
lz4 |
for ≥16GB systems with a discrete GPU |
lz4 |
for ≥24GB systems with an iGPU |
-
swap-prioritycontrols the relative swap priority, a value between -1 and 32767. Higher numbers indicate higher priority. If unset, 100 is used, see zram-generator.conf(5). If you have more than one swap file or swap partition you should ensure any disk swap has a lower priority value (0 to 32767) so that zram is used first. This makes zram the preferred swap. The system will use swap areas of higher priority before using swap areas of lower priority. For example, if you have a faster disk and a slower disk, assign a higher priority to the swap area located on the fastest device. Priorities can be assigned in etc/fstab via thepriparameter:
UUID=f9fe0b69-a280-415d-a03a-a32752370dee none swap defaults,pri=100 0 0
UUID=d7eb6062-01c8-4367-ac1d-3bf1167de8bb none swap defaults,pri=10 0 0Make sure the related zswap kernel feature remains disabled, to disable zswap permanently on kernels where it is enabled by default, add zswap.enabled=0 to your kernel parameters.
options root=UUID=0a3407de-014b-458b-b5c1-848e92a327a3 rw zswap.enabled=0Then run daemon-reload, start your configured systemd-zram-setup@zramN.service instance (N matching the numerical instance-ID, in the example it is systemd-zram-setup@zram0.service).
# systemctl daemon-reload
# systemctl restart systemd-zram-setup@zram0.service
When memory usage reaches a certain threshold, the kernel starts looking at active memory and seeing what it can free up. File data can be written out to the file system (if changed), unloaded and re-loaded later; other data must be written to swap before it can be unloaded.
The swappiness sysctl parameter represents the kernel's preference for writing to swap instead of files. It can have a value between 0 and 200 (max 100 if Linux < 5.8); the default value is 60. A low value causes the kernel to prefer freeing up open files, a high value causes the kernel to try to use swap space, and a value of 100 means IO cost is assumed to be equal.
To check the current swappiness value:
$ sysctl vm.swappiness- Default (60): balanced
- Higher (100–200): more aggressive swapping (use zram sooner)
- Lower (≤60): defer swap use
Since zram behaves differently than disk swap, we can configure the system's swap to take full potential of the zram advantages. To set the swappiness value permanently, create a sysctl.d(5) configuration file in /etc/sysctl.d/99-vm-zram-parameters.conf and add the following:
vm.swappiness = 180
vm.watermark_boost_factor = 0
vm.watermark_scale_factor = 125
vm.page-cluster = 0On a system with a hard drive, random I/O against the in-memory device would be orders of magnitude faster than I/O against the filesystem, so swappiness should be ~200. Even on a system with a fast SSD, a high swappiness value may be ideal.
You can check the swap status of your configured /dev/zramN device(s) by reading the unit status of your systemd-zram-setup@zramN.service instance(s), by using zramctl(8), or by using swapon(8).
$ zramctl
NAME ALGORITHM DISKSIZE DATA COMPR TOTAL STREAMS MOUNTPOINT
/dev/zram0 zstd 32G 1.9G 318.6M 424.9M 16 [SWAP]- DISKSIZE = 32G: this zram device will store up to 32 GiB of uncompressed data.
- DATA = 1.9G: currently, 1.9 GiB (uncompressed) of data is being stored in this zram device
- COMPR = 318.6M: the 1.9 GiB uncompressed data was compressed to 318.6 MiB
- TOTAL = 424.9M: including metadata, the 1.9 GiB of uncompressed data is using up 424.9 MiB of physical RAM
Arch Linux is based on the Linux kernel. There are various alternative Linux kernels available for Arch Linux in addition to the latest stable kernel.
-
Zen Kernel — Result of a collaborative effort of kernel hackers to provide the best Linux kernel possible for everyday systems. For more details see FAQ and Detailed Feature List. https://github.com/zen-kernel/zen-kernel ||
linux-zen -
CachyOS Kernel — The Linux SCHED-EXT + BORE + Cachy Sauce Kernel by CachyOS with other patches and improvements kernel and modules https://github.com/CachyOS/linux-cachyos ||
linux-cachyosAUR
1. System Configuration
1.1. AUR helper and makepkg configuration
1.1.1. AUR helper: yay
1.1.2. Makepkg optimization
1.1.2.1. Parallel compilation
1.1.2.2. Disable debug packages and LTO
1.2. Package manager configuration
1.2.1. Pacman utilities
1.2.2. Downgrading packages
1.2.3. Parallel downloads
1.2.4. Enabling the multilib repository
1.3. Cache hooks
1.3.1. Pacman cache hook
1.3.2. AUR helper (yay) cache hook
1.4. Compressed RAM block device
1.4.1. Creating zram device
1.4.2. Setting sysctl swappiness
1.4.3. Checking zram as swap status