Prevent ninja starting new job when physical memory become low.#2605
Prevent ninja starting new job when physical memory become low.#2605Marc-Pierre-Barbier wants to merge 9 commits intoninja-build:masterfrom
Conversation
|
Marked as draft until I can test on macOS so I can use sysconf. |
8ad4204 to
267d85b
Compare
| if (config_.desired_free_ram > 0) { | ||
| long memory_capacity = GetFreeMemory() / config_.desired_free_ram; | ||
| if (memory_capacity < capacity) | ||
| capacity = memory_capacity; |
There was a problem hiding this comment.
just do an early return instead of redefining capacity
return memory_capacity;
There was a problem hiding this comment.
In this function, there is a check later on that does the following:
if (capacity == 0 && subprocs_.running_.empty())
// Ensure that we make progress.
capacity = 1;That's why there is no other usage of early returns in this function, as this mechanism prevent lockups even if we have to ignore our ram condition.
kevin-robb
left a comment
There was a problem hiding this comment.
Random person here, I've been using a build of this branch (built via ./configure.py --bootstrap) on Ubuntu 22 for a large CMake project, and this has worked wonderfully. Using --keep-free-memory 4G does the trick, making ninja usable and still faster than default Unix make. Thanks for implementing this! I'd love to see this get merged into the release version of ninja
|
This is a very useful feature. What further work needs to be done to get this merged? |
Inspired by #1571
this adds a new option: --keep-free-memory AMOUNT
and the amount can be specified with G/M/m/K/k/B units (defaulting to byte)
If the amount specified is greater than the available memory then we stop starting new build jobs.
Most importantly, this doesn't solve all memory issues you will need to swap if you don't put a great enough value, too big of a value will result in having very few core being used. This is purely here to stop the problem from getting worse and not fix it.