diff --git a/src/basic/fileio.c b/src/basic/fileio.c index efed64cda0..e69b888315 100644 --- a/src/basic/fileio.c +++ b/src/basic/fileio.c @@ -433,6 +433,11 @@ int read_virtual_file(const char *filename, size_t max_size, char **ret_contents } n_retries--; + } else if (n_retries > 1) { + /* Files in /proc are generally smaller than the page size so let's start with a page size + * buffer from malloc and only use the max buffer on the final try. */ + size = MIN3(page_size() - 1, READ_VIRTUAL_BYTES_MAX, max_size); + n_retries = 1; } else { size = MIN(READ_VIRTUAL_BYTES_MAX, max_size); n_retries = 0;