Skip to content

Commit 333d607

Browse files
committed
Fix bug #77930: Remove mmap limit
First, the limitation already doesn't trigger if you copy the whole file (i.e. use copy() or stream_copy_to_stream() and don't specify a length). This happens because length will be 0 at the time of the check and only later calculated based on the file size. This means that we're already completely blowing the length limit for what is likely the most common case, and it doesn't seem like anyone complained about that. Second, the premise of the code comment ("to avoid runaway swapping") seems incorrect to me. Because this performs a file-backed non-private mmap, no swap backing is needed for the mapping. Concerns over "memory usage" are also misplaced, as this is a virtual mapping.
1 parent 0055f1e commit 333d607

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 7.4.0RC6
44

5+
- Standard:
6+
. Fixed bug #77930 (stream_copy_to_stream should use mmap more often).
7+
(Nikita)
58

69
31 Oct 2019, PHP 7.4.0RC5
710

main/streams/mmap.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,6 @@ PHPAPI char *_php_stream_mmap_range(php_stream *stream, size_t offset, size_t le
2929
range.mode = mode;
3030
range.mapped = NULL;
3131

32-
/* For now, we impose an arbitrary limit to avoid
33-
* runaway swapping when large files are passed through. */
34-
if (length > 4 * 1024 * 1024) {
35-
return NULL;
36-
}
37-
3832
if (PHP_STREAM_OPTION_RETURN_OK == php_stream_set_option(stream, PHP_STREAM_OPTION_MMAP_API, PHP_STREAM_MMAP_MAP_RANGE, &range)) {
3933
if (mapped_len) {
4034
*mapped_len = range.length;

0 commit comments

Comments
 (0)