Improved icd build g++ memory article authored by Marcus Schilling's avatar Marcus Schilling
......@@ -740,7 +740,7 @@ Trying to send a msg, I get the following error message from CII:
My ICD definition looks like this
```
```xml
<enum name="PiezoInput">
<enumerator name="PIEZO_INPUT_SETMODE" />
<enumerator name="PIEZO_INPUT_MOVE" />
......@@ -788,7 +788,7 @@ My code looks like this
```
[...]
auto piezo = mal->createDataEntity<::fcfif::Piezo>();
auto piezo = mal->createDataEntity<::fcfif::Piezo>();
piezo->setId("foo");
auto input = piezo->getInput();
......@@ -1208,7 +1208,7 @@ For more information, see also: [KB: PYBIND errors \[ICD waf build\]](onenote:#K
**Problem**
Trying to build an ICD-module or MAL-application, the build takes a long time, and eventually fails with an error message like this:
Trying to build an ICD-module or MAL-application, the build takes a long time, and/or fails with an error message like this:
```
g++: fatal error: Killed signal terminated program cc1plus
......@@ -1216,7 +1216,8 @@ compilation terminated.
```
```
Software/CcsLibs/CcsTestData/python/bindings/src/ModCcstestdata.cpp:18:1: note: in expansion of macro ‘PYBIND11_MODULE’
Software/CcsLibs/CcsTestData/python/bindings/src/ModCcstestdata.cpp:18:1: note:
in expansion of macro ‘PYBIND11_MODULE’
PYBIND11_MODULE(ModCcstestdata, modccstestdata) {
^
g++: internal compiler error: Killed (program cc1plus)
......@@ -1227,17 +1228,18 @@ g++: internal compiler error: Killed (program cc1plus)
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
from wtools import module
# Disable OPCUA and DDS, since not part of this interface.
module.declare_malicd(mal_opts={'opcua_disabled': True, 'dds_disabled': True})
```
**Solution 2: Reduce build parallelity**
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:
In the module wscript:
~~~python
......@@ -1302,21 +1304,16 @@ def configure(cnf):
package.declare_package(recurse='m4lcsif m4amlcsif m4cslcsif m4kslcsif')
~~~
4 Refactor your ICD
**Solution 4: Refactor your ICD**
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**
2. Add temporary swap space to your host
```
# As root:
fallocate -l 8G /swapfile
......@@ -1330,9 +1327,9 @@ sudo cii-services stop elasticsearch
rm -f /swapfile
```
**Solution 7: Ask your system administrator to assign more RAM to your VM**
3. Add permanent memory to your VM
Assess the necessary amount by using the "Rule Of Thumb" above.
Increase your RAM, respectively ask your system administrator to do it. Assess the necessary amount by using the "Rule Of Thumb" above.
--------------------------------------------------------------------------
......
......