From 333d607d47ca6eec96637c1c8686591dec6f5a0b Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Wed, 30 Oct 2019 13:15:05 +0100 Subject: [PATCH] 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. --- NEWS | 3 +++ main/streams/mmap.c | 6 ------ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/NEWS b/NEWS index b63d82438c..a344936ce2 100644 --- a/NEWS +++ b/NEWS @@ -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 diff --git a/main/streams/mmap.c b/main/streams/mmap.c index 8f3fcf97a6..63bae87505 100644 --- a/main/streams/mmap.c +++ b/main/streams/mmap.c @@ -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; -- 2.40.0