Enable TRIM on eMMC

edited July 2019 in AML-S805X-AC
As there is ONLY eMMC and no sdcard support one must take care of the expensive eMMC card. Please enable trim for meson-gx-mmc. Trimming works fine in uboot with "mmc erase" command (one has to erase the whole card or manually know which blocks to erase) but for linux the mmc controller driver must tell the OS that it supports it.

Linux even correctly reports  /sys/devices/platform/soc/d0000000.apb/d0074000.mmc/mmc_host/mmc0/mmc0:0001/erase_size and /sys/devices/platform/soc/d0000000.apb/d0074000.mmc/mmc_host/mmc0/mmc0:0001/preferred_erase_size but the controller driver does not enable trimming.
Change needed:
In kernel source drivers/mmc/host/meson-gx-mmc.c in section mmc->caps declare MMC_CAP_ERASE.

Comments

  • A quick way to later check that the OS is supporting trimming is:
    lsblk -D
    Example output on RPi:
    root@raspberrypi:~# lsblk -D
    NAME        DISC-ALN DISC-GRAN DISC-MAX DISC-ZERO
    mmcblk0            0        4M     124M         0
    __mmcblk0p1        0        4M     124M         0
    __mmcblk0p2        0        4M     124M         0

    4M corresponds to:
    root@raspberrypi:~# cat /sys/devices/platform/soc/20202000.mmc/mmc_host/mmc0/mmc0\:59b4/preferred_erase_size
    4194304

    Same command on La Frite shows that trimming is not declared even though preferred_erase_size is set:
    root@libre-computer:~# lsblk -D
    NAME         DISC-ALN DISC-GRAN DISC-MAX DISC-ZERO
    mmcblk0             0        0B       0B         0
    ├─mmcblk0p1         0        0B       0B         0
    ├─mmcblk0p2         0        0B       0B         0
    └─mmcblk0p3         0        0B       0B         0
    mmcblk0boot0        0        0B       0B         0
    mmcblk0boot1        0        0B       0B         0

    root@libre-computer:~# cat /sys/devices/platform/soc/d0000000.apb/d0074000.mmc/mmc_host/mmc0/mmc0\:0001/preferred_erase_size
    4194304

  • MMC erase sizes vary depending on the flash controller used. Most modern eMMC controllers no longer need TRIM and will TRIM automatically when you dd /dev/zero to the device. Since this is taken directly from upstream Linux, please see the linux-meson mailing list for changes like these.
Sign In or Register to comment.