You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
io/lab/quiz: Mention copy_file_range syscall for cp
`coreutils` 9.0 reimplemented `cp` using the `copy_file_range()` syscall,
which performs zero-copy [1]. Therefore, the existing comparison between
`mmap_cp` and `cp` is no longer valid. This commit mentions the new
implementation and its effects on performance. This version of
`coreutils` is available by default on newer Ubuntu systems such as
23.04.
[1] https://lists.gnu.org/archive/html/info-gnu/2021-09/msg00010.html
Signed-off-by: Teodor Dutu <teodor.dutu@gmail.com>
@@ -37,12 +39,12 @@ Benchmarking mmap_cp on a 1 GB file...
37
39
38
40
real 0m27,803s
39
41
user 0m0,590s
40
-
sys0m2,114s
42
+
sys0m2,114s
41
43
Benchmarking cp on a 1 GB file...
42
44
43
45
real 0m35,607s
44
46
user 0m0,033s
45
-
sys0m2,564s
47
+
sys0m2,564s
46
48
```
47
49
48
50
So it seems that using `mmap()` rather than `read()` and `write()` yields about a 15% increase in performance.
@@ -51,3 +53,21 @@ This depends on your storage device (SSD vs HDD) and its specific speed (like it
51
53
So the more conservative answer is to say that this depends on external aspects and that, in general, the 2 implementations are more or less equivalent.
52
54
53
55
If you want to know why there isn't much of a difference between the 2 implementations, check out [this explanation](https://stackoverflow.com/a/27987994).
56
+
57
+
However, some newer Linux systems use an updated `cp` that doesn't use `read` and `write` anymore, but instead uses zero-copy, by means of the `copy_file_range()` syscall.
58
+
This implementation is likely going to be significantly faster than the one using `mmap`, as shown in the snippet below:
[This syscall](https://man7.org/linux/man-pages/man2/copy_file_range.2.html) copies files inside the kernel without having the data pass through the user space.
0 commit comments