The file "/usr/lib/zfs-linux/trim" doesn't seem to work properly.

mpobieda

Member
Aug 3, 2022
17
0
6
Hello.
The file "/usr/lib/zfs-linux/trim" doesn't seem to work properly.
You can set autotrim=off for the pool and if it is a pool with nvme disks, zpool trim will be performed anyway.
For other SSDs setting autotrim=on does not perform zpool trim.

Maybe it's better to ask just about autotrim?:
Code:
#!/bin/sh -eu

# directly exit successfully when zfs module is not loaded
if ! [ -d /sys/module/zfs ]; then
        exit 0
fi

# [auto] / enable / disable
PROPERTY_NAME="org.debian:periodic-trim"

#get_property () {
#       # Detect the ${PROPERTY_NAME} property on a given pool.
#       # We are abusing user-defined properties on the root dataset,
#       # since they're not available on pools https://github.com/openzfs/zfs/pull/11680
#       # TODO: use zpool user-defined property when such feature is available.
#       pool="$1"
#       zfs get -H -o value "${PROPERTY_NAME}" "${pool}" 2>/dev/null || return 1
#}

trim_if_not_already_trimming () {
        pool="$1"
        if ! zpool status "${pool}" | grep -q "trimming"; then
                # Ignore errors (i.e. HDD pools),
                # and continue with trimming other pools.
                zpool trim "${pool}" || true
        fi
}

#zpool_is_nvme_only () {
#       zpool=$1
#       # get a list of devices attached to the specified zpool
#       zpool list -vHPL "${zpool}" |
#               awk -F'\t' '$2 ~ /^\/dev\// {
#                       if($2 !~ /^\/dev\/nvme/)
#                               exit 1
#               }'
#}

# TRIM all healthy pools that are not already trimming as per their configs.
zpool list -H -o health,name 2>&1 | \
        awk -F'\t' '$1 == "ONLINE" {print $2}' | \
while read pool
do
        # read user-defined config
#       ret=$(get_property "${pool}")
        ret=`zpool get -o all autotrim ${pool} | grep on | awk '{ print $3 }'`
        if [ $? -ne 0 ] || [ "disable" = "${ret}" ]; then
                :
#       elif [ "enable" = "${ret}" ]; then
        elif [ "on" = "${ret}" ]; then
                trim_if_not_already_trimming "${pool}"
                #echo "${pool}"
#       elif [ "-" = "${ret}" ] || [ "auto" = "${ret}" ]; then
#               if zpool_is_nvme_only "${pool}"; then
#                       trim_if_not_already_trimming "${pool}"
#               fi
        else
                cat > /dev/stderr <<EOF
$0: [WARNING] illegal value "${ret}" for property "${PROPERTY_NAME}" of ZFS dataset "${pool}".
$0: Acceptable choices for this property are: auto, enable, disable. The default is auto.
EOF
        fi
done
 
Hi,
it's not broken, it just doesn't use the autotrim property to check, but org.debian:periodic-trim. You are right that the script will run by default for NVMes and not others, see here for the full table and rationales: https://wiki.debian.org/ZFS#Periodic_TRIM
 
Hi,
it's not broken, it just doesn't use the autotrim property to check, but org.debian:periodic-trim. You are right that the script will run by default for NVMes and not others, see here for the full table and rationales: https://wiki.debian.org/ZFS#Periodic_TRIM
This information MUST be added to the "wiki/Installation" page.
I can't believe I've been using Proxmox thinking it was automagically trimming my SATA SSDs for more than a year just to find out it was all a lie.
 
Hi,
This information MUST be added to the "wiki/Installation" page.
I can't believe I've been using Proxmox thinking it was automagically trimming my SATA SSDs for more than a year just to find out it was all a lie.
feel free to open a feature request for this: https://bugzilla.proxmox.com/