[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [Nbd] NBD kernel module, client and server with support for TRIM

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.

# Example script to test the TRIM command
# Must be run as root. Remember to chown the file afterwards


ulimit -c unlimited

echo "\n$0: Clearing dmesg...\n"
dmesg -c > /dev/null

cat >${conffile} <<EOF
        exportname = $tmpnam
        trim = true
./nbd-server -C ${conffile} -p ${pidfile} &

dd if=/dev/zero of=${tmpnam} bs=1M count=256
./nbd-client -N export1 /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}
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} ]
        kill `cat ${pidfile}`
        rm -f ${pidfile}
        kill $PID
rm -f $tmpnam ${conffile}
echo "\n$0: Dumping dmesg:\n"

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?


On Fri, Mar 16, 2012 at 10:58 AM, Wouter Verhelst <w@...112...> 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

Reply to: