site  contact  subhomenews

Mesa package much bigger than it needs to be

November 06, 2021 — BarryK

I have known about this for years, and not known what to do about it. There are drivers in /usr/lib/dri, however they are identical, or almost identical. I used the 'cmp' utility and in EasyOS they are in two identical groups:

identical:
kms_swrast_dri.so
nouveau_dri.so
nouveau_vieux_dri.so
r300_dri.so
swrast_dri.so
virtio_gpu_dri.so
vmwgfx_dri.so
identical:
i915_dri.so
i965_dri.so
r200_dri.so
radeon_dri.so

Furthermore, those two groups are only different by 25 bytes.

I could post-process the mesa package and convert the two groups into symlinks. So instead of 11 files occupying 139MB, there would be just 2 files occupying 26MB. The size difference is staggering!

Today I decided to try and find out how this has come about in the first place. Well, it seems that the mesa developers created these drivers as hardlinked files, as hardlinked files cannot be copied across filesystems, they become separate files. The mesa project has done this right from the start, which I find extraordinary.

Do they have some good reason to do this? Have I misunderstood something?

Perhaps they can justify why it is done that way. I did a bit of a look around, to find out if anyone else has pondered over this. Strangely, hardly anyone. However, a couple of people have tried to rectify this -- there are a couple of patches to install symlinked drivers instead of hardlinked:

https://mail.gnu.org/archive/html/guix-commits/2017-11/msg00418.html

https://code.vitrostudios.com/phil/my_nixpkgs_fork/-/blob/1a52fdc3c6a81b0b652ea21e59e7dd705fef5f2e/pkgs/development/libraries/mesa/symlink-drivers.patch

...the second one looks good, however, it is 5 years old, and created when the mesa package used autotools. Mesa now uses meson, that I am totally unfamiliar with, and cannot see how to modify that patch.

To save around 110MB, yeah I want to do that.

EDIT:
I downloaded 'libgl1-mesa-dri' amd64 DEB package from Debian, and, very interesting, the hardlinks are preserved when I unpack the DEB. Total size shown by "du -m" is 34MB.

If I copy folder 'dri' to a different partition, "du -m" shows 267MB.

The compile is done in OpenEmbedded, and when the mesa package is imported into woofQ, which is done by copying the individual files, the hardlinking is lost, and I end up with separate large files.

Hmmm, I did the above test by dragging the folder from one Rox window to another. If I copy with "cp -a", the hardlinks are preserved, across partitions. Now that is odd, because "cp -a" is being used to import packages from OE into woofQ. I need to go back to OE and find out what is going on.

EDIT:
I have implemented a fix. Instead of going back and studying what happened in the OE build, I have created packages-templates/mesa/pinstall.sh, a script in woofQ that will operate upon the folder 'rootfs-complete', which will then become 'easy.sfs'. This is pinstall.sh:

#!/bin/sh
#the hardlinks may have gone, recreate them. ref:
# https://bkhome.org/news/202111/mesa-package-much-bigger-than-it-needs-to-be.html
#in easyos reduces /usr/libdri from 139MB to 26MB.

if [ -d usr/lib/dri ];then
PREFIX="usr/lib/"
else
if [ -d usr/lib64/dri ];then
PREFIX="usr/lib64/"
else
PREFIX="$(find usr/lib -mindepth 2 -maxdepth 2 -type d -name dri | cut -f 1-3 -d '/' | head -n 1)/"
fi
fi

if [ -d ${PREFIX}dri ];then
DRVS0="$(ls -1 ${PREFIX}dri)"

while [ "$DRVS0" ];do
DRVS1=''
aDRV="$(echo "$DRVS0" | head -n 1)"
for aaDRV in ${DRVS0}
do
[ "$aaDRV" == "" ] && continue
[ "$aaDRV" == "$aDRV" ] && continue
cmp -s ${PREFIX}dri/${aDRV} ${PREFIX}dri/${aaDRV}
if [ $? -eq 0 ];then
ln -f ${PREFIX}dri/${aDRV} ${PREFIX}dri/${aaDRV}
else
if [ ! "$DRVS1" ];then
DRVS1="${aaDRV}"
else
DRVS1="${DRVS1}
${aaDRV}"
fi
fi
done
DRVS0="$DRVS1"
done
sync
fi

...this reduces the size from 139MB to 26MB.       

Tags: easy