We are looking into using BtrFS on an array of SSD disks and I have been asked to verify that BtrFS does in fact perform TRIM operations upon deleting a file. So far I have been unable to verify that the TRIM command is sent to the disks.
I know BtrFS is not considered production ready, but we like the bleeding edge, therefore I'm testing it. The server is Ubuntu 11.04 server 64-bit release (mkfs.btrfs version 0.19). I have installed the Linux 3.0.0 kernel as the BtrFS changelog states that bulk TRIM is not available in the kernel shipped with Ubuntu 11.04 (2.6.38).
Here's my testing methodology (initially adopted from http://andyduffell.com/techblog/?p=852, with modifications to work with BtrFS):
- Manually TRIM the disks before starting:
for i in {0..10} ; do let A="$i * 65536" ; hdparm --trim-sector-ranges $A:65535 --please-destroy-my-drive /dev/sda ; done
- Verify the drive was TRIM'd:
./sectors.pl |grep + | tee sectors-$(date +%s)
- Partition the drive:
fdisk /dev/sda
- Make the file system:
mkfs.btrfs /dev/sda1
- Mount:
sudo mount -t btrfs -o ssd /dev/sda1 /mnt
- Create a file:
dd if=/dev/urandom of=/mnt/testfile bs=1k count=50000 oflag=direct
- Verify the file is on the disk:
./sectors.pl | tee sectors-$(date +%s)
- Delete the test file:
rm /mnt/testfile
- See that the test file is TRIM'd from the disk:
./sectors.pl | tee sectors-$(date +%s)
- Verify the TRIM'd blocks:
diff
the two most recentsectors-*
files
At this point, the pre-delete and post delete verifications still show the same disk blocks in use. I should instead see a reduction in the number of in use blocks. Waiting an hour (in case it takes a while for the TRIM command to be issued) after the test file is deleted still shows the same blocks in use.
I have also tried mounting with the -o ssd,discard
options, but that doesn't seem to help at all.
Partition that was created from fdisk
above (I keep the partition small so the verification can go faster):
root@ubuntu:~# fdisk -l -u /dev/sda
Disk /dev/sda: 512.1 GB, 512110190592 bytes
255 heads, 63 sectors/track, 62260 cylinders, total 1000215216 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 identifier: 0x6bb7542b
Device Boot Start End Blocks Id System
/dev/sda1 63 546209 273073+ 83 Linux
My sectors.pl
script (I know this is inefficient, but it gets the job done):
#!/usr/bin/perl -w
use strict;
my $device = '/dev/sda';
my $start = 0;
my $limit = 655360;
foreach ($start..$limit) {
printf "\n%6d ", $_ if !($_ % 50);
my @sector = `/sbin/hdparm --read-sector $_ $device`;
my $status = '.';
foreach my $line (@sector) {
chomp $line;
next if $line eq '';
next if $line =~ /$device/;
next if $line =~ /^reading sector/;
if ($line !~ /0000 0000 0000 0000 0000 0000 0000 0000/) {
$status = '+';
}
}
print $status;
}
print "\n";
Is my testing methodology flawed? Am I missing something here?
Thanks for the help.