A few observations -- 1) When I remove the line "trim = true" from the config file and also remove all mount options while mounting (the effective command being "mount -t ext4 /dev/nbd0 /mnt/remote"), I find that the size of the NBD backend file remains the same after the large file is deleted from the filesystem.
2) If I include the 'data=journal' option while mounting (mount -t ext4 -odata=journal /dev/nbd0 /mnt/remote), I find that the NBD backend file shrinks. What is happening here exactly? I haven't include the words 'trim' or 'discard' anywhere and still the results indicate that TRIM is working by enabling the mount option 'data=journal'? Thanks, T G On Mon, Mar 19, 2012 at 11:43 AM, katon goukakyuuno <[email protected]> wrote: > Hi Wouter, > > I wrote the following bash script - discard.sh - which tests the TRIM > command on a kernel that has been patched to support it. This script > is based on the "maketr" script that already exists in the nbd-3.0 > directory available for download. > > #!/bin/sh > # > # Example script to test the TRIM command > # Must be run as root. Remember to chown the file afterwards > > tmpnam=`mktemp` > conffile=${tmpnam}.conf > pidfile=${tmpnam}.pid > > ulimit -c unlimited > > echo "\n$0: Clearing dmesg...\n" > dmesg -c > /dev/null > > cat >${conffile} <<EOF > [generic] > [export1] > exportname = $tmpnam > trim = true > EOF > ./nbd-server -C ${conffile} -p ${pidfile} & > PID=$! > > dd if=/dev/zero of=${tmpnam} bs=1M count=256 > ./nbd-client -N export1 127.0.0.1 /dev/nbd0 > mkfs.ext4 /dev/nbd0 > > echo "$0: mounting ext4 with \"discard\" option\n" > mount -t ext4 -odata=journal,discard /dev/nbd0 /mnt/remote > (cd /mnt/remote ; dd if=/dev/zero of=/mnt/remote/trial.img count=50 > bs=512; sync) 2>&1 >/dev/null > echo "\n$0: \"du\" output after creating temp file\n" > du ${tmpnam} > echo > rm -f /mnt/remote/trial.img ; sync > echo "\n$0: \"du\" output after deleting temp file\n" > du ${tmpnam} > > umount /mnt/remote > ./nbd-client -d /dev/nbd0 > if [ -f ${pidfile} ] > then > kill `cat ${pidfile}` > rm -f ${pidfile} > else > kill $PID > fi > rm -f $tmpnam ${conffile} > echo "\n$0: Dumping dmesg:\n" > dmesg > > On running, I get the following output (I'm showing only the more > important messages): > > ./discard.sh: Clearing dmesg... > > ./discard.sh: mounting ext4 with "discard" option > > # Output of: dd if=/dev/zero of=/mnt/remote/trial.img count=50 bs=512 > 50+0 records in > 50+0 records out > 25600 bytes (26 kB) copied, 0.000411365 s, 62.2 MB/s > > ./discard.sh: "du" output after creating temp file > > 262200 /tmp/tmp.OdfAMDXMCL > > ./discard.sh: "du" output after deleting temp file > > 262168 /tmp/tmp.OdfAMDXMCL > Disconnecting: que, disconnect, sock, done > > ./discard.sh: Dumping dmesg: > > [ 5321.494980] EXT4-fs (nbd0): mounted filesystem with journalled data > mode. Opts: data=journal,discard > [ 5325.478361] block nbd0: NBD_DISCONNECT > [ 5325.478813] block nbd0: Receive control failed (result -32) > [ 5325.478854] block nbd0: queue cleared > > It looks like TRIM is working perfectly on my patched kernel! :-) > > BTW, looking at dmesg, there is a broken pipe error. Is that something > to worry about? > > Thanks, > T G > > On Fri, Mar 16, 2012 at 10:58 AM, Wouter Verhelst <[email protected]> wrote: >> >> On Fri, Mar 16, 2012 at 10:42:03AM -0700, katon goukakyuuno wrote: >> > Hi Wouter, >> > >> > Thank you very much for replying! I have patched my kernel to support >> > only >> > TRIM. I hope I need not apply the patch for FLUSH/FUA as well to just >> > use TRIM? >> > I hope all patches are added to the latest Linux kernel soon! >> > >> > I have also updated the nbd client and server to version 3.0 (the latest >> > version) which does support TRIM. >> > >> > How do I test if TRIM is working properly on my system? Are there any >> > test >> > scripts readily available; >> >> Not at this time. In fact, while I expect it to be working, I haven't >> actually tested it much myself. >> >> > or, do I need to create a new /dev/nbd and mount a >> > file system which supports TRIM and then try to issue some commands from >> > userspace? I haven't completely figured out this part yet. >> >> Something like that. This should work: >> - set the 'trim' option to 'true' in an nbd export >> - connect to that NBD export from a client (may be the same machine) >> - create an ext4 filesystem on that device >> - mount the filesystem with the option 'discard' >> - create a large file on the filesystem >> - sync >> - run 'du' on the nbd backend file >> - remove the file >> - sync again >> - run 'du' again, and see if the file is now smaller. If it is, then a >> TRIM command was sent successfully to the server. >> >> -- >> The volume of a pizza of thickness a and radius z can be described by >> the following formula: >> >> pi zz a ------------------------------------------------------------------------------ This SF email is sponsosred by: Try Windows Azure free for 90 days Click Here http://p.sf.net/sfu/sfd2d-msazure _______________________________________________ Nbd-general mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/nbd-general
