What is icon-theme.cache?
When I run the following command on my Lubuntu 12.10
[11:09 PM] ~ $ find /usr/share/icons/ -iname icon-theme.cache -type f
I get the following (after adding the last modified date and size):
/usr/share/icons/lubuntu/icon-theme.cache 20121125 61.2 KiB
/usr/share/icons/Humanity-Dark/icon-theme.cache 20120810 40.6 KiB
/usr/share/icons/Humanity/icon-theme.cache 20120810 931.9 KiB
/usr/share/icons/gnome/icon-theme.cache 20121017 65.8 MiB
/usr/share/icons/ubuntu-mono-light/icon-theme.cache 20130408 140.0 KiB
/usr/share/icons/LoginIcons/icon-theme.cache 20130408 628 bytes
/usr/share/icons/ubuntu-mono-dark/icon-theme.cache 20130408 139.9 KiB
/usr/share/icons/hicolor/icon-theme.cache 20130406 12.4 MiB
/usr/share/icons/elementary-mono-dark/icon-theme.cache 20120926 12.4 KiB
And all these files, as shown in the example below, are of type TrueType font data
:
[11:09 PM] ~ $ file /usr/share/icons/hicolor/icon-theme.cache
/usr/share/icons/hicolor/icon-theme.cache: TrueType font data
My questions, all closely related, are:
- What is
icon-theme.cache
and what is its function? What is the meaning ofcache
in these filenames? The cache tag definition is this: "a cache stores temporary data nearby so that it can be retrieved much more quickly than fetching it from the real backing store (disk, network), or recalculating some result all over again". - Why are the file sizes so diverse? Are the
gnome
andhicolor
ones the largest because they provide the fallback icons (as I read somewhere)? - What about the dates? I'm only sure about the
ubuntu-mono
ones because they came along when I installedlight-themes
on 20130408. So do these files get modified during the course of switching themes or are the dates just a reflection of the date of installation?
Solution 1:
To understand why we need these files, you need to first understand the concept of mapping files to memory.
Memory Mapped Files: Memory mapped files are segments of virtual memory that are directly mapped to a physical file on disk, byte-by-byte. It has a number of benefits over traditional stream based I/O, such as performance during random access to large files, or the ability to share the mapped memory between different threads and processes.
Accessing memory mapped files is faster than using direct read and write operations for two reasons. Firstly, a system call is orders of magnitude slower than a simple change to a program's local memory. Secondly, in most operating systems the memory region mapped actually is the kernel's page cache (file cache), meaning that no copies need to be created in user space.
Now, taking your questions one by one:
- What is icon-theme.cache and what is its function? What is the meaning of cache in these filenames?
The file icon-theme.cache contains cached information about the icons in the directory tree below a certain directory (which happens to be the one containing index.theme
for the particular theme).
GTK+ can use the cache files to avoid a lot of system call and disk seek overhead when the application starts. Since the format of the cache files allows them to be memory mapped shared between multiple applications, the overall memory consumption is reduced as well.
- Why are the file sizes so diverse?
The file sizes depend on the number of icons in the icon theme.
- What about the dates?
If we take memory caches, something is present in cache only if some process accesses a particular memory location and remains there unless the cache is full and that element needs to be removed.
Hence, the modification date would most likely depend on when some process updated it. In this case, it might be when the icons from the theme were used.
There is, indeed, a command to update the icon cache named gtk-update-icon-cache
.
Sources and further information:
-
Wikipedia - Memory Mapped File
-
StackOverflow - Advantages of Memory Mapped Files
-
MSDN - Memory Mapped File Quirks
-
gtk-update-theme-cache
man page -
man gtk-update-icon-cache
in current (13.04) man pages