qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Richard W.M. Jones" <rjones@redhat.com>
To: qemu-devel@nongnu.org
Cc: pbonzini@redhat.com
Subject: [Qemu-devel] Trying to get fstrim / discard=unmap to work
Date: Mon, 10 Mar 2014 16:11:20 +0000	[thread overview]
Message-ID: <20140310161119.GA6744@redhat.com> (raw)


I'm trying to get fstrim in a guest to cause the host disk to become
sparse, without success so far.  I wonder if anyone can see what I'm
missing?

Guest:
 - guest kernel: 3.13.4-200.fc20.x86_64
 - ext4 guest filesystem
 - fstrim from util-linux 2.24.1
 - cat /sys/block/sda/device/scsi_disk/*/provisioning_mode
   unmap

Qemu:
 - qemu from git today (e9d818b8b1a)
 - Drive uses virtio-scsi
 - Drive uses discard=unmap

/home/rjones/d/qemu/x86_64-softmmu/qemu-system-x86_64 -L /home/rjones/d/qemu/pc-bios -global virtio-blk-pci.scsi=off -nodefconfig -enable-fips -nodefaults -display none -machine accel=kvm:tcg -m 500 -no-reboot -rtc driftfix=slew -no-hpet -global kvm-pit.lost_tick_policy=discard -kernel /home/rjones/d/libguestfs/tmp/.guestfs-1000/appliance.d/kernel -initrd /home/rjones/d/libguestfs/tmp/.guestfs-1000/appliance.d/initrd -device virtio-scsi-pci,id=scsi -drive file=/home/rjones/d/libguestfs/test1.img,cache=writeback,discard=unmap,format=raw,id=hd0,if=none -device scsi-hd,drive=hd0 -drive file=/home/rjones/d/libguestfs/tmp/.guestfs-1000/appliance.d/root,snapshot=on,id=appliance,cache=unsafe,if=none -device scsi-hd,drive=appliance -device virtio-serial-pci -serial stdio -device sga -chardev socket,path=/home/rjones/d/libguestfs/tmp/libguestfsSwrSCg/guestfsd.sock,id=channel0 -device virtserialport,chardev=channel0,name=org.libguestfs.channel.0 -append "panic=1 console=ttyS0 udevtimeout=600 no_timer_check acpi=off printk.time=1 cgroup_disable=memory root=/dev/sdb selinux=0 TERM=xterm-256color"

Host:
 - host kernel: 3.12.5-302.fc20.x86_64
 - ext4 host filesystem
 - backed by m-SATA SDD

Methodology:

(0) Observe the file size on host:

$ ls -ls test1.img 
0 -rw-rw-r--. 1 rjones rjones 1073741824 Mar 10 16:08 test1.img
^
+---- sparse file, 0 blocks used

(1) Create an ext4 filesystem on /dev/sda in the guest.

(2) Create a big data file of random data (10 MB) & sync.

(3) Observe the file size on the host:

$ ls -ls test1.img 
59804 -rw-rw-r--. 1 rjones rjones 1073741824 Mar 10 16:09 test1.img

(4) rm /data in guest

(5) fstrim / in guest  [actually, I do this several times]

(6) sync

(6) Observe the file size on host:

$ ls -ls test1.img 
59804 -rw-rw-r--. 1 rjones rjones 1073741824 Mar 10 16:10 test1.img

Unchanged!  I'm expecting the first number (59804 blocks) to get
substantially smaller.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine.  Supports Linux and Windows.
http://people.redhat.com/~rjones/virt-df/

             reply	other threads:[~2014-03-10 16:11 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-10 16:11 Richard W.M. Jones [this message]
2014-03-10 16:14 ` [Qemu-devel] Trying to get fstrim / discard=unmap to work Richard W.M. Jones
2014-03-10 16:57   ` Paolo Bonzini
2014-03-10 17:15     ` Richard W.M. Jones
2014-03-11 20:00     ` Richard W.M. Jones
2014-03-12 17:55       ` Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140310161119.GA6744@redhat.com \
    --to=rjones@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).