FedoraForum.org - Fedora Support Forums and Community
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2004
    Location
    Maryland, US
    Posts
    7,286

    fstrim shows discardable blocks even after using discard option

    I expected only the first usage of the fstrim command after my installation of Fedora 16 on a SSD to actually have blocks to trim. I then set the discard option on the mounts to the SSD and rebooted. I then used the system for a while and for the hell of it ran the fstrim -v command and was surprised there were still SSD blocks reported for being discarded.

    Doesn't using discard on ext4 on a SSD mean that all "fstrim -v" usages on the SSD would then not find any blocks to discard?

    Another thing that's odd is that the number of trimmed bytes reported is huge, like 116GB on my 128GB SSD. If I immediately re-run 'fstrim -v / ' I get 0 bytes trimmed like I'd expect.

  2. #2
    stevea Guest

    Re: fstrim shows discardable blocks even after using discard option

    fstrim makes a single syscall withthe open mountpoint.
    This call falls to the kernel filesystem code (ext4, btrfs, whatever) which then walks the file system data structures to find all unused blocks in the block device that have not been discarded since the mount. Since the kernel has no idea which blocks have already been discarded - it discards ALL unused blocks of the filesystem (except maybe ones that if KNOWS have been discadred already since mount. Then it discards all of these.

    When you run fstrim a second time on an mounted FS, then for ext4 at least it KNOWS all the blocks have been trim'ed already- so the it reports 0 trimmed.

    For btrfs it discards ALL unused blocks on every use of 'fstrim. IOW btrfs isn't smart enough to keep

    If you reboot or umount and mount the same FS - then it will report the big number - essentially the number of unused blocks.



    Example for a btrfs fs
    [root@crucibulum /]# mount /dev/sda5 /tmp/mp -o discard,ssd
    [root@crucibulum /]# fstrim -v /tmp/mp
    /tmp/mp: 2566369280 bytes were trimmed
    [root@crucibulum /]# fstrim -v /tmp/mp
    /tmp/mp: 2566369280 bytes were trimmed
    this is for an ext4 fs
    [root@crucibulum ~]# mount -t ext4 -o discard /dev/sda5 /tmp/mp
    [root@crucibulum ~]# fstrim -v /tmp/mp
    /tmp/mp: 31813779456 bytes were trimmed
    [root@crucibulum ~]# fstrim -v /tmp/mp
    /tmp/mp: 0 bytes were trimmed
    [root@crucibulum ~]# umount /tmp/mp
    [root@crucibulum ~]# mount -t ext4 -o discard /dev/sda5 /tmp/mp
    [root@crucibulum ~]# fstrim -v /tmp/mp
    /tmp/mp: 31813779456 bytes were trimmed
    So ext4 KEEPs the trim info between fstrim calls, while btrfs does not.
    Neither can keep the keep the info between mounts or boots.
    Last edited by stevea; 8th April 2012 at 06:03 AM.

Similar Threads

  1. F17 and Discard (TRIM) support on LUKS/dm-crypt devices
    By Japplo in forum F17 Development Forum
    Replies: 19
    Last Post: 30th May 2012, 06:17 AM
  2. Replies: 0
    Last Post: 19th September 2011, 08:07 PM
  3. Fedora 16 and Discard (TRIM) support on LUKS/dm-crypt devices
    By NoHumanBeing in forum F16 Development
    Replies: 9
    Last Post: 19th September 2011, 07:52 PM
  4. Bad Blocks
    By CrystalCowboy in forum Using Fedora
    Replies: 3
    Last Post: 11th September 2005, 10:46 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •