KDE System Administration/Caches: Difference between revisions

From KDE UserBase Wiki
m (1 revision imported)
m (→‎KSycoca: fixing typo)
 
(3 intermediate revisions by one other user not shown)
Line 6: Line 6:
until the Desktop session becomes usable.
until the Desktop session becomes usable.


This page is intended to give an overview of the existing caches and
This page gives an overview of the existing caches and
provide tips on how to improve the caching behavior in your setup.
provides tips on how to improve the caching behavior in your setup.


== General ==
== General ==
Caches are placed by default into /var/tmp/kdecache-<username> and
In KDE 5, caches are placed in <code>$HOME/.cache</code>.
a symlink pointing to that cache is placed in the KDEHOME directory
In KDE 4, caches are placed by default into <code>/var/tmp/kdecache-''username''</code> and
under cache-<hostname>. You can move that loctation by modifing the
a symlink pointing to that cache is placed in the KDEHOME (<code>$HOME/.kde</code> if not set) directory
[http://techbase.kde.org/KDE_System_Administration/Environment_Variables#KDEVARTMP KDEVARTMP]
under <code>cache-''hostname''</code>. You can change that location by setting the
[https://techbase.kde.org/KDE_System_Administration/Environment_Variables#KDEVARTMP KDEVARTMP]
environment variable.
environment variable.


All caches are memory mapped at startup to improve perfomance when
All caches are memory mapped at startup to improve performance when
their contents are accessed. Each user needs is own cache with write
their contents are accessed. Each user needs their own cache with write
access to it.
access to it.


=== KSycoca ===
=== KSycoca ===
KSycoca is the "KDE SYstem COnfiguration CAche". It contains a binary
KSycoca is the "KDE SYstem COnfiguration CAche". It contains a binary
representation of the various .desktop files that provide information
representation of the various <code>.desktop</code> files that provide information
about installed software and services and which default applications
about installed software and services and which default applications
should be used. (See [http://techbase.kde.org/KDE_System_Administration/XDG_Filesystem_Hierarchy
should be used.
XDG_Filesystem_Hierarchy] for more information about desktop files.
(See [http://techbase.kde.org/KDE_System_Administration/XDG_Filesystem_Hierarchy XDG Filesystem Hierarchy]
for more information about desktop files.)
Due to the potential number of desktop files and locations where
Due to the potential number of desktop files and locations where
the desktop files can be stored rebuilding the KSycoca cache can take
the desktop files can be stored rebuilding the KSycoca cache can take
Line 32: Line 34:


To check how long this takes on your system you can trigger a full rebuild
To check how long this takes on your system you can trigger a full rebuild
of the KSycoca database by executing:
of the KSycoca database by executing the following in a terminal:
     kbuildsycoca4 --noincremental
     kbuildsycoca5 --noincremental


KSycoca should rebuild as necessary when your configuration changes, but you can always rebuild it manually by running <kbd>kbuildsycoca5</kbd>
==== Caches and Rebuilding KSycoca in a flatpak ====
When you run a KDE application as a sandboxed [[community:Guidelines_and_HOWTOs/Flatpak|Flatpak,]] it has its own local cache directory.
If the KSycoca database in this cache does not update automatically (see {{bug|408010}}), you can rebuild it for a Flatpak application by executing the following in a terminal:
  flatpak run --command=kbuildsycoca5 ''APPID''
where ''APPID'' is the application ID, for example <code>org.kde.skrooge</code>.
Within the Flatpak application's environment, the XDG_CACHE_HOME environment variable specifies the cache directory,
a subdirectory of the per-user per-application directory specified by FLATPAK_SANDBOX_DIR;
as of Flatpak version 1.2 this is <code>$HOME/.var/app/''APPID''/cache</code>.


=== Icon Cache ===
=== Icon Cache ===
Line 57: Line 70:
mostly small and do not considerably affect the performance of the
mostly small and do not considerably affect the performance of the
Desktop session as a whole.
Desktop session as a whole.


== Using prepared caches to increase performance ==
== Using prepared caches to increase performance ==
Line 63: Line 75:
you can create an up to date cache for your system and copy it on
you can create an up to date cache for your system and copy it on
startup into the users cache directory. This will significantly reduce
startup into the users cache directory. This will significantly reduce
the number of "open" system calls excuted when starting a KDE
the number of "open" system calls executed when starting a KDE
Desktop session.
Desktop session.
In a deployment where the start of a desktop session took ~80 seconds
In a deployment where the start of a desktop session took ~80 seconds

Latest revision as of 06:05, 25 October 2020

System Caches

There are several caches for KDE data that are created when they are first needed. Especially in setups where there is no persistent HOME directory available or where NFS is used, the creation of the caches can considerably increase the time it takes after login until the Desktop session becomes usable.

This page gives an overview of the existing caches and provides tips on how to improve the caching behavior in your setup.

General

In KDE 5, caches are placed in $HOME/.cache. In KDE 4, caches are placed by default into /var/tmp/kdecache-username and a symlink pointing to that cache is placed in the KDEHOME ($HOME/.kde if not set) directory under cache-hostname. You can change that location by setting the KDEVARTMP environment variable.

All caches are memory mapped at startup to improve performance when their contents are accessed. Each user needs their own cache with write access to it.

KSycoca

KSycoca is the "KDE SYstem COnfiguration CAche". It contains a binary representation of the various .desktop files that provide information about installed software and services and which default applications should be used. (See XDG Filesystem Hierarchy for more information about desktop files.) Due to the potential number of desktop files and locations where the desktop files can be stored rebuilding the KSycoca cache can take a while, especially if your /usr directory is mounted on a Network File System.

To check how long this takes on your system you can trigger a full rebuild of the KSycoca database by executing the following in a terminal:

   kbuildsycoca5  --noincremental

KSycoca should rebuild as necessary when your configuration changes, but you can always rebuild it manually by running kbuildsycoca5

Caches and Rebuilding KSycoca in a flatpak

When you run a KDE application as a sandboxed Flatpak, it has its own local cache directory. If the KSycoca database in this cache does not update automatically (see bug #408010), you can rebuild it for a Flatpak application by executing the following in a terminal:

 flatpak run --command=kbuildsycoca5 APPID

where APPID is the application ID, for example org.kde.skrooge.

Within the Flatpak application's environment, the XDG_CACHE_HOME environment variable specifies the cache directory, a subdirectory of the per-user per-application directory specified by FLATPAK_SANDBOX_DIR; as of Flatpak version 1.2 this is $HOME/.var/app/APPID/cache.

Icon Cache

The icon cache is used to store the decompressed pixmaps of used icons so that they can be shared in multiple applications. Although the icon cache does not considerably affect the time it takes for the KDE Desktop to become available after login, it can create a bad user experience when after a long login the users finally opens an icon intensive application like the Start Menu as this will again result in a large number of system calls to find the best size of an icon in various locations.

Plasma Cache

The plasma cache is the largest of the caches when you use Plasma Desktop. But again this contains mostly decompressed Pixmaps of images (like your wallpaper). As those pixmaps are transferred while they are still compressed, persisting this cache on an NFS might even negatively affect your performance.

Other Caches

There are some other caches used by various applications but those are mostly small and do not considerably affect the performance of the Desktop session as a whole.

Using prepared caches to increase performance

To avoid rebuilding the KSycoca and the Icon cache for each new user you can create an up to date cache for your system and copy it on startup into the users cache directory. This will significantly reduce the number of "open" system calls executed when starting a KDE Desktop session. In a deployment where the start of a desktop session took ~80 seconds the startup time could be reduced by this measure to ~50 seconds.

The downside is that you have to manually update this cache after installing or updating new software.

To create your caches:

  • Log in with a fresh user. Open the start menu, maybe start an often used application like dolphin.
  • Copy the files: icon-cache.kcache kdesycoca4 and kdesycoca4stamp from the users cache directory to a globally readable folder e.g.: /var/cache/kde
  • Set an environment variable pointing to the cache. You can do this with:
echo "export KDE_PREP_CACHE=/var/cache/kde" > /usr/share/env/global-cache.sh

(This will be sourced by the startkde script)


Then apply the following patch to your startkde script (or do something similar in there):

--- startkde.orig 2012-11-28 10:38:50.000000000 +0000
+++ startkde 2012-11-29 10:50:05.000000000 +0000
@@ -255,6 +255,28 @@
     fi
 done
 
+# Check if there are prepared caches and copy them to the
+# users location if he does not have any caches.
+# You can use this to speed up initial KDE startup times.
+if test -n "$KDE_PREP_CACHE"; then
+    cache_config_path=$(kde4-config --path cache)
+    if test -f "${KDE_PREP_CACHE}/icon-cache.kcache"; then
+        cp -u --preserve=timestamps "${KDE_PREP_CACHE}/icon-cache.kcache" "${cache_config_path}/icon-cache.kcache"
+        touch ${cache_config_path}/global_icon_cache_used
+    fi
+    if test -f "${KDE_PREP_CACHE}/ksycoca4" -a "${KDE_PREP_CACHE}/ksycoca4stamp"; then
+        if test -n "${KDESYCOCA}"; then
+            cp -u --preserve=timestamps "${KDE_PREP_CACHE}/ksycoca4" "${KDESYCOCA}"
+            cp -u --preserve=timestamps "${KDE_PREP_CACHE}/ksycoca4stamp" "${KDESYCOCA}stamp"
+            touch ${cache_config_path}/global_sycoca_used
+        else
+            cp -u --preserve=timestamps "${KDE_PREP_CACHE}/ksycoca4" "${cache_config_path}"
+            cp -u --preserve=timestamps "${KDE_PREP_CACHE}/ksycoca4stamp" "${cache_config_path}"
+            touch ${cache_config_path}/global_sycoca_used
+        fi
+    fi
+fi
+
 # In case of dcop sockets left by a previous session, cleanup
 #dcopserver_shutdown