[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: cp(1) fails to copy file from /proc
From: |
Jim Meyering |
Subject: |
Re: cp(1) fails to copy file from /proc |
Date: |
Fri, 17 Apr 2009 18:46:33 +0200 |
Jim Meyering wrote:
...
> I've confirmed this on the following kernels:
>
> debian unstable 2.6.26-2-amd64
> fedora 10 2.6.27.21-170.2.56.fc10.x86_64
> ubuntu 2.6.28-11-generic
> fedora rawhide 2.6.29.1-70.fc11.x86_64
The misbehavior is reproducible on 2.6.9-78.0.17.ELsmp, too.
But on 2.4.9-e.62smp, (yep, 2.*4*) it is not a problem.
Plus I did some quick timings, using cp -r to copy a tree of 201
directories and 400,000 1-byte files (top dir, then 200 directories,
each containing 200 files). Dir and file names were all very short,
e.g.,
$ find z|head
z
z/63
z/63/63
z/63/54
z/63/166
z/63/12
z/63/94
z/63/186
z/63/147
z/63/61
I ran the tests on both an ext3 file system
and on a tmpfs file system on an idle x86_64 Fedora 10 system.
The timings suggest that the save-one-read-syscall optimization
results in no more than a 2% speed-up, in this pathological case.
In normal usage, I suspect that any speed-up would be immeasurably small.
So I have no qualms about removing the optimization.
If anyone can measure a significant regression, say on NFS,
please provide details. Here's the patch I'm considering.
I'll see about adding a test, too.
>From 4b2a62e3b46f50ed6035fdfb7c678ec38c70e35d Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Fri, 17 Apr 2009 18:44:18 +0200
Subject: [PATCH] copy.c: remove optimization that avoided up to 50% of read
syscalls
Do not assume that a short read on a regular file indicates EOF.
When reading from a file in /proc on linux [at least 2.6.9 - 2.6.29]
into a 4k-byte buffer or larger, a short read does not always indicate
EOF. For example, "cp /proc/slabinfo /tmp" copies only 4068 of the
total 7493 bytes. This optimization appears to have been worth less
than a 2% speed-up, so the impact of removing it is negligible.
* src/copy.c (copy_reg): Don't exit the loop early.
---
src/copy.c | 4 ----
1 files changed, 0 insertions(+), 4 deletions(-)
diff --git a/src/copy.c b/src/copy.c
index 9b0e139..3cbeba4 100644
--- a/src/copy.c
+++ b/src/copy.c
@@ -699,10 +699,6 @@ copy_reg (char const *src_name, char const *dst_name,
goto close_src_and_dst_desc;
}
last_write_made_hole = false;
-
- /* A short read on a regular file means EOF. */
- if (n_read != buf_size && S_ISREG (src_open_sb.st_mode))
- break;
}
}
--
1.6.3.rc0.200.g4086
- cp(1) fails to copy file from /proc, Jukka Salmi, 2009/04/16
- Re: cp(1) fails to copy file from /proc, Jim Meyering, 2009/04/16
- Re: cp(1) fails to copy file from /proc, Jim Meyering, 2009/04/16
- Re: cp(1) fails to copy file from /proc, James Youngman, 2009/04/17
- Re: cp(1) fails to copy file from /proc,
Jim Meyering <=
- Re: cp(1) fails to copy file from /proc, James Youngman, 2009/04/17
- Re: cp(1) fails to copy file from /proc, Mike Frysinger, 2009/04/18
- Re: cp(1) fails to copy file from /proc, Jim Meyering, 2009/04/18
- Re: cp(1) fails to copy file from /proc, Mike Frysinger, 2009/04/18
- Re: cp(1) fails to copy file from /proc, Jim Meyering, 2009/04/18
- Re: cp(1) fails to copy file from /proc, Andreas Schwab, 2009/04/19
- Re: cp(1) fails to copy file from /proc, Jim Meyering, 2009/04/19
- Re: cp(1) fails to copy file from /proc, James Youngman, 2009/04/19
- Re: cp(1) fails to copy file from /proc, Jim Meyering, 2009/04/23
- Re: cp(1) fails to copy file from /proc, Mike Frysinger, 2009/04/26