Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 29 May 2002 23:19:00 -0400 (EDT)
From:      Jason Hunt <jhunt@lynden.on.ca>
To:        FreeBSD LIST <FreeBSD-Questions@FreeBSD.ORG>
Subject:   Re: mv vs. tar [overlapping]
Message-ID:  <20020529225057.L95828-100000@lethargic.dyndns.org>
In-Reply-To: <20020529223005.O79882-100000@earl-grey.cloud9.net>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, 29 May 2002, Peter Leftwich wrote:

> On Thu, 30 May 2002, Matthias Buelow wrote:
> > Dan Nelson writes:
> > > A tar pipe will be much faster, since reading and writing will be overlapped.
> > > ( cd /source ; tar cf - . ) | ( cd destination ; tar xfp - )
> > eh?  sorry but I think that's nonsense. --mkb
>
> Actually, it's an interesting point... I think what Dan means is that read
> and write processes run concurrently (have you ever run multiple HTTP
> requests at once? it's a lot like that I suppose).  So it would seem
> tarring is quickest when moving a directory within the same filesystem!
>


I'm not an expert on filesystems, but I'm pretty sure that this is the
jist of what happens;

When 'cp'ing files, the system must look up all information for the files
in each directory, read the data from each vnode, create a new vnode,
copy the data into the new vnode, and then add this information to the
directory tree.  When using 'tar'/'gzip'/etc then pretty much the same
method as with 'cp' is being performed, except routines for concatenation
and compression are also being performed by the CPU.

When 'mv'ing files between locations on the same physical disk, then
the only filesystem operation that is being performed is to update the
directory tree.  An exception to this is when using 'mv' between different
physical disks or over NFS mount points, in which case the method for 'cp'
ends up being performed.

Basically, 'mv' will be much faster in most scenarios.  Refer to my other
e-mail from about an hour ago for when you might not want to use 'mv'.

Once again, I am no expert.  I'm probably wrong on a few points and/or
overlooked some things.  I havn't gotten that far yet in reading "The
Design and Implementation of the 4.4BSD Operating System", which
is an excellent book if you want to learn what goes on behind the scenes.
:)


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020529225057.L95828-100000>