Skip to content

Commit

Permalink
Fix bug #77930: Remove mmap limit
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nikic committed Oct 31, 2019
1 parent 0055f1e commit 333d607
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? ????, PHP 7.4.0RC6

- Standard:
. Fixed bug #77930 (stream_copy_to_stream should use mmap more often).
(Nikita)

31 Oct 2019, PHP 7.4.0RC5

Expand Down
6 changes: 0 additions & 6 deletions main/streams/mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ PHPAPI char *_php_stream_mmap_range(php_stream *stream, size_t offset, size_t le
range.mode = mode;
range.mapped = NULL;

/* For now, we impose an arbitrary limit to avoid
* runaway swapping when large files are passed through. */
if (length > 4 * 1024 * 1024) {
return NULL;
}

if (PHP_STREAM_OPTION_RETURN_OK == php_stream_set_option(stream, PHP_STREAM_OPTION_MMAP_API, PHP_STREAM_MMAP_MAP_RANGE, &range)) {
if (mapped_len) {
*mapped_len = range.length;
Expand Down

0 comments on commit 333d607

Please sign in to comment.