The cpp compiler runs out of memory and crashes. You can see the effect by running htop in a separate terminal, all memory (including swap space) is consumed by the g++ compiler, which consequently crashes.
Memory needed for building a given ICD module: There is a base load that is the same for all ICD modules. On top of that,
the ICD file contents determine how much memory is needed to build the module.
_Memory needed for building a given ICD module_
There is a base load that is the same for all ICD modules. On top of that, the ICD file contents determine how much memory is needed to build the module.
_Rule of Thumb_
| MAL version | Base Load | Mem per ICD-Struct |
| --- | ---- | ---- |
| MAL 1.8 | 650 MB (2/3 GB) | 320 MB (1/3 GB) |
| MAL 1.x | 650 MB (2/3 GB) | 320 MB (1/3 GB) |
| MAL 2.0 | 650 MB (2/3 GB) | 110 MB (1/8 GB) |
So building an ICD with 20 structs under MAL 1.8 will require around 7 GB of available free memory for the gcc compiler.
Thus, if your biggest ICD contains 20 structs, building under MAL 1.x will require around 7 GB of available free memory.
_Measuring_
...
...
@@ -1253,37 +1255,37 @@ cpu 765%
pf 166
```
- If you see high page fault counts (`pf 1168635`), see next section.
-If the build process crashes, the time-command's output will not be fully reliable (it will show lower statistics than what they are in reality). See next section.
- If the build crashes, the time-command's output will not be fully reliable (the real memory need is higher than what the output shows).
-High page fault counts (`pf 1168635`) generally indicate you should reduce the module's footprint, see Solutions below.
More info is available at [ECII-109](https://jira.eso.org/browse/ECII-109)
**Solution 1: Remove unnecessary middlewares**
**Solution 1: Decrease the module's footprint**
Example module-wscipt:
1. Remove unnecessary middlewares
Use the `xyz_disabled` options:
```python
fromwtoolsimportmodule
# Disable OPCUA and DDS, since not part of this interface.
Reduce parallelity of build (default: all cores used).
2. Reduce build parallelism
Example: Build with only 4 cores
By default the build system uses all cores on the host. Less parallelism means less memory consumers during the build. This is controlled by the waf `-j` option.
To build with only 4 cores:
` $ time waf -j4 build `
and try different numbers of cores. Use the time-command output
to find an optimum between real, page faults, and cpu.
On a 12 core host with 16 GB RAM, a parallelism of 8 may be a good choice. Try different numbers of cores and use the output from the time-command (see above) to find an optimum between real, page faults, and cpu.
**Solution 3: Change compiler flags**
(_to be confirmed_)
3. Adjust the compiler flags
Pass custom compiler flags for your ICD-module
The default set of compiler flags applied by the build system consume significant memory.
We recommend using "-O2 -flto -pipe" (_to be confirmed_) instead. This is how you pass custom compiler flags for your ICD-module:
Reduce the memory need by splitting the big ICDs up into 2 or more smaller ICD modules.
If the above optimisations were not enough, you can further reduce the memory need by splitting the ICD up into 2 or more smaller ICD modules.
**Solution 2: Increase the available memory**
**Solution 5: Free available memory**
Find RAM consumers and stop them, at least temporarily. For example, ElasticSearch uses a significant amount of RAM.
```
sudo cii-services stop elasticsearch
```
1. Find RAM consumers and stop them, at least temporarily. For example, ElasticSearch uses a significant amount of RAM: `sudo cii-services stop elasticsearch`
**Solution 6: Add temporary swap space to your machine**