Ben Stienstra

Linux, Unix, network, radio and more...

User Tools

Site Tools


linux_test_ssd_trim

Test SSD TRIM with LVM

  • check if the device report discard_zeroes_data:1 The example below does not write zero's!
    # grep -s "" /sys/block/sda/queue/*
    /sys/block/sda/queue/add_random:1
    /sys/block/sda/queue/discard_granularity:512
    /sys/block/sda/queue/discard_max_bytes:2147450880
    /sys/block/sda/queue/discard_zeroes_data:0
    /sys/block/sda/queue/hw_sector_size:512
    /sys/block/sda/queue/iostats:1
    /sys/block/sda/queue/logical_block_size:512
    /sys/block/sda/queue/max_hw_sectors_kb:32767
    /sys/block/sda/queue/max_integrity_segments:0
    /sys/block/sda/queue/max_sectors_kb:512
    /sys/block/sda/queue/max_segments:168
    /sys/block/sda/queue/max_segment_size:65536
    /sys/block/sda/queue/minimum_io_size:512
    /sys/block/sda/queue/nomerges:0
    /sys/block/sda/queue/nr_requests:128
    /sys/block/sda/queue/optimal_io_size:0
    /sys/block/sda/queue/physical_block_size:512
    /sys/block/sda/queue/read_ahead_kb:128
    /sys/block/sda/queue/rotational:0
    /sys/block/sda/queue/rq_affinity:1
    /sys/block/sda/queue/scheduler:noop deadline [cfq]
    /sys/block/sda/queue/write_same_max_bytes:0
  • Note the LVM PV offset, in this case 1050624:
    # fdisk -l /dev/sda
    
    Disk /dev/sda: 30.0 GB, 30016659456 bytes, 58626288 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk label type: dos
    Disk identifier: 0x00052410
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *        2048     1050623      524288   83  Linux
    /dev/sda2         1050624    58626047    28787712   8e  Linux LVM
  • Note LV payload offset, in this case for /var 1050624:
    # dmsetup table
    vg-lv_home: 0 1048576 linear 8:2 2048
    vg-lv_swap: 0 1048576 linear 8:2 17827840
    vg-lv_root: 0 8388608 linear 8:2 9439232
    vg-lv_var: 0 8388608 linear 8:2 1050624
  • Create file with random data:
    # cd /var/tmp/
    # dd if=/dev/urandom of=tempfile bs=1M count=3
    # sync
  • Find first sector for file, here 2101112:
    # hdparm --fibmap tempfile
    
    tempfile:
     filesystem blocksize 4096, begins at LBA 0; assuming 512 byte sectors.
     byte_offset  begin_LBA    end_LBA    sectors
               0    2101112    2107255       6144
  • Add the offsets from the first two steps to the begin_LBA, and read the sector from disk, you should see random data:
    # hdparm --read-sector 4202360 /dev/sda
    
    /dev/sda:
    reading sector 4202360: succeeded
    3e80 9f15 efd5 27c1 95d5 d6fb 9ea4 eda1
    c8de 8a76 7903 37a4 5472 74bc c156 0ba3
    639d f70c 2eff 7820 6677 7d9e e111 e44d
    a607 3e4f cdee 6507 9770 da35 e1b9 ec76
    3eb6 5fb3 d482 28cf 6ec4 a03e f7ec 58d9<snip>
  • You can verify the data with hexdump:
    # hexdump tempfile | head -5
    0000000 3e80 9f15 efd5 27c1 95d5 d6fb 9ea4 eda1
    0000010 c8de 8a76 7903 37a4 5472 74bc c156 0ba3
    0000020 639d f70c 2eff 7820 6677 7d9e e111 e44d
    0000030 a607 3e4f cdee 6507 9770 da35 e1b9 ec76
    0000040 3eb6 5fb3 d482 28cf 6ec4 a03e f7ec 58d9
  • Delete the file fstrim the file system:
    # rm tempfile
    # sync
    # fstrim -v /var
    /var: 3.9 GiB (4195037184 bytes) trimmed
  • Check data data is now all zero's, you might need to wait a few minutes:
    # hdparm --read-sector 4202360 /dev/sda
    
    /dev/sda:
    reading sector 4202360: succeeded
    0000 0000 0000 0000 0000 0000 0000 0000
    0000 0000 0000 0000 0000 0000 0000 0000
    0000 0000 0000 0000 0000 0000 0000 0000
    0000 0000 0000 0000 0000 0000 0000 0000
    0000 0000 0000 0000 0000 0000 0000 0000<snip>
linux_test_ssd_trim.txt · Last modified: 2014/12/29 19:30 by admin