|
37 | 37 | use ReflectionClass;
|
38 | 38 | use RuntimeException;
|
39 | 39 | use Symfony\Component\Filesystem\Path;
|
| 40 | +use Throwable; |
40 | 41 |
|
41 | 42 | use function array_filter;
|
42 | 43 | use function array_key_exists;
|
|
51 | 52 | use function defined;
|
52 | 53 | use function extension_loaded;
|
53 | 54 | use function file_exists;
|
| 55 | +use function file_get_contents; |
54 | 56 | use function file_put_contents;
|
55 | 57 | use function function_exists;
|
56 | 58 | use function fwrite;
|
|
79 | 81 | use function str_starts_with;
|
80 | 82 | use function strlen;
|
81 | 83 | use function substr;
|
| 84 | +use function trim; |
82 | 85 | use function wordwrap;
|
83 | 86 |
|
84 | 87 | use const DIRECTORY_SEPARATOR;
|
@@ -985,6 +988,34 @@ private static function restart(array $options, int $threads, int $scanThreads,
|
985 | 988 | $progress->write('Exiting because JIT was requested but is not available.' . PHP_EOL . PHP_EOL);
|
986 | 989 | exit(1);
|
987 | 990 | }
|
| 991 | + |
| 992 | + $overcommit = null; |
| 993 | + try { |
| 994 | + $overcommit = trim(file_get_contents('/proc/sys/vm/overcommit_memory')); |
| 995 | + } catch (Throwable) { |
| 996 | + } |
| 997 | + |
| 998 | + if ($overcommit === '2') { |
| 999 | + $err = 'ERROR: VM overcommiting is disabled.' . PHP_EOL . PHP_EOL |
| 1000 | + . "TL;DR: to fix, run these two commands:" . PHP_EOL . PHP_EOL |
| 1001 | + . "echo 1 | sudo tee /proc/sys/vm/overcommit_memory" . PHP_EOL |
| 1002 | + . "echo vm.overcommit_memory=1 | sudo tee /etc/sysctl.d/40-psalm.conf # For persistence" . PHP_EOL |
| 1003 | + . PHP_EOL |
| 1004 | + . "Explanation: disabling VM overcommitting *WILL* cause failures when running Psalm " |
| 1005 | + . "in multithreaded mode during analysis," . PHP_EOL |
| 1006 | + . 'as Psalm relies very heavily on the copy-on-write semantics of fork(), which are currently disabled.' |
| 1007 | + . PHP_EOL . PHP_EOL . PHP_EOL |
| 1008 | + . "Please enable VM overcommitting to greatly speed up Psalm and avoid crashes in multithreaded mode." |
| 1009 | + . PHP_EOL . PHP_EOL . PHP_EOL |
| 1010 | + . "This warning may be ignored by setting the PSALM_IGNORE_NO_OVERCOMMIT=1 environment variable " |
| 1011 | + . "(not recommended)." |
| 1012 | + . PHP_EOL . PHP_EOL; |
| 1013 | + |
| 1014 | + fwrite(STDERR, $err); |
| 1015 | + if (getenv('PSALM_IGNORE_NO_OVERCOMMIT') !== '1') { |
| 1016 | + exit(1); |
| 1017 | + } |
| 1018 | + } |
988 | 1019 | }
|
989 | 1020 |
|
990 | 1021 | /** @psalm-suppress UnusedParam $argv is being reported as unused */
|
|
0 commit comments