linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Moving contents from one subvol to another
@ 2014-11-29 14:21 Shriramana Sharma
  2014-11-29 14:28 ` Hugo Mills
  0 siblings, 1 reply; 6+ messages in thread
From: Shriramana Sharma @ 2014-11-29 14:21 UTC (permalink / raw)
  To: linux-btrfs

Hello. I am now taking the first steps to making my backup external
HDD in BtrFS. From
http://askubuntu.com/questions/119014/btrfs-subvolumes-vs-folders I
understand that the only difference between subvolumes and ordinary
folders is that the former can be snapshotted and independently
mounted.

But I have a question. I have two subvols test1, test2.

$ cd test1
$ dd if=/dev/urandom of=file bs=1M count=500
500+0 records in
500+0 records out
524288000 bytes (524 MB) copied, 36.2291 s, 14.5 MB/s
$ time mv file ../test2/
real    0m2.061s
user    0m0.013s
sys     0m0.459s
$ time { cp --reflink ../test2/file . && rm ../test2/file ; }
real    0m0.677s
user    0m0.022s
sys     0m0.086s
$ mkdir foo
$ time mv file foo/
real    0m0.096s
user    0m0.008s
sys     0m0.013s

It seems that mv is not CoW aware and hence is not able to create
reflinks so it is actually processing the entire file because it
thinks test2 is a different device/filesystem/partition or such. Is
this understanding correct?

So doing cp --reflink with rm is much faster. But it is still slower
than doing mv within the same subvol. Is it because of the
housekeeping with updating the metadata of the two subvols?

Methinks --reflink option should be added to mv for the above usecase.
Do people think this is useful? Why or why not?

My concern is that if somebody wants to consolidate two subvols into
one, though really only the metadata needs to be processed using
ordinary mv isn't aware of this and using cp --reflink with rm is
unnecessarily complicated, especially if it will involve multiple
files.

And it's not clear to me what it would entail to cp --reflink + rm an
entire directory tree because IIUC I'd have to handle each file
separately. Perhaps something (unnecessarily convoluted) like:

find . | while read f
do
[ -d "$f" ] && mkdir target/"$f" && touch target/"$f" -r "$f"
[ -f "$f" ] && cp -a --reflink "$f" target/ && rm "$f"
done

Again, what would happen to files which are not regular directories or files?

And why isn't --reflink given a single letter alias for cp?

-- 
Shriramana Sharma ஶ்ரீரமணஶர்மா श्रीरमणशर्मा

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-11-30 13:05 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-29 14:21 Moving contents from one subvol to another Shriramana Sharma
2014-11-29 14:28 ` Hugo Mills
2014-11-29 15:15   ` Shriramana Sharma
2014-11-29 17:07     ` Robert White
2014-11-30  3:53       ` Shriramana Sharma
2014-11-30 13:04         ` Shriramana Sharma

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).