From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Richard W.M. Jones" Subject: Making discard/fstrim reliable Date: Wed, 26 Mar 2014 20:47:08 +0000 Message-ID: <20140326204708.GA29191@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: pbonzini@redhat.com To: linux-fsdevel@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:46663 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751683AbaCZUrK (ORCPT ); Wed, 26 Mar 2014 16:47:10 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s2QKl98g027402 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 26 Mar 2014 16:47:09 -0400 Content-Disposition: inline Sender: linux-fsdevel-owner@vger.kernel.org List-ID: virt-sparsify is a tool for trimming free space in virtual disk images. The new implementation uses vfs/kernel/qemu discard support. Essentially it does: for each filesystem: mount -o discard $fs /mnt sync fstrim /mnt umount /mnt sync # qemu is killed after sync returns Although typing these commands by hand works fine, when you run them from a program the fstrim doesn't happen all the way down the stack reliably. Mostly it works, but sometimes it only trims some space from the host file. It appears that when the host is slow / under load, the problem happens more frequently. Also it may happen more frequently on i686 than on x86-64 (possibly also due to speed of host). The question is: What can I do to make sure the trim happens reliably, all the way down the stack, before qemu is killed? I am testing this using the latest upstream kernel & qemu. 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/