Optimising Gimp’s temporary and swap storage

Whilst Gimp is a great piece of software, its default behaviour is to put temporary files into the home drive. If for some reason it needs to cache to disk it can become very slow. For me, I thought that creating my swap partition on the SSD would address this. However Gimp doesn’t make use of that space.
In order to address this issue I changed serverpc’s system configuration to use a swap file instead of a swap partion, and placed that file on the system volume (where Debian is installed). Off memory Debian doesn’t provide the option for a swap file at installation, whereas these days Ubuntu defaults to it if you don’t specify a swap partition or use the automatic partitioner. In any case I used these commands to change to a swap file. This system doesn’t hibernate so I don’t need to muck around changing hibernation settings:
  • dd if=/dev/zero of=/swapfile bs=1024 count=X
  • chmod 600 /swapfile
  • mkswap /swapfile
  • swapon /swapfile
In all cases /swapfile is the path and filename of the new swapfile. The dd command creates this file and preallocates its full size as zeros. This ensures the file is contiguous and not fragmented. The other commands are for setting permissions and enabling the swap.
The next step is to add an entry to /etc/fstab:
/swapfile none swap sw 0 0
Reboot and the next step is to change the partition to a regular partition. You can use fdisk’s option to change a partition type. Change the swap partition to type 83. Then use mkfs to format the partition as ext4. Finally, create a directory off / to mount the partition to and then add its entry into fstab.
To change the settings for Gimp you need to edit /etc/gimp/2.0/gimprc and look for the options that specify temporary space and swap space. It’s possible the temp space may not need to be changed as it is possibly only used during saves, when saving an existing file requires a temporary file to be written and then copied over the old file. The swap is the most important setting.
After playing with the settings and tweaking I was able to get a much faster and quieter editing process of some large images because the SSD was used instead of the regular HDD. A particular operation Gimp had struggled to do before was editing a 23 layer aerial mosaic which needed a unified transform of a layer that had been UT’d twice already. The software responded much faster even though there was still a lot of disk activity.
Doing this type of thing with Gimp is worthwhile if it is a lot cheaper than adding more RAM or a bigger SSD to a system. It also eliminates space usage for temporary files gobbling precious disk space. I face a constant battle with the large mosaics and massive volumes of aerial photography downloads to keep enough free space on this computer without running out. Gimp seems to use a lot of this space at times and has been responsible for disk full errors on several occasions.
Mainpc uses hibernation and it is simpler to stick with the current arrangement as I don’t have to use Gimp on this PC so I will look at options for next time I reinstall this computer, for example adding another SSD if there are free ports. This mainboard in mainpc is quite a high spec one and has a M2 port onboard as well as a lot of Sata ports so it should be possible as in fact let’s face it, the cheapest option for a high spec computer would be extra RAM (only 8 GB) in mainpc and extra SSD for temporary space and so on.

UPDATE: I have given up on playing with the temp settings and simply let the swap space be used as normal, as Gimp does seem to be quite capable of using swap in 2.10+. The main reason for doing this is that now that Gimp is installed from a flatpak, you just don’t have the same ability to customise Gimp’s own settings, and letting it use the Linux swap (which it apparently is quite OK with) is by far the best solution. So for my two PCs that use Gimp, each has 100 GB of SSD  available as swap and it does get used from time to time.